federation-api: Make remaining request / response types non-exhaustive

This commit is contained in:
Jonas Platte 2020-08-23 18:00:58 +02:00
parent 417b65def5
commit f84287038e
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
8 changed files with 123 additions and 5 deletions

View File

@ -36,8 +36,10 @@ ruma_api! {
latest_events: &'a [EventId],
}
#[derive(Default)]
#[non_exhaustive]
response: {
/// The missing events.
/// The missing PDUs.
events: Vec<Pdu>
}
}

View File

@ -9,12 +9,22 @@ use serde::{Deserialize, Serialize};
/// Full state of the room.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct RoomState {
/// The resident server's DNS name.
pub origin: String,
/// The full set of authorization events that make up the state of the room,
/// and their authorization events, recursively.
pub auth_chain: Vec<Raw<Pdu>>,
/// The room state.
pub state: Vec<Raw<Pdu>>,
}
impl RoomState {
/// Creates an empty `RoomState` with the given `origin`.
pub fn new(origin: String) -> Self {
Self { origin, auth_chain: Vec::new(), state: Vec::new() }
}
}

View File

@ -17,6 +17,7 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// The room ID that is about to be joined.
#[ruma_api(path)]
@ -31,6 +32,7 @@ ruma_api! {
pub pdu_stub: Raw<PduStub>,
}
#[non_exhaustive]
response: {
/// Full state and auth chain of the room prior to the join event.
#[ruma_api(body)]
@ -38,3 +40,18 @@ ruma_api! {
pub room_state: RoomState,
}
}
// FIXME: Construct from Pdu, same for similar endpoints
impl<'a> Request<'a> {
/// Creates a `Request` from the given room ID, event ID and `PduStub`.
pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu_stub: Raw<PduStub>) -> Self {
Self { room_id, event_id, pdu_stub }
}
}
impl Response {
/// Creates a new `Response` with the given room state.
pub fn new(room_state: RoomState) -> Self {
Self { room_state }
}
}

View File

@ -17,23 +17,40 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// The room ID that is about to be joined.
#[ruma_api(path)]
pub room_id: RoomId,
pub room_id: &'a RoomId,
/// The user ID the join event will be for.
#[ruma_api(path)]
pub event_id: EventId,
pub event_id: &'a EventId,
/// PDU type without event and room IDs.
#[ruma_api(body)]
pub pdu_stub: Raw<PduStub>,
}
#[non_exhaustive]
response: {
/// Full state of the room.
#[ruma_api(body)]
pub room_state: RoomState,
}
}
// FIXME: Construct from Pdu, same for similar endpoints
impl<'a> Request<'a> {
/// Creates a `Request` from the given room ID, event ID and `PduStub`.
pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu_stub: Raw<PduStub>) -> Self {
Self { room_id, event_id, pdu_stub }
}
}
impl Response {
/// Creates a new `Response` with the given room state.
pub fn new(room_state: RoomState) -> Self {
Self { room_state }
}
}

View File

@ -13,14 +13,30 @@ ruma_api! {
requires_authentication: false,
}
#[non_exhaustive]
request: {
/// The OpenID access token to get information about the owner for.
#[ruma_api(query)]
pub access_token: &'a str,
}
#[non_exhaustive]
response: {
/// The Matrix User ID who generated the token.
pub sub: 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: UserId) -> Self {
Self { sub }
}
}

View File

@ -14,10 +14,11 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// User ID to query.
#[ruma_api(query)]
pub user_id: UserId,
pub user_id: &'a UserId,
/// Profile field to query.
#[serde(skip_serializing_if = "Option::is_none")]
@ -25,6 +26,8 @@ ruma_api! {
pub field: Option<ProfileField>,
}
#[derive(Default)]
#[non_exhaustive]
response: {
/// Display name of the user.
#[serde(skip_serializing_if = "Option::is_none")]
@ -36,8 +39,22 @@ ruma_api! {
}
}
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.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum ProfileField {
/// Display name of the user.
#[serde(rename = "displayname")]

View File

@ -13,12 +13,14 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// Room alias to query.
#[ruma_api(query)]
pub room_alias: &'a RoomAliasId,
}
#[non_exhaustive]
response: {
/// Room ID mapped to queried alias.
pub room_id: RoomId,
@ -27,3 +29,17 @@ ruma_api! {
pub servers: Vec<String>,
}
}
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: RoomId, servers: Vec<String>) -> Self {
Self { room_id, servers }
}
}

View File

@ -18,6 +18,7 @@ ruma_api! {
requires_authentication: true,
}
#[non_exhaustive]
request: {
/// A transaction ID unique between sending and receiving homeservers.
#[ruma_api(path)]
@ -43,6 +44,8 @@ ruma_api! {
pub edus: &'a [Edu],
}
#[derive(Default)]
#[non_exhaustive]
response: {
/// Map of event IDs and response for each PDU given in the request.
#[serde(with = "crate::serde::pdu_process_response")]
@ -50,6 +53,26 @@ ruma_api! {
}
}
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 str,
origin: &'a ServerName,
origin_server_ts: SystemTime,
) -> 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<EventId, Result<(), String>>) -> Self {
Self { pdus }
}
}
/// Type for passing ephemeral data to homeservers.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Edu {