Skip to main content

ruma_client_api/
profile.rs

1//! Endpoints for user profiles.
2
3#[cfg(feature = "unstable-msc4466")]
4use ruma_common::serde::StringEnum;
5#[cfg(feature = "client")]
6use ruma_common::{
7    api::{
8        MatrixVersion,
9        path_builder::{StablePathSelector, VersionHistory},
10    },
11    profile::ProfileFieldName,
12};
13
14#[cfg(feature = "unstable-msc4466")]
15use crate::PrivOwnedStr;
16
17pub mod delete_profile_field;
18pub mod get_avatar_url;
19pub mod get_display_name;
20pub mod get_profile;
21pub mod get_profile_field;
22#[cfg(feature = "client")]
23mod profile_field_serde;
24pub mod set_avatar_url;
25pub mod set_display_name;
26pub mod set_profile_field;
27mod static_profile_field;
28
29pub use self::static_profile_field::*;
30
31/// Endpoint version history valid only for profile fields that didn't exist before Matrix 1.16.
32#[cfg(feature = "client")]
33const EXTENDED_PROFILE_FIELD_HISTORY: VersionHistory = VersionHistory::new(
34    &[(
35        Some("uk.tcpip.msc4133"),
36        "/_matrix/client/unstable/uk.tcpip.msc4133/profile/{user_id}/{field}",
37    )],
38    &[(
39        StablePathSelector::Version(MatrixVersion::V1_16),
40        "/_matrix/client/v3/profile/{user_id}/{field}",
41    )],
42    None,
43    None,
44);
45
46/// Whether the given field name existed already before custom fields were officially supported in
47/// profiles.
48#[cfg(feature = "client")]
49fn field_existed_before_extended_profiles(field_name: &ProfileFieldName) -> bool {
50    matches!(field_name, ProfileFieldName::AvatarUrl | ProfileFieldName::DisplayName)
51}
52
53/// Controls which rooms the server should send an updated `m.room.member` event in
54/// when changing `displayname` or `avatar_url` in a user's profile. Defined by [MSC4466][1].
55///
56/// [1]: https://github.com/matrix-org/matrix-spec-proposals/pull/4466
57#[cfg(feature = "unstable-msc4466")]
58#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
59#[derive(Clone, Default, StringEnum)]
60#[ruma_enum(rename_all = "snake_case")]
61#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
62pub enum PropagateTo {
63    /// The server must send a `m.room.member` event in all of the user's
64    /// joined rooms.
65    #[default]
66    All,
67
68    /// The server must only send a `m.room.member` event in rooms where the profile
69    /// field being updated does _not_ differ from its value in the user's global profile data.
70    Unchanged,
71
72    /// The server must not send a `m.room.member` event to any rooms.
73    None,
74
75    #[doc(hidden)]
76    _Custom(PrivOwnedStr),
77}