Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Show whether the user is deactivated on the homeserver in the GraphQL…
Browse files Browse the repository at this point in the history
… API

Fix #2375
  • Loading branch information
sandhose committed Jul 16, 2024
1 parent e9a57a4 commit 6c0effd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crates/handlers/src/graphql/model/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The Matrix.org Foundation C.I.C.
// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,9 @@ pub struct MatrixUser {

/// The avatar URL of the user, if any.
avatar_url: Option<String>,

/// Whether the user is deactivated on the homeserver.
deactivated: bool,
}

impl MatrixUser {
Expand All @@ -40,6 +43,7 @@ impl MatrixUser {
mxid,
display_name: info.displayname,
avatar_url: info.avatar_url,
deactivated: info.deactivated,
})
}
}
1 change: 1 addition & 0 deletions crates/matrix-synapse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl HomeserverConnection for SynapseConnection {
Ok(MatrixUser {
displayname: body.display_name,
avatar_url: body.avatar_url,
deactivated: body.deactivated.unwrap_or(false),
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/matrix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub type BoxHomeserverConnection<Error = anyhow::Error> =
pub struct MatrixUser {
pub displayname: Option<String>,
pub avatar_url: Option<String>,
pub deactivated: bool,
}

#[derive(Debug, Default)]
Expand Down
10 changes: 9 additions & 1 deletion crates/matrix/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct MockUser {
devices: HashSet<String>,
emails: Option<Vec<String>>,
cross_signing_reset_allowed: bool,
deactivated: bool,
}

/// A mock implementation of a [`HomeserverConnection`], which never fails and
Expand Down Expand Up @@ -69,6 +70,7 @@ impl crate::HomeserverConnection for HomeserverConnection {
Ok(MatrixUser {
displayname: user.displayname.clone(),
avatar_url: user.avatar_url.clone(),
deactivated: user.deactivated,
})
}

Expand All @@ -82,6 +84,7 @@ impl crate::HomeserverConnection for HomeserverConnection {
devices: HashSet::new(),
emails: None,
cross_signing_reset_allowed: false,
deactivated: false,
});

anyhow::ensure!(
Expand Down Expand Up @@ -140,6 +143,7 @@ impl crate::HomeserverConnection for HomeserverConnection {
let user = users.get_mut(mxid).context("User not found")?;
user.devices.clear();
user.emails = None;
user.deactivated = true;
if erase {
user.avatar_url = None;
user.displayname = None;
Expand All @@ -148,7 +152,11 @@ impl crate::HomeserverConnection for HomeserverConnection {
Ok(())
}

async fn reactivate_user(&self, _mxid: &str) -> Result<(), Self::Error> {
async fn reactivate_user(&self, mxid: &str) -> Result<(), Self::Error> {
let mut users = self.users.write().await;
let user = users.get_mut(mxid).context("User not found")?;
user.deactivated = false;

Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ type MatrixUser {
The avatar URL of the user, if any.
"""
avatarUrl: String
"""
Whether the user is deactivated on the homeserver.
"""
deactivated: Boolean!
}

"""
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ export type MatrixUser = {
__typename?: 'MatrixUser';
/** The avatar URL of the user, if any. */
avatarUrl?: Maybe<Scalars['String']['output']>;
/** Whether the user is deactivated on the homeserver. */
deactivated: Scalars['Boolean']['output'];
/** The display name of the user, if any. */
displayName?: Maybe<Scalars['String']['output']>;
/** The Matrix ID of the user. */
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/gql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,17 @@ export default {
},
"args": []
},
{
"name": "deactivated",
"type": {
"kind": "NON_NULL",
"ofType": {
"kind": "SCALAR",
"name": "Any"
}
},
"args": []
},
{
"name": "displayName",
"type": {
Expand Down

0 comments on commit 6c0effd

Please sign in to comment.