events: Stabilize annotations and reactions

This commit is contained in:
Kévin Commaille 2023-05-25 21:22:03 +02:00 committed by Kévin Commaille
parent ce30aeb775
commit 2d697fcc95
11 changed files with 11 additions and 29 deletions

View File

@ -36,6 +36,7 @@ Improvements:
- `user_can_trigger_room_notification`
- Add `MessageType::sanitize` behind the `unstable-sanitize` feature
- Add `MatrixVersion::V1_7`
- Stabilize support for annotations and reactions (MSC2677 / Matrix 1.7)
# 0.11.3

View File

@ -30,7 +30,6 @@ rand = ["dep:rand", "dep:uuid"]
unstable-exhaustive-types = []
unstable-msc1767 = []
unstable-msc2448 = []
unstable-msc2677 = []
unstable-msc2746 = []
unstable-msc2747 = []
unstable-msc2870 = []

View File

@ -149,7 +149,6 @@ pub mod policy;
pub mod poll;
pub mod presence;
pub mod push_rules;
#[cfg(feature = "unstable-msc2677")]
pub mod reaction;
pub mod receipt;
pub mod relation;

View File

@ -79,7 +79,6 @@ event_enum! {
#[cfg(feature = "unstable-msc3381")]
#[ruma_enum(alias = "m.poll.end")]
"org.matrix.msc3381.v2.poll.end" => super::poll::end,
#[cfg(feature = "unstable-msc2677")]
"m.reaction" => super::reaction,
"m.room.encrypted" => super::room::encrypted,
"m.room.message" => super::room::message,
@ -313,7 +312,6 @@ impl AnyMessageLikeEventContent {
| Self::KeyVerificationDone(KeyVerificationDoneEventContent { relates_to, .. }) => {
Some(encrypted::Relation::Reference(relates_to.clone()))
},
#[cfg(feature = "unstable-msc2677")]
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),

View File

@ -1,4 +1,6 @@
//! Types for the `m.reaction` event.
//! Types for the [`m.reaction`] event.
//!
//! [`m.reaction`]: https://spec.matrix.org/latest/client-server-api/#mreaction
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};

View File

@ -34,9 +34,8 @@ impl InReplyTo {
/// An [annotation] for an event.
///
/// [annotation]: https://github.com/matrix-org/matrix-spec-proposals/pull/2677
/// [annotation]: https://spec.matrix.org/latest/client-server-api/#event-annotations-and-reactions
#[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 {
@ -52,7 +51,6 @@ pub struct Annotation {
pub key: String,
}
#[cfg(feature = "unstable-msc2677")]
impl Annotation {
/// Creates a new `Annotation` with the given event ID and key.
pub fn new(event_id: OwnedEventId, key: String) -> Self {
@ -290,7 +288,6 @@ impl BundledStateRelations {
#[non_exhaustive]
pub enum RelationType {
/// `m.annotation`, an annotation, principally used by reactions.
#[cfg(feature = "unstable-msc2677")]
Annotation,
/// `m.replace`, a replacement.

View File

@ -9,10 +9,8 @@ use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::message;
#[cfg(feature = "unstable-msc2677")]
use crate::events::relation::Annotation;
use crate::{
events::relation::{InReplyTo, Reference, Thread},
events::relation::{Annotation, InReplyTo, Reference, Thread},
OwnedDeviceId, OwnedEventId,
};
@ -106,7 +104,6 @@ pub enum Relation {
Reference(Reference),
/// An annotation to an event.
#[cfg(feature = "unstable-msc2677")]
Annotation(Annotation),
/// An event that belongs to a thread.

View File

@ -1,8 +1,6 @@
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "unstable-msc2677")]
use super::Annotation;
use super::{InReplyTo, Reference, Relation, Replacement, Thread};
use super::{Annotation, InReplyTo, Reference, Relation, Replacement, Thread};
use crate::OwnedEventId;
pub(crate) fn deserialize_relation<'de, D>(deserializer: D) -> Result<Option<Relation>, D::Error>
@ -23,7 +21,6 @@ where
Some(Relation::Reply { in_reply_to })
} else {
ev.relates_to.relation.map(|relation| match relation {
#[cfg(feature = "unstable-msc2677")]
RelationJsonRepr::Annotation(a) => Relation::Annotation(a),
RelationJsonRepr::Reference(r) => Relation::Reference(r),
RelationJsonRepr::Replacement(Replacement { event_id }) => {
@ -48,7 +45,6 @@ impl Serialize for Relation {
{
#[allow(clippy::needless_update)]
let relates_to = match self {
#[cfg(feature = "unstable-msc2677")]
Relation::Annotation(r) => RelatesToJsonRepr {
relation: Some(RelationJsonRepr::Annotation(r.clone())),
..Default::default()
@ -137,7 +133,6 @@ struct ThreadUnstableJsonRepr {
#[serde(tag = "rel_type")]
enum RelationJsonRepr {
/// An annotation to an event.
#[cfg(feature = "unstable-msc2677")]
#[serde(rename = "m.annotation")]
Annotation(Annotation),

View File

@ -30,9 +30,8 @@ impl Ruleset {
ConditionalPushRule::contains_display_name(),
ConditionalPushRule::roomnotif(),
ConditionalPushRule::tombstone(),
ConditionalPushRule::server_acl(),
#[cfg(feature = "unstable-msc2677")]
ConditionalPushRule::reaction(),
ConditionalPushRule::server_acl(),
]
.into(),
underride: [
@ -227,9 +226,9 @@ impl ConditionalPushRule {
}
}
/// Matches emoji reactions to a message
/// MSC2677: Annotations and Reactions
#[cfg(feature = "unstable-msc2677")]
/// Matches [reactions] to a message.
///
/// [reactions]: https://spec.matrix.org/latest/client-server-api/#event-annotations-and-reactions
pub fn reaction() -> Self {
Self {
actions: vec![],
@ -469,7 +468,6 @@ pub enum PredefinedOverrideRuleId {
RoomServerAcl,
/// `.m.rule.reaction`
#[cfg(feature = "unstable-msc2677")]
Reaction,
#[doc(hidden)]

View File

@ -386,7 +386,6 @@ fn content_thread_deserialization() {
}
#[test]
#[cfg(feature = "unstable-msc2677")]
fn content_annotation_serialization() {
use ruma_common::events::relation::Annotation;
@ -421,7 +420,6 @@ fn content_annotation_serialization() {
}
#[test]
#[cfg(feature = "unstable-msc2677")]
fn content_annotation_deserialization() {
let json = json!({
"algorithm": "m.megolm.v1.aes-sha2",

View File

@ -157,7 +157,6 @@ unstable-msc2448 = [
]
unstable-msc2654 = ["ruma-client-api?/unstable-msc2654"]
unstable-msc2666 = ["ruma-client-api?/unstable-msc2666"]
unstable-msc2677 = ["ruma-common/unstable-msc2677"]
unstable-msc2746 = ["ruma-common/unstable-msc2746"]
unstable-msc2747 = ["ruma-common/unstable-msc2747"]
unstable-msc2870 = ["ruma-common/unstable-msc2870"]
@ -203,7 +202,6 @@ __ci = [
"unstable-msc2448",
"unstable-msc2654",
"unstable-msc2666",
"unstable-msc2677",
"unstable-msc2746",
"unstable-msc2747",
"unstable-msc2870",