federation-api: Add support for partial state in send_join
According to MSC3706
This commit is contained in:
parent
12e4aa47b6
commit
9b239663fb
@ -4,9 +4,14 @@ Bug fixes:
|
|||||||
|
|
||||||
* Add the `event` field to `RoomState` according to MSC3083 / Matrix v1.2
|
* Add the `event` field to `RoomState` according to MSC3083 / Matrix v1.2
|
||||||
|
|
||||||
|
Breaking changes:
|
||||||
|
|
||||||
|
* Split `membership::create_join_event::RoomState` into separate types in the `v1` and `v2` modules
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
* Add unstable support to get an event by timestamp (MSC3030)
|
* Add unstable support to get an event by timestamp (MSC3030)
|
||||||
|
* Add unstable support to request partial state in `send_join` (MSC3706)
|
||||||
|
|
||||||
# 0.6.0
|
# 0.6.0
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ unstable-exhaustive-types = []
|
|||||||
unstable-msc2448 = []
|
unstable-msc2448 = []
|
||||||
unstable-msc3030 = []
|
unstable-msc3030 = []
|
||||||
unstable-msc3618 = []
|
unstable-msc3618 = []
|
||||||
|
unstable-msc3706 = []
|
||||||
unstable-msc3723 = []
|
unstable-msc3723 = []
|
||||||
unstable-unspecified = []
|
unstable-unspecified = []
|
||||||
|
|
||||||
|
@ -4,56 +4,3 @@
|
|||||||
|
|
||||||
pub mod v1;
|
pub mod v1;
|
||||||
pub mod v2;
|
pub mod v2;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
|
||||||
|
|
||||||
/// Full state of the room.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
|
||||||
pub struct RoomState {
|
|
||||||
#[cfg(not(feature = "unstable-unspecified"))]
|
|
||||||
/// 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<Box<RawJsonValue>>,
|
|
||||||
|
|
||||||
/// The room state.
|
|
||||||
pub state: Vec<Box<RawJsonValue>>,
|
|
||||||
|
|
||||||
/// The signed copy of the membership event sent to other servers by the
|
|
||||||
/// resident server, including the resident server's signature.
|
|
||||||
///
|
|
||||||
/// Required if the room version supports restricted join rules.
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub event: Option<Box<RawJsonValue>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "unstable-unspecified")]
|
|
||||||
impl Default for RoomState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RoomState {
|
|
||||||
#[cfg(not(feature = "unstable-unspecified"))]
|
|
||||||
/// Creates an empty `RoomState` with the given `origin`.
|
|
||||||
///
|
|
||||||
/// With the `unstable-unspecified` feature, this method doesn't take any parameters.
|
|
||||||
/// See [matrix-spec#374](https://github.com/matrix-org/matrix-spec/issues/374).
|
|
||||||
pub fn new(origin: String) -> Self {
|
|
||||||
Self { origin, auth_chain: Vec::new(), state: Vec::new(), event: None }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "unstable-unspecified")]
|
|
||||||
/// Creates an empty `RoomState` with the given `origin`.
|
|
||||||
///
|
|
||||||
/// Without the `unstable-unspecified` feature, this method takes a parameter for the origin
|
|
||||||
/// See [matrix-spec#374](https://github.com/matrix-org/matrix-spec/issues/374).
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self { auth_chain: Vec::new(), state: Vec::new(), event: None }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -6,10 +6,9 @@ use ruma_common::{
|
|||||||
api::{request, response, Metadata},
|
api::{request, response, Metadata},
|
||||||
metadata, OwnedEventId, OwnedRoomId,
|
metadata, OwnedEventId, OwnedRoomId,
|
||||||
};
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use super::RoomState;
|
|
||||||
|
|
||||||
const METADATA: Metadata = metadata! {
|
const METADATA: Metadata = metadata! {
|
||||||
method: PUT,
|
method: PUT,
|
||||||
rate_limited: false,
|
rate_limited: false,
|
||||||
@ -60,12 +59,62 @@ impl Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Full state of the room.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
pub struct RoomState {
|
||||||
|
#[cfg(not(feature = "unstable-unspecified"))]
|
||||||
|
/// 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<Box<RawJsonValue>>,
|
||||||
|
|
||||||
|
/// The room state.
|
||||||
|
pub state: Vec<Box<RawJsonValue>>,
|
||||||
|
|
||||||
|
/// The signed copy of the membership event sent to other servers by the
|
||||||
|
/// resident server, including the resident server's signature.
|
||||||
|
///
|
||||||
|
/// Required if the room version supports restricted join rules.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub event: Option<Box<RawJsonValue>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-unspecified")]
|
||||||
|
impl Default for RoomState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RoomState {
|
||||||
|
#[cfg(not(feature = "unstable-unspecified"))]
|
||||||
|
/// Creates an empty `RoomState` with the given `origin`.
|
||||||
|
///
|
||||||
|
/// With the `unstable-unspecified` feature, this method doesn't take any parameters.
|
||||||
|
/// See [matrix-spec#374](https://github.com/matrix-org/matrix-spec/issues/374).
|
||||||
|
pub fn new(origin: String) -> Self {
|
||||||
|
Self { origin, auth_chain: Vec::new(), state: Vec::new(), event: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-unspecified")]
|
||||||
|
/// Creates an empty `RoomState` with the given `origin`.
|
||||||
|
///
|
||||||
|
/// Without the `unstable-unspecified` feature, this method takes a parameter for the origin.
|
||||||
|
/// See [matrix-spec#374](https://github.com/matrix-org/matrix-spec/issues/374).
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self { auth_chain: Vec::new(), state: Vec::new(), event: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(test, feature = "server", not(feature = "unstable-unspecified")))]
|
#[cfg(all(test, feature = "server", not(feature = "unstable-unspecified")))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ruma_common::api::OutgoingResponse;
|
use ruma_common::api::OutgoingResponse;
|
||||||
use serde_json::{from_slice as from_json_slice, json, Value as JsonValue};
|
use serde_json::{from_slice as from_json_slice, json, Value as JsonValue};
|
||||||
|
|
||||||
use super::{super::RoomState, Response};
|
use super::{Response, RoomState};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn response_body() {
|
fn response_body() {
|
||||||
|
@ -6,10 +6,9 @@ use ruma_common::{
|
|||||||
api::{request, response, Metadata},
|
api::{request, response, Metadata},
|
||||||
metadata, OwnedEventId, OwnedRoomId,
|
metadata, OwnedEventId, OwnedRoomId,
|
||||||
};
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use super::RoomState;
|
|
||||||
|
|
||||||
const METADATA: Metadata = metadata! {
|
const METADATA: Metadata = metadata! {
|
||||||
method: PUT,
|
method: PUT,
|
||||||
rate_limited: false,
|
rate_limited: false,
|
||||||
@ -35,6 +34,19 @@ pub struct Request {
|
|||||||
/// The PDU.
|
/// The PDU.
|
||||||
#[ruma_api(body)]
|
#[ruma_api(body)]
|
||||||
pub pdu: Box<RawJsonValue>,
|
pub pdu: Box<RawJsonValue>,
|
||||||
|
|
||||||
|
/// Indicates whether the calling server can accept a reduced response.
|
||||||
|
///
|
||||||
|
/// If `true`, membership events are omitted from `state` and redundant events are omitted from
|
||||||
|
/// `auth_chain` in the response.
|
||||||
|
#[cfg(feature = "unstable-msc3706")]
|
||||||
|
#[ruma_api(query)]
|
||||||
|
#[serde(
|
||||||
|
rename = "org.matrix.msc3706.partial_state",
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "ruma_common::serde::is_default"
|
||||||
|
)]
|
||||||
|
pub omit_members: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Response type for the `create_join_event` endpoint.
|
/// Response type for the `create_join_event` endpoint.
|
||||||
@ -48,7 +60,13 @@ pub struct Response {
|
|||||||
impl Request {
|
impl Request {
|
||||||
/// Creates a new `Request` from the given room ID, event ID and PDU.
|
/// Creates a new `Request` from the given room ID, event ID and PDU.
|
||||||
pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, pdu: Box<RawJsonValue>) -> Self {
|
pub fn new(room_id: OwnedRoomId, event_id: OwnedEventId, pdu: Box<RawJsonValue>) -> Self {
|
||||||
Self { room_id, event_id, pdu }
|
Self {
|
||||||
|
room_id,
|
||||||
|
event_id,
|
||||||
|
pdu,
|
||||||
|
#[cfg(feature = "unstable-msc3706")]
|
||||||
|
omit_members: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,3 +76,99 @@ impl Response {
|
|||||||
Self { room_state }
|
Self { room_state }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Full state of the room.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
pub struct RoomState {
|
||||||
|
#[cfg(not(feature = "unstable-unspecified"))]
|
||||||
|
/// The resident server's DNS name.
|
||||||
|
pub origin: String,
|
||||||
|
|
||||||
|
/// Whether `m.room.member` events have been omitted from `state`.
|
||||||
|
///
|
||||||
|
/// Defaults to `false`.
|
||||||
|
#[cfg(feature = "unstable-msc3706")]
|
||||||
|
#[serde(
|
||||||
|
rename = "org.matrix.msc3706.partial_state",
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "ruma_common::serde::is_default"
|
||||||
|
)]
|
||||||
|
pub members_omitted: bool,
|
||||||
|
|
||||||
|
/// The full set of authorization events that make up the state of the room,
|
||||||
|
/// and their authorization events, recursively.
|
||||||
|
///
|
||||||
|
/// With the `unstable-msc3706` feature, if the request had `omit_members` set to `true`, then
|
||||||
|
/// any events that are returned in `state` may be omitted from `auth_chain`, whether or
|
||||||
|
/// not membership events are omitted from `state`.
|
||||||
|
pub auth_chain: Vec<Box<RawJsonValue>>,
|
||||||
|
|
||||||
|
/// The room state.
|
||||||
|
///
|
||||||
|
/// With the `unstable-msc3706` feature, if the request had `omit_members` set to `true`,
|
||||||
|
/// events of type `m.room.member` may be omitted from the response to reduce the size of
|
||||||
|
/// the response. If this is done, `members_omitted` must be set to `true`.
|
||||||
|
pub state: Vec<Box<RawJsonValue>>,
|
||||||
|
|
||||||
|
/// The signed copy of the membership event sent to other servers by the
|
||||||
|
/// resident server, including the resident server's signature.
|
||||||
|
///
|
||||||
|
/// Required if the room version supports restricted join rules.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub event: Option<Box<RawJsonValue>>,
|
||||||
|
|
||||||
|
/// A list of the servers active in the room (ie, those with joined members) before the join.
|
||||||
|
///
|
||||||
|
/// Required if `members_omitted` is set to `true`.
|
||||||
|
#[cfg(feature = "unstable-msc3706")]
|
||||||
|
#[serde(
|
||||||
|
rename = "org.matrix.msc3706.servers_in_room",
|
||||||
|
skip_serializing_if = "Option::is_none"
|
||||||
|
)]
|
||||||
|
pub servers_in_room: Option<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-unspecified")]
|
||||||
|
impl Default for RoomState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RoomState {
|
||||||
|
#[cfg(not(feature = "unstable-unspecified"))]
|
||||||
|
/// Creates an empty `RoomState` with the given `origin`.
|
||||||
|
///
|
||||||
|
/// With the `unstable-unspecified` feature, this method doesn't take any parameters.
|
||||||
|
/// See [matrix-spec#374](https://github.com/matrix-org/matrix-spec/issues/374).
|
||||||
|
pub fn new(origin: String) -> Self {
|
||||||
|
Self {
|
||||||
|
origin,
|
||||||
|
auth_chain: Vec::new(),
|
||||||
|
state: Vec::new(),
|
||||||
|
event: None,
|
||||||
|
#[cfg(feature = "unstable-msc3706")]
|
||||||
|
members_omitted: false,
|
||||||
|
#[cfg(feature = "unstable-msc3706")]
|
||||||
|
servers_in_room: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-unspecified")]
|
||||||
|
/// Creates an empty `RoomState` with the given `origin`.
|
||||||
|
///
|
||||||
|
/// Without the `unstable-unspecified` feature, this method takes a parameter for the origin.
|
||||||
|
/// See [matrix-spec#374](https://github.com/matrix-org/matrix-spec/issues/374).
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
auth_chain: Vec::new(),
|
||||||
|
state: Vec::new(),
|
||||||
|
event: None,
|
||||||
|
#[cfg(feature = "unstable-msc3706")]
|
||||||
|
members_omitted: false,
|
||||||
|
#[cfg(feature = "unstable-msc3706")]
|
||||||
|
servers_in_room: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -74,7 +74,7 @@ mod tests {
|
|||||||
use serde_json::{json, to_value as to_json_value};
|
use serde_json::{json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{deserialize, serialize};
|
use super::{deserialize, serialize};
|
||||||
use crate::membership::create_join_event::RoomState;
|
use crate::membership::create_join_event::v1::RoomState;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_response() {
|
fn deserialize_response() {
|
||||||
|
@ -153,6 +153,7 @@ unstable-msc3553 = ["ruma-common/unstable-msc3553"]
|
|||||||
unstable-msc3554 = ["ruma-common/unstable-msc3554"]
|
unstable-msc3554 = ["ruma-common/unstable-msc3554"]
|
||||||
unstable-msc3575 = ["ruma-client-api?/unstable-msc3575"]
|
unstable-msc3575 = ["ruma-client-api?/unstable-msc3575"]
|
||||||
unstable-msc3618 = ["ruma-federation-api?/unstable-msc3618"]
|
unstable-msc3618 = ["ruma-federation-api?/unstable-msc3618"]
|
||||||
|
unstable-msc3706 = ["ruma-federation-api?/unstable-msc3706"]
|
||||||
unstable-msc3723 = ["ruma-federation-api?/unstable-msc3723"]
|
unstable-msc3723 = ["ruma-federation-api?/unstable-msc3723"]
|
||||||
unstable-msc3783 = ["ruma-common/unstable-msc3783"]
|
unstable-msc3783 = ["ruma-common/unstable-msc3783"]
|
||||||
unstable-msc3931 = ["ruma-common/unstable-msc3931"]
|
unstable-msc3931 = ["ruma-common/unstable-msc3931"]
|
||||||
@ -193,6 +194,7 @@ __ci = [
|
|||||||
"unstable-msc3554",
|
"unstable-msc3554",
|
||||||
"unstable-msc3575",
|
"unstable-msc3575",
|
||||||
"unstable-msc3618",
|
"unstable-msc3618",
|
||||||
|
"unstable-msc3706",
|
||||||
"unstable-msc3723",
|
"unstable-msc3723",
|
||||||
"unstable-msc3783",
|
"unstable-msc3783",
|
||||||
"unstable-msc3932",
|
"unstable-msc3932",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user