From 12a2e9342bdd664f795a7e2b7d9ed5c63d78a5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Thu, 5 Sep 2024 11:46:33 +0200 Subject: [PATCH] client-api: Add m.get_login_token capability According to a clarification in the spec. --- crates/ruma-client-api/CHANGELOG.md | 2 ++ .../src/discovery/get_capabilities.rs | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index dc11b822..580b1a3e 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -34,6 +34,8 @@ Improvements: - Change types of `SyncRequestListFilters::{room_types,not_room_types}` to `Vec` instead of a vector of strings - This is a breaking change, but only for users of `unstable-msc3575` +- Add the `get_login_token` field to `Capabilities`, according to a + clarification in the spec. Bug fixes: diff --git a/crates/ruma-client-api/src/discovery/get_capabilities.rs b/crates/ruma-client-api/src/discovery/get_capabilities.rs index fc4427ee..a407c7bc 100644 --- a/crates/ruma-client-api/src/discovery/get_capabilities.rs +++ b/crates/ruma-client-api/src/discovery/get_capabilities.rs @@ -63,6 +63,15 @@ pub struct Capabilities { )] pub thirdparty_id_changes: ThirdPartyIdChangesCapability, + /// Capability to indicate if the user can generate tokens to log further clients into their + /// account. + #[serde( + rename = "m.get_login_token", + default, + skip_serializing_if = "GetLoginTokenCapability::is_default" + )] + pub get_login_token: GetLoginTokenCapability, + /// Any other custom capabilities that the server supports outside of the specification, /// labeled using the Java package naming convention and stored as arbitrary JSON values. #[serde(flatten)] @@ -292,6 +301,26 @@ impl Default for ThirdPartyIdChangesCapability { } } +/// Information about the `m.get_login_token` capability. +#[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] +pub struct GetLoginTokenCapability { + /// Whether the user can request a login token. + pub enabled: bool, +} + +impl GetLoginTokenCapability { + /// Creates a new `GetLoginTokenCapability` with the given enabled flag. + pub fn new(enabled: bool) -> Self { + Self { enabled } + } + + /// Returns whether all fields have their default value. + pub fn is_default(&self) -> bool { + !self.enabled + } +} + #[cfg(test)] mod tests { use std::borrow::Cow;