Add leave event endpoints

This commit is contained in:
q-b 2020-09-17 20:04:41 +02:00 committed by GitHub
parent 219cea9c1e
commit 192db0371c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 316 additions and 0 deletions

View File

@ -3,3 +3,5 @@
pub mod create_invite;
pub mod create_join_event;
pub mod create_join_event_template;
pub mod create_leave_event;
pub mod get_leave_event;

View File

@ -0,0 +1,4 @@
//! Endpoint to submits a signed leave event to the receiving server for it to accept it into the room's graph.
pub mod v1;
pub mod v2;

View File

@ -0,0 +1,114 @@
//! [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)
use std::time::SystemTime;
use js_int::UInt;
use ruma_api::ruma_api;
use ruma_common::Raw;
use ruma_events::{room::member::MemberEventContent, EventType};
use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
use ruma_serde::empty::Empty;
ruma_api! {
metadata: {
description: "Submits a signed leave event to the receiving server for it to accept it into the room's graph.",
name: "create_leave_event",
method: PUT,
path: "/_matrix/federation/v1/send_leave/:room_id/:event_id",
rate_limited: false,
requires_authentication: true,
}
request: {
/// The room ID that is about to be left.
#[ruma_api(path)]
pub room_id: &'a RoomId,
/// The event ID for the leave event.
#[ruma_api(path)]
pub event_id: &'a EventId,
/// The user ID of the leaving member.
#[ruma_api(query)]
pub sender: &'a UserId,
/// The name of the leaving homeserver.
#[ruma_api(query)]
pub origin: &'a ServerName,
/// A timestamp added by the leaving homeserver.
#[ruma_api(query)]
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
pub origin_server_ts: SystemTime,
/// The value `m.room.member`.
#[ruma_api(query)]
#[serde(rename = "type")]
pub event_type: EventType,
/// The user ID of the leaving member.
#[ruma_api(query)]
pub state_key: &'a str,
/// The content of the event.
#[ruma_api(query)]
pub content: Raw<MemberEventContent>,
/// This field must be present but is ignored; it may be 0.
#[ruma_api(query)]
pub depth: UInt,
}
response: {
/// - no description -
#[ruma_api(body)]
#[serde(with = "crate::serde::v1_pdu")]
pub event: Empty,
}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with:
/// * the room ID that is about to be left.
/// * the event ID for the leave event.
/// * the user ID of the leaving member.
/// * the name of the leaving homeserver.
/// * a timestamp added by the leaving homeserver.
/// * the value `m.room.member`.
/// * the user ID of the leaving member.
/// * the content of the event.
/// * this field must be present but is ignored; it may be 0.
#[allow(clippy::too_many_arguments)]
pub fn new(
room_id: &'a RoomId,
event_id: &'a EventId,
sender: &'a UserId,
origin: &'a ServerName,
origin_server_ts: SystemTime,
event_type: EventType,
state_key: &'a str,
content: Raw<MemberEventContent>,
depth: UInt,
) -> Self {
Self {
room_id,
event_id,
sender,
origin,
origin_server_ts,
event_type,
state_key,
content,
depth,
}
}
}
impl Response {
/// Creates a new `Response` with an empty event,
/// to indicate the event was accepted into the
/// graph by the receiving homeserver.
pub fn new(event: Empty) -> Self {
Self { event }
}
}

View File

@ -0,0 +1,113 @@
//! [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)
use std::time::SystemTime;
use js_int::UInt;
use ruma_api::ruma_api;
use ruma_common::Raw;
use ruma_events::{room::member::MemberEventContent, EventType};
use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
use ruma_serde::empty::Empty;
ruma_api! {
metadata: {
description: "Submits a signed leave event to the receiving server for it to accept it into the room's graph.",
name: "create_leave_event",
method: PUT,
path: "/_matrix/federation/v1/send_leave/:room_id/:event_id",
rate_limited: false,
requires_authentication: true,
}
request: {
/// The room ID that is about to be left.
#[ruma_api(path)]
pub room_id: &'a RoomId,
/// The event ID for the leave event.
#[ruma_api(path)]
pub event_id: &'a EventId,
/// The user ID of the leaving member.
#[ruma_api(query)]
pub sender: &'a UserId,
/// The name of the leaving homeserver.
#[ruma_api(query)]
pub origin: &'a ServerName,
/// A timestamp added by the leaving homeserver.
#[ruma_api(query)]
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
pub origin_server_ts: SystemTime,
/// The value `m.room.member`.
#[ruma_api(query)]
#[serde(rename = "type")]
pub event_type: EventType,
/// The user ID of the leaving member.
#[ruma_api(query)]
pub state_key: &'a str,
/// The content of the event.
#[ruma_api(query)]
pub content: Raw<MemberEventContent>,
/// This field must be present but is ignored; it may be 0.
#[ruma_api(query)]
pub depth: UInt,
}
response: {
/// - no description -
#[ruma_api(body)]
pub event: Empty,
}
}
impl<'a> Request<'a> {
/// Creates a new `Request` with:
/// * the room ID that is about to be left.
/// * the event ID for the leave event.
/// * the user ID of the leaving member.
/// * the name of the leaving homeserver.
/// * a timestamp added by the leaving homeserver.
/// * the value `m.room.member`.
/// * the user ID of the leaving member.
/// * the content of the event.
/// * this field must be present but is ignored; it may be 0.
#[allow(clippy::too_many_arguments)]
pub fn new(
room_id: &'a RoomId,
event_id: &'a EventId,
sender: &'a UserId,
origin: &'a ServerName,
origin_server_ts: SystemTime,
event_type: EventType,
state_key: &'a str,
content: Raw<MemberEventContent>,
depth: UInt,
) -> Self {
Self {
room_id,
event_id,
sender,
origin,
origin_server_ts,
event_type,
state_key,
content,
depth,
}
}
}
impl Response {
/// Creates a new `Response` with an empty event,
/// to indicate the event was accepted into the
/// graph by the receiving homeserver.
pub fn new(event: Empty) -> Self {
Self { event }
}
}

View File

@ -0,0 +1,3 @@
//! Endpoint to asks the receiving server to return information that the sending server will need to prepare a leave event to get out of the room.
pub mod v1;

View File

@ -0,0 +1,80 @@
//! [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 std::time::SystemTime;
use ruma_api::ruma_api;
use ruma_common::Raw;
use ruma_events::{room::member::MemberEventContent, EventType};
use ruma_identifiers::{RoomId, RoomVersionId, ServerNameBox, UserId};
use serde::{Deserialize, Serialize};
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,
path: "/_matrix/federation/v1/make_leave/:room_id/:user_id",
rate_limited: false,
requires_authentication: true,
}
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: EventTemplate,
}
}
/// 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.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct EventTemplate {
/// The user ID of the leaving member.
pub sender: UserId,
/// The name of the resident homeserver.
pub origin: ServerNameBox,
/// A timestamp added by the resident homeserver.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
pub origin_server_ts: SystemTime,
/// The value `m.room.member`.
#[serde(rename = "type")]
pub event_type: EventType,
/// The user ID of the leaving member.
pub state_key: String,
/// The content of the event.
pub content: Raw<MemberEventContent>,
}
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: EventTemplate) -> Self {
Self { room_version, event }
}
}