Add knock feature (unstable-pre-spec)
This commit is contained in:
parent
118ea0f85a
commit
6dfd89b98d
@ -12,6 +12,9 @@ pub mod device;
|
||||
pub mod directory;
|
||||
pub mod filter;
|
||||
pub mod keys;
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||
pub mod knock;
|
||||
pub mod media;
|
||||
pub mod membership;
|
||||
pub mod message;
|
||||
|
@ -6,6 +6,7 @@ pub mod get_room_visibility;
|
||||
pub mod set_room_visibility;
|
||||
|
||||
use js_int::{uint, UInt};
|
||||
use ruma_events::room::join_rules::JoinRule;
|
||||
use ruma_identifiers::{MxcUri, RoomAliasId, RoomId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -53,6 +54,10 @@ pub struct PublicRoomsChunk {
|
||||
serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
|
||||
)]
|
||||
pub avatar_url: Option<MxcUri>,
|
||||
|
||||
/// The joining rule for the room.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub join_rule: Option<JoinRule>,
|
||||
}
|
||||
|
||||
impl PublicRoomsChunk {
|
||||
@ -72,6 +77,7 @@ impl PublicRoomsChunk {
|
||||
world_readable: false,
|
||||
guest_can_join: false,
|
||||
avatar_url: None,
|
||||
join_rule: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3
crates/ruma-client-api/src/r0/knock.rs
Normal file
3
crates/ruma-client-api/src/r0/knock.rs
Normal file
@ -0,0 +1,3 @@
|
||||
//! Endpoints to knock on a room.
|
||||
|
||||
pub mod knock_room;
|
51
crates/ruma-client-api/src/r0/knock/knock_room.rs
Normal file
51
crates/ruma-client-api/src/r0/knock/knock_room.rs
Normal file
@ -0,0 +1,51 @@
|
||||
//! [POST /_matrix/client/r0/knock/{roomIdOrAlias}](https://spec.matrix.org/unstable/client-server-api/#post_matrixclientr0knockroomidoralias)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomId, RoomIdOrAliasId, ServerNameBox};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Knock on a room.",
|
||||
method: POST,
|
||||
name: "knock_room",
|
||||
path: "/_matrix/client/r0/knock/:room_id_or_alias",
|
||||
rate_limited: true,
|
||||
authentication: AccessToken,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The room the user should knock on.
|
||||
#[ruma_api(path)]
|
||||
pub room_id_or_alias: RoomIdOrAliasId,
|
||||
|
||||
/// The reason for joining a room.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reason: Option<&'a str>,
|
||||
|
||||
/// The servers to attempt to knock on the room through.
|
||||
///
|
||||
/// One of the servers must be participating in the room.
|
||||
#[ruma_api(query)]
|
||||
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
|
||||
pub server_name: &'a [ServerNameBox],
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The room that the user knocked on.
|
||||
pub room_id: RoomId,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given room ID or alias.
|
||||
pub fn new(room_id_or_alias: RoomIdOrAliasId) -> Self {
|
||||
Self { room_id_or_alias, reason: None, server_name: &[] }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given room ID.
|
||||
pub fn new(room_id: RoomId) -> Self {
|
||||
Self { room_id }
|
||||
}
|
||||
}
|
@ -181,6 +181,12 @@ pub struct Rooms {
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub invite: BTreeMap<RoomId, InvitedRoom>,
|
||||
|
||||
/// The rooms that the user has knocked on.
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub knock: BTreeMap<RoomId, KnockedRoom>,
|
||||
|
||||
#[cfg(not(feature = "unstable-exhaustive-types"))]
|
||||
#[doc(hidden)]
|
||||
#[serde(skip, default = "crate::private")]
|
||||
@ -205,6 +211,8 @@ impl Default for Rooms {
|
||||
leave: BTreeMap::new(),
|
||||
join: BTreeMap::new(),
|
||||
invite: BTreeMap::new(),
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
knock: BTreeMap::new(),
|
||||
#[cfg(not(feature = "unstable-exhaustive-types"))]
|
||||
__test_exhaustive: crate::private(),
|
||||
}
|
||||
@ -326,6 +334,26 @@ impl Default for JoinedRoom {
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates to knocked rooms.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct KnockedRoom {
|
||||
/// The knock state.
|
||||
pub knock_state: KnockState,
|
||||
}
|
||||
|
||||
/// A mapping from a key `events` to a list of `StrippedStateEvent`.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct KnockState {
|
||||
/// The list of events.
|
||||
pub events: Vec<AnyStrippedStateEvent>,
|
||||
}
|
||||
|
||||
/// Unread notifications count.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct UnreadNotificationsCount {
|
||||
|
4
crates/ruma-federation-api/src/knock.rs
Normal file
4
crates/ruma-federation-api/src/knock.rs
Normal file
@ -0,0 +1,4 @@
|
||||
//! Endpoints for handling room knocking.
|
||||
|
||||
pub mod create_knock_event_template;
|
||||
pub mod send_knock;
|
@ -0,0 +1,3 @@
|
||||
//! Endpoint to query information to prepare a knock event.
|
||||
|
||||
pub mod v1;
|
@ -0,0 +1,57 @@
|
||||
//! [GET /_matrix/federation/v1/make_knock/{roomId}/{userId}](https://spec.matrix.org/unstable/server-server-api/#get_matrixfederationv1make_knockroomiduserid)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_events::pdu::Pdu;
|
||||
use ruma_identifiers::{RoomId, RoomVersionId, UserId};
|
||||
use ruma_serde::Raw;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Send a request for a knock event template to a resident server.",
|
||||
name: "create_knock_event_template",
|
||||
method: GET,
|
||||
path: "/_matrix/federation/v1/make_knock/:room_id/:user_id",
|
||||
rate_limited: false,
|
||||
authentication: ServerSignatures,
|
||||
}
|
||||
|
||||
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::Version1]`.
|
||||
#[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: Raw<Pdu>,
|
||||
}
|
||||
}
|
||||
|
||||
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::Version1] }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given room version ID and event.
|
||||
pub fn new(room_version: RoomVersionId, event: Raw<Pdu>) -> Self {
|
||||
Self { room_version, event }
|
||||
}
|
||||
}
|
3
crates/ruma-federation-api/src/knock/send_knock.rs
Normal file
3
crates/ruma-federation-api/src/knock/send_knock.rs
Normal file
@ -0,0 +1,3 @@
|
||||
//! Endpoint to submit a signed knock event to the resident homeserver.
|
||||
|
||||
pub mod v1;
|
49
crates/ruma-federation-api/src/knock/send_knock/v1.rs
Normal file
49
crates/ruma-federation-api/src/knock/send_knock/v1.rs
Normal file
@ -0,0 +1,49 @@
|
||||
//! [PUT /_matrix/federation/v1/send_knock/{roomId}/{eventId}](https://spec.matrix.org/unstable/server-server-api/#put_matrixfederationv1send_knockroomideventid)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_events::{room::member::MemberEvent, AnyStrippedStateEvent};
|
||||
use ruma_identifiers::{EventId, RoomId};
|
||||
|
||||
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,
|
||||
path: "/_matrix/federation/v1/send_knock/:room_id/:event_id",
|
||||
rate_limited: false,
|
||||
authentication: ServerSignatures,
|
||||
}
|
||||
|
||||
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 full knock event.
|
||||
#[ruma_api(body)]
|
||||
pub knock_event: &'a MemberEvent,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// State events providing public room metadata.
|
||||
pub knock_room_state: Vec<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, knock_event: &'a MemberEvent) -> Self {
|
||||
Self { room_id, event_id, knock_event }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given public room metadata state events.
|
||||
pub fn new(knock_room_state: Vec<AnyStrippedStateEvent>) -> Self {
|
||||
Self { knock_room_state }
|
||||
}
|
||||
}
|
@ -17,6 +17,9 @@ pub mod directory;
|
||||
pub mod discovery;
|
||||
pub mod event;
|
||||
pub mod keys;
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||
pub mod knock;
|
||||
pub mod membership;
|
||||
pub mod openid;
|
||||
pub mod query;
|
||||
|
Loading…
x
Reference in New Issue
Block a user