federation-api: Fix various issues
This commit is contained in:
parent
6aee819d5d
commit
21eb1e8e41
@ -26,13 +26,36 @@ ruma_api! {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
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)]
|
||||
#[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()
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ ruma_api! {
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The keys to be claimed.
|
||||
one_time_keys: OneTimeKeyClaims,
|
||||
pub one_time_keys: OneTimeKeyClaims,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// One-time keys for the queried devices
|
||||
one_time_keys: OneTimeKeys,
|
||||
pub one_time_keys: OneTimeKeys,
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,11 +51,19 @@ pub type OneTimeKeyClaims = BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeyAlgo
|
||||
pub type OneTimeKeys = BTreeMap<UserId, BTreeMap<DeviceIdBox, BTreeMap<DeviceKeyId, KeyObject>>>;
|
||||
|
||||
/// A key and its signature
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct KeyObject {
|
||||
/// The key, encoded using unpadded base64.
|
||||
key: String,
|
||||
pub key: String,
|
||||
|
||||
/// Signature of the key object.
|
||||
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
pub signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
}
|
||||
|
||||
impl KeyObject {
|
||||
/// Creates a new `KeyObject` with the given key and signatures.
|
||||
pub fn new(key: String, signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>) -> Self {
|
||||
Self { key, signatures }
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ ruma_api! {
|
||||
request: {
|
||||
/// The keys to be downloaded. Gives all keys for a given user if the list of device ids is
|
||||
/// empty.
|
||||
device_keys: BTreeMap<UserId, Vec<DeviceIdBox>>,
|
||||
pub device_keys: BTreeMap<UserId, Vec<DeviceIdBox>>,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// Keys from the queried devices.
|
||||
device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>,
|
||||
pub device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,17 +22,17 @@ ruma_api! {
|
||||
request: {
|
||||
/// The room ID that the user is being invited to.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The event ID for the invite event, generated by the inviting server.
|
||||
#[ruma_api(path)]
|
||||
pub event_id: EventId,
|
||||
pub event_id: &'a EventId,
|
||||
|
||||
/// The matrix ID of the user who sent the original `m.room.third_party_invite`.
|
||||
pub sender: UserId,
|
||||
pub sender: &'a UserId,
|
||||
|
||||
/// The name of the inviting homeserver.
|
||||
pub origin: Box<ServerName>,
|
||||
pub origin: &'a ServerName,
|
||||
|
||||
/// A timestamp added by the inviting homeserver.
|
||||
pub origin_server_ts: UInt,
|
||||
@ -42,12 +42,13 @@ ruma_api! {
|
||||
pub kind: EventType,
|
||||
|
||||
/// The user ID of the invited member.
|
||||
pub state_key: UserId,
|
||||
pub state_key: &'a UserId,
|
||||
|
||||
/// The content of the event.
|
||||
pub content: MemberEventContent,
|
||||
|
||||
/// Information included alongside the event that is not signed.
|
||||
#[serde(default, skip_serializing_if = "UnsignedEventContent::is_empty")]
|
||||
pub unsigned: UnsignedEventContent,
|
||||
}
|
||||
|
||||
@ -56,38 +57,52 @@ ruma_api! {
|
||||
/// The response invite event
|
||||
#[ruma_api(body)]
|
||||
#[serde(with = "crate::serde::invite_response")]
|
||||
event: InviteEvent,
|
||||
pub event: InviteEvent,
|
||||
}
|
||||
}
|
||||
|
||||
/// Information included alongside an event that is not signed.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct UnsignedEventContent {
|
||||
/// An optional list of simplified events to help the receiver of the invite identify the room.
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
impl UnsignedEventContent {
|
||||
/// Creates an empty `UnsignedEventContent`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Checks whether all of the fields are empty.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.invite_room_state.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
/// Initial set of fields of `Request`.
|
||||
pub struct RequestInit {
|
||||
pub struct RequestInit<'a> {
|
||||
/// The room ID that the user is being invited to.
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The event ID for the invite event, generated by the inviting server.
|
||||
pub event_id: EventId,
|
||||
pub event_id: &'a EventId,
|
||||
|
||||
/// The matrix ID of the user who sent the original `m.room.third_party_invite`.
|
||||
pub sender: UserId,
|
||||
pub sender: &'a UserId,
|
||||
|
||||
/// The name of the inviting homeserver.
|
||||
pub origin: Box<ServerName>,
|
||||
pub origin: &'a ServerName,
|
||||
|
||||
/// A timestamp added by the inviting homeserver.
|
||||
pub origin_server_ts: UInt,
|
||||
|
||||
/// The user ID of the invited member.
|
||||
pub state_key: UserId,
|
||||
pub state_key: &'a UserId,
|
||||
|
||||
/// The content of the event.
|
||||
pub content: MemberEventContent,
|
||||
@ -96,9 +111,9 @@ pub struct RequestInit {
|
||||
pub unsigned: UnsignedEventContent,
|
||||
}
|
||||
|
||||
impl From<RequestInit> for Request {
|
||||
impl<'a> From<RequestInit<'a>> for Request<'a> {
|
||||
/// Creates a new `Request` with the given parameters.
|
||||
fn from(init: RequestInit) -> Self {
|
||||
fn from(init: RequestInit<'a>) -> Self {
|
||||
Self {
|
||||
room_id: init.room_id,
|
||||
event_id: init.event_id,
|
||||
|
@ -19,31 +19,31 @@ ruma_api! {
|
||||
request: {
|
||||
/// The room ID that the user is being invited to.
|
||||
#[ruma_api(path)]
|
||||
room_id: RoomId,
|
||||
pub room_id: RoomId,
|
||||
|
||||
/// The event ID for the invite event, generated by the inviting server.
|
||||
#[ruma_api(path)]
|
||||
event_id: EventId,
|
||||
pub event_id: EventId,
|
||||
|
||||
/// The version of the room where the user is being invited to.
|
||||
room_version: RoomVersionId,
|
||||
pub room_version: RoomVersionId,
|
||||
|
||||
/// An invite event.
|
||||
event: InviteEvent,
|
||||
pub event: InviteEvent,
|
||||
|
||||
/// An optional list of simplified events to help the receiver of the invite identify the room.
|
||||
invite_room_state: StrippedState,
|
||||
pub invite_room_state: StrippedState,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// An invite event.
|
||||
event: InviteEvent,
|
||||
pub event: InviteEvent,
|
||||
}
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given parameters
|
||||
/// Creates a new `Request` with the given parameters.
|
||||
pub fn new(
|
||||
room_id: RoomId,
|
||||
event_id: EventId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user