events: Use Annotation instead of events::reaction::Relation

This commit is contained in:
Kévin Commaille 2022-11-25 19:45:12 +01:00 committed by Kévin Commaille
parent 6648954bd2
commit e63896b916
4 changed files with 18 additions and 44 deletions

View File

@ -35,6 +35,7 @@ Breaking changes:
* Move relation structs under `events::room::message` to `events::relation` * Move relation structs under `events::room::message` to `events::relation`
* Move common relation structs under `events::room::encrypted` to `events::relation` and remove * Move common relation structs under `events::room::encrypted` to `events::relation` and remove
duplicate types duplicate types
* Remove `events::reaction::Relation` and use `events::relation::Annotation` instead
Improvements: Improvements:

View File

@ -8,9 +8,8 @@ use super::{
Redact, Relations, Redact, Relations,
}; };
use crate::{ use crate::{
events::relation::{Annotation, Reference}, events::relation::Reference, serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch,
serde::from_raw_json_value, OwnedRoomId, RoomId, RoomVersionId, TransactionId, UserId,
EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId, RoomVersionId, TransactionId, UserId,
}; };
event_enum! { event_enum! {
@ -332,15 +331,7 @@ impl AnyMessageLikeEventContent {
})) }))
} }
#[cfg(feature = "unstable-msc2677")] #[cfg(feature = "unstable-msc2677")]
Self::Reaction(ev) => { Self::Reaction(ev) => Some(encrypted::Relation::Annotation(ev.relates_to.clone())),
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::RoomEncrypted(ev) => ev.relates_to.clone(), Self::RoomEncrypted(ev) => ev.relates_to.clone(),
Self::RoomMessage(ev) => ev.relates_to.clone().map(Into::into), Self::RoomMessage(ev) => ev.relates_to.clone().map(Into::into),
#[cfg(feature = "unstable-msc1767")] #[cfg(feature = "unstable-msc1767")]

View File

@ -3,7 +3,7 @@
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::OwnedEventId; use super::relation::Annotation;
/// The payload for a `m.reaction` event. /// The payload for a `m.reaction` event.
/// ///
@ -14,48 +14,24 @@ use crate::OwnedEventId;
pub struct ReactionEventContent { pub struct ReactionEventContent {
/// Information about the related event. /// Information about the related event.
#[serde(rename = "m.relates_to")] #[serde(rename = "m.relates_to")]
pub relates_to: Relation, pub relates_to: Annotation,
} }
impl ReactionEventContent { 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`. /// You can also construct a `ReactionEventContent` from an annotation using `From` / `Into`.
pub fn new(relates_to: Relation) -> Self { pub fn new(relates_to: Annotation) -> Self {
Self { relates_to } Self { relates_to }
} }
} }
impl From<Relation> for ReactionEventContent { impl From<Annotation> for ReactionEventContent {
fn from(relates_to: Relation) -> Self { fn from(relates_to: Annotation) -> Self {
Self::new(relates_to) 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)] #[cfg(test)]
mod tests { mod tests {
use assert_matches::assert_matches; use assert_matches::assert_matches;

View File

@ -36,11 +36,17 @@ impl InReplyTo {
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg(feature = "unstable-msc2677")] #[cfg(feature = "unstable-msc2677")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "rel_type", rename = "m.annotation")]
pub struct Annotation { pub struct Annotation {
/// The event that is being annotated. /// The event that is being annotated.
pub event_id: OwnedEventId, 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, pub key: String,
} }