From 6c0effdcbbe70f9adb5caa37cae0e665865f5d4e Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Fri, 12 Jul 2024 14:55:24 +0200 Subject: [PATCH] Show whether the user is deactivated on the homeserver in the GraphQL API Fix #2375 --- crates/handlers/src/graphql/model/matrix.rs | 6 +++++- crates/matrix-synapse/src/lib.rs | 1 + crates/matrix/src/lib.rs | 1 + crates/matrix/src/mock.rs | 10 +++++++++- frontend/schema.graphql | 4 ++++ frontend/src/gql/graphql.ts | 2 ++ frontend/src/gql/schema.ts | 11 +++++++++++ 7 files changed, 33 insertions(+), 2 deletions(-) diff --git a/crates/handlers/src/graphql/model/matrix.rs b/crates/handlers/src/graphql/model/matrix.rs index 0903439aa..2efb7f95e 100644 --- a/crates/handlers/src/graphql/model/matrix.rs +++ b/crates/handlers/src/graphql/model/matrix.rs @@ -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. @@ -25,6 +25,9 @@ pub struct MatrixUser { /// The avatar URL of the user, if any. avatar_url: Option, + + /// Whether the user is deactivated on the homeserver. + deactivated: bool, } impl MatrixUser { @@ -40,6 +43,7 @@ impl MatrixUser { mxid, display_name: info.displayname, avatar_url: info.avatar_url, + deactivated: info.deactivated, }) } } diff --git a/crates/matrix-synapse/src/lib.rs b/crates/matrix-synapse/src/lib.rs index 626e6a384..ecc01e2b7 100644 --- a/crates/matrix-synapse/src/lib.rs +++ b/crates/matrix-synapse/src/lib.rs @@ -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), }) } diff --git a/crates/matrix/src/lib.rs b/crates/matrix/src/lib.rs index 7ae7538be..779c263f6 100644 --- a/crates/matrix/src/lib.rs +++ b/crates/matrix/src/lib.rs @@ -26,6 +26,7 @@ pub type BoxHomeserverConnection = pub struct MatrixUser { pub displayname: Option, pub avatar_url: Option, + pub deactivated: bool, } #[derive(Debug, Default)] diff --git a/crates/matrix/src/mock.rs b/crates/matrix/src/mock.rs index c895c722b..d834dec01 100644 --- a/crates/matrix/src/mock.rs +++ b/crates/matrix/src/mock.rs @@ -27,6 +27,7 @@ struct MockUser { devices: HashSet, emails: Option>, cross_signing_reset_allowed: bool, + deactivated: bool, } /// A mock implementation of a [`HomeserverConnection`], which never fails and @@ -69,6 +70,7 @@ impl crate::HomeserverConnection for HomeserverConnection { Ok(MatrixUser { displayname: user.displayname.clone(), avatar_url: user.avatar_url.clone(), + deactivated: user.deactivated, }) } @@ -82,6 +84,7 @@ impl crate::HomeserverConnection for HomeserverConnection { devices: HashSet::new(), emails: None, cross_signing_reset_allowed: false, + deactivated: false, }); anyhow::ensure!( @@ -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; @@ -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(()) } diff --git a/frontend/schema.graphql b/frontend/schema.graphql index d7aaf6749..6e007a8d2 100644 --- a/frontend/schema.graphql +++ b/frontend/schema.graphql @@ -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! } """ diff --git a/frontend/src/gql/graphql.ts b/frontend/src/gql/graphql.ts index 35c3adb58..f544593cb 100644 --- a/frontend/src/gql/graphql.ts +++ b/frontend/src/gql/graphql.ts @@ -449,6 +449,8 @@ export type MatrixUser = { __typename?: 'MatrixUser'; /** The avatar URL of the user, if any. */ avatarUrl?: Maybe; + /** Whether the user is deactivated on the homeserver. */ + deactivated: Scalars['Boolean']['output']; /** The display name of the user, if any. */ displayName?: Maybe; /** The Matrix ID of the user. */ diff --git a/frontend/src/gql/schema.ts b/frontend/src/gql/schema.ts index 298645ee8..1971ae5cb 100644 --- a/frontend/src/gql/schema.ts +++ b/frontend/src/gql/schema.ts @@ -1120,6 +1120,17 @@ export default { }, "args": [] }, + { + "name": "deactivated", + "type": { + "kind": "NON_NULL", + "ofType": { + "kind": "SCALAR", + "name": "Any" + } + }, + "args": [] + }, { "name": "displayName", "type": {