Skip to content
Merged
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
Loading
Loading