Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion crates/matrix-sdk-base/src/store/send_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,19 @@ impl SerializableEventContent {
self.event.deserialize_with_type(&self.event_type)
}

/// Returns the raw event content along with its type.
/// Returns the raw event content along with its type, borrowed variant.
///
/// Useful for callers manipulating custom events.
pub fn raw(&self) -> (&Raw<AnyMessageLikeEventContent>, &str) {
(&self.event, &self.event_type)
}

/// Returns the raw event content along with its type, owned variant.
///
/// Useful for callers manipulating custom events.
pub fn into_raw(self) -> (Raw<AnyMessageLikeEventContent>, String) {
(self.event, self.event_type)
}
}

/// The kind of a send queue request.
Expand Down
21 changes: 20 additions & 1 deletion crates/matrix-sdk-common/src/serde_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

use ruma::{
OwnedEventId,
events::{AnySyncMessageLikeEvent, AnySyncTimelineEvent, relation::BundledThread},
events::{
AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnySyncTimelineEvent,
relation::BundledThread,
},
serde::Raw,
};
use serde::Deserialize;
Expand Down Expand Up @@ -45,6 +48,22 @@ struct SimplifiedContent {
relates_to: Option<RelatesTo>,
}

/// Try to extract the thread root from an event's content, if provided.
///
/// The thread root is the field located at `m.relates_to`.`event_id`,
/// if the field at `m.relates_to`.`rel_type` is `m.thread`.
///
/// Returns `None` if we couldn't find a thread root, or if there was an issue
/// during deserialization.
pub fn extract_thread_root_from_content(
content: Raw<AnyMessageLikeEventContent>,
) -> Option<OwnedEventId> {
let relates_to = content.deserialize_as_unchecked::<SimplifiedContent>().ok()?.relates_to?;
match relates_to.rel_type {
RelationsType::Thread => relates_to.event_id,
}
}

/// Try to extract the thread root from a timeline event, if provided.
///
/// The thread root is the field located at `content`.`m.relates_to`.`event_id`,
Expand Down
1 change: 1 addition & 0 deletions crates/matrix-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ futures-util.workspace = true
http.workspace = true
imbl = { workspace = true, features = ["serde"] }
indexmap.workspace = true
itertools.workspace = true
js_int = "0.2.2"
language-tags = { version = "0.3.2" }
matrix-sdk-base.workspace = true
Expand Down
Loading
Loading