From 80a8dcf28ad2c070caafddf2f1228e6fa6bf4f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 20 Jun 2022 17:15:18 +0200 Subject: [PATCH] events: Stabilize MSC2675 --- crates/ruma-common/CHANGELOG.md | 1 + crates/ruma-common/Cargo.toml | 1 - crates/ruma-common/src/events.rs | 4 +- crates/ruma-common/src/events/relation.rs | 22 ++++++---- crates/ruma-common/src/events/unsigned.rs | 51 ++++++----------------- crates/ruma/Cargo.toml | 4 -- 6 files changed, 30 insertions(+), 53 deletions(-) diff --git a/crates/ruma-common/CHANGELOG.md b/crates/ruma-common/CHANGELOG.md index 3bb3ac1c..8bed3c06 100644 --- a/crates/ruma-common/CHANGELOG.md +++ b/crates/ruma-common/CHANGELOG.md @@ -29,6 +29,7 @@ Improvements: * Add support for knocking in `events::room::member::MembershipChange` * Add `MatrixVersion::V1_3` * Deprecate the `sender_key` and `device_id` fields for encrypted events (MSC3700) +* Move the `relations` field of `events::unsigned` types out of `unstable-msc2675` # 0.9.2 diff --git a/crates/ruma-common/Cargo.toml b/crates/ruma-common/Cargo.toml index 6bcef7a7..130cf50e 100644 --- a/crates/ruma-common/Cargo.toml +++ b/crates/ruma-common/Cargo.toml @@ -34,7 +34,6 @@ unstable-pdu = [] unstable-pre-spec = [] unstable-msc1767 = [] unstable-msc2448 = [] -unstable-msc2675 = [] unstable-msc2676 = [] unstable-msc2677 = [] unstable-msc2746 = [] diff --git a/crates/ruma-common/src/events.rs b/crates/ruma-common/src/events.rs index 3a947141..47eb88cb 100644 --- a/crates/ruma-common/src/events.rs +++ b/crates/ruma-common/src/events.rs @@ -153,7 +153,6 @@ pub mod push_rules; #[cfg(feature = "unstable-msc2677")] pub mod reaction; pub mod receipt; -#[cfg(feature = "unstable-msc2675")] pub mod relation; pub mod room; pub mod room_key; @@ -169,12 +168,11 @@ pub mod video; #[cfg(feature = "unstable-msc3245")] pub mod voice; -#[cfg(feature = "unstable-msc2675")] -pub use self::relation::Relations; pub use self::{ content::*, enums::*, kinds::*, + relation::Relations, state_key::EmptyStateKey, unsigned::{MessageLikeUnsigned, RedactedUnsigned, StateUnsigned}, }; diff --git a/crates/ruma-common/src/events/relation.rs b/crates/ruma-common/src/events/relation.rs index 7ed8b282..c68b5a0d 100644 --- a/crates/ruma-common/src/events/relation.rs +++ b/crates/ruma-common/src/events/relation.rs @@ -1,15 +1,22 @@ -//! Types describing event relations after MSC 2674, 2675, 2676, 2677. +//! Types describing [relationships between events]. +//! +//! [relationships between events]: https://spec.matrix.org/v1.3/client-server-api/#forming-relationships-between-events use std::fmt::Debug; +#[cfg(any(feature = "unstable-msc2677", feature = "unstable-msc3440"))] use js_int::UInt; use serde::{Deserialize, Serialize}; +#[cfg(feature = "unstable-msc3440")] use super::AnySyncMessageLikeEvent; -use crate::{ - serde::{Raw, StringEnum}, - MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, PrivOwnedStr, -}; +#[cfg(feature = "unstable-msc3440")] +use crate::serde::Raw; +#[cfg(feature = "unstable-msc2677")] +use crate::MilliSecondsSinceUnixEpoch; +use crate::{serde::StringEnum, PrivOwnedStr}; +#[cfg(feature = "unstable-msc2676")] +use crate::{OwnedEventId, OwnedUserId}; /// Summary of all annotations to an event with the given key and type. #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] @@ -130,7 +137,9 @@ impl BundledThread { } } -/// Precompiled list of relations to this event grouped by relation type. +/// [Bundled aggregations] of related child events. +/// +/// [Bundled aggregations]: https://spec.matrix.org/v1.3/client-server-api/#aggregations #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Relations { @@ -160,7 +169,6 @@ impl Relations { /// Relation types as defined in `rel_type` of an `m.relates_to` field. #[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)] -#[cfg(any(feature = "unstable-msc3440", feature = "unstable-msc2675"))] #[non_exhaustive] pub enum RelationType { /// `m.annotation`, an annotation, principally used by reactions. diff --git a/crates/ruma-common/src/events/unsigned.rs b/crates/ruma-common/src/events/unsigned.rs index 013b01e2..f66f6080 100644 --- a/crates/ruma-common/src/events/unsigned.rs +++ b/crates/ruma-common/src/events/unsigned.rs @@ -2,9 +2,7 @@ use js_int::Int; use serde::{Deserialize, Serialize}; use serde_json::{from_str as from_json_str, value::RawValue as RawJsonValue}; -#[cfg(feature = "unstable-msc2675")] -use super::relation::Relations; -use super::{room::redaction::SyncRoomRedactionEvent, StateEventContent}; +use super::{relation::Relations, room::redaction::SyncRoomRedactionEvent, StateEventContent}; use crate::{serde::Raw, OwnedTransactionId}; /// Extra information about a message event that is not incorporated into the event's hash. @@ -24,8 +22,9 @@ pub struct MessageLikeUnsigned { #[serde(skip_serializing_if = "Option::is_none")] pub transaction_id: Option, - /// Server-compiled information from other events relating to this event. - #[cfg(feature = "unstable-msc2675")] + /// [Bundled aggregations] of related child events. + /// + /// [Bundled aggregations]: https://spec.matrix.org/v1.3/client-server-api/#aggregations #[serde(rename = "m.relations", skip_serializing_if = "Option::is_none")] pub relations: Option, } @@ -42,15 +41,7 @@ impl MessageLikeUnsigned { /// events. Do not use it to determine whether an incoming `unsigned` field was present - it /// could still have been present but contained none of the known fields. pub fn is_empty(&self) -> bool { - #[cfg(not(feature = "unstable-msc2675"))] - { - self.age.is_none() && self.transaction_id.is_none() - } - - #[cfg(feature = "unstable-msc2675")] - { - self.age.is_none() && self.transaction_id.is_none() && self.relations.is_none() - } + self.age.is_none() && self.transaction_id.is_none() && self.relations.is_none() } } @@ -75,8 +66,9 @@ pub struct StateUnsigned { #[serde(skip_serializing_if = "Option::is_none")] pub prev_content: Option, - /// Server-compiled information from other events relating to this event. - #[cfg(feature = "unstable-msc2675")] + /// [Bundled aggregations] of related child events. + /// + /// [Bundled aggregations]: https://spec.matrix.org/v1.3/client-server-api/#aggregations #[serde(rename = "m.relations", skip_serializing_if = "Option::is_none")] pub relations: Option, } @@ -84,13 +76,7 @@ pub struct StateUnsigned { impl StateUnsigned { /// Create a new `Unsigned` with fields set to `None`. pub fn new() -> Self { - Self { - age: None, - transaction_id: None, - prev_content: None, - #[cfg(feature = "unstable-msc2675")] - relations: None, - } + Self { age: None, transaction_id: None, prev_content: None, relations: None } } /// Whether this unsigned data is empty (all fields are `None`). @@ -99,18 +85,10 @@ impl StateUnsigned { /// events. Do not use it to determine whether an incoming `unsigned` field was present - it /// could still have been present but contained none of the known fields. pub fn is_empty(&self) -> bool { - #[cfg(not(feature = "unstable-msc2675"))] - { - self.age.is_none() && self.transaction_id.is_none() && self.prev_content.is_none() - } - - #[cfg(feature = "unstable-msc2675")] - { - self.age.is_none() - && self.transaction_id.is_none() - && self.prev_content.is_none() - && self.relations.is_none() - } + self.age.is_none() + && self.transaction_id.is_none() + && self.prev_content.is_none() + && self.relations.is_none() } } @@ -128,7 +106,6 @@ impl StateUnsigned { #[serde(skip_serializing_if = "Option::is_none")] transaction_id: Option, prev_content: Option>, - #[cfg(feature = "unstable-msc2675")] #[serde(rename = "m.relations", skip_serializing_if = "Option::is_none")] relations: Option, } @@ -140,7 +117,6 @@ impl StateUnsigned { Ok(Self { age: raw.age, transaction_id: raw.transaction_id, - #[cfg(feature = "unstable-msc2675")] relations: raw.relations, prev_content, }) @@ -154,7 +130,6 @@ impl StateUnsigned { age: self.age, transaction_id: self.transaction_id.clone(), prev_content: self.prev_content.as_ref().map(f), - #[cfg(feature = "unstable-msc2675")] relations: self.relations.clone(), } } diff --git a/crates/ruma/Cargo.toml b/crates/ruma/Cargo.toml index 2f2e9f9d..7b3b2cca 100644 --- a/crates/ruma/Cargo.toml +++ b/crates/ruma/Cargo.toml @@ -125,9 +125,6 @@ unstable-msc2448 = [ ] unstable-msc2654 = ["ruma-client-api?/unstable-msc2654"] unstable-msc2666 = ["ruma-client-api?/unstable-msc2666"] -unstable-msc2675 = [ - "ruma-common/unstable-msc2675", -] unstable-msc2676 = [ "ruma-client-api?/unstable-msc2676", "ruma-common/unstable-msc2676", @@ -165,7 +162,6 @@ __ci = [ "unstable-msc2448", "unstable-msc2666", "unstable-msc2654", - "unstable-msc2675", "unstable-msc2676", "unstable-msc2677", "unstable-msc2746",