Use ruma-api-macros for the presence endpoints.
This commit is contained in:
parent
ebb05dc076
commit
c447a612d3
@ -30,7 +30,7 @@ pub mod r0 {
|
|||||||
pub mod filter;
|
pub mod filter;
|
||||||
pub mod media;
|
pub mod media;
|
||||||
pub mod membership;
|
pub mod membership;
|
||||||
// pub mod presence;
|
pub mod presence;
|
||||||
// pub mod profile;
|
// pub mod profile;
|
||||||
// pub mod push;
|
// pub mod push;
|
||||||
// pub mod receipt;
|
// pub mod receipt;
|
||||||
|
@ -2,247 +2,132 @@
|
|||||||
|
|
||||||
/// [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status)
|
/// [PUT /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-presence-userid-status)
|
||||||
pub mod set_presence {
|
pub mod set_presence {
|
||||||
|
use ruma_api_macros::ruma_api;
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
use ruma_events::presence::PresenceState;
|
use ruma_events::presence::PresenceState;
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
ruma_api! {
|
||||||
#[derive(Clone, Copy, Debug)]
|
metadata {
|
||||||
pub struct Endpoint;
|
description: "Set presence status for this user.",
|
||||||
|
method: Method::Put,
|
||||||
/// This API endpoint's path parameters.
|
name: "set_presence",
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
path: "/_matrix/client/r0/presence/:user_id/status",
|
||||||
pub struct PathParams {
|
rate_limited: true,
|
||||||
pub user_id: UserId
|
requires_authentication: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This API endpoint's body parameters.
|
request {
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
/// The new presence state.
|
||||||
pub struct BodyParams {
|
pub presence: PresenceState,
|
||||||
|
/// The status message to attach to this state.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub status_msg: Option<String>,
|
pub status_msg: Option<String>,
|
||||||
pub presence: PresenceState
|
/// The user whose presence state will be updated.
|
||||||
|
#[ruma_api(path)]
|
||||||
|
pub user_id: UserId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
response {}
|
||||||
type BodyParams = BodyParams;
|
|
||||||
type PathParams = PathParams;
|
|
||||||
type QueryParams = ();
|
|
||||||
type Response = ();
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Put
|
|
||||||
}
|
|
||||||
|
|
||||||
fn request_path(params: Self::PathParams) -> String {
|
|
||||||
format!(
|
|
||||||
"/_matrix/client/r0/presence/{}/status",
|
|
||||||
params.user_id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
|
||||||
"/_matrix/client/r0/presence/:user_id/status"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"set_presence"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Set presence status for this user."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status)
|
/// [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-userid-status)
|
||||||
pub mod get_presence {
|
pub mod get_presence {
|
||||||
use ruma_identifiers::UserId;
|
use ruma_api_macros::ruma_api;
|
||||||
use ruma_events::presence::PresenceState;
|
use ruma_events::presence::PresenceState;
|
||||||
|
use ruma_identifiers::UserId;
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
ruma_api! {
|
||||||
#[derive(Clone, Copy, Debug)]
|
metadata {
|
||||||
pub struct Endpoint;
|
description: "Get presence status for this user.",
|
||||||
|
method: Method::Get,
|
||||||
/// This API endpoint's path parameters.
|
name: "get_presence",
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
path: "/_matrix/client/r0/presence/:user_id/status",
|
||||||
pub struct PathParams {
|
rate_limited: false,
|
||||||
pub user_id: UserId
|
requires_authentication: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This API endpoint's response.
|
request {
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
/// The user whose presence state will be retrieved.
|
||||||
pub struct Response {
|
#[ruma_api(path)]
|
||||||
|
pub user_id: UserId,
|
||||||
|
}
|
||||||
|
|
||||||
|
response {
|
||||||
|
/// The state message for this user if one was set.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub status_msg: Option<String>,
|
pub status_msg: Option<String>,
|
||||||
|
/// Whether or not the user is currently active.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub currently_active: Option<bool>,
|
pub currently_active: Option<bool>,
|
||||||
|
/// The length of time in milliseconds since an action was performed by the user.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub last_active_ago: Option<u64>,
|
pub last_active_ago: Option<u64>,
|
||||||
pub presence: PresenceState
|
/// The user's presence state.
|
||||||
}
|
pub presence: PresenceState,
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
|
||||||
type BodyParams = ();
|
|
||||||
type PathParams = PathParams;
|
|
||||||
type QueryParams = ();
|
|
||||||
type Response = Response;
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Get
|
|
||||||
}
|
|
||||||
|
|
||||||
fn request_path(params: Self::PathParams) -> String {
|
|
||||||
format!(
|
|
||||||
"/_matrix/client/r0/presence/{}/status",
|
|
||||||
params.user_id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
|
||||||
"/_matrix/client/r0/presence/:user_id/status"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"get_presence"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Get presence status for this user."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid)
|
/// [POST /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-presence-list-userid)
|
||||||
pub mod update_presence_subscriptions {
|
pub mod update_presence_subscriptions {
|
||||||
|
use ruma_api_macros::ruma_api;
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
ruma_api! {
|
||||||
#[derive(Clone, Copy, Debug)]
|
metadata {
|
||||||
pub struct Endpoint;
|
description: "Update the presence subscriptions of the user.",
|
||||||
|
method: Method::Post,
|
||||||
/// This API endpoint's path parameters.
|
name: "update_presence_subscriptions",
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
path: "/_matrix/client/r0/presence/list/:user_id",
|
||||||
pub struct PathParams {
|
rate_limited: true,
|
||||||
pub user_id: UserId
|
requires_authentication: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This API endpoint's body parameters.
|
request {
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
/// A list of user IDs to remove from the list.
|
||||||
pub struct BodyParams {
|
|
||||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
drop: Vec<UserId>,
|
pub drop: Vec<UserId>,
|
||||||
|
/// A list of user IDs to add to the list.
|
||||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
invite: Vec<UserId>
|
pub invite: Vec<UserId>,
|
||||||
|
/// The user whose presence state will be updated.
|
||||||
|
#[ruma_api(path)]
|
||||||
|
pub user_id: UserId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
response {}
|
||||||
type BodyParams = BodyParams;
|
|
||||||
type PathParams = PathParams;
|
|
||||||
type QueryParams = ();
|
|
||||||
type Response = ();
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Post
|
|
||||||
}
|
|
||||||
|
|
||||||
fn request_path(params: Self::PathParams) -> String {
|
|
||||||
format!(
|
|
||||||
"/_matrix/client/r0/presence/list/{}",
|
|
||||||
params.user_id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
|
||||||
"/_matrix/client/r0/presence/list/:user_id"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"update_presence_subscriptions"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Update the presence subscriptions of the user."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid)
|
/// [GET /_matrix/client/r0/presence/list/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-presence-list-userid)
|
||||||
pub mod get_subscribed_presences {
|
pub mod get_subscribed_presences {
|
||||||
use ruma_identifiers::UserId;
|
use ruma_api_macros::ruma_api;
|
||||||
use ruma_events::presence::PresenceEvent;
|
use ruma_events::presence::PresenceEvent;
|
||||||
|
use ruma_identifiers::UserId;
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
ruma_api! {
|
||||||
#[derive(Clone, Copy, Debug)]
|
metadata {
|
||||||
pub struct Endpoint;
|
description: "Get the precence status from the user's subscriptions.",
|
||||||
|
method: Method::Get,
|
||||||
/// This API endpoint's path parameters.
|
name: "get_subscribed_presences",
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
path: "/_matrix/client/r0/presence/list/:user_id",
|
||||||
pub struct PathParams {
|
rate_limited: false,
|
||||||
pub user_id: UserId
|
requires_authentication: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
request {
|
||||||
type BodyParams = ();
|
/// The user whose presence state will be retrieved.
|
||||||
type PathParams = PathParams;
|
#[ruma_api(path)]
|
||||||
type QueryParams = ();
|
pub user_id: UserId,
|
||||||
type Response = Vec<PresenceEvent>;
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Get
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(params: Self::PathParams) -> String {
|
response {
|
||||||
format!(
|
/// A list of presence events for every user on this list.
|
||||||
"/_matrix/client/r0/presence/list/{}",
|
#[ruma_api(body)]
|
||||||
params.user_id
|
presence_events: Vec<PresenceEvent>,
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
|
||||||
"/_matrix/client/r0/presence/list/:user_id"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"get_subscribed_presences"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Get the precence status from the user's subscriptions."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
// TODO: not sure why this does not require authentication
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user