Skip to content

Commit

Permalink
events: Add support for bundled reference relations
Browse files Browse the repository at this point in the history
According to MSC3267 / Matrix 1.5
  • Loading branch information
zecakeh committed Nov 25, 2022
1 parent 1ecd7ef commit 583ee2c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/ruma-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Improvements:
* `Ruleset::insert` to add or update user push rules
* `Ruleset::set_enabled` to change the enabled state of push rules
* `Ruleset::set_actions` to change the actions of push rules
* Add support for bundled reference relations (MSC3267 / Matrix 1.5)

# 0.10.5

Expand Down
41 changes: 38 additions & 3 deletions crates/ruma-common/src/events/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,36 @@ impl BundledThread {
}
}

/// A bundled reference.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct BundledReference {
/// The ID of the event referencing this event.
pub event_id: OwnedEventId,
}

impl BundledReference {
/// Creates a new `BundledThread` with the given event ID.
pub fn new(event_id: OwnedEventId) -> Self {
Self { event_id }
}
}

/// A chunk of references.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct ReferenceChunk {
/// A batch of bundled references.
pub chunk: Vec<BundledReference>,
}

impl ReferenceChunk {
/// Creates a new `ReferenceChunk` with the given chunk.
pub fn new(chunk: Vec<BundledReference>) -> Self {
Self { chunk }
}
}

/// [Bundled aggregations] of related child events.
///
/// [Bundled aggregations]: https://spec.matrix.org/v1.4/client-server-api/#aggregations
Expand All @@ -149,6 +179,10 @@ pub struct Relations {
/// Thread relation.
#[serde(rename = "m.thread")]
pub thread: Option<BundledThread>,

/// Reference relations.
#[serde(rename = "m.reference")]
pub reference: Option<ReferenceChunk>,
}

impl Relations {
Expand All @@ -161,21 +195,22 @@ impl Relations {
/// Relation types as defined in `rel_type` of an `m.relates_to` field.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "m.snake_case")]
#[non_exhaustive]
pub enum RelationType {
/// `m.annotation`, an annotation, principally used by reactions.
#[cfg(feature = "unstable-msc2677")]
#[ruma_enum(rename = "m.annotation")]
Annotation,

/// `m.replace`, a replacement.
#[ruma_enum(rename = "m.replace")]
Replacement,

/// `m.thread`, a participant to a thread.
#[ruma_enum(rename = "m.thread")]
Thread,

/// `m.reference`, a reference to another event.
Reference,

#[doc(hidden)]
_Custom(PrivOwnedStr),
}

0 comments on commit 583ee2c

Please sign in to comment.