Skip to content

feat(threads): automatically subscribe a user to a thread under the semantics of MSC4306 #5462

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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