federation-api: Improve create_invite endpoint
This commit is contained in:
parent
eae0b58163
commit
63421dfca6
@ -1,85 +1,4 @@
|
||||
//! Endpoint for inviting a remote user to a room
|
||||
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ruma_events::{room::member::MemberEventContent, EventType};
|
||||
use ruma_identifiers::{ServerName, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
pub mod v1;
|
||||
pub mod v2;
|
||||
|
||||
/// A simplified event that helps the server identify a room.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct StrippedState {
|
||||
/// The `content` for the event.
|
||||
pub content: JsonValue,
|
||||
|
||||
/// The `state_key` for the event.
|
||||
pub state_key: String,
|
||||
|
||||
/// The `type` for the event.
|
||||
#[serde(rename = "type")]
|
||||
pub kind: EventType,
|
||||
|
||||
/// The `sender` for the event.
|
||||
pub sender: UserId,
|
||||
}
|
||||
|
||||
/// The invite event sent as a response.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
pub struct InviteEvent {
|
||||
/// The matrix ID of the user who sent the original `m.room.third_party_invite`.
|
||||
pub sender: UserId,
|
||||
|
||||
/// The name of the inviting homeserver.
|
||||
pub origin: Box<ServerName>,
|
||||
|
||||
/// A timestamp added by the inviting homeserver.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The event type (should always be `m.room.member`).
|
||||
#[serde(rename = "type")]
|
||||
pub kind: EventType,
|
||||
|
||||
/// The user ID of the invited member.
|
||||
pub state_key: UserId,
|
||||
|
||||
/// The content of the event. Must include a `membership` of invite.
|
||||
pub content: MemberEventContent,
|
||||
}
|
||||
|
||||
/// Initial set of fields for `Response`.
|
||||
pub struct InviteEventInit {
|
||||
/// The matrix ID of the user who sent the original `m.room.third_party_invite`.
|
||||
pub sender: UserId,
|
||||
|
||||
/// The name of the inviting homeserver.
|
||||
pub origin: Box<ServerName>,
|
||||
|
||||
/// A timestamp added by the inviting homeserver.
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The user ID of the invited member.
|
||||
pub state_key: UserId,
|
||||
|
||||
/// The content of the event. Must include a `membership` of invite.
|
||||
pub content: MemberEventContent,
|
||||
}
|
||||
|
||||
impl From<InviteEventInit> for InviteEvent {
|
||||
/// Creates a new `Response` with the given inital values
|
||||
fn from(init: InviteEventInit) -> Self {
|
||||
InviteEvent {
|
||||
sender: init.sender,
|
||||
origin: init.origin,
|
||||
origin_server_ts: init.origin_server_ts,
|
||||
kind: EventType::RoomMember,
|
||||
state_key: init.state_key,
|
||||
content: init.content,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,11 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_events::{room::member::MemberEventContent, EventType};
|
||||
use ruma_events::{pdu::Pdu, room::member::MemberEventContent, AnyStrippedStateEvent, EventType};
|
||||
use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
|
||||
use ruma_serde::Raw;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{InviteEvent, StrippedState};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Invites a remote user to a room.",
|
||||
@ -54,10 +53,10 @@ ruma_api! {
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The response invite event
|
||||
/// The signed invite event.
|
||||
#[ruma_api(body)]
|
||||
#[serde(with = "crate::serde::v1_pdu")]
|
||||
pub event: InviteEvent,
|
||||
pub event: Raw<Pdu>,
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +68,7 @@ pub struct UnsignedEventContent {
|
||||
/// The recommended events to include are the join rules, canonical alias, avatar, and name of
|
||||
/// the room.
|
||||
#[serde(skip_serializing_if = "<[_]>::is_empty")]
|
||||
pub invite_room_state: Vec<StrippedState>,
|
||||
pub invite_room_state: Vec<Raw<AnyStrippedStateEvent>>,
|
||||
}
|
||||
|
||||
impl UnsignedEventContent {
|
||||
@ -130,7 +129,7 @@ impl<'a> From<RequestInit<'a>> for Request<'a> {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given invite event.
|
||||
pub fn new(event: InviteEvent) -> Self {
|
||||
pub fn new(event: Raw<Pdu>) -> Self {
|
||||
Self { event }
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! [PUT /_matrix/federation/v2/invite/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-invite-roomid-eventid)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_events::{pdu::Pdu, AnyStrippedStateEvent};
|
||||
use ruma_identifiers::{EventId, RoomId, RoomVersionId};
|
||||
|
||||
use super::{InviteEvent, StrippedState};
|
||||
use ruma_serde::Raw;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -27,16 +27,16 @@ ruma_api! {
|
||||
/// The version of the room where the user is being invited to.
|
||||
pub room_version: RoomVersionId,
|
||||
|
||||
/// An invite event.
|
||||
pub event: InviteEvent,
|
||||
/// The invite event which needs to be signed.
|
||||
pub event: Raw<Pdu>,
|
||||
|
||||
/// An optional list of simplified events to help the receiver of the invite identify the room.
|
||||
pub invite_room_state: StrippedState,
|
||||
pub invite_room_state: Vec<Raw<AnyStrippedStateEvent>>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// An invite event.
|
||||
pub event: InviteEvent,
|
||||
/// The signed invite event.
|
||||
pub event: Raw<Pdu>,
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,8 +46,8 @@ impl Request {
|
||||
room_id: RoomId,
|
||||
event_id: EventId,
|
||||
room_version: RoomVersionId,
|
||||
event: InviteEvent,
|
||||
invite_room_state: StrippedState,
|
||||
event: Raw<Pdu>,
|
||||
invite_room_state: Vec<Raw<AnyStrippedStateEvent>>,
|
||||
) -> Self {
|
||||
Self { room_id, event_id, room_version, event, invite_room_state }
|
||||
}
|
||||
@ -55,7 +55,7 @@ impl Request {
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given invite event.
|
||||
pub fn new(event: InviteEvent) -> Self {
|
||||
pub fn new(event: Raw<Pdu>) -> Self {
|
||||
Self { event }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user