events: Change BundledAnnotation to a struct
This commit is contained in:
parent
8bf74a0ce7
commit
baa6dc591e
@ -9,6 +9,8 @@ Breaking changes:
|
|||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
* All push rules are now considered to not apply to events sent by the user themselves
|
* All push rules are now considered to not apply to events sent by the user themselves
|
||||||
|
* Change `events::relation::BundledAnnotation` to a struct instead of an enum
|
||||||
|
* Remove `BundledReaction`
|
||||||
|
|
||||||
# 0.9.2
|
# 0.9.2
|
||||||
|
|
||||||
|
@ -6,45 +6,56 @@ use js_int::UInt;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::AnySyncMessageLikeEvent;
|
use super::AnySyncMessageLikeEvent;
|
||||||
use crate::{serde::Raw, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId};
|
use crate::{
|
||||||
|
serde::{Raw, StringEnum},
|
||||||
|
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, PrivOwnedStr,
|
||||||
|
};
|
||||||
|
|
||||||
/// Summary of all reactions with the given key to an event.
|
/// Summary of all annotations to an event with the given key and type.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, 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)]
|
||||||
pub struct BundledReaction {
|
pub struct BundledAnnotation {
|
||||||
/// The key used for the reaction.
|
/// The type of the annotation.
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub annotation_type: AnnotationType,
|
||||||
|
|
||||||
|
/// The key used for the annotation.
|
||||||
pub key: String,
|
pub key: String,
|
||||||
|
|
||||||
/// Time of the bundled reaction being compiled on the server.
|
/// Time of the bundled annotation being compiled on the server.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub origin_server_ts: Option<MilliSecondsSinceUnixEpoch>,
|
pub origin_server_ts: Option<MilliSecondsSinceUnixEpoch>,
|
||||||
|
|
||||||
/// Number of reactions.
|
/// Number of annotations.
|
||||||
pub count: UInt,
|
pub count: UInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-msc2677")]
|
#[cfg(feature = "unstable-msc2677")]
|
||||||
impl BundledReaction {
|
impl BundledAnnotation {
|
||||||
/// Creates a new `BundledReaction`.
|
/// Creates a new `BundledAnnotation` with the given type, key and count.
|
||||||
pub fn new(
|
pub fn new(annotation_type: AnnotationType, key: String, count: UInt) -> Self {
|
||||||
key: String,
|
Self { annotation_type, key, count, origin_server_ts: None }
|
||||||
origin_server_ts: Option<MilliSecondsSinceUnixEpoch>,
|
}
|
||||||
count: UInt,
|
|
||||||
) -> Self {
|
/// Creates a new `BundledAnnotation` for a reaction with the given key and count.
|
||||||
Self { key, origin_server_ts, count }
|
pub fn reaction(key: String, count: UInt) -> Self {
|
||||||
|
Self::new(AnnotationType::Reaction, key, count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type of bundled annotation.
|
/// Type of annotation.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||||
#[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 = "type")]
|
pub enum AnnotationType {
|
||||||
pub enum BundledAnnotation {
|
/// A reaction.
|
||||||
/// An emoji reaction and its count.
|
#[ruma_enum(rename = "m.reaction")]
|
||||||
#[serde(rename = "m.reaction")]
|
Reaction,
|
||||||
Reaction(BundledReaction),
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
_Custom(PrivOwnedStr),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The first chunk of annotations with a token for loading more.
|
/// The first chunk of annotations with a token for loading more.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user