diff --git a/crates/ruma-federation-api/src/authorization/get_event_authorization.rs b/crates/ruma-federation-api/src/authorization/get_event_authorization.rs index 7e202632..34c2babe 100644 --- a/crates/ruma-federation-api/src/authorization/get_event_authorization.rs +++ b/crates/ruma-federation-api/src/authorization/get_event_authorization.rs @@ -1,3 +1,55 @@ +//! `GET /_matrix/federation/*/event_auth/{roomId}/{eventId}` +//! //! Endpoint to retrieve the complete auth chain for a given event. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1event_authroomideventid + + use ruma_api::ruma_api; + use ruma_identifiers::{EventId, RoomId}; + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Retrieves the complete auth chain for a given event.", + name: "get_event_authorization", + method: GET, + stable_path: "/_matrix/federation/v1/event_auth/:room_id/:event_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The room ID to get the auth chain for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The event ID to get the auth chain for. + #[ruma_api(path)] + pub event_id: &'a EventId, + } + + response: { + /// The full set of authorization events that make up the state of the room, + /// and their authorization events, recursively. + pub auth_chain: Vec>, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given room id and event id. + pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self { + Self { room_id, event_id } + } + } + + impl Response { + /// Creates a new `Response` with the given auth chain. + pub fn new(auth_chain: Vec>) -> Self { + Self { auth_chain } + } + } +} diff --git a/crates/ruma-federation-api/src/authorization/get_event_authorization/v1.rs b/crates/ruma-federation-api/src/authorization/get_event_authorization/v1.rs deleted file mode 100644 index ec15c867..00000000 --- a/crates/ruma-federation-api/src/authorization/get_event_authorization/v1.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! [GET /_matrix/federation/v1/event_auth/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-event-auth-roomid-eventid) - -use ruma_api::ruma_api; -use ruma_identifiers::{EventId, RoomId}; -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Retrieves the complete auth chain for a given event.", - name: "get_event_authorization", - method: GET, - stable_path: "/_matrix/federation/v1/event_auth/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The room ID to get the auth chain for. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// The event ID to get the auth chain for. - #[ruma_api(path)] - pub event_id: &'a EventId, - } - - response: { - /// The full set of authorization events that make up the state of the room, - /// and their authorization events, recursively. - pub auth_chain: Vec>, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given room id and event id. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self { - Self { room_id, event_id } - } -} - -impl Response { - /// Creates a new `Response` with the given auth chain. - pub fn new(auth_chain: Vec>) -> Self { - Self { auth_chain } - } -} diff --git a/crates/ruma-federation-api/src/backfill/get_backfill.rs b/crates/ruma-federation-api/src/backfill/get_backfill.rs index 540d0c19..a2d96c77 100644 --- a/crates/ruma-federation-api/src/backfill/get_backfill.rs +++ b/crates/ruma-federation-api/src/backfill/get_backfill.rs @@ -1,3 +1,77 @@ +//! `GET /_matrix/federation/*/backfill/{roomId}` +//! //! Endpoint to request more history from another homeserver. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1backfillroomid + + use js_int::UInt; + use ruma_api::ruma_api; + use ruma_common::MilliSecondsSinceUnixEpoch; + use ruma_identifiers::{EventId, RoomId, ServerName}; + + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Request more history from another homeserver", + name: "get_backfill", + method: GET, + stable_path: "/_matrix/federation/v1/backfill/:room_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The room ID to backfill. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The event IDs to backfill from. + #[ruma_api(query)] + pub v: &'a [Box], + + /// The maximum number of PDUs to retrieve, including the given events. + #[ruma_api(query)] + pub limit: UInt, + } + + response: { + /// The `server_name` of the homeserver sending this transaction. + pub origin: Box, + + /// POSIX timestamp in milliseconds on originating homeserver when this transaction started. + pub origin_server_ts: MilliSecondsSinceUnixEpoch, + + /// List of persistent updates to rooms. + pub pdus: Vec>, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with: + /// * the given room id. + /// * the event IDs to backfill from. + /// * the maximum number of PDUs to retrieve, including the given events. + pub fn new(room_id: &'a RoomId, v: &'a [Box], limit: UInt) -> Self { + Self { room_id, v, limit } + } + } + + impl Response { + /// Creates a new `Response` with: + /// * the `server_name` of the homeserver. + /// * the timestamp in milliseconds of when this transaction started. + /// * the list of persistent updates to rooms. + pub fn new( + origin: Box, + origin_server_ts: MilliSecondsSinceUnixEpoch, + pdus: Vec>, + ) -> Self { + Self { origin, origin_server_ts, pdus } + } + } +} diff --git a/crates/ruma-federation-api/src/backfill/get_backfill/v1.rs b/crates/ruma-federation-api/src/backfill/get_backfill/v1.rs deleted file mode 100644 index 7647e58f..00000000 --- a/crates/ruma-federation-api/src/backfill/get_backfill/v1.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! [GET /_matrix/federation/v1/backfill/{roomId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-backfill-roomid) - -use js_int::UInt; -use ruma_api::ruma_api; -use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_identifiers::{EventId, RoomId, ServerName}; - -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Request more history from another homeserver", - name: "get_backfill", - method: GET, - stable_path: "/_matrix/federation/v1/backfill/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The room ID to backfill. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// The event IDs to backfill from. - #[ruma_api(query)] - pub v: &'a [Box], - - /// The maximum number of PDUs to retrieve, including the given events. - #[ruma_api(query)] - pub limit: UInt, - } - - response: { - /// The `server_name` of the homeserver sending this transaction. - pub origin: Box, - - /// POSIX timestamp in milliseconds on originating homeserver when this transaction started. - pub origin_server_ts: MilliSecondsSinceUnixEpoch, - - /// List of persistent updates to rooms. - pub pdus: Vec>, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with: - /// * the given room id. - /// * the event IDs to backfill from. - /// * the maximum number of PDUs to retrieve, including the given events. - pub fn new(room_id: &'a RoomId, v: &'a [Box], limit: UInt) -> Self { - Self { room_id, v, limit } - } -} - -impl Response { - /// Creates a new `Response` with: - /// * the `server_name` of the homeserver. - /// * the timestamp in milliseconds of when this transaction started. - /// * the list of persistent updates to rooms. - pub fn new( - origin: Box, - origin_server_ts: MilliSecondsSinceUnixEpoch, - pdus: Vec>, - ) -> Self { - Self { origin, origin_server_ts, pdus } - } -} diff --git a/crates/ruma-federation-api/src/device/get_devices.rs b/crates/ruma-federation-api/src/device/get_devices.rs index aa6513af..df7a44bd 100644 --- a/crates/ruma-federation-api/src/device/get_devices.rs +++ b/crates/ruma-federation-api/src/device/get_devices.rs @@ -1,3 +1,88 @@ +//! `GET /_matrix/federation/*/user/devices/{userId}` +//! //! Endpoint to get information about a user's devices -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1userdevicesuserid + + use js_int::UInt; + use ruma_api::ruma_api; + use ruma_common::encryption::DeviceKeys; + use ruma_identifiers::{DeviceId, UserId}; + use ruma_serde::Raw; + use serde::{Deserialize, Serialize}; + + ruma_api! { + metadata: { + description: "Gets information on all of the user's devices.", + name: "get_devices", + method: GET, + stable_path: "/_matrix/federation/v1/user/devices/:user_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The user ID to retrieve devices for. + /// + /// Must be a user local to the receiving homeserver. + #[ruma_api(path)] + pub user_id: &'a UserId, + } + + response: { + /// The user ID devices were requested for. + pub user_id: Box, + + /// A unique ID for a given user_id which describes the version of the returned device list. + /// + /// This is matched with the `stream_id` field in `m.device_list_update` EDUs in order to + /// incrementally update the returned device_list. + pub stream_id: UInt, + + /// The user's devices. + pub devices: Vec, + } + } + + 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 user id and stream id. + /// + /// The device list will be empty. + pub fn new(user_id: Box, stream_id: UInt) -> Self { + Self { user_id, stream_id, devices: Vec::new() } + } + } + + /// Information about a user's device. + #[derive(Clone, Debug, Serialize, Deserialize)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] + pub struct UserDevice { + /// The device ID. + pub device_id: Box, + + /// Identity keys for the device. + pub keys: Raw, + + /// Optional display name for the device + #[serde(skip_serializing_if = "Option::is_none")] + pub device_display_name: Option, + } + + impl UserDevice { + /// Creates a new `UserDevice` with the given device id and keys. + pub fn new(device_id: Box, keys: Raw) -> Self { + Self { device_id, keys, device_display_name: None } + } + } +} diff --git a/crates/ruma-federation-api/src/device/get_devices/v1.rs b/crates/ruma-federation-api/src/device/get_devices/v1.rs deleted file mode 100644 index 63c369d8..00000000 --- a/crates/ruma-federation-api/src/device/get_devices/v1.rs +++ /dev/null @@ -1,80 +0,0 @@ -//! [GET /_matrix/federation/v1/user/devices/{userId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-user-devices-userid) - -use js_int::UInt; -use ruma_api::ruma_api; -use ruma_common::encryption::DeviceKeys; -use ruma_identifiers::{DeviceId, UserId}; -use ruma_serde::Raw; -use serde::{Deserialize, Serialize}; - -ruma_api! { - metadata: { - description: "Gets information on all of the user's devices.", - name: "get_devices", - method: GET, - stable_path: "/_matrix/federation/v1/user/devices/:user_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The user ID to retrieve devices for. - /// - /// Must be a user local to the receiving homeserver. - #[ruma_api(path)] - pub user_id: &'a UserId, - } - - response: { - /// The user ID devices were requested for. - pub user_id: Box, - - /// A unique ID for a given user_id which describes the version of the returned device list. - /// - /// This is matched with the `stream_id` field in `m.device_list_update` EDUs in order to - /// incrementally update the returned device_list. - pub stream_id: UInt, - - /// The user's devices. - pub devices: Vec, - } -} - -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 user id and stream id. - /// - /// The device list will be empty. - pub fn new(user_id: Box, stream_id: UInt) -> Self { - Self { user_id, stream_id, devices: Vec::new() } - } -} - -/// Information about a user's device. -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct UserDevice { - /// The device ID. - pub device_id: Box, - - /// Identity keys for the device. - pub keys: Raw, - - /// Optional display name for the device - #[serde(skip_serializing_if = "Option::is_none")] - pub device_display_name: Option, -} - -impl UserDevice { - /// Creates a new `UserDevice` with the given device id and keys. - pub fn new(device_id: Box, keys: Raw) -> Self { - Self { device_id, keys, device_display_name: None } - } -} diff --git a/crates/ruma-federation-api/src/directory/get_public_rooms.rs b/crates/ruma-federation-api/src/directory/get_public_rooms.rs index eb9b0dab..72c9061c 100644 --- a/crates/ruma-federation-api/src/directory/get_public_rooms.rs +++ b/crates/ruma-federation-api/src/directory/get_public_rooms.rs @@ -1,3 +1,74 @@ +//! `GET /_matrix/federation/*/publicRooms` +//! //! Endpoint to query a homeserver's public rooms. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#post_matrixfederationv1publicrooms + + use js_int::UInt; + use ruma_api::ruma_api; + use ruma_common::directory::{IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}; + + ruma_api! { + metadata: { + description: "Gets all the public rooms for the homeserver.", + method: GET, + name: "get_public_rooms", + stable_path: "/_matrix/federation/v1/publicRooms", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + #[derive(Default)] + request: { + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub limit: Option, + + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub since: Option<&'a str>, + + /// Network to fetch the public room lists from. + #[serde(flatten, skip_serializing_if = "ruma_serde::is_default")] + #[ruma_api(query)] + pub room_network: RoomNetwork<'a>, + } + + #[derive(Default)] + response: { + /// A paginated chunk of public rooms. + pub chunk: Vec, + + /// A pagination token for the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, + + /// A pagination token that allows fetching previous results. + #[serde(skip_serializing_if = "Option::is_none")] + pub prev_batch: Option, + + /// An estimate on the total number of public rooms, if the server has an estimate. + pub total_room_count_estimate: Option, + } + } + + impl Request<'_> { + /// Creates an empty `Request`. + pub fn new() -> Self { + Default::default() + } + } + + impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Default::default() + } + } +} diff --git a/crates/ruma-federation-api/src/directory/get_public_rooms/v1.rs b/crates/ruma-federation-api/src/directory/get_public_rooms/v1.rs deleted file mode 100644 index c22a2a21..00000000 --- a/crates/ruma-federation-api/src/directory/get_public_rooms/v1.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! [GET /_matrix/federation/v1/publicRooms](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-publicrooms) - -use js_int::UInt; -use ruma_api::ruma_api; -use ruma_common::directory::{IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}; - -ruma_api! { - metadata: { - description: "Gets all the public rooms for the homeserver.", - method: GET, - name: "get_public_rooms", - stable_path: "/_matrix/federation/v1/publicRooms", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - #[derive(Default)] - request: { - /// Limit for the number of results to return. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, - - /// Pagination token from a previous request. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub since: Option<&'a str>, - - /// Network to fetch the public room lists from. - #[serde(flatten, skip_serializing_if = "ruma_serde::is_default")] - #[ruma_api(query)] - pub room_network: RoomNetwork<'a>, - } - - #[derive(Default)] - response: { - /// A paginated chunk of public rooms. - pub chunk: Vec, - - /// A pagination token for the response. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, - - /// A pagination token that allows fetching previous results. - #[serde(skip_serializing_if = "Option::is_none")] - pub prev_batch: Option, - - /// An estimate on the total number of public rooms, if the server has an estimate. - pub total_room_count_estimate: Option, - } -} - -impl Request<'_> { - /// Creates an empty `Request`. - pub fn new() -> Self { - Default::default() - } -} - -impl Response { - /// Creates an empty `Response`. - pub fn new() -> Self { - Default::default() - } -} diff --git a/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs b/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs index 937e5fed..2fb97a8f 100644 --- a/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs +++ b/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs @@ -1,3 +1,75 @@ +//! `POST /_matrix/federation/*/publicRooms` +//! //! Endpoint to query a homeserver's public rooms with an optional filter. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#post_matrixfederationv1publicrooms + + use js_int::UInt; + use ruma_api::ruma_api; + use ruma_common::directory::{ + Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork, + }; + + ruma_api! { + metadata: { + description: "Get the list of rooms in this homeserver's public directory.", + method: POST, + name: "get_public_rooms_filtered", + stable_path: "/_matrix/federation/v1/publicRooms", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + #[derive(Default)] + request: { + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + pub since: Option<&'a str>, + + /// Filter to apply to the results. + #[serde(default, skip_serializing_if = "Filter::is_empty")] + pub filter: Filter<'a>, + + /// Network to fetch the public room lists from. + #[serde(flatten, skip_serializing_if = "ruma_serde::is_default")] + pub room_network: RoomNetwork<'a>, + } + + #[derive(Default)] + response: { + /// A paginated chunk of public rooms. + pub chunk: Vec, + + /// A pagination token for the response. + pub next_batch: Option, + + /// A pagination token that allows fetching previous results. + pub prev_batch: Option, + + /// An estimate on the total number of public rooms, if the server has an estimate. + pub total_room_count_estimate: Option, + } + } + + impl Request<'_> { + /// Creates an empty `Request`. + pub fn new() -> Self { + Default::default() + } + } + + impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Default::default() + } + } +} diff --git a/crates/ruma-federation-api/src/directory/get_public_rooms_filtered/v1.rs b/crates/ruma-federation-api/src/directory/get_public_rooms_filtered/v1.rs deleted file mode 100644 index 1777de2d..00000000 --- a/crates/ruma-federation-api/src/directory/get_public_rooms_filtered/v1.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! [POST /_matrix/federation/v1/publicRooms](https://matrix.org/docs/spec/server_server/r0.1.4#post-matrix-federation-v1-publicrooms) - -use js_int::UInt; -use ruma_api::ruma_api; -use ruma_common::directory::{ - Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork, -}; - -ruma_api! { - metadata: { - description: "Get the list of rooms in this homeserver's public directory.", - method: POST, - name: "get_public_rooms_filtered", - stable_path: "/_matrix/federation/v1/publicRooms", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - #[derive(Default)] - request: { - /// Limit for the number of results to return. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - - /// Pagination token from a previous request. - #[serde(skip_serializing_if = "Option::is_none")] - pub since: Option<&'a str>, - - /// Filter to apply to the results. - #[serde(default, skip_serializing_if = "Filter::is_empty")] - pub filter: Filter<'a>, - - /// Network to fetch the public room lists from. - #[serde(flatten, skip_serializing_if = "ruma_serde::is_default")] - pub room_network: RoomNetwork<'a>, - } - - #[derive(Default)] - response: { - /// A paginated chunk of public rooms. - pub chunk: Vec, - - /// A pagination token for the response. - pub next_batch: Option, - - /// A pagination token that allows fetching previous results. - pub prev_batch: Option, - - /// An estimate on the total number of public rooms, if the server has an estimate. - pub total_room_count_estimate: Option, - } -} - -impl Request<'_> { - /// Creates an empty `Request`. - pub fn new() -> Self { - Default::default() - } -} - -impl Response { - /// Creates an empty `Response`. - pub fn new() -> Self { - Default::default() - } -} diff --git a/crates/ruma-federation-api/src/discovery/discover_homeserver.rs b/crates/ruma-federation-api/src/discovery/discover_homeserver.rs index 8b8a6a5d..e7d25782 100644 --- a/crates/ruma-federation-api/src/discovery/discover_homeserver.rs +++ b/crates/ruma-federation-api/src/discovery/discover_homeserver.rs @@ -1,4 +1,6 @@ -//! [GET /.well-known/matrix/server](https://matrix.org/docs/spec/server_server/r0.1.4#get-well-known-matrix-server) +//! `GET /.well-known/matrix/server` ([spec]) +//! +//! [spec]: https://spec.matrix.org/v1.2/server-server-api/#getwell-knownmatrixserver use ruma_api::ruma_api; use ruma_identifiers::ServerName; diff --git a/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs b/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs index 4270fd93..22fdb4e8 100644 --- a/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs +++ b/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs @@ -1,4 +1,66 @@ +//! `GET /_matrix/key/*/query/{serverName}/{keyId}` +//! //! Query for another server's keys. The receiving (notary) server must sign the keys returned by //! the queried server. -pub mod v2; +pub mod v2 { + //! `/v2/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixkeyv2queryservernamekeyid + + use ruma_api::ruma_api; + use ruma_common::MilliSecondsSinceUnixEpoch; + use ruma_identifiers::ServerName; + + use crate::discovery::ServerSigningKeys; + + ruma_api! { + metadata: { + description: "Query for another server's keys.", + method: GET, + name: "get_remote_server_keys", + // Note: The spec has an additional, deprecated path parameter on this. We may want to + // support an additional parameter at the end, even if it is ignored. + stable_path: "/_matrix/key/v2/query/:server_name", + rate_limited: false, + authentication: None, + added: 1.0, + } + + request: { + /// The server's DNS name to query + #[ruma_api(path)] + pub server_name: &'a ServerName, + + /// A millisecond POSIX timestamp in milliseconds indicating when the returned certificates + /// will need to be valid until to be useful to the requesting server. + /// + /// If not supplied, the current time as determined by the receiving server is used. + #[ruma_api(query)] + #[serde(default = "MilliSecondsSinceUnixEpoch::now")] + pub minimum_valid_until_ts: MilliSecondsSinceUnixEpoch, + } + + response: { + /// The queried server's keys, signed by the notary server. + pub server_keys: Vec, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given server name and `minimum_valid_until` timestamp. + pub fn new( + server_name: &'a ServerName, + minimum_valid_until_ts: MilliSecondsSinceUnixEpoch, + ) -> Self { + Self { server_name, minimum_valid_until_ts } + } + } + + impl Response { + /// Creates a new `Response` with the given keys. + pub fn new(server_keys: Vec) -> Self { + Self { server_keys } + } + } +} diff --git a/crates/ruma-federation-api/src/discovery/get_remote_server_keys/v2.rs b/crates/ruma-federation-api/src/discovery/get_remote_server_keys/v2.rs deleted file mode 100644 index a2d77220..00000000 --- a/crates/ruma-federation-api/src/discovery/get_remote_server_keys/v2.rs +++ /dev/null @@ -1,57 +0,0 @@ -//! [GET /_matrix/key/v2/query/{serverName}/{keyId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-key-v2-query-servername-keyid) - -use ruma_api::ruma_api; -use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_identifiers::ServerName; - -use crate::discovery::ServerSigningKeys; - -ruma_api! { - metadata: { - description: "Query for another server's keys.", - method: GET, - name: "get_remote_server_keys", - // Note: The spec has an additional, deprecated path parameter on this. We may want to - // support an additional parameter at the end, even if it is ignored. - stable_path: "/_matrix/key/v2/query/:server_name", - rate_limited: false, - authentication: None, - added: 1.0, - } - - request: { - /// The server's DNS name to query - #[ruma_api(path)] - pub server_name: &'a ServerName, - - /// A millisecond POSIX timestamp in milliseconds indicating when the returned certificates - /// will need to be valid until to be useful to the requesting server. - /// - /// If not supplied, the current time as determined by the receiving server is used. - #[ruma_api(query)] - #[serde(default = "MilliSecondsSinceUnixEpoch::now")] - pub minimum_valid_until_ts: MilliSecondsSinceUnixEpoch, - } - - response: { - /// The queried server's keys, signed by the notary server. - pub server_keys: Vec, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given server name and `minimum_valid_until` timestamp. - pub fn new( - server_name: &'a ServerName, - minimum_valid_until_ts: MilliSecondsSinceUnixEpoch, - ) -> Self { - Self { server_name, minimum_valid_until_ts } - } -} - -impl Response { - /// Creates a new `Response` with the given keys. - pub fn new(server_keys: Vec) -> Self { - Self { server_keys } - } -} diff --git a/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch.rs b/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch.rs index 7c967994..c76ee008 100644 --- a/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch.rs +++ b/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch.rs @@ -1,4 +1,92 @@ +//! `POST /_matrix/key/*/query` +//! //! Query for keys from multiple servers in a batch format. The receiving (notary) server must sign //! the keys returned by the queried servers. -pub mod v2; +pub mod v2 { + //! `/v2/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#post_matrixkeyv2query + + use std::collections::BTreeMap; + + use ruma_api::ruma_api; + use ruma_common::MilliSecondsSinceUnixEpoch; + use ruma_identifiers::{ServerName, ServerSigningKeyId}; + use serde::{Deserialize, Serialize}; + + use crate::discovery::ServerSigningKeys; + + ruma_api! { + metadata: { + description: "Query for keys from multiple servers in a batch format.", + method: POST, + name: "get_remote_server_keys_batch", + stable_path: "/_matrix/key/v2/query", + rate_limited: false, + authentication: None, + added: 1.0, + } + + request: { + /// The query criteria. + /// + /// The outer string key on the object is the server name (eg: matrix.org). The inner + /// string key is the Key ID to query for the particular server. If no key IDs are given to + /// be queried, the notary server should query for all keys. If no servers are given, the + /// notary server must return an empty server_keys array in the response. + /// + /// The notary server may return multiple keys regardless of the Key IDs given. + pub server_keys: BTreeMap, BTreeMap, QueryCriteria>>, + + } + + response: { + /// The queried server's keys, signed by the notary server. + pub server_keys: Vec, + } + } + + impl Request { + /// Creates a new `Request` with the given query criteria. + pub fn new( + server_keys: BTreeMap< + Box, + BTreeMap, QueryCriteria>, + >, + ) -> Self { + Self { server_keys } + } + } + + impl Response { + /// Creates a new `Response` with the given keys. + pub fn new(server_keys: Vec) -> Self { + Self { server_keys } + } + } + + /// The query criteria. + #[derive(Clone, Debug, Default, Deserialize, Serialize)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] + pub struct QueryCriteria { + /// A millisecond POSIX timestamp in milliseconds indicating when the + /// returned certificates will need to be valid until to be useful to the + /// requesting server. + /// + /// If not supplied, the current time as determined by the notary server is + /// used. + // This doesn't use `serde(default)` because the default would then be + // determined by the client rather than the server (and it would take more + // bandwidth because `skip_serializing_if` couldn't be used). + #[serde(skip_serializing_if = "Option::is_none")] + pub minimum_valid_until_ts: Option, + } + + impl QueryCriteria { + /// Creates empty `QueryCriteria`. + pub fn new() -> Self { + Default::default() + } + } +} diff --git a/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch/v2.rs b/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch/v2.rs deleted file mode 100644 index d26adccb..00000000 --- a/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch/v2.rs +++ /dev/null @@ -1,80 +0,0 @@ -//! [POST /_matrix/key/v2/query](https://matrix.org/docs/spec/server_server/r0.1.4#post-matrix-key-v2-query) - -use std::collections::BTreeMap; - -use ruma_api::ruma_api; -use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_identifiers::{ServerName, ServerSigningKeyId}; -use serde::{Deserialize, Serialize}; - -use crate::discovery::ServerSigningKeys; - -ruma_api! { - metadata: { - description: "Query for keys from multiple servers in a batch format.", - method: POST, - name: "get_remote_server_keys_batch", - stable_path: "/_matrix/key/v2/query", - rate_limited: false, - authentication: None, - added: 1.0, - } - - request: { - /// The query criteria. - /// - /// The outer string key on the object is the server name (eg: matrix.org). The inner - /// string key is the Key ID to query for the particular server. If no key IDs are given to - /// be queried, the notary server should query for all keys. If no servers are given, the - /// notary server must return an empty server_keys array in the response. - /// - /// The notary server may return multiple keys regardless of the Key IDs given. - pub server_keys: BTreeMap, BTreeMap, QueryCriteria>>, - - } - - response: { - /// The queried server's keys, signed by the notary server. - pub server_keys: Vec, - } -} - -impl Request { - /// Creates a new `Request` with the given query criteria. - pub fn new( - server_keys: BTreeMap, BTreeMap, QueryCriteria>>, - ) -> Self { - Self { server_keys } - } -} - -impl Response { - /// Creates a new `Response` with the given keys. - pub fn new(server_keys: Vec) -> Self { - Self { server_keys } - } -} - -/// The query criteria. -#[derive(Clone, Debug, Default, Deserialize, Serialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct QueryCriteria { - /// A millisecond POSIX timestamp in milliseconds indicating when the - /// returned certificates will need to be valid until to be useful to the - /// requesting server. - /// - /// If not supplied, the current time as determined by the notary server is - /// used. - // This doesn't use `serde(default)` because the default would then be - // determined by the client rather than the server (and it would take more - // bandwidth because `skip_serializing_if` couldn't be used). - #[serde(skip_serializing_if = "Option::is_none")] - pub minimum_valid_until_ts: Option, -} - -impl QueryCriteria { - /// Creates empty `QueryCriteria`. - pub fn new() -> Self { - Default::default() - } -} diff --git a/crates/ruma-federation-api/src/discovery/get_server_keys.rs b/crates/ruma-federation-api/src/discovery/get_server_keys.rs index 4de7144b..a87b8592 100644 --- a/crates/ruma-federation-api/src/discovery/get_server_keys.rs +++ b/crates/ruma-federation-api/src/discovery/get_server_keys.rs @@ -1,3 +1,57 @@ -//! Endpdoint for retrieving a server's published signing keys. +//! `GET /_matrix/key/*/server` +//! +//! Endpoint for retrieving a server's published signing keys. -pub mod v2; +pub mod v2 { + //! `/v2/` ([spec]) + //! + //! Note: The specification includes `/{keyID}`, but this is deprecated, and the trailing slash + //! then made optional. + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixkeyv2serverkeyid + + use ruma_api::ruma_api; + + use crate::discovery::ServerSigningKeys; + + ruma_api! { + metadata: { + description: "Gets the homeserver's published signing keys.", + method: GET, + name: "get_server_keys", + stable_path: "/_matrix/key/v2/server", + rate_limited: false, + authentication: None, + added: 1.0, + } + + #[derive(Default)] + request: {} + + response: { + /// Queried server key, signed by the notary server. + #[ruma_api(body)] + pub server_key: ServerSigningKeys, + } + } + + impl Request { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self {} + } + } + + impl Response { + /// Creates a new `Response` with the given server key. + pub fn new(server_key: ServerSigningKeys) -> Self { + Self { server_key } + } + } + + impl From for Response { + fn from(server_key: ServerSigningKeys) -> Self { + Self::new(server_key) + } + } +} diff --git a/crates/ruma-federation-api/src/discovery/get_server_keys/v2.rs b/crates/ruma-federation-api/src/discovery/get_server_keys/v2.rs deleted file mode 100644 index 26fb01f0..00000000 --- a/crates/ruma-federation-api/src/discovery/get_server_keys/v2.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! [GET /_matrix/key/v2/server](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-key-v2-server-keyid) - -use ruma_api::ruma_api; - -use crate::discovery::ServerSigningKeys; - -ruma_api! { - metadata: { - description: "Gets the homeserver's published signing keys.", - method: GET, - name: "get_server_keys", - stable_path: "/_matrix/key/v2/server", - rate_limited: false, - authentication: None, - added: 1.0, - } - - #[derive(Default)] - request: {} - - response: { - /// Queried server key, signed by the notary server. - #[ruma_api(body)] - pub server_key: ServerSigningKeys, - } -} - -impl Request { - /// Creates an empty `Request`. - pub fn new() -> Self { - Self {} - } -} - -impl Response { - /// Creates a new `Response` with the given server key. - pub fn new(server_key: ServerSigningKeys) -> Self { - Self { server_key } - } -} - -impl From for Response { - fn from(server_key: ServerSigningKeys) -> Self { - Self::new(server_key) - } -} diff --git a/crates/ruma-federation-api/src/discovery/get_server_version.rs b/crates/ruma-federation-api/src/discovery/get_server_version.rs index 35431f43..9cfe4b98 100644 --- a/crates/ruma-federation-api/src/discovery/get_server_version.rs +++ b/crates/ruma-federation-api/src/discovery/get_server_version.rs @@ -1,3 +1,70 @@ +//! `GET /_matrix/federation/*/version` +//! //! Endpoint to retrieve metadata about a server implementation. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1version + + use ruma_api::ruma_api; + use serde::{Deserialize, Serialize}; + + ruma_api! { + metadata: { + description: "Get the implementation name and version of this homeserver.", + method: GET, + name: "get_server_version", + stable_path: "/_matrix/federation/v1/version", + rate_limited: false, + authentication: None, + added: 1.0, + } + + #[derive(Default)] + request: {} + + #[derive(Default)] + response: { + /// Information about the homeserver implementation + #[serde(skip_serializing_if = "Option::is_none")] + pub server: Option, + } + } + + impl Request { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self {} + } + } + + impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Default::default() + } + } + + /// Arbitrary values that identify this implementation. + #[derive(Clone, Debug, Default, Serialize, Deserialize)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] + pub struct Server { + /// Arbitrary name that identifies this implementation. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + + /// Version of this implementation. + /// + /// The version format depends on the implementation. + #[serde(skip_serializing_if = "Option::is_none")] + pub version: Option, + } + + impl Server { + /// Creates an empty `Server`. + pub fn new() -> Self { + Default::default() + } + } +} diff --git a/crates/ruma-federation-api/src/discovery/get_server_version/v1.rs b/crates/ruma-federation-api/src/discovery/get_server_version/v1.rs deleted file mode 100644 index e9816a61..00000000 --- a/crates/ruma-federation-api/src/discovery/get_server_version/v1.rs +++ /dev/null @@ -1,62 +0,0 @@ -//! [GET /_matrix/federation/v1/version](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-version) - -use ruma_api::ruma_api; -use serde::{Deserialize, Serialize}; - -ruma_api! { - metadata: { - description: "Get the implementation name and version of this homeserver.", - method: GET, - name: "get_server_version", - stable_path: "/_matrix/federation/v1/version", - rate_limited: false, - authentication: None, - added: 1.0, - } - - #[derive(Default)] - request: {} - - #[derive(Default)] - response: { - /// Information about the homeserver implementation - #[serde(skip_serializing_if = "Option::is_none")] - pub server: Option, - } -} - -impl Request { - /// Creates an empty `Request`. - pub fn new() -> Self { - Self {} - } -} - -impl Response { - /// Creates an empty `Response`. - pub fn new() -> Self { - Default::default() - } -} - -/// Arbitrary values that identify this implementation. -#[derive(Clone, Debug, Default, Serialize, Deserialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct Server { - /// Arbitrary name that identifies this implementation. - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option, - - /// Version of this implementation. - /// - /// The version format depends on the implementation. - #[serde(skip_serializing_if = "Option::is_none")] - pub version: Option, -} - -impl Server { - /// Creates an empty `Server`. - pub fn new() -> Self { - Default::default() - } -} diff --git a/crates/ruma-federation-api/src/event/get_event.rs b/crates/ruma-federation-api/src/event/get_event.rs index 767985e3..dd4d707a 100644 --- a/crates/ruma-federation-api/src/event/get_event.rs +++ b/crates/ruma-federation-api/src/event/get_event.rs @@ -1,3 +1,63 @@ +//! `GET /_matrix/federation/*/event/{eventId}` +//! //! Retrieves a single event. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1eventeventid + + use ruma_api::ruma_api; + use ruma_common::MilliSecondsSinceUnixEpoch; + use ruma_identifiers::{EventId, ServerName}; + + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Retrieves a single event.", + method: GET, + name: "get_event", + stable_path: "/_matrix/federation/v1/event/:event_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The event ID to get. + #[ruma_api(path)] + pub event_id: &'a EventId, + } + + response: { + /// The `server_name` of the homeserver sending this transaction. + pub origin: Box, + + /// Time on originating homeserver when this transaction started. + pub origin_server_ts: MilliSecondsSinceUnixEpoch, + + /// The event. + #[serde(rename = "pdus", with = "ruma_serde::single_element_seq")] + pub pdu: Box, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given event id. + pub fn new(event_id: &'a EventId) -> Self { + Self { event_id } + } + } + + impl Response { + /// Creates a new `Response` with the given server name, timestamp, and event. + pub fn new( + origin: Box, + origin_server_ts: MilliSecondsSinceUnixEpoch, + pdu: Box, + ) -> Self { + Self { origin, origin_server_ts, pdu } + } + } +} diff --git a/crates/ruma-federation-api/src/event/get_event/v1.rs b/crates/ruma-federation-api/src/event/get_event/v1.rs deleted file mode 100644 index cd7bfcdb..00000000 --- a/crates/ruma-federation-api/src/event/get_event/v1.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! [GET /_matrix/federation/v1/event/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-event-eventid) - -use ruma_api::ruma_api; -use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_identifiers::{EventId, ServerName}; - -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Retrieves a single event.", - method: GET, - name: "get_event", - stable_path: "/_matrix/federation/v1/event/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The event ID to get. - #[ruma_api(path)] - pub event_id: &'a EventId, - } - - response: { - /// The `server_name` of the homeserver sending this transaction. - pub origin: Box, - - /// Time on originating homeserver when this transaction started. - pub origin_server_ts: MilliSecondsSinceUnixEpoch, - - /// The event. - #[serde(rename = "pdus", with = "ruma_serde::single_element_seq")] - pub pdu: Box, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given event id. - pub fn new(event_id: &'a EventId) -> Self { - Self { event_id } - } -} - -impl Response { - /// Creates a new `Response` with the given server name, timestamp, and event. - pub fn new( - origin: Box, - origin_server_ts: MilliSecondsSinceUnixEpoch, - pdu: Box, - ) -> Self { - Self { origin, origin_server_ts, pdu } - } -} diff --git a/crates/ruma-federation-api/src/event/get_missing_events.rs b/crates/ruma-federation-api/src/event/get_missing_events.rs index 8e276abb..fb97708a 100644 --- a/crates/ruma-federation-api/src/event/get_missing_events.rs +++ b/crates/ruma-federation-api/src/event/get_missing_events.rs @@ -1,3 +1,91 @@ +//! `POST /_matrix/federation/*/get_missing_events/{roomId}` +//! //! Retrieves previous events that the sender is missing. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#post_matrixfederationv1get_missing_eventsroomid + + use js_int::{uint, UInt}; + use ruma_api::ruma_api; + use ruma_identifiers::{EventId, RoomId}; + + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Retrieves previous events that the sender is missing.", + method: POST, + name: "get_missing_events", + stable_path: "/_matrix/federation/v1/get_missing_events/:room_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The room ID to search in. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The maximum number of events to retrieve. + /// + /// Defaults to 10. + #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] + pub limit: UInt, + + /// The minimum depth of events to retrieve. + /// + /// Defaults to 0. + #[serde(default, skip_serializing_if = "ruma_serde::is_default")] + pub min_depth: UInt, + + /// The latest event IDs that the sender already has. + /// + /// These are skipped when retrieving the previous events of `latest_events`. + pub earliest_events: &'a [Box], + + /// The event IDs to retrieve the previous events for. + pub latest_events: &'a [Box], + } + + #[derive(Default)] + response: { + /// The missing PDUs. + pub events: Vec>, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` for events in the given room with the given constraints. + pub fn new( + room_id: &'a RoomId, + earliest_events: &'a [Box], + latest_events: &'a [Box], + ) -> Self { + Self { + room_id, + limit: default_limit(), + min_depth: UInt::default(), + earliest_events, + latest_events, + } + } + } + + impl Response { + /// Creates a new `Response` with the given events. + pub fn new(events: Vec>) -> Self { + Self { events } + } + } + + fn default_limit() -> UInt { + uint!(10) + } + + fn is_default_limit(val: &UInt) -> bool { + *val == default_limit() + } +} diff --git a/crates/ruma-federation-api/src/event/get_missing_events/v1.rs b/crates/ruma-federation-api/src/event/get_missing_events/v1.rs deleted file mode 100644 index f1ea0253..00000000 --- a/crates/ruma-federation-api/src/event/get_missing_events/v1.rs +++ /dev/null @@ -1,83 +0,0 @@ -//! [POST /_matrix/federation/v1/get_missing_events/{roomId}](https://matrix.org/docs/spec/server_server/r0.1.4#post-matrix-federation-v1-get-missing-events-roomid) - -use js_int::{uint, UInt}; -use ruma_api::ruma_api; -use ruma_identifiers::{EventId, RoomId}; - -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Retrieves previous events that the sender is missing.", - method: POST, - name: "get_missing_events", - stable_path: "/_matrix/federation/v1/get_missing_events/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The room ID to search in. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// The maximum number of events to retrieve. - /// - /// Defaults to 10. - #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] - pub limit: UInt, - - /// The minimum depth of events to retrieve. - /// - /// Defaults to 0. - #[serde(default, skip_serializing_if = "ruma_serde::is_default")] - pub min_depth: UInt, - - /// The latest event IDs that the sender already has. - /// - /// These are skipped when retrieving the previous events of `latest_events`. - pub earliest_events: &'a [Box], - - /// The event IDs to retrieve the previous events for. - pub latest_events: &'a [Box], - } - - #[derive(Default)] - response: { - /// The missing PDUs. - pub events: Vec>, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` for events in the given room with the given constraints. - pub fn new( - room_id: &'a RoomId, - earliest_events: &'a [Box], - latest_events: &'a [Box], - ) -> Self { - Self { - room_id, - limit: default_limit(), - min_depth: UInt::default(), - earliest_events, - latest_events, - } - } -} - -impl Response { - /// Creates a new `Response` with the given events. - pub fn new(events: Vec>) -> Self { - Self { events } - } -} - -fn default_limit() -> UInt { - uint!(10) -} - -fn is_default_limit(val: &UInt) -> bool { - *val == default_limit() -} diff --git a/crates/ruma-federation-api/src/event/get_room_state.rs b/crates/ruma-federation-api/src/event/get_room_state.rs index f59e8204..c916b13a 100644 --- a/crates/ruma-federation-api/src/event/get_room_state.rs +++ b/crates/ruma-federation-api/src/event/get_room_state.rs @@ -1,3 +1,59 @@ +//! `GET /_matrix/federation/*/state/{roomId}` +//! //! Retrieves a snapshot of a room's state at a given event. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1stateroomid + + use ruma_api::ruma_api; + use ruma_identifiers::{EventId, RoomId}; + + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Retrieves a snapshot of a room's state at a given event.", + method: GET, + name: "get_room_state", + stable_path: "/_matrix/federation/v1/state/:room_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The room ID to get state for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// An event ID in the room to retrieve the state at. + #[ruma_api(query)] + pub event_id: &'a EventId, + } + + response: { + /// The full set of authorization events that make up the state of the + /// room, and their authorization events, recursively. + pub auth_chain: Vec>, + + /// The fully resolved state of the room at the given event. + pub pdus: Vec>, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given event ID and room ID. + pub fn new(event_id: &'a EventId, room_id: &'a RoomId) -> Self { + Self { room_id, event_id } + } + } + + impl Response { + /// Creates a new `Response` with the given auth chain and room state. + pub fn new(auth_chain: Vec>, pdus: Vec>) -> Self { + Self { auth_chain, pdus } + } + } +} diff --git a/crates/ruma-federation-api/src/event/get_room_state/v1.rs b/crates/ruma-federation-api/src/event/get_room_state/v1.rs deleted file mode 100644 index bcc5d7c2..00000000 --- a/crates/ruma-federation-api/src/event/get_room_state/v1.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! [GET /_matrix/federation/v1/state/{roomId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-state-roomid) - -use ruma_api::ruma_api; -use ruma_identifiers::{EventId, RoomId}; - -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Retrieves a snapshot of a room's state at a given event.", - method: GET, - name: "get_room_state", - stable_path: "/_matrix/federation/v1/state/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The room ID to get state for. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// An event ID in the room to retrieve the state at. - #[ruma_api(query)] - pub event_id: &'a EventId, - } - - response: { - /// The full set of authorization events that make up the state of the - /// room, and their authorization events, recursively. - pub auth_chain: Vec>, - - /// The fully resolved state of the room at the given event. - pub pdus: Vec>, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given event ID and room ID. - pub fn new(event_id: &'a EventId, room_id: &'a RoomId) -> Self { - Self { room_id, event_id } - } -} - -impl Response { - /// Creates a new `Response` with the given auth chain and room state. - pub fn new(auth_chain: Vec>, pdus: Vec>) -> Self { - Self { auth_chain, pdus } - } -} diff --git a/crates/ruma-federation-api/src/event/get_room_state_ids.rs b/crates/ruma-federation-api/src/event/get_room_state_ids.rs index 6d0e7e60..901cdd62 100644 --- a/crates/ruma-federation-api/src/event/get_room_state_ids.rs +++ b/crates/ruma-federation-api/src/event/get_room_state_ids.rs @@ -1,3 +1,57 @@ +//! `GET /_matrix/federation/*/state_ids/{roomId}` +//! //! Retrieves a snapshot of a room's state at a given event, in the form of event IDs. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1state_idsroomid + + use ruma_api::ruma_api; + use ruma_identifiers::{EventId, RoomId}; + + ruma_api! { + metadata: { + description: "Retrieves a snapshot of a room's state at a given event, in the form of event IDs", + method: GET, + name: "get_room_state_ids", + stable_path: "/_matrix/federation/v1/state_ids/:room_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The room ID to get state for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// An event ID in the room to retrieve the state at. + #[ruma_api(query)] + pub event_id: &'a EventId, + } + + response: { + /// The full set of authorization events that make up the state of the + /// room, and their authorization events, recursively. + pub auth_chain_ids: Vec>, + + /// The fully resolved state of the room at the given event. + pub pdu_ids: Vec>, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given event id and room id. + pub fn new(event_id: &'a EventId, room_id: &'a RoomId) -> Self { + Self { room_id, event_id } + } + } + + impl Response { + /// Creates a new `Response` with the given auth chain IDs and room state IDs. + pub fn new(auth_chain_ids: Vec>, pdu_ids: Vec>) -> Self { + Self { auth_chain_ids, pdu_ids } + } + } +} diff --git a/crates/ruma-federation-api/src/event/get_room_state_ids/v1.rs b/crates/ruma-federation-api/src/event/get_room_state_ids/v1.rs deleted file mode 100644 index a0b81ee2..00000000 --- a/crates/ruma-federation-api/src/event/get_room_state_ids/v1.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! [GET /_matrix/federation/v1/state_ids/{roomId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-state-ids-roomid) - -use ruma_api::ruma_api; -use ruma_identifiers::{EventId, RoomId}; - -ruma_api! { - metadata: { - description: "Retrieves a snapshot of a room's state at a given event, in the form of event IDs", - method: GET, - name: "get_room_state_ids", - stable_path: "/_matrix/federation/v1/state_ids/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The room ID to get state for. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// An event ID in the room to retrieve the state at. - #[ruma_api(query)] - pub event_id: &'a EventId, - } - - response: { - /// The full set of authorization events that make up the state of the - /// room, and their authorization events, recursively. - pub auth_chain_ids: Vec>, - - /// The fully resolved state of the room at the given event. - pub pdu_ids: Vec>, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given event id and room id. - pub fn new(event_id: &'a EventId, room_id: &'a RoomId) -> Self { - Self { room_id, event_id } - } -} - -impl Response { - /// Creates a new `Response` with the given auth chain IDs and room state IDs. - pub fn new(auth_chain_ids: Vec>, pdu_ids: Vec>) -> Self { - Self { auth_chain_ids, pdu_ids } - } -} diff --git a/crates/ruma-federation-api/src/keys/claim_keys.rs b/crates/ruma-federation-api/src/keys/claim_keys.rs index 855ef0ab..ee250353 100644 --- a/crates/ruma-federation-api/src/keys/claim_keys.rs +++ b/crates/ruma-federation-api/src/keys/claim_keys.rs @@ -1,3 +1,81 @@ +//! `POST /_matrix/federation/*/user/keys/claim` +//! //! Endpoint to claim one-time keys for use in pre-key messages -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#post_matrixfederationv1userkeysclaim + + use std::collections::BTreeMap; + + use ruma_api::ruma_api; + use ruma_common::encryption::OneTimeKey; + use ruma_identifiers::{DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId}; + use ruma_serde::{Base64, Raw}; + use serde::{Deserialize, Serialize}; + + ruma_api! { + metadata: { + description: "Claims one-time keys for use in pre-key messages.", + method: POST, + name: "claim_keys", + stable_path: "/_matrix/federation/v1/user/keys/claim", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The keys to be claimed. + pub one_time_keys: OneTimeKeyClaims, + } + + response: { + /// One-time keys for the queried devices + pub one_time_keys: OneTimeKeys, + } + } + + impl Request { + /// Creates a new `Request` with the given one time key claims. + pub fn new(one_time_keys: OneTimeKeyClaims) -> Self { + Self { one_time_keys } + } + } + + impl Response { + /// Creates a new `Response` with the given one time keys. + pub fn new(one_time_keys: OneTimeKeys) -> Self { + Self { one_time_keys } + } + } + + /// A claim for one time keys + pub type OneTimeKeyClaims = BTreeMap, BTreeMap, DeviceKeyAlgorithm>>; + + /// One time keys for use in pre-key messages + pub type OneTimeKeys = + BTreeMap, BTreeMap, BTreeMap, Raw>>>; + + /// A key and its signature + #[derive(Debug, Clone, Serialize, Deserialize)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] + pub struct KeyObject { + /// The key, encoded using unpadded base64. + pub key: Base64, + + /// Signature of the key object. + pub signatures: BTreeMap, BTreeMap, String>>, + } + + impl KeyObject { + /// Creates a new `KeyObject` with the given key and signatures. + pub fn new( + key: Base64, + signatures: BTreeMap, BTreeMap, String>>, + ) -> Self { + Self { key, signatures } + } + } +} diff --git a/crates/ruma-federation-api/src/keys/claim_keys/v1.rs b/crates/ruma-federation-api/src/keys/claim_keys/v1.rs deleted file mode 100644 index 327adf59..00000000 --- a/crates/ruma-federation-api/src/keys/claim_keys/v1.rs +++ /dev/null @@ -1,74 +0,0 @@ -//! [POST -//! /_matrix/federation/v1/user/keys/claim](https://matrix.org/docs/spec/server_server/r0.1.4#post-matrix-federation-v1-user-keys-claim) - -use std::collections::BTreeMap; - -use ruma_api::ruma_api; -use ruma_common::encryption::OneTimeKey; -use ruma_identifiers::{DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId}; -use ruma_serde::{Base64, Raw}; -use serde::{Deserialize, Serialize}; - -ruma_api! { - metadata: { - description: "Claims one-time keys for use in pre-key messages.", - method: POST, - name: "claim_keys", - stable_path: "/_matrix/federation/v1/user/keys/claim", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The keys to be claimed. - pub one_time_keys: OneTimeKeyClaims, - } - - response: { - /// One-time keys for the queried devices - pub one_time_keys: OneTimeKeys, - } -} - -impl Request { - /// Creates a new `Request` with the given one time key claims. - pub fn new(one_time_keys: OneTimeKeyClaims) -> Self { - Self { one_time_keys } - } -} - -impl Response { - /// Creates a new `Response` with the given one time keys. - pub fn new(one_time_keys: OneTimeKeys) -> Self { - Self { one_time_keys } - } -} - -/// A claim for one time keys -pub type OneTimeKeyClaims = BTreeMap, BTreeMap, DeviceKeyAlgorithm>>; - -/// One time keys for use in pre-key messages -pub type OneTimeKeys = - BTreeMap, BTreeMap, BTreeMap, Raw>>>; - -/// A key and its signature -#[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct KeyObject { - /// The key, encoded using unpadded base64. - pub key: Base64, - - /// Signature of the key object. - pub signatures: BTreeMap, BTreeMap, String>>, -} - -impl KeyObject { - /// Creates a new `KeyObject` with the given key and signatures. - pub fn new( - key: Base64, - signatures: BTreeMap, BTreeMap, String>>, - ) -> Self { - Self { key, signatures } - } -} diff --git a/crates/ruma-federation-api/src/keys/get_keys.rs b/crates/ruma-federation-api/src/keys/get_keys.rs index 9d9eeffb..cb539d15 100644 --- a/crates/ruma-federation-api/src/keys/get_keys.rs +++ b/crates/ruma-federation-api/src/keys/get_keys.rs @@ -1,3 +1,65 @@ +//! `POST /_matrix/federation/*/user/keys/query` +//! //! Module for getting information about the current devices and identity keys for the given users -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#post_matrixfederationv1userkeysquery + + use std::collections::BTreeMap; + + use ruma_api::ruma_api; + use ruma_common::encryption::{CrossSigningKey, DeviceKeys}; + use ruma_identifiers::{DeviceId, UserId}; + use ruma_serde::Raw; + + ruma_api! { + metadata: { + description: "Returns the current devices and identity keys for the given users.", + method: POST, + name: "get_keys", + stable_path: "/_matrix/federation/v1/user/keys/query", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The keys to be downloaded. + /// + /// Gives all keys for a given user if the list of device ids is empty. + pub device_keys: BTreeMap, Vec>>, + } + + #[derive(Default)] + response: { + /// Keys from the queried devices. + pub device_keys: BTreeMap, BTreeMap, Raw>>, + + /// Information on the master cross-signing keys of the queried users. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub master_keys: BTreeMap, Raw>, + + /// Information on the self-signing keys of the queried users. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub self_signing_keys: BTreeMap, Raw>, + } + } + + impl Request { + /// Creates a new `Request` asking for the given device keys. + pub fn new(device_keys: BTreeMap, Vec>>) -> Self { + Self { device_keys } + } + } + + impl Response { + /// Creates a new `Response` with the given device keys. + pub fn new( + device_keys: BTreeMap, BTreeMap, Raw>>, + ) -> Self { + Self { device_keys, ..Default::default() } + } + } +} diff --git a/crates/ruma-federation-api/src/keys/get_keys/v1.rs b/crates/ruma-federation-api/src/keys/get_keys/v1.rs deleted file mode 100644 index 80442ba5..00000000 --- a/crates/ruma-federation-api/src/keys/get_keys/v1.rs +++ /dev/null @@ -1,57 +0,0 @@ -//! [POST /_matrix/federation/v1/user/keys/query](https://spec.matrix.org/v1.1/server-server-api/#post_matrixfederationv1userkeysquery) - -use std::collections::BTreeMap; - -use ruma_api::ruma_api; -use ruma_common::encryption::{CrossSigningKey, DeviceKeys}; -use ruma_identifiers::{DeviceId, UserId}; -use ruma_serde::Raw; - -ruma_api! { - metadata: { - description: "Returns the current devices and identity keys for the given users.", - method: POST, - name: "get_keys", - stable_path: "/_matrix/federation/v1/user/keys/query", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The keys to be downloaded. - /// - /// Gives all keys for a given user if the list of device ids is empty. - pub device_keys: BTreeMap, Vec>>, - } - - #[derive(Default)] - response: { - /// Keys from the queried devices. - pub device_keys: BTreeMap, BTreeMap, Raw>>, - - /// Information on the master cross-signing keys of the queried users. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub master_keys: BTreeMap, Raw>, - - /// Information on the self-signing keys of the queried users. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub self_signing_keys: BTreeMap, Raw>, - } -} - -impl Request { - /// Creates a new `Request` asking for the given device keys. - pub fn new(device_keys: BTreeMap, Vec>>) -> Self { - Self { device_keys } - } -} - -impl Response { - /// Creates a new `Response` with the given device keys. - pub fn new( - device_keys: BTreeMap, BTreeMap, Raw>>, - ) -> Self { - Self { device_keys, ..Default::default() } - } -} diff --git a/crates/ruma-federation-api/src/knock/create_knock_event_template.rs b/crates/ruma-federation-api/src/knock/create_knock_event_template.rs index 67f958f7..6b06d2f2 100644 --- a/crates/ruma-federation-api/src/knock/create_knock_event_template.rs +++ b/crates/ruma-federation-api/src/knock/create_knock_event_template.rs @@ -1,3 +1,66 @@ +//! `GET /_matrix/federation/*/make_knock/{roomId}/{userId}` +//! //! Endpoint to query information to prepare a knock event. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1make_knockroomiduserid + + use ruma_api::ruma_api; + use ruma_identifiers::{RoomId, RoomVersionId, UserId}; + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Send a request for a knock event template to a resident server.", + name: "create_knock_event_template", + method: GET, + unstable_path: "/_matrix/federation/unstable/xyz.amorgan.knock/make_knock/:room_id/:user_id", + stable_path: "/_matrix/federation/v1/make_knock/:room_id/:user_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.1, + } + + request: { + /// The room ID that should receive the knock. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The user ID the knock event will be for. + #[ruma_api(path)] + pub user_id: &'a UserId, + + /// The room versions the sending has support for. + /// + /// Defaults to `&[RoomVersionId::V1]`. + #[ruma_api(query)] + pub ver: &'a [RoomVersionId], + } + + response: { + /// The version of the room where the server is trying to knock. + pub room_version: RoomVersionId, + + /// An unsigned template event. + /// + /// May differ between room versions. + pub event: Box, + } + } + + impl<'a> Request<'a> { + /// Creates a `Request` with the given room ID and user ID. + pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { + Self { room_id, user_id, ver: &[RoomVersionId::V1] } + } + } + + impl Response { + /// Creates a new `Response` with the given room version ID and event. + pub fn new(room_version: RoomVersionId, event: Box) -> Self { + Self { room_version, event } + } + } +} diff --git a/crates/ruma-federation-api/src/knock/create_knock_event_template/v1.rs b/crates/ruma-federation-api/src/knock/create_knock_event_template/v1.rs deleted file mode 100644 index e02f22f7..00000000 --- a/crates/ruma-federation-api/src/knock/create_knock_event_template/v1.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! [GET /_matrix/federation/v1/make_knock/{roomId}/{userId}](https://spec.matrix.org/v1.1/server-server-api/#get_matrixfederationv1make_knockroomiduserid) - -use ruma_api::ruma_api; -use ruma_identifiers::{RoomId, RoomVersionId, UserId}; -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Send a request for a knock event template to a resident server.", - name: "create_knock_event_template", - method: GET, - unstable_path: "/_matrix/federation/unstable/xyz.amorgan.knock/make_knock/:room_id/:user_id", - stable_path: "/_matrix/federation/v1/make_knock/:room_id/:user_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.1, - } - - request: { - /// The room ID that should receive the knock. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// The user ID the knock event will be for. - #[ruma_api(path)] - pub user_id: &'a UserId, - - /// The room versions the sending has support for. - /// - /// Defaults to `&[RoomVersionId::V1]`. - #[ruma_api(query)] - pub ver: &'a [RoomVersionId], - } - - response: { - /// The version of the room where the server is trying to knock. - pub room_version: RoomVersionId, - - /// An unsigned template event. - /// - /// May differ between room versions. - pub event: Box, - } -} - -impl<'a> Request<'a> { - /// Creates a `Request` with the given room ID and user ID. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { - Self { room_id, user_id, ver: &[RoomVersionId::V1] } - } -} - -impl Response { - /// Creates a new `Response` with the given room version ID and event. - pub fn new(room_version: RoomVersionId, event: Box) -> Self { - Self { room_version, event } - } -} diff --git a/crates/ruma-federation-api/src/knock/send_knock.rs b/crates/ruma-federation-api/src/knock/send_knock.rs index 1fdcd4c8..dce4f894 100644 --- a/crates/ruma-federation-api/src/knock/send_knock.rs +++ b/crates/ruma-federation-api/src/knock/send_knock.rs @@ -1,3 +1,61 @@ +//! `PUT /_matrix/federation/*/send_knock/{roomId}/{eventId}` +//! //! Endpoint to submit a signed knock event to the resident homeserver. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv1send_knockroomideventid + + use ruma_api::ruma_api; + use ruma_events::AnyStrippedStateEvent; + use ruma_identifiers::{EventId, RoomId}; + use ruma_serde::Raw; + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Submits a signed knock event to the resident homeserver for it to accept into the room's graph.", + name: "send_knock", + method: PUT, + unstable_path: "/_matrix/federation/unstable/xyz.amorgan.knock/send_knock/:room_id/:event_id", + stable_path: "/_matrix/federation/v1/send_knock/:room_id/:event_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.1, + } + + request: { + /// The room ID that should receive the knock. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The event ID for the knock event. + #[ruma_api(path)] + pub event_id: &'a EventId, + + /// The PDU. + #[ruma_api(body)] + pub pdu: &'a RawJsonValue, + } + + response: { + /// State events providing public room metadata. + pub knock_room_state: Vec>, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given room ID, event ID and knock event. + pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: &'a RawJsonValue) -> Self { + Self { room_id, event_id, pdu } + } + } + + impl Response { + /// Creates a new `Response` with the given public room metadata state events. + pub fn new(knock_room_state: Vec>) -> Self { + Self { knock_room_state } + } + } +} diff --git a/crates/ruma-federation-api/src/knock/send_knock/v1.rs b/crates/ruma-federation-api/src/knock/send_knock/v1.rs deleted file mode 100644 index fce3eba6..00000000 --- a/crates/ruma-federation-api/src/knock/send_knock/v1.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! [PUT /_matrix/federation/v1/send_knock/{roomId}/{eventId}](https://spec.matrix.org/v1.1/server-server-api/#put_matrixfederationv1send_knockroomideventid) - -use ruma_api::ruma_api; -use ruma_events::AnyStrippedStateEvent; -use ruma_identifiers::{EventId, RoomId}; -use ruma_serde::Raw; -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Submits a signed knock event to the resident homeserver for it to accept into the room's graph.", - name: "send_knock", - method: PUT, - unstable_path: "/_matrix/federation/unstable/xyz.amorgan.knock/send_knock/:room_id/:event_id", - stable_path: "/_matrix/federation/v1/send_knock/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.1, - } - - request: { - /// The room ID that should receive the knock. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// The event ID for the knock event. - #[ruma_api(path)] - pub event_id: &'a EventId, - - /// The PDU. - #[ruma_api(body)] - pub pdu: &'a RawJsonValue, - } - - response: { - /// State events providing public room metadata. - pub knock_room_state: Vec>, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given room ID, event ID and knock event. - pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: &'a RawJsonValue) -> Self { - Self { room_id, event_id, pdu } - } -} - -impl Response { - /// Creates a new `Response` with the given public room metadata state events. - pub fn new(knock_room_state: Vec>) -> Self { - Self { knock_room_state } - } -} diff --git a/crates/ruma-federation-api/src/lib.rs b/crates/ruma-federation-api/src/lib.rs index 9b182c74..911afc4d 100644 --- a/crates/ruma-federation-api/src/lib.rs +++ b/crates/ruma-federation-api/src/lib.rs @@ -3,7 +3,7 @@ //! (De)serializable types for the [Matrix Server-Server API][federation-api]. //! These types are used by server code. //! -//! [federation-api]: https://matrix.org/docs/spec/server_server/r0.1.4.html +//! [federation-api]: https://spec.matrix.org/v1.2/server-server-api/ #![warn(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] diff --git a/crates/ruma-federation-api/src/membership/create_invite.rs b/crates/ruma-federation-api/src/membership/create_invite.rs index 9b992188..d90cb793 100644 --- a/crates/ruma-federation-api/src/membership/create_invite.rs +++ b/crates/ruma-federation-api/src/membership/create_invite.rs @@ -1,3 +1,5 @@ +//! `PUT /_matrix/federation/*/invite/{roomId}/{eventId}` +//! //! Endpoint for inviting a remote user to a room pub mod v1; diff --git a/crates/ruma-federation-api/src/membership/create_invite/v1.rs b/crates/ruma-federation-api/src/membership/create_invite/v1.rs index b08858f1..3c7b80a4 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v1.rs @@ -1,4 +1,6 @@ -//! [PUT /_matrix/federation/v1/invite/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-invite-roomid-eventid) +//! `/v1/` ([spec]) +//! +//! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv1inviteroomideventid use ruma_api::ruma_api; use ruma_common::MilliSecondsSinceUnixEpoch; diff --git a/crates/ruma-federation-api/src/membership/create_invite/v2.rs b/crates/ruma-federation-api/src/membership/create_invite/v2.rs index a6000b39..5bafbb40 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v2.rs @@ -1,4 +1,6 @@ -//! [PUT /_matrix/federation/v2/invite/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-invite-roomid-eventid) +//! `/v2/` ([spec]) +//! +//! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv2inviteroomideventid use ruma_api::ruma_api; use ruma_events::AnyStrippedStateEvent; diff --git a/crates/ruma-federation-api/src/membership/create_join_event.rs b/crates/ruma-federation-api/src/membership/create_join_event.rs index 169feef7..dfedfbaf 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event.rs @@ -1,3 +1,5 @@ +//! `PUT /_matrix/federation/*/send_join/{roomId}/{eventId}` +//! //! Endpoint to send join events to remote homeservers. pub mod v1; diff --git a/crates/ruma-federation-api/src/membership/create_join_event/v1.rs b/crates/ruma-federation-api/src/membership/create_join_event/v1.rs index 3b11af7f..9a19ed34 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event/v1.rs @@ -1,4 +1,6 @@ -//! [PUT /_matrix/federation/v1/send_join/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-send-join-roomid-eventid) +//! `/v1/` ([spec]) +//! +//! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv1send_joinroomideventid use ruma_api::ruma_api; use ruma_identifiers::{EventId, RoomId}; diff --git a/crates/ruma-federation-api/src/membership/create_join_event/v2.rs b/crates/ruma-federation-api/src/membership/create_join_event/v2.rs index c4f7df0f..3d23e495 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event/v2.rs @@ -1,4 +1,6 @@ -//! [PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-send-join-roomid-eventid) +//! `/v2/` ([spec]) +//! +//! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv2send_joinroomideventid use ruma_api::ruma_api; use ruma_identifiers::{EventId, RoomId}; diff --git a/crates/ruma-federation-api/src/membership/create_join_event_template.rs b/crates/ruma-federation-api/src/membership/create_join_event_template.rs index 1007e5ba..b9ec0e8c 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event_template.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event_template.rs @@ -1,3 +1,74 @@ +//! `GET /_matrix/federation/*/make_join/{roomId}/{userId}` +//! //! Endpoint to request a template for join events. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1make_joinroomiduserid + + use ruma_api::ruma_api; + use ruma_identifiers::{RoomId, RoomVersionId, UserId}; + + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Send a request for a join event template to a resident server.", + name: "create_join_event_template", + method: GET, + stable_path: "/_matrix/federation/v1/make_join/:room_id/:user_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The room ID that is about to be joined. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The user ID the join event will be for. + #[ruma_api(path)] + pub user_id: &'a UserId, + + /// The room versions the sending server has support for. + /// + /// Defaults to `&[RoomVersionId::V1]`. + #[ruma_api(query)] + #[serde(default = "default_ver", skip_serializing_if = "is_default_ver")] + pub ver: &'a [RoomVersionId], + } + + response: { + /// The version of the room where the server is trying to join. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_version: Option, + + /// An unsigned template event. + pub event: Box, + } + } + + fn default_ver() -> Vec { + vec![RoomVersionId::V1] + } + + fn is_default_ver(ver: &&[RoomVersionId]) -> bool { + **ver == [RoomVersionId::V1] + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given room id and user id. + pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { + Self { room_id, user_id, ver: &[RoomVersionId::V1] } + } + } + + impl Response { + /// Creates a new `Response` with the given template event. + pub fn new(event: Box) -> Self { + Self { room_version: None, event } + } + } +} diff --git a/crates/ruma-federation-api/src/membership/create_join_event_template/v1.rs b/crates/ruma-federation-api/src/membership/create_join_event_template/v1.rs deleted file mode 100644 index e78f2fc4..00000000 --- a/crates/ruma-federation-api/src/membership/create_join_event_template/v1.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! [GET /_matrix/federation/v1/make_join/{roomId}/{userId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-make-join-roomid-userid) - -use ruma_api::ruma_api; -use ruma_identifiers::{RoomId, RoomVersionId, UserId}; - -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Send a request for a join event template to a resident server.", - name: "create_join_event_template", - method: GET, - stable_path: "/_matrix/federation/v1/make_join/:room_id/:user_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The room ID that is about to be joined. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// The user ID the join event will be for. - #[ruma_api(path)] - pub user_id: &'a UserId, - - /// The room versions the sending server has support for. - /// - /// Defaults to `&[RoomVersionId::V1]`. - #[ruma_api(query)] - #[serde(default = "default_ver", skip_serializing_if = "is_default_ver")] - pub ver: &'a [RoomVersionId], - } - - response: { - /// The version of the room where the server is trying to join. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_version: Option, - - /// An unsigned template event. - pub event: Box, - } -} - -fn default_ver() -> Vec { - vec![RoomVersionId::V1] -} - -fn is_default_ver(ver: &&[RoomVersionId]) -> bool { - **ver == [RoomVersionId::V1] -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given room id and user id. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { - Self { room_id, user_id, ver: &[RoomVersionId::V1] } - } -} - -impl Response { - /// Creates a new `Response` with the given template event. - pub fn new(event: Box) -> Self { - Self { room_version: None, event } - } -} diff --git a/crates/ruma-federation-api/src/membership/create_leave_event.rs b/crates/ruma-federation-api/src/membership/create_leave_event.rs index 279bd927..47edac4e 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event.rs @@ -1,3 +1,5 @@ +//! `PUT /_matrix/federation/*/send_leave/{roomId}/{eventId}` +//! //! Endpoint to submits a signed leave event to the receiving server for it to accept it into the //! room's graph. diff --git a/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs b/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs index 45d162b6..833957c9 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs @@ -1,4 +1,6 @@ -//! [PUT /_matrix/federation/v1/send_leave/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-send-leave-roomid-eventid) +//! `/v1/` ([spec]) +//! +//! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv1send_leaveroomideventid use js_int::UInt; use ruma_api::ruma_api; diff --git a/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs b/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs index 1b1429e8..e281ac3a 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs @@ -1,4 +1,6 @@ -//! [PUT /_matrix/federation/v2/send_leave/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-send-leave-roomid-eventid) +//! `/v2/` ([spec]) +//! +//! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv2send_leaveroomideventid use ruma_api::ruma_api; use ruma_identifiers::{EventId, RoomId}; diff --git a/crates/ruma-federation-api/src/membership/get_leave_event.rs b/crates/ruma-federation-api/src/membership/get_leave_event.rs index 65a72f7f..b2168851 100644 --- a/crates/ruma-federation-api/src/membership/get_leave_event.rs +++ b/crates/ruma-federation-api/src/membership/get_leave_event.rs @@ -1,4 +1,66 @@ +//! `GET /_matrix/federation/*/make_leave/{roomId}/{userId}` +//! //! Endpoint to asks the receiving server to return information that the sending server will need //! to prepare a leave event to get out of the room. -pub mod v1; +pub mod v1 { + //! [GET /_matrix/federation/v1/make_leave/{roomId}/{userId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-make-leave-roomid-userid) + + use ruma_api::ruma_api; + use ruma_identifiers::{RoomId, RoomVersionId, UserId}; + + use serde_json::value::RawValue as RawJsonValue; + + ruma_api! { + metadata: { + description: "Asks the receiving server to return information that the sending server will need to prepare a leave event to get out of the room.", + name: "get_leave_event", + method: GET, + stable_path: "/_matrix/federation/v1/make_leave/:room_id/:user_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// The room ID that is about to be left. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The user ID the leave event will be for. + #[ruma_api(path)] + pub user_id: &'a UserId, + } + + response: { + /// The version of the room where the server is trying to leave. + /// + /// If not provided, the room version is assumed to be either "1" or "2". + pub room_version: Option, + + /// An unsigned template event. + /// + /// Note that events have a different format depending on the room version - check the room + /// version specification for precise event formats. + pub event: Box, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with: + /// * the room ID that is about to be left. + /// * the user ID the leave event will be for. + pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { + Self { room_id, user_id } + } + } + + impl Response { + /// Creates a new `Response` with: + /// * the version of the room where the server is trying to leave. + /// * an unsigned template event. + pub fn new(room_version: Option, event: Box) -> Self { + Self { room_version, event } + } + } +} diff --git a/crates/ruma-federation-api/src/membership/get_leave_event/v1.rs b/crates/ruma-federation-api/src/membership/get_leave_event/v1.rs deleted file mode 100644 index 69668ac0..00000000 --- a/crates/ruma-federation-api/src/membership/get_leave_event/v1.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! [GET /_matrix/federation/v1/make_leave/{roomId}/{userId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-make-leave-roomid-userid) - -use ruma_api::ruma_api; -use ruma_identifiers::{RoomId, RoomVersionId, UserId}; - -use serde_json::value::RawValue as RawJsonValue; - -ruma_api! { - metadata: { - description: "Asks the receiving server to return information that the sending server will need to prepare a leave event to get out of the room.", - name: "get_leave_event", - method: GET, - stable_path: "/_matrix/federation/v1/make_leave/:room_id/:user_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// The room ID that is about to be left. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// The user ID the leave event will be for. - #[ruma_api(path)] - pub user_id: &'a UserId, - } - - response: { - /// The version of the room where the server is trying to leave. - /// - /// If not provided, the room version is assumed to be either "1" or "2". - pub room_version: Option, - - /// An unsigned template event. - /// - /// Note that events have a different format depending on the room version - check the room - /// version specification for precise event formats. - pub event: Box, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with: - /// * the room ID that is about to be left. - /// * the user ID the leave event will be for. - pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { - Self { room_id, user_id } - } -} - -impl Response { - /// Creates a new `Response` with: - /// * the version of the room where the server is trying to leave. - /// * an unsigned template event. - pub fn new(room_version: Option, event: Box) -> Self { - Self { room_version, event } - } -} diff --git a/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs b/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs index 2166974b..8559d7de 100644 --- a/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs +++ b/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs @@ -1,3 +1,49 @@ +//! `GET /_matrix/federation/*/openid/userinfo` +//! //! Endpdoint for retrieving OpenID userinfo. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1openiduserinfo + + use ruma_api::ruma_api; + use ruma_identifiers::UserId; + + ruma_api! { + metadata: { + description: "Exchanges an OpenID access token for information about the user who generated the token.", + method: GET, + name: "get_openid_userinfo", + stable_path: "/_matrix/federation/v1/openid/userinfo", + rate_limited: false, + authentication: None, + added: 1.0, + } + + request: { + /// The OpenID access token to get information about the owner for. + #[ruma_api(query)] + pub access_token: &'a str, + } + + response: { + /// The Matrix User ID who generated the token. + pub sub: Box, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given access token. + pub fn new(access_token: &'a str) -> Self { + Self { access_token } + } + } + + impl Response { + /// Creates a new `Response` with the given user id. + pub fn new(sub: Box) -> Self { + Self { sub } + } + } +} diff --git a/crates/ruma-federation-api/src/openid/get_openid_userinfo/v1.rs b/crates/ruma-federation-api/src/openid/get_openid_userinfo/v1.rs deleted file mode 100644 index fb51cbd2..00000000 --- a/crates/ruma-federation-api/src/openid/get_openid_userinfo/v1.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! [GET /_matrix/federation/v1/openid/userinfo](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-openid-userinfo) - -use ruma_api::ruma_api; -use ruma_identifiers::UserId; - -ruma_api! { - metadata: { - description: "Exchanges an OpenID access token for information about the user who generated the token.", - method: GET, - name: "get_openid_userinfo", - stable_path: "/_matrix/federation/v1/openid/userinfo", - rate_limited: false, - authentication: None, - added: 1.0, - } - - request: { - /// The OpenID access token to get information about the owner for. - #[ruma_api(query)] - pub access_token: &'a str, - } - - response: { - /// The Matrix User ID who generated the token. - pub sub: Box, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given access token. - pub fn new(access_token: &'a str) -> Self { - Self { access_token } - } -} - -impl Response { - /// Creates a new `Response` with the given user id. - pub fn new(sub: Box) -> Self { - Self { sub } - } -} diff --git a/crates/ruma-federation-api/src/query/get_custom_information.rs b/crates/ruma-federation-api/src/query/get_custom_information.rs index b52ed1ef..5d8110a1 100644 --- a/crates/ruma-federation-api/src/query/get_custom_information.rs +++ b/crates/ruma-federation-api/src/query/get_custom_information.rs @@ -1,3 +1,56 @@ +//! `GET /_matrix/federation/*/query/{queryType}` +//! //! Generic query endpoint for performing custom queries. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1queryquerytype + + use std::collections::BTreeMap; + + use ruma_api::ruma_api; + use serde_json::Value as JsonValue; + + ruma_api! { + metadata: { + description: "Performs a single query request on the receiving homeserver. The query string arguments are dependent on which type of query is being made.", + method: GET, + name: "get_custom_information", + stable_path: "/_matrix/federation/v1/query/:query_type", + rate_limited: false, + authentication: AccessToken, + added: 1.0, + } + + request: { + /// The type of query to make. + #[ruma_api(path)] + pub query_type: &'a str, + + /// The query parameters. + #[ruma_api(query_map)] + pub params: BTreeMap, + } + + response: { + /// The body of the response. + #[ruma_api(body)] + pub body: JsonValue, + } + } + + impl<'a> Request<'a> { + /// Creates a new request with the given type and query parameters. + pub fn new(query_type: &'a str, params: BTreeMap) -> Self { + Self { query_type, params } + } + } + + impl Response { + /// Creates a new response with the given body. + pub fn new(body: JsonValue) -> Self { + Self { body } + } + } +} diff --git a/crates/ruma-federation-api/src/query/get_custom_information/v1.rs b/crates/ruma-federation-api/src/query/get_custom_information/v1.rs deleted file mode 100644 index dcc2fcd2..00000000 --- a/crates/ruma-federation-api/src/query/get_custom_information/v1.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! [GET /_matrix/federation/v1/query/{queryType}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-query-querytype) - -use std::collections::BTreeMap; - -use ruma_api::ruma_api; -use serde_json::Value as JsonValue; - -ruma_api! { - metadata: { - description: "Performs a single query request on the receiving homeserver. The query string arguments are dependent on which type of query is being made.", - method: GET, - name: "get_custom_information", - stable_path: "/_matrix/federation/v1/query/:query_type", - rate_limited: false, - authentication: AccessToken, - added: 1.0, - } - - request: { - /// The type of query to make. - #[ruma_api(path)] - pub query_type: &'a str, - - /// The query parameters. - #[ruma_api(query_map)] - pub params: BTreeMap, - } - - response: { - /// The body of the response. - #[ruma_api(body)] - pub body: JsonValue, - } -} - -impl<'a> Request<'a> { - /// Creates a new request with the given type and query parameters. - pub fn new(query_type: &'a str, params: BTreeMap) -> Self { - Self { query_type, params } - } -} - -impl Response { - /// Creates a new response with the given body. - pub fn new(body: JsonValue) -> Self { - Self { body } - } -} diff --git a/crates/ruma-federation-api/src/query/get_profile_information.rs b/crates/ruma-federation-api/src/query/get_profile_information.rs index 4454f06c..43d88323 100644 --- a/crates/ruma-federation-api/src/query/get_profile_information.rs +++ b/crates/ruma-federation-api/src/query/get_profile_information.rs @@ -1,3 +1,104 @@ +//! `GET /_matrix/federation/*/query/profile` +//! //! Endpoint to query profile information with a user id and optional field. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1queryprofile + + use ruma_api::ruma_api; + use ruma_identifiers::{MxcUri, UserId}; + use ruma_serde::StringEnum; + + use crate::PrivOwnedStr; + + ruma_api! { + metadata: { + description: "Get profile information, such as a display name or avatar, for a given user.", + name: "get_profile_information", + method: GET, + stable_path: "/_matrix/federation/v1/query/profile", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// User ID to query. + #[ruma_api(query)] + pub user_id: &'a UserId, + + /// Profile field to query. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub field: Option<&'a ProfileField>, + } + + #[derive(Default)] + response: { + /// Display name of the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, + + /// Avatar URL for the user's avatar. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will result + /// in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_serde::empty_string_as_none") + )] + pub avatar_url: Option>, + + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448). + #[cfg(feature = "unstable-msc2448")] + #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] + pub blurhash: Option, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given user id. + pub fn new(user_id: &'a UserId) -> Self { + Self { user_id, field: None } + } + } + + impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Default::default() + } + } + + /// Profile fields to specify in query. + /// + /// This type can hold an arbitrary string. To check for formats that are not available as a + /// documented variant here, use its string representation, obtained through `.as_str()`. + #[derive(Clone, Debug, PartialEq, Eq, StringEnum)] + #[non_exhaustive] + pub enum ProfileField { + /// Display name of the user. + #[ruma_enum(rename = "displayname")] + DisplayName, + + /// Avatar URL for the user's avatar. + #[ruma_enum(rename = "avatar_url")] + AvatarUrl, + + #[doc(hidden)] + _Custom(PrivOwnedStr), + } + + impl ProfileField { + /// Creates a string slice from this `ProfileField`. + pub fn as_str(&self) -> &str { + self.as_ref() + } + } +} diff --git a/crates/ruma-federation-api/src/query/get_profile_information/v1.rs b/crates/ruma-federation-api/src/query/get_profile_information/v1.rs deleted file mode 100644 index 7261275a..00000000 --- a/crates/ruma-federation-api/src/query/get_profile_information/v1.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! [GET /_matrix/federation/v1/query/profile](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-query-profile) - -use ruma_api::ruma_api; -use ruma_identifiers::{MxcUri, UserId}; -use ruma_serde::StringEnum; - -use crate::PrivOwnedStr; - -ruma_api! { - metadata: { - description: "Get profile information, such as a display name or avatar, for a given user.", - name: "get_profile_information", - method: GET, - stable_path: "/_matrix/federation/v1/query/profile", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// User ID to query. - #[ruma_api(query)] - pub user_id: &'a UserId, - - /// Profile field to query. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub field: Option<&'a ProfileField>, - } - - #[derive(Default)] - response: { - /// Display name of the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, - - /// Avatar URL for the user's avatar. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_serde::empty_string_as_none") - )] - pub avatar_url: Option>, - - /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. - /// - /// This uses the unstable prefix in - /// [MSC2448](https://github.com/matrix-org/matrix-doc/pull/2448). - #[cfg(feature = "unstable-msc2448")] - #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] - pub blurhash: Option, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given user id. - pub fn new(user_id: &'a UserId) -> Self { - Self { user_id, field: None } - } -} - -impl Response { - /// Creates an empty `Response`. - pub fn new() -> Self { - Default::default() - } -} - -/// Profile fields to specify in query. -/// -/// This type can hold an arbitrary string. To check for formats that are not available as a -/// documented variant here, use its string representation, obtained through `.as_str()`. -#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] -#[non_exhaustive] -pub enum ProfileField { - /// Display name of the user. - #[ruma_enum(rename = "displayname")] - DisplayName, - - /// Avatar URL for the user's avatar. - #[ruma_enum(rename = "avatar_url")] - AvatarUrl, - - #[doc(hidden)] - _Custom(PrivOwnedStr), -} - -impl ProfileField { - /// Creates a string slice from this `ProfileField`. - pub fn as_str(&self) -> &str { - self.as_ref() - } -} diff --git a/crates/ruma-federation-api/src/query/get_room_information.rs b/crates/ruma-federation-api/src/query/get_room_information.rs index 0779d3ef..5c7c95e5 100644 --- a/crates/ruma-federation-api/src/query/get_room_information.rs +++ b/crates/ruma-federation-api/src/query/get_room_information.rs @@ -1,3 +1,52 @@ +//! `GET /_matrix/federation/*/query/directory` +//! //! Endpoint to query room information with a room alias. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#get_matrixfederationv1querydirectory + + use ruma_api::ruma_api; + use ruma_identifiers::{RoomAliasId, RoomId, ServerName}; + + ruma_api! { + metadata: { + description: "Get mapped room ID and resident homeservers for a given room alias.", + name: "get_room_information", + method: GET, + stable_path: "/_matrix/federation/v1/query/directory", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// Room alias to query. + #[ruma_api(query)] + pub room_alias: &'a RoomAliasId, + } + + response: { + /// Room ID mapped to queried alias. + pub room_id: Box, + + /// An array of server names that are likely to hold the given room. + pub servers: Vec>, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given room alias ID. + pub fn new(room_alias: &'a RoomAliasId) -> Self { + Self { room_alias } + } + } + + impl Response { + /// Creates a new `Response` with the given room IDs and servers. + pub fn new(room_id: Box, servers: Vec>) -> Self { + Self { room_id, servers } + } + } +} diff --git a/crates/ruma-federation-api/src/query/get_room_information/v1.rs b/crates/ruma-federation-api/src/query/get_room_information/v1.rs deleted file mode 100644 index 38913cca..00000000 --- a/crates/ruma-federation-api/src/query/get_room_information/v1.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! [GET /_matrix/federation/v1/query/directory](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-query-directory) - -use ruma_api::ruma_api; -use ruma_identifiers::{RoomAliasId, RoomId, ServerName}; - -ruma_api! { - metadata: { - description: "Get mapped room ID and resident homeservers for a given room alias.", - name: "get_room_information", - method: GET, - stable_path: "/_matrix/federation/v1/query/directory", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// Room alias to query. - #[ruma_api(query)] - pub room_alias: &'a RoomAliasId, - } - - response: { - /// Room ID mapped to queried alias. - pub room_id: Box, - - /// An array of server names that are likely to hold the given room. - pub servers: Vec>, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given room alias ID. - pub fn new(room_alias: &'a RoomAliasId) -> Self { - Self { room_alias } - } -} - -impl Response { - /// Creates a new `Response` with the given room IDs and servers. - pub fn new(room_id: Box, servers: Vec>) -> Self { - Self { room_id, servers } - } -} diff --git a/crates/ruma-federation-api/src/thirdparty/bind_callback.rs b/crates/ruma-federation-api/src/thirdparty/bind_callback.rs index bb7a8951..c4df5de3 100644 --- a/crates/ruma-federation-api/src/thirdparty/bind_callback.rs +++ b/crates/ruma-federation-api/src/thirdparty/bind_callback.rs @@ -1,4 +1,105 @@ +//! `PUT /_matrix/federation/*/3pid/onbind` +//! //! Used by identity servers to notify the homeserver that one of its users has bound a third party //! identifier successfully, including any pending room invites the identity server has been made //! aware of. -pub mod v1; + +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv13pidonbind + + use std::collections::BTreeMap; + + use ruma_api::ruma_api; + use ruma_common::thirdparty::Medium; + use ruma_identifiers::{RoomId, ServerName, ServerSigningKeyId, UserId}; + use serde::{Deserialize, Serialize}; + + ruma_api! { + metadata: { + description: "Used by identity servers to notify the homeserver that one of its users has bound a third party identifier successfully", + method: PUT, + name: "bind_callback", + stable_path: "/_matrix/federation/v1/3pid/onbind", + rate_limited: false, + authentication: None, + added: 1.0, + } + + request: { + /// The type of third party identifier. + /// + /// Currently only `Medium::Email` is supported. + pub medium: &'a Medium, + + /// The third party identifier itself. + /// + /// For example: an email address. + pub address: &'a str, + + /// The user that is now bound to the third party identifier. + pub mxid: &'a UserId, + + /// A list of pending invites that the third party identifier has received. + pub invites: &'a [ThirdPartyInvite], + } + + response: {} + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given medium, address, user ID and third party invites. + pub fn new( + medium: &'a Medium, + address: &'a str, + mxid: &'a UserId, + invites: &'a [ThirdPartyInvite], + ) -> Self { + Self { medium, address, mxid, invites } + } + + /// Creates a new `Request` with the given email address, user ID and third party invites. + pub fn email(address: &'a str, mxid: &'a UserId, invites: &'a [ThirdPartyInvite]) -> Self { + Self::new(&Medium::Email, address, mxid, invites) + } + } + + /// A pending invite the third party identifier has received. + #[derive(Debug, Clone, Deserialize, Serialize)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] + pub struct ThirdPartyInvite { + /// The type of third party invite issues. + /// + /// Currently only `Medium::Email` is used. + pub medium: Medium, + + /// The third party identifier that received the invite. + pub address: String, + + /// The now-bound user ID that received the invite. + pub mxid: Box, + + /// The room ID the invite is valid for. + pub room_id: Box, + + /// The user ID that sent the invite. + pub sender: Box, + + /// Signature from the identity server using a long-term private key. + pub signed: BTreeMap, BTreeMap, String>>, + } + + impl ThirdPartyInvite { + /// Creates a new third party invite with the given parameters. + pub fn new( + address: String, + mxid: Box, + room_id: Box, + sender: Box, + signed: BTreeMap, BTreeMap, String>>, + ) -> Self { + Self { medium: Medium::Email, address, mxid, room_id, sender, signed } + } + } +} diff --git a/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs b/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs deleted file mode 100644 index 765943a2..00000000 --- a/crates/ruma-federation-api/src/thirdparty/bind_callback/v1.rs +++ /dev/null @@ -1,95 +0,0 @@ -//! [PUT /_matrix/federation/v1/3pid/onbind](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-3pid-onbind) - -use std::collections::BTreeMap; - -use ruma_api::ruma_api; -use ruma_common::thirdparty::Medium; -use ruma_identifiers::{RoomId, ServerName, ServerSigningKeyId, UserId}; -use serde::{Deserialize, Serialize}; - -ruma_api! { - metadata: { - description: "Used by identity servers to notify the homeserver that one of its users has bound a third party identifier successfully", - method: PUT, - name: "bind_callback", - stable_path: "/_matrix/federation/v1/3pid/onbind", - rate_limited: false, - authentication: None, - added: 1.0, - } - - request: { - /// The type of third party identifier. - /// - /// Currently only `Medium::Email` is supported. - pub medium: &'a Medium, - - /// The third party identifier itself. - /// - /// For example: an email address. - pub address: &'a str, - - /// The user that is now bound to the third party identifier. - pub mxid: &'a UserId, - - /// A list of pending invites that the third party identifier has received. - pub invites: &'a [ThirdPartyInvite], - } - - response: {} -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given medium, address, user ID and third party invites. - pub fn new( - medium: &'a Medium, - address: &'a str, - mxid: &'a UserId, - invites: &'a [ThirdPartyInvite], - ) -> Self { - Self { medium, address, mxid, invites } - } - - /// Creates a new `Request` with the given email address, user ID and third party invites. - pub fn email(address: &'a str, mxid: &'a UserId, invites: &'a [ThirdPartyInvite]) -> Self { - Self::new(&Medium::Email, address, mxid, invites) - } -} - -/// A pending invite the third party identifier has received. -#[derive(Debug, Clone, Deserialize, Serialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct ThirdPartyInvite { - /// The type of third party invite issues. - /// - /// Currently only `Medium::Email` is used. - pub medium: Medium, - - /// The third party identifier that received the invite. - pub address: String, - - /// The now-bound user ID that received the invite. - pub mxid: Box, - - /// The room ID the invite is valid for. - pub room_id: Box, - - /// The user ID that sent the invite. - pub sender: Box, - - /// Signature from the identity server using a long-term private key. - pub signed: BTreeMap, BTreeMap, String>>, -} - -impl ThirdPartyInvite { - /// Creates a new third party invite with the given parameters. - pub fn new( - address: String, - mxid: Box, - room_id: Box, - sender: Box, - signed: BTreeMap, BTreeMap, String>>, - ) -> Self { - Self { medium: Medium::Email, address, mxid, room_id, sender, signed } - } -} diff --git a/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs b/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs index 4b3999b9..563554d3 100644 --- a/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs +++ b/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs @@ -1,7 +1,72 @@ +//! `PUT /_matrix/federation/*/exchange_third_party_invite/{roomId}` +//! //! The receiving server will verify the partial `m.room.member` event given in the request body. //! If valid, the receiving server will issue an invite as per the [Inviting to a room] section //! before returning a response to this request. //! -//! [Inviting to a room]: https://matrix.org/docs/spec/server_server/r0.1.4#inviting-to-a-room +//! [Inviting to a room]: https://spec.matrix.org/v1.2/server-server-api/#inviting-to-a-room -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv1exchange_third_party_inviteroomid + + use ruma_api::ruma_api; + use ruma_events::{room::member::ThirdPartyInvite, EventType}; + use ruma_identifiers::{RoomId, UserId}; + + ruma_api! { + metadata: { + description: "The receiving server will verify the partial m.room.member event given in the request body.", + method: PUT, + name: "exchange_invite", + stable_path: "/_matrix/federation/v1/exchange_third_party_invite/:room_id", + rate_limited: false, + authentication: AccessToken, + added: 1.0, + } + + request: { + /// The room ID to exchange a third party invite in. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The event type. + /// + /// Must be `EventType::RoomMember`. + #[serde(rename = "type")] + pub kind: EventType, + + /// The user ID of the user who sent the original invite event. + pub sender: &'a UserId, + + /// The user ID of the invited user. + pub state_key: &'a UserId, + + /// The content of the invite event. + pub content: &'a ThirdPartyInvite, + } + + #[derive(Default)] + response: {} + } + + impl<'a> Request<'a> { + /// Creates a new `Request` for a third party invite exchange + pub fn new( + room_id: &'a RoomId, + sender: &'a UserId, + state_key: &'a UserId, + content: &'a ThirdPartyInvite, + ) -> Self { + Self { room_id, kind: EventType::RoomMember, sender, state_key, content } + } + } + + impl Response { + /// Creates a new `Response`. + pub fn new() -> Self { + Self {} + } + } +} diff --git a/crates/ruma-federation-api/src/thirdparty/exchange_invite/v1.rs b/crates/ruma-federation-api/src/thirdparty/exchange_invite/v1.rs deleted file mode 100644 index 1d9dca67..00000000 --- a/crates/ruma-federation-api/src/thirdparty/exchange_invite/v1.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! [PUT /_matrix/federation/v1/exchange_third_party_invite/{roomId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-exchange-third-party-invite-roomid) - -use ruma_api::ruma_api; -use ruma_events::{room::member::ThirdPartyInvite, EventType}; -use ruma_identifiers::{RoomId, UserId}; - -ruma_api! { - metadata: { - description: "The receiving server will verify the partial m.room.member event given in the request body.", - method: PUT, - name: "exchange_invite", - stable_path: "/_matrix/federation/v1/exchange_third_party_invite/:room_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, - } - - request: { - /// The room ID to exchange a third party invite in. - #[ruma_api(path)] - pub room_id: &'a RoomId, - - /// The event type. - /// - /// Must be `EventType::RoomMember`. - #[serde(rename = "type")] - pub kind: EventType, - - /// The user ID of the user who sent the original invite event. - pub sender: &'a UserId, - - /// The user ID of the invited user. - pub state_key: &'a UserId, - - /// The content of the invite event. - pub content: &'a ThirdPartyInvite, - } - - #[derive(Default)] - response: {} -} - -impl<'a> Request<'a> { - /// Creates a new `Request` for a third party invite exchange - pub fn new( - room_id: &'a RoomId, - sender: &'a UserId, - state_key: &'a UserId, - content: &'a ThirdPartyInvite, - ) -> Self { - Self { room_id, kind: EventType::RoomMember, sender, state_key, content } - } -} - -impl Response { - /// Creates a new `Response`. - pub fn new() -> Self { - Self {} - } -} diff --git a/crates/ruma-federation-api/src/transactions/send_transaction_message.rs b/crates/ruma-federation-api/src/transactions/send_transaction_message.rs index 135bfb5f..093ab90d 100644 --- a/crates/ruma-federation-api/src/transactions/send_transaction_message.rs +++ b/crates/ruma-federation-api/src/transactions/send_transaction_message.rs @@ -1,3 +1,90 @@ +//! `PUT /_matrix/federation/*/send/{txnId}` +//! //! Endpoint to send live activity messages to another server. -pub mod v1; +pub mod v1 { + //! `/v1/` ([spec]) + //! + //! [spec]: https://spec.matrix.org/v1.2/server-server-api/#put_matrixfederationv1sendtxnid + + use std::collections::BTreeMap; + + use ruma_api::ruma_api; + use ruma_common::MilliSecondsSinceUnixEpoch; + use ruma_identifiers::{EventId, ServerName, TransactionId}; + use ruma_serde::Raw; + use serde_json::value::RawValue as RawJsonValue; + + use crate::transactions::edu::Edu; + + ruma_api! { + metadata: { + description: "Send transaction messages to another server", + name: "send_transaction_message", + method: PUT, + stable_path: "/_matrix/federation/v1/send/:transaction_id", + rate_limited: false, + authentication: ServerSignatures, + added: 1.0, + } + + request: { + /// A transaction ID unique between sending and receiving homeservers. + #[ruma_api(path)] + pub transaction_id: &'a TransactionId, + + /// The server_name of the homeserver sending this transaction. + pub origin: &'a ServerName, + + /// POSIX timestamp in milliseconds on the originating homeserver when this transaction + /// started. + pub origin_server_ts: MilliSecondsSinceUnixEpoch, + + /// List of persistent updates to rooms. + /// + /// Must not be more than 50 items. + /// + /// With the `unstable-pre-spec` feature, sending `pdus` is optional. + /// See [matrix-doc#2824](https://github.com/matrix-org/matrix-doc/issues/2824). + #[cfg_attr(feature = "unstable-pre-spec", serde(default, skip_serializing_if = "<[_]>::is_empty"))] + pub pdus: &'a [Box], + + /// List of ephemeral messages. + /// + /// Must not be more than 100 items. + #[serde(default, skip_serializing_if = "<[_]>::is_empty")] + pub edus: &'a [Raw], + } + + #[derive(Default)] + response: { + /// Map of event IDs and response for each PDU given in the request. + /// + /// With the `unstable-msc3618` feature, returning `pdus` is optional. + /// See [MSC3618](https://github.com/matrix-org/matrix-doc/pull/3618). + #[cfg_attr(feature = "unstable-msc3618", serde(default))] + #[serde(with = "crate::serde::pdu_process_response")] + pub pdus: BTreeMap, Result<(), String>>, + } + } + + impl<'a> Request<'a> { + /// Creates a new `Request` with the given transaction ID, origin, timestamp. + /// + /// The PDU and EDU lists will start off empty. + pub fn new( + transaction_id: &'a TransactionId, + origin: &'a ServerName, + origin_server_ts: MilliSecondsSinceUnixEpoch, + ) -> Self { + Self { transaction_id, origin, origin_server_ts, pdus: &[], edus: &[] } + } + } + + impl Response { + /// Creates a new `Response` with the given PDUs. + pub fn new(pdus: BTreeMap, Result<(), String>>) -> Self { + Self { pdus } + } + } +} diff --git a/crates/ruma-federation-api/src/transactions/send_transaction_message/v1.rs b/crates/ruma-federation-api/src/transactions/send_transaction_message/v1.rs deleted file mode 100644 index 505f1de5..00000000 --- a/crates/ruma-federation-api/src/transactions/send_transaction_message/v1.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! [PUT /_matrix/federation/v1/send/{txnId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-send-txnid) - -use std::collections::BTreeMap; - -use ruma_api::ruma_api; -use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_identifiers::{EventId, ServerName, TransactionId}; -use ruma_serde::Raw; -use serde_json::value::RawValue as RawJsonValue; - -use crate::transactions::edu::Edu; - -ruma_api! { - metadata: { - description: "Send transaction messages to another server", - name: "send_transaction_message", - method: PUT, - stable_path: "/_matrix/federation/v1/send/:transaction_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, - } - - request: { - /// A transaction ID unique between sending and receiving homeservers. - #[ruma_api(path)] - pub transaction_id: &'a TransactionId, - - /// The server_name of the homeserver sending this transaction. - pub origin: &'a ServerName, - - /// POSIX timestamp in milliseconds on the originating homeserver when this transaction - /// started. - pub origin_server_ts: MilliSecondsSinceUnixEpoch, - - /// List of persistent updates to rooms. - /// - /// Must not be more than 50 items. - /// - /// With the `unstable-pre-spec` feature, sending `pdus` is optional. - /// See [matrix-doc#2824](https://github.com/matrix-org/matrix-doc/issues/2824). - #[cfg_attr(feature = "unstable-pre-spec", serde(default, skip_serializing_if = "<[_]>::is_empty"))] - pub pdus: &'a [Box], - - /// List of ephemeral messages. - /// - /// Must not be more than 100 items. - #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub edus: &'a [Raw], - } - - #[derive(Default)] - response: { - /// Map of event IDs and response for each PDU given in the request. - /// - /// With the `unstable-msc3618` feature, returning `pdus` is optional. - /// See [MSC3618](https://github.com/matrix-org/matrix-doc/pull/3618). - #[cfg_attr(feature = "unstable-msc3618", serde(default))] - #[serde(with = "crate::serde::pdu_process_response")] - pub pdus: BTreeMap, Result<(), String>>, - } -} - -impl<'a> Request<'a> { - /// Creates a new `Request` with the given transaction ID, origin, timestamp. - /// - /// The PDU and EDU lists will start off empty. - pub fn new( - transaction_id: &'a TransactionId, - origin: &'a ServerName, - origin_server_ts: MilliSecondsSinceUnixEpoch, - ) -> Self { - Self { transaction_id, origin, origin_server_ts, pdus: &[], edus: &[] } - } -} - -impl Response { - /// Creates a new `Response` with the given PDUs. - pub fn new(pdus: BTreeMap, Result<(), String>>) -> Self { - Self { pdus } - } -}