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 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:

View File

@ -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")]

View File

@ -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<Relation> for ReactionEventContent {
fn from(relates_to: Relation) -> Self {
impl From<Annotation> 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;

View File

@ -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,
}