Skip to main content

ruma_client_api/
profile.rs

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