diff --git a/crates/ruma-events/src/reaction.rs b/crates/ruma-events/src/reaction.rs index 530f610a..9e8ad21d 100644 --- a/crates/ruma-events/src/reaction.rs +++ b/crates/ruma-events/src/reaction.rs @@ -1,15 +1,10 @@ //! Types for the *m.reaction* event. -use std::convert::TryFrom; - use ruma_events_macros::EventContent; use ruma_identifiers::EventId; use serde::{Deserialize, Serialize}; -use crate::{ - room::relationships::{Annotation, RelatesToJsonRepr, RelationJsonRepr}, - MessageEvent, -}; +use crate::MessageEvent; /// A reaction to another event. pub type ReactionEvent = MessageEvent; @@ -21,28 +16,28 @@ pub type ReactionEvent = MessageEvent; pub struct ReactionEventContent { /// Information about the related event. #[serde(rename = "m.relates_to")] - pub relation: Relation, + pub relates_to: Relation, } impl ReactionEventContent { /// Creates a new `ReactionEventContent` from the given relation. /// /// You can also construct a `ReactionEventContent` from a relation using `From` / `Into`. - pub fn new(relation: Relation) -> Self { - Self { relation } + pub fn new(relates_to: Relation) -> Self { + Self { relates_to } } } impl From for ReactionEventContent { - fn from(relation: Relation) -> Self { - Self::new(relation) + fn from(relates_to: Relation) -> Self { + Self::new(relates_to) } } /// The relation that contains info which event the reaction is applying to. #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[serde(try_from = "RelatesToJsonRepr", into = "RelatesToJsonRepr")] +#[serde(tag = "rel_type", rename = "m.annotation")] pub struct Relation { /// The event that is being reacted to. pub event_id: EventId, @@ -57,24 +52,3 @@ impl Relation { Self { event_id, emoji } } } - -impl From for RelatesToJsonRepr { - fn from(relation: Relation) -> Self { - RelatesToJsonRepr::Relation(RelationJsonRepr::Annotation(Annotation { - event_id: relation.event_id, - key: relation.emoji, - })) - } -} - -impl TryFrom for Relation { - type Error = &'static str; - - fn try_from(value: RelatesToJsonRepr) -> Result { - if let RelatesToJsonRepr::Relation(RelationJsonRepr::Annotation(a)) = value { - Ok(Relation { event_id: a.event_id, emoji: a.key }) - } else { - Err("Expected a relation with a rel_type of `annotation`") - } - } -}