Use ruma-api-macros for the presence endpoints.

This commit is contained in:
Jimmy Cuadra 2017-07-04 16:39:30 -07:00
parent ebb05dc076
commit c447a612d3
2 changed files with 86 additions and 201 deletions

View File

@ -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;

View File

@ -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.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub status_msg: Option<String>,
pub presence: PresenceState
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Put
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The new presence state.
"/_matrix/client/r0/presence/{}/status", pub presence: PresenceState,
params.user_id /// The status message to attach to this state.
) #[serde(skip_serializing_if = "Option::is_none")]
pub status_msg: Option<String>,
/// The user whose presence state will be updated.
#[ruma_api(path)]
pub user_id: UserId,
} }
fn router_path() -> &'static str { response {}
"/_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.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
#[serde(skip_serializing_if = "Option::is_none")]
pub status_msg: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currently_active: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_active_ago: Option<u64>,
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 { request {
format!( /// The user whose presence state will be retrieved.
"/_matrix/client/r0/presence/{}/status", #[ruma_api(path)]
params.user_id pub user_id: UserId,
)
} }
fn router_path() -> &'static str { response {
"/_matrix/client/r0/presence/:user_id/status" /// The state message for this user if one was set.
} #[serde(skip_serializing_if = "Option::is_none")]
pub status_msg: Option<String>,
fn name() -> &'static str { /// Whether or not the user is currently active.
"get_presence" #[serde(skip_serializing_if = "Option::is_none")]
} pub currently_active: Option<bool>,
/// The length of time in milliseconds since an action was performed by the user.
fn description() -> &'static str { #[serde(skip_serializing_if = "Option::is_none")]
"Get presence status for this user." pub last_active_ago: Option<u64>,
} /// The user's presence state.
pub presence: PresenceState,
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.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BodyParams {
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
drop: Vec<UserId>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
invite: Vec<UserId>
}
impl ::Endpoint for Endpoint {
type BodyParams = BodyParams;
type PathParams = PathParams;
type QueryParams = ();
type Response = ();
fn method() -> ::Method {
::Method::Post
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// A list of user IDs to remove from the list.
"/_matrix/client/r0/presence/list/{}", #[serde(skip_serializing_if = "Vec::is_empty")]
params.user_id #[serde(default)]
) pub drop: Vec<UserId>,
/// A list of user IDs to add to the list.
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub invite: Vec<UserId>,
/// The user whose presence state will be updated.
#[ruma_api(path)]
pub user_id: UserId,
} }
fn router_path() -> &'static str { response {}
"/_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 {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = ();
type Response = Vec<PresenceEvent>;
fn method() -> ::Method {
::Method::Get
} }
fn request_path(params: Self::PathParams) -> String { request {
format!( /// The user whose presence state will be retrieved.
"/_matrix/client/r0/presence/list/{}", #[ruma_api(path)]
params.user_id pub user_id: UserId,
)
} }
fn router_path() -> &'static str { response {
"/_matrix/client/r0/presence/list/:user_id" /// A list of presence events for every user on this list.
} #[ruma_api(body)]
presence_events: Vec<PresenceEvent>,
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
} }
} }
} }