diff --git a/ruma-client-api/src/r0/presence/get_presence.rs b/ruma-client-api/src/r0/presence/get_presence.rs index 880b077b..4bb40db2 100644 --- a/ruma-client-api/src/r0/presence/get_presence.rs +++ b/ruma-client-api/src/r0/presence/get_presence.rs @@ -16,12 +16,14 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The user whose presence state will be retrieved. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The state message for this user if one was set. #[serde(skip_serializing_if = "Option::is_none")] @@ -45,3 +47,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user ID. + pub fn new(user_id: &'a UserId) -> Self { + Self { user_id } + } +} + +impl Response { + /// Creates a new `Response` with the given presence state. + pub fn new(presence: PresenceState) -> Self { + Self { presence, status_msg: None, currently_active: None, last_active_ago: None } + } +} diff --git a/ruma-client-api/src/r0/presence/set_presence.rs b/ruma-client-api/src/r0/presence/set_presence.rs index 854a5fac..f2dff6fe 100644 --- a/ruma-client-api/src/r0/presence/set_presence.rs +++ b/ruma-client-api/src/r0/presence/set_presence.rs @@ -14,20 +14,37 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The user whose presence state will be updated. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, /// The new presence state. pub presence: PresenceState, /// The status message to attach to this state. #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option, + pub status_msg: Option<&'a str>, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user ID and presence state. + pub fn new(user_id: &'a UserId, presence: PresenceState) -> Self { + Self { user_id, presence, status_msg: None } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +}