mas_handlers/graphql/model/
matrix.rs

1// Copyright 2024 New Vector Ltd.
2// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE in the repository root for full details.
6
7use async_graphql::SimpleObject;
8use mas_matrix::HomeserverConnection;
9
10#[derive(SimpleObject)]
11pub struct MatrixUser {
12    /// The Matrix ID of the user.
13    mxid: String,
14
15    /// The display name of the user, if any.
16    display_name: Option<String>,
17
18    /// The avatar URL of the user, if any.
19    avatar_url: Option<String>,
20
21    /// Whether the user is deactivated on the homeserver.
22    deactivated: bool,
23}
24
25impl MatrixUser {
26    pub(crate) async fn load<C: HomeserverConnection + ?Sized>(
27        conn: &C,
28        user: &str,
29    ) -> Result<MatrixUser, anyhow::Error> {
30        let mxid = conn.mxid(user);
31
32        let info = conn.query_user(&mxid).await?;
33
34        Ok(MatrixUser {
35            mxid,
36            display_name: info.displayname,
37            avatar_url: info.avatar_url,
38            deactivated: info.deactivated,
39        })
40    }
41}