From c322bd4d1e78c5a8cd9dd6e3a4168ecf1dff71e4 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 24 Nov 2020 02:31:09 +0100 Subject: [PATCH] events: Feature-gate reactions and make relationships module public. The re-export idea doesn't make sense with annotations being used in both reactions and messages. --- ruma-events/src/enums.rs | 1 + ruma-events/src/lib.rs | 1 + ruma-events/src/room.rs | 2 +- ruma-events/src/room/message.rs | 18 ++++++++---------- ruma-events/src/room/relationships.rs | 5 +++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ruma-events/src/enums.rs b/ruma-events/src/enums.rs index de0ab6b1..00dd1285 100644 --- a/ruma-events/src/enums.rs +++ b/ruma-events/src/enums.rs @@ -36,6 +36,7 @@ event_enum! { "m.call.invite", "m.call.hangup", "m.call.candidates", + #[cfg(feature = "unstable-pre-spec")] "m.reaction", "m.room.encrypted", "m.room.message", diff --git a/ruma-events/src/lib.rs b/ruma-events/src/lib.rs index b0d10578..dc0c3851 100644 --- a/ruma-events/src/lib.rs +++ b/ruma-events/src/lib.rs @@ -170,6 +170,7 @@ pub mod pdu; pub mod policy; pub mod presence; pub mod push_rules; +#[cfg(feature = "unstable-pre-spec")] pub mod reaction; pub mod receipt; pub mod room; diff --git a/ruma-events/src/room.rs b/ruma-events/src/room.rs index f9e51e5d..7bb20ba7 100644 --- a/ruma-events/src/room.rs +++ b/ruma-events/src/room.rs @@ -22,7 +22,7 @@ pub mod name; pub mod pinned_events; pub mod power_levels; pub mod redaction; -pub(crate) mod relationships; +pub mod relationships; pub mod server_acl; pub mod third_party_invite; pub mod tombstone; diff --git a/ruma-events/src/room/message.rs b/ruma-events/src/room/message.rs index cbb9ddd2..c809fb63 100644 --- a/ruma-events/src/room/message.rs +++ b/ruma-events/src/room/message.rs @@ -6,15 +6,12 @@ use ruma_events_macros::MessageEventContent; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; -use super::{ - relationships::{RelatesToJsonRepr, RelationJsonRepr}, - EncryptedFile, ImageInfo, ThumbnailInfo, -}; - -pub use super::relationships::{Annotation, InReplyTo}; - #[cfg(feature = "unstable-pre-spec")] -pub use super::relationships::{Reference, Replacement}; +use super::relationships::{Annotation, Reference, RelationJsonRepr, Replacement}; +use super::{relationships::RelatesToJsonRepr, EncryptedFile, ImageInfo, ThumbnailInfo}; + +// FIXME: Do we want to keep re-exporting this? +pub use super::relationships::InReplyTo; pub mod feedback; @@ -78,6 +75,7 @@ pub enum Relation { Reference(Reference), /// An annotation to an event. + #[cfg(feature = "unstable-pre-spec")] Annotation(Annotation), /// An event that replaces another event. @@ -98,6 +96,7 @@ pub enum Relation { impl From for RelatesToJsonRepr { fn from(value: Relation) -> Self { match value { + #[cfg(feature = "unstable-pre-spec")] Relation::Annotation(r) => RelatesToJsonRepr::Relation(RelationJsonRepr::Annotation(r)), #[cfg(feature = "unstable-pre-spec")] Relation::Reference(r) => RelatesToJsonRepr::Relation(RelationJsonRepr::Reference(r)), @@ -114,11 +113,10 @@ impl From for RelatesToJsonRepr { impl From for Relation { fn from(value: RelatesToJsonRepr) -> Self { match value { + #[cfg(feature = "unstable-pre-spec")] RelatesToJsonRepr::Relation(r) => match r { RelationJsonRepr::Annotation(a) => Self::Annotation(a), - #[cfg(feature = "unstable-pre-spec")] RelationJsonRepr::Reference(r) => Self::Reference(r), - #[cfg(feature = "unstable-pre-spec")] RelationJsonRepr::Replacement(r) => Self::Replacement(r), }, RelatesToJsonRepr::Reply { in_reply_to } => Self::Reply { in_reply_to }, diff --git a/ruma-events/src/room/relationships.rs b/ruma-events/src/room/relationships.rs index 1feed9fb..f3a141ff 100644 --- a/ruma-events/src/room/relationships.rs +++ b/ruma-events/src/room/relationships.rs @@ -17,6 +17,7 @@ use serde_json::Value as JsonValue; pub(crate) enum RelatesToJsonRepr { /// A relation which contains subtypes indicating the type of the /// relationship with the `rel_type` field. + #[cfg(feature = "unstable-pre-spec")] Relation(RelationJsonRepr), /// An `m.in_reply_to` relationship indicating that the event is a reply to @@ -33,6 +34,7 @@ pub(crate) enum RelatesToJsonRepr { /// A relation, which associates new information to an existing event. #[derive(Clone, Debug, Deserialize, Serialize)] +#[cfg(feature = "unstable-pre-spec")] #[serde(tag = "rel_type")] pub(crate) enum RelationJsonRepr { /// An annotation to an event. @@ -40,12 +42,10 @@ pub(crate) enum RelationJsonRepr { Annotation(Annotation), /// A reference to another event. - #[cfg(feature = "unstable-pre-spec")] #[serde(rename = "m.reference")] Reference(Reference), /// An event that replaces another event. - #[cfg(feature = "unstable-pre-spec")] #[serde(rename = "m.replace")] Replacement(Replacement), } @@ -142,6 +142,7 @@ mod test { } #[test] + #[cfg(feature = "unstable-pre-spec")] fn annotation_deserialize() { let event_id = event_id!("$1598361704261elfgc:localhost");