ruma-federation-api: Refactor file structure and add docs

This commit is contained in:
Jonathan de Jong 2022-02-13 17:15:55 +01:00 committed by Jonas Platte
parent 66b939e6b8
commit 5768f181ca
63 changed files with 1835 additions and 1681 deletions

View File

@ -1,3 +1,55 @@
//! `GET /_matrix/federation/*/event_auth/{roomId}/{eventId}`
//!
//! Endpoint to retrieve the complete auth chain for a given event. //! 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<Box<RawJsonValue>>,
}
}
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<Box<RawJsonValue>>) -> Self {
Self { auth_chain }
}
}
}

View File

@ -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<Box<RawJsonValue>>,
}
}
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<Box<RawJsonValue>>) -> Self {
Self { auth_chain }
}
}

View File

@ -1,3 +1,77 @@
//! `GET /_matrix/federation/*/backfill/{roomId}`
//!
//! Endpoint to request more history from another homeserver. //! 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<EventId>],
/// 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<ServerName>,
/// 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<Box<RawJsonValue>>,
}
}
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<EventId>], 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<ServerName>,
origin_server_ts: MilliSecondsSinceUnixEpoch,
pdus: Vec<Box<RawJsonValue>>,
) -> Self {
Self { origin, origin_server_ts, pdus }
}
}
}

View File

@ -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<EventId>],
/// 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<ServerName>,
/// 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<Box<RawJsonValue>>,
}
}
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<EventId>], 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<ServerName>,
origin_server_ts: MilliSecondsSinceUnixEpoch,
pdus: Vec<Box<RawJsonValue>>,
) -> Self {
Self { origin, origin_server_ts, pdus }
}
}

View File

@ -1,3 +1,88 @@
//! `GET /_matrix/federation/*/user/devices/{userId}`
//!
//! Endpoint to get information about a user's devices //! 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<UserId>,
/// 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<UserDevice>,
}
}
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<UserId>, 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<DeviceId>,
/// Identity keys for the device.
pub keys: Raw<DeviceKeys>,
/// Optional display name for the device
#[serde(skip_serializing_if = "Option::is_none")]
pub device_display_name: Option<String>,
}
impl UserDevice {
/// Creates a new `UserDevice` with the given device id and keys.
pub fn new(device_id: Box<DeviceId>, keys: Raw<DeviceKeys>) -> Self {
Self { device_id, keys, device_display_name: None }
}
}
}

View File

@ -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<UserId>,
/// 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<UserDevice>,
}
}
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<UserId>, 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<DeviceId>,
/// Identity keys for the device.
pub keys: Raw<DeviceKeys>,
/// Optional display name for the device
#[serde(skip_serializing_if = "Option::is_none")]
pub device_display_name: Option<String>,
}
impl UserDevice {
/// Creates a new `UserDevice` with the given device id and keys.
pub fn new(device_id: Box<DeviceId>, keys: Raw<DeviceKeys>) -> Self {
Self { device_id, keys, device_display_name: None }
}
}

View File

@ -1,3 +1,74 @@
//! `GET /_matrix/federation/*/publicRooms`
//!
//! Endpoint to query a homeserver's public rooms. //! 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<UInt>,
/// 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<PublicRoomsChunk>,
/// A pagination token for the response.
#[serde(skip_serializing_if = "Option::is_none")]
pub next_batch: Option<String>,
/// A pagination token that allows fetching previous results.
#[serde(skip_serializing_if = "Option::is_none")]
pub prev_batch: Option<String>,
/// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>,
}
}
impl Request<'_> {
/// Creates an empty `Request`.
pub fn new() -> Self {
Default::default()
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Default::default()
}
}
}

View File

@ -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<UInt>,
/// 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<PublicRoomsChunk>,
/// A pagination token for the response.
#[serde(skip_serializing_if = "Option::is_none")]
pub next_batch: Option<String>,
/// A pagination token that allows fetching previous results.
#[serde(skip_serializing_if = "Option::is_none")]
pub prev_batch: Option<String>,
/// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>,
}
}
impl Request<'_> {
/// Creates an empty `Request`.
pub fn new() -> Self {
Default::default()
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Default::default()
}
}

View File

@ -1,3 +1,75 @@
//! `POST /_matrix/federation/*/publicRooms`
//!
//! Endpoint to query a homeserver's public rooms with an optional filter. //! 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<UInt>,
/// 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<PublicRoomsChunk>,
/// A pagination token for the response.
pub next_batch: Option<String>,
/// A pagination token that allows fetching previous results.
pub prev_batch: Option<String>,
/// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>,
}
}
impl Request<'_> {
/// Creates an empty `Request`.
pub fn new() -> Self {
Default::default()
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Default::default()
}
}
}

View File

@ -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<UInt>,
/// 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<PublicRoomsChunk>,
/// A pagination token for the response.
pub next_batch: Option<String>,
/// A pagination token that allows fetching previous results.
pub prev_batch: Option<String>,
/// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>,
}
}
impl Request<'_> {
/// Creates an empty `Request`.
pub fn new() -> Self {
Default::default()
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Default::default()
}
}

View File

@ -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_api::ruma_api;
use ruma_identifiers::ServerName; use ruma_identifiers::ServerName;

View File

@ -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 //! Query for another server's keys. The receiving (notary) server must sign the keys returned by
//! the queried server. //! 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<ServerSigningKeys>,
}
}
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<ServerSigningKeys>) -> Self {
Self { server_keys }
}
}
}

View File

@ -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<ServerSigningKeys>,
}
}
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<ServerSigningKeys>) -> Self {
Self { server_keys }
}
}

View File

@ -1,4 +1,92 @@
//! `POST /_matrix/key/*/query`
//!
//! Query for keys from multiple servers in a batch format. The receiving (notary) server must sign //! Query for keys from multiple servers in a batch format. The receiving (notary) server must sign
//! the keys returned by the queried servers. //! 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<Box<ServerName>, BTreeMap<Box<ServerSigningKeyId>, QueryCriteria>>,
}
response: {
/// The queried server's keys, signed by the notary server.
pub server_keys: Vec<ServerSigningKeys>,
}
}
impl Request {
/// Creates a new `Request` with the given query criteria.
pub fn new(
server_keys: BTreeMap<
Box<ServerName>,
BTreeMap<Box<ServerSigningKeyId>, QueryCriteria>,
>,
) -> Self {
Self { server_keys }
}
}
impl Response {
/// Creates a new `Response` with the given keys.
pub fn new(server_keys: Vec<ServerSigningKeys>) -> 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<MilliSecondsSinceUnixEpoch>,
}
impl QueryCriteria {
/// Creates empty `QueryCriteria`.
pub fn new() -> Self {
Default::default()
}
}
}

View File

@ -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<Box<ServerName>, BTreeMap<Box<ServerSigningKeyId>, QueryCriteria>>,
}
response: {
/// The queried server's keys, signed by the notary server.
pub server_keys: Vec<ServerSigningKeys>,
}
}
impl Request {
/// Creates a new `Request` with the given query criteria.
pub fn new(
server_keys: BTreeMap<Box<ServerName>, BTreeMap<Box<ServerSigningKeyId>, QueryCriteria>>,
) -> Self {
Self { server_keys }
}
}
impl Response {
/// Creates a new `Response` with the given keys.
pub fn new(server_keys: Vec<ServerSigningKeys>) -> 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<MilliSecondsSinceUnixEpoch>,
}
impl QueryCriteria {
/// Creates empty `QueryCriteria`.
pub fn new() -> Self {
Default::default()
}
}

View File

@ -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<ServerSigningKeys> for Response {
fn from(server_key: ServerSigningKeys) -> Self {
Self::new(server_key)
}
}
}

View File

@ -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<ServerSigningKeys> for Response {
fn from(server_key: ServerSigningKeys) -> Self {
Self::new(server_key)
}
}

View File

@ -1,3 +1,70 @@
//! `GET /_matrix/federation/*/version`
//!
//! Endpoint to retrieve metadata about a server implementation. //! 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<Server>,
}
}
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<String>,
/// Version of this implementation.
///
/// The version format depends on the implementation.
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
impl Server {
/// Creates an empty `Server`.
pub fn new() -> Self {
Default::default()
}
}
}

View File

@ -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<Server>,
}
}
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<String>,
/// Version of this implementation.
///
/// The version format depends on the implementation.
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
impl Server {
/// Creates an empty `Server`.
pub fn new() -> Self {
Default::default()
}
}

View File

@ -1,3 +1,63 @@
//! `GET /_matrix/federation/*/event/{eventId}`
//!
//! Retrieves a single event. //! 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<ServerName>,
/// 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<RawJsonValue>,
}
}
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<ServerName>,
origin_server_ts: MilliSecondsSinceUnixEpoch,
pdu: Box<RawJsonValue>,
) -> Self {
Self { origin, origin_server_ts, pdu }
}
}
}

View File

@ -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<ServerName>,
/// 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<RawJsonValue>,
}
}
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<ServerName>,
origin_server_ts: MilliSecondsSinceUnixEpoch,
pdu: Box<RawJsonValue>,
) -> Self {
Self { origin, origin_server_ts, pdu }
}
}

View File

@ -1,3 +1,91 @@
//! `POST /_matrix/federation/*/get_missing_events/{roomId}`
//!
//! Retrieves previous events that the sender is missing. //! 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<EventId>],
/// The event IDs to retrieve the previous events for.
pub latest_events: &'a [Box<EventId>],
}
#[derive(Default)]
response: {
/// The missing PDUs.
pub events: Vec<Box<RawJsonValue>>,
}
}
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<EventId>],
latest_events: &'a [Box<EventId>],
) -> 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<Box<RawJsonValue>>) -> Self {
Self { events }
}
}
fn default_limit() -> UInt {
uint!(10)
}
fn is_default_limit(val: &UInt) -> bool {
*val == default_limit()
}
}

View File

@ -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<EventId>],
/// The event IDs to retrieve the previous events for.
pub latest_events: &'a [Box<EventId>],
}
#[derive(Default)]
response: {
/// The missing PDUs.
pub events: Vec<Box<RawJsonValue>>,
}
}
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<EventId>],
latest_events: &'a [Box<EventId>],
) -> 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<Box<RawJsonValue>>) -> Self {
Self { events }
}
}
fn default_limit() -> UInt {
uint!(10)
}
fn is_default_limit(val: &UInt) -> bool {
*val == default_limit()
}

View File

@ -1,3 +1,59 @@
//! `GET /_matrix/federation/*/state/{roomId}`
//!
//! Retrieves a snapshot of a room's state at a given event. //! 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<Box<RawJsonValue>>,
/// The fully resolved state of the room at the given event.
pub pdus: Vec<Box<RawJsonValue>>,
}
}
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<Box<RawJsonValue>>, pdus: Vec<Box<RawJsonValue>>) -> Self {
Self { auth_chain, pdus }
}
}
}

View File

@ -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<Box<RawJsonValue>>,
/// The fully resolved state of the room at the given event.
pub pdus: Vec<Box<RawJsonValue>>,
}
}
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<Box<RawJsonValue>>, pdus: Vec<Box<RawJsonValue>>) -> Self {
Self { auth_chain, pdus }
}
}

View File

@ -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. //! 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<Box<EventId>>,
/// The fully resolved state of the room at the given event.
pub pdu_ids: Vec<Box<EventId>>,
}
}
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<Box<EventId>>, pdu_ids: Vec<Box<EventId>>) -> Self {
Self { auth_chain_ids, pdu_ids }
}
}
}

View File

@ -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<Box<EventId>>,
/// The fully resolved state of the room at the given event.
pub pdu_ids: Vec<Box<EventId>>,
}
}
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<Box<EventId>>, pdu_ids: Vec<Box<EventId>>) -> Self {
Self { auth_chain_ids, pdu_ids }
}
}

View File

@ -1,3 +1,81 @@
//! `POST /_matrix/federation/*/user/keys/claim`
//!
//! Endpoint to claim one-time keys for use in pre-key messages //! 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<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>;
/// One time keys for use in pre-key messages
pub type OneTimeKeys =
BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>>;
/// 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<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
}
impl KeyObject {
/// Creates a new `KeyObject` with the given key and signatures.
pub fn new(
key: Base64,
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
) -> Self {
Self { key, signatures }
}
}
}

View File

@ -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<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>;
/// One time keys for use in pre-key messages
pub type OneTimeKeys =
BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>>;
/// 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<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
}
impl KeyObject {
/// Creates a new `KeyObject` with the given key and signatures.
pub fn new(
key: Base64,
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
) -> Self {
Self { key, signatures }
}
}

View File

@ -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 //! 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<Box<UserId>, Vec<Box<DeviceId>>>,
}
#[derive(Default)]
response: {
/// Keys from the queried devices.
pub device_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, Raw<DeviceKeys>>>,
/// Information on the master cross-signing keys of the queried users.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub master_keys: BTreeMap<Box<UserId>, Raw<CrossSigningKey>>,
/// Information on the self-signing keys of the queried users.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub self_signing_keys: BTreeMap<Box<UserId>, Raw<CrossSigningKey>>,
}
}
impl Request {
/// Creates a new `Request` asking for the given device keys.
pub fn new(device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>) -> Self {
Self { device_keys }
}
}
impl Response {
/// Creates a new `Response` with the given device keys.
pub fn new(
device_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, Raw<DeviceKeys>>>,
) -> Self {
Self { device_keys, ..Default::default() }
}
}
}

View File

@ -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<Box<UserId>, Vec<Box<DeviceId>>>,
}
#[derive(Default)]
response: {
/// Keys from the queried devices.
pub device_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, Raw<DeviceKeys>>>,
/// Information on the master cross-signing keys of the queried users.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub master_keys: BTreeMap<Box<UserId>, Raw<CrossSigningKey>>,
/// Information on the self-signing keys of the queried users.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub self_signing_keys: BTreeMap<Box<UserId>, Raw<CrossSigningKey>>,
}
}
impl Request {
/// Creates a new `Request` asking for the given device keys.
pub fn new(device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>) -> Self {
Self { device_keys }
}
}
impl Response {
/// Creates a new `Response` with the given device keys.
pub fn new(
device_keys: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, Raw<DeviceKeys>>>,
) -> Self {
Self { device_keys, ..Default::default() }
}
}

View File

@ -1,3 +1,66 @@
//! `GET /_matrix/federation/*/make_knock/{roomId}/{userId}`
//!
//! Endpoint to query information to prepare a knock event. //! 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<RawJsonValue>,
}
}
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<RawJsonValue>) -> Self {
Self { room_version, event }
}
}
}

View File

@ -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<RawJsonValue>,
}
}
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<RawJsonValue>) -> Self {
Self { room_version, event }
}
}

View File

@ -1,3 +1,61 @@
//! `PUT /_matrix/federation/*/send_knock/{roomId}/{eventId}`
//!
//! Endpoint to submit a signed knock event to the resident homeserver. //! 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<Raw<AnyStrippedStateEvent>>,
}
}
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<Raw<AnyStrippedStateEvent>>) -> Self {
Self { knock_room_state }
}
}
}

View File

@ -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<Raw<AnyStrippedStateEvent>>,
}
}
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<Raw<AnyStrippedStateEvent>>) -> Self {
Self { knock_room_state }
}
}

View File

@ -3,7 +3,7 @@
//! (De)serializable types for the [Matrix Server-Server API][federation-api]. //! (De)serializable types for the [Matrix Server-Server API][federation-api].
//! These types are used by server code. //! 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)] #![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]

View File

@ -1,3 +1,5 @@
//! `PUT /_matrix/federation/*/invite/{roomId}/{eventId}`
//!
//! Endpoint for inviting a remote user to a room //! Endpoint for inviting a remote user to a room
pub mod v1; pub mod v1;

View File

@ -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_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_common::MilliSecondsSinceUnixEpoch;

View File

@ -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_api::ruma_api;
use ruma_events::AnyStrippedStateEvent; use ruma_events::AnyStrippedStateEvent;

View File

@ -1,3 +1,5 @@
//! `PUT /_matrix/federation/*/send_join/{roomId}/{eventId}`
//!
//! Endpoint to send join events to remote homeservers. //! Endpoint to send join events to remote homeservers.
pub mod v1; pub mod v1;

View File

@ -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_api::ruma_api;
use ruma_identifiers::{EventId, RoomId}; use ruma_identifiers::{EventId, RoomId};

View File

@ -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_api::ruma_api;
use ruma_identifiers::{EventId, RoomId}; use ruma_identifiers::{EventId, RoomId};

View File

@ -1,3 +1,74 @@
//! `GET /_matrix/federation/*/make_join/{roomId}/{userId}`
//!
//! Endpoint to request a template for join events. //! 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<RoomVersionId>,
/// An unsigned template event.
pub event: Box<RawJsonValue>,
}
}
fn default_ver() -> Vec<RoomVersionId> {
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<RawJsonValue>) -> Self {
Self { room_version: None, event }
}
}
}

View File

@ -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<RoomVersionId>,
/// An unsigned template event.
pub event: Box<RawJsonValue>,
}
}
fn default_ver() -> Vec<RoomVersionId> {
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<RawJsonValue>) -> Self {
Self { room_version: None, event }
}
}

View File

@ -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 //! Endpoint to submits a signed leave event to the receiving server for it to accept it into the
//! room's graph. //! room's graph.

View File

@ -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 js_int::UInt;
use ruma_api::ruma_api; use ruma_api::ruma_api;

View File

@ -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_api::ruma_api;
use ruma_identifiers::{EventId, RoomId}; use ruma_identifiers::{EventId, RoomId};

View File

@ -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 //! 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. //! 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<RoomVersionId>,
/// 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<RawJsonValue>,
}
}
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<RoomVersionId>, event: Box<RawJsonValue>) -> Self {
Self { room_version, event }
}
}
}

View File

@ -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<RoomVersionId>,
/// 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<RawJsonValue>,
}
}
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<RoomVersionId>, event: Box<RawJsonValue>) -> Self {
Self { room_version, event }
}
}

View File

@ -1,3 +1,49 @@
//! `GET /_matrix/federation/*/openid/userinfo`
//!
//! Endpdoint for retrieving 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<UserId>,
}
}
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<UserId>) -> Self {
Self { sub }
}
}
}

View File

@ -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<UserId>,
}
}
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<UserId>) -> Self {
Self { sub }
}
}

View File

@ -1,3 +1,56 @@
//! `GET /_matrix/federation/*/query/{queryType}`
//!
//! Generic query endpoint for performing custom queries. //! 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<String, String>,
}
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<String, String>) -> Self {
Self { query_type, params }
}
}
impl Response {
/// Creates a new response with the given body.
pub fn new(body: JsonValue) -> Self {
Self { body }
}
}
}

View File

@ -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<String, String>,
}
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<String, String>) -> Self {
Self { query_type, params }
}
}
impl Response {
/// Creates a new response with the given body.
pub fn new(body: JsonValue) -> Self {
Self { body }
}
}

View File

@ -1,3 +1,104 @@
//! `GET /_matrix/federation/*/query/profile`
//!
//! Endpoint to query profile information with a user id and optional field. //! 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<String>,
/// 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<Box<MxcUri>>,
/// 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<String>,
}
}
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()
}
}
}

View File

@ -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<String>,
/// 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<Box<MxcUri>>,
/// 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<String>,
}
}
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()
}
}

View File

@ -1,3 +1,52 @@
//! `GET /_matrix/federation/*/query/directory`
//!
//! Endpoint to query room information with a room alias. //! 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<RoomId>,
/// An array of server names that are likely to hold the given room.
pub servers: Vec<Box<ServerName>>,
}
}
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<RoomId>, servers: Vec<Box<ServerName>>) -> Self {
Self { room_id, servers }
}
}
}

View File

@ -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<RoomId>,
/// An array of server names that are likely to hold the given room.
pub servers: Vec<Box<ServerName>>,
}
}
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<RoomId>, servers: Vec<Box<ServerName>>) -> Self {
Self { room_id, servers }
}
}

View File

@ -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 //! 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 //! identifier successfully, including any pending room invites the identity server has been made
//! aware of. //! 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<UserId>,
/// The room ID the invite is valid for.
pub room_id: Box<RoomId>,
/// The user ID that sent the invite.
pub sender: Box<UserId>,
/// Signature from the identity server using a long-term private key.
pub signed: BTreeMap<Box<ServerName>, BTreeMap<Box<ServerSigningKeyId>, String>>,
}
impl ThirdPartyInvite {
/// Creates a new third party invite with the given parameters.
pub fn new(
address: String,
mxid: Box<UserId>,
room_id: Box<RoomId>,
sender: Box<UserId>,
signed: BTreeMap<Box<ServerName>, BTreeMap<Box<ServerSigningKeyId>, String>>,
) -> Self {
Self { medium: Medium::Email, address, mxid, room_id, sender, signed }
}
}
}

View File

@ -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<UserId>,
/// The room ID the invite is valid for.
pub room_id: Box<RoomId>,
/// The user ID that sent the invite.
pub sender: Box<UserId>,
/// Signature from the identity server using a long-term private key.
pub signed: BTreeMap<Box<ServerName>, BTreeMap<Box<ServerSigningKeyId>, String>>,
}
impl ThirdPartyInvite {
/// Creates a new third party invite with the given parameters.
pub fn new(
address: String,
mxid: Box<UserId>,
room_id: Box<RoomId>,
sender: Box<UserId>,
signed: BTreeMap<Box<ServerName>, BTreeMap<Box<ServerSigningKeyId>, String>>,
) -> Self {
Self { medium: Medium::Email, address, mxid, room_id, sender, signed }
}
}

View File

@ -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. //! 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 //! If valid, the receiving server will issue an invite as per the [Inviting to a room] section
//! before returning a response to this request. //! 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 {}
}
}
}

View File

@ -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 {}
}
}

View File

@ -1,3 +1,90 @@
//! `PUT /_matrix/federation/*/send/{txnId}`
//!
//! Endpoint to send live activity messages to another server. //! 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<RawJsonValue>],
/// List of ephemeral messages.
///
/// Must not be more than 100 items.
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
pub edus: &'a [Raw<Edu>],
}
#[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<Box<EventId>, 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<Box<EventId>, Result<(), String>>) -> Self {
Self { pdus }
}
}
}

View File

@ -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<RawJsonValue>],
/// List of ephemeral messages.
///
/// Must not be more than 100 items.
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
pub edus: &'a [Raw<Edu>],
}
#[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<Box<EventId>, 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<Box<EventId>, Result<(), String>>) -> Self {
Self { pdus }
}
}