diff --git a/crates/ruma-common/CHANGELOG.md b/crates/ruma-common/CHANGELOG.md index 2357317d..af2e2fba 100644 --- a/crates/ruma-common/CHANGELOG.md +++ b/crates/ruma-common/CHANGELOG.md @@ -35,6 +35,7 @@ Breaking changes: * Move relation structs under `events::room::message` to `events::relation` * Move common relation structs under `events::room::encrypted` to `events::relation` and remove duplicate types + * Remove `events::reaction::Relation` and use `events::relation::Annotation` instead Improvements: diff --git a/crates/ruma-common/src/events/enums.rs b/crates/ruma-common/src/events/enums.rs index d6419935..1bf83e15 100644 --- a/crates/ruma-common/src/events/enums.rs +++ b/crates/ruma-common/src/events/enums.rs @@ -8,9 +8,8 @@ use super::{ Redact, Relations, }; use crate::{ - events::relation::{Annotation, Reference}, - serde::from_raw_json_value, - EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId, RoomVersionId, TransactionId, UserId, + events::relation::Reference, serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, + OwnedRoomId, RoomId, RoomVersionId, TransactionId, UserId, }; event_enum! { @@ -332,15 +331,7 @@ impl AnyMessageLikeEventContent { })) } #[cfg(feature = "unstable-msc2677")] - Self::Reaction(ev) => { - use super::reaction; - - let reaction::Relation { event_id, key } = &ev.relates_to; - Some(encrypted::Relation::Annotation(Annotation { - event_id: event_id.clone(), - key: key.clone(), - })) - } + Self::Reaction(ev) => Some(encrypted::Relation::Annotation(ev.relates_to.clone())), Self::RoomEncrypted(ev) => ev.relates_to.clone(), Self::RoomMessage(ev) => ev.relates_to.clone().map(Into::into), #[cfg(feature = "unstable-msc1767")] diff --git a/crates/ruma-common/src/events/reaction.rs b/crates/ruma-common/src/events/reaction.rs index 33352ad6..be2182da 100644 --- a/crates/ruma-common/src/events/reaction.rs +++ b/crates/ruma-common/src/events/reaction.rs @@ -3,7 +3,7 @@ use ruma_macros::EventContent; use serde::{Deserialize, Serialize}; -use crate::OwnedEventId; +use super::relation::Annotation; /// The payload for a `m.reaction` event. /// @@ -14,48 +14,24 @@ use crate::OwnedEventId; pub struct ReactionEventContent { /// Information about the related event. #[serde(rename = "m.relates_to")] - pub relates_to: Relation, + pub relates_to: Annotation, } impl ReactionEventContent { - /// Creates a new `ReactionEventContent` from the given relation. + /// Creates a new `ReactionEventContent` from the given annotation. /// - /// You can also construct a `ReactionEventContent` from a relation using `From` / `Into`. - pub fn new(relates_to: Relation) -> Self { + /// You can also construct a `ReactionEventContent` from an annotation using `From` / `Into`. + pub fn new(relates_to: Annotation) -> Self { Self { relates_to } } } -impl From for ReactionEventContent { - fn from(relates_to: Relation) -> Self { +impl From for ReactionEventContent { + fn from(relates_to: Annotation) -> Self { Self::new(relates_to) } } -/// Information about an annotation relation. -#[derive(Clone, Debug, Deserialize, Serialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[serde(tag = "rel_type", rename = "m.annotation")] -pub struct Relation { - /// The event that is being annotated. - pub event_id: OwnedEventId, - - /// A string that indicates the annotation being applied. - /// - /// When sending emoji reactions, this field should include the colourful variation-16 when - /// applicable. - /// - /// Clients should render reactions that have a long `key` field in a sensible manner. - pub key: String, -} - -impl Relation { - /// Creates a new `Relation` with the given event ID and key. - pub fn new(event_id: OwnedEventId, key: String) -> Self { - Self { event_id, key } - } -} - #[cfg(test)] mod tests { use assert_matches::assert_matches; diff --git a/crates/ruma-common/src/events/relation.rs b/crates/ruma-common/src/events/relation.rs index c1af79aa..52ae83bb 100644 --- a/crates/ruma-common/src/events/relation.rs +++ b/crates/ruma-common/src/events/relation.rs @@ -36,11 +36,17 @@ impl InReplyTo { #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg(feature = "unstable-msc2677")] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] +#[serde(tag = "rel_type", rename = "m.annotation")] pub struct Annotation { /// The event that is being annotated. pub event_id: OwnedEventId, - /// The annotation. + /// A string that indicates the annotation being applied. + /// + /// When sending emoji reactions, this field should include the colourful variation-16 when + /// applicable. + /// + /// Clients should render reactions that have a long `key` field in a sensible manner. pub key: String, }