Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events: Add support for bundled reference relations #1391

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ruma-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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),
}