Skip to content

Commit 5753ca3

Browse files
authored
misc(ffi): add thread_id to NotificationItem (#4895)
This is needed to identify the event as being in a thread, and to reply to it inside the thread instead of in the room's timeline. <!-- description of the changes in this PR --> - [ ] Public API changes documented in changelogs (optional) <!-- Sign-off, if not part of the commits --> <!-- See CONTRIBUTING.md if you don't know what this is --> Signed-off-by:
1 parent f3291d1 commit 5753ca3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

crates/matrix-sdk-ui/src/notification_client.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ use ruma::{
2929
events::{
3030
room::{
3131
member::{MembershipState, StrippedRoomMemberEvent},
32-
message::SyncRoomMessageEvent,
32+
message::{Relation, SyncRoomMessageEvent},
3333
},
34-
AnyFullStateEventContent, AnyStateEvent, AnySyncMessageLikeEvent, AnySyncTimelineEvent,
35-
FullStateEventContent, StateEventType, TimelineEventType,
34+
AnyFullStateEventContent, AnyMessageLikeEventContent, AnyStateEvent,
35+
AnySyncMessageLikeEvent, AnySyncTimelineEvent, FullStateEventContent, StateEventType,
36+
TimelineEventType,
3637
},
3738
html::RemoveReplyFallback,
3839
push::Action,
@@ -668,6 +669,7 @@ pub struct NotificationItem {
668669
/// It is set if and only if the push actions could be determined.
669670
pub is_noisy: Option<bool>,
670671
pub has_mention: Option<bool>,
672+
pub thread_id: Option<String>,
671673
}
672674

673675
impl NotificationItem {
@@ -735,6 +737,18 @@ impl NotificationItem {
735737
let is_noisy = push_actions.map(|actions| actions.iter().any(|a| a.sound().is_some()));
736738
let has_mention = push_actions.map(|actions| actions.iter().any(|a| a.is_highlight()));
737739

740+
let thread_id = 'thread_id: {
741+
if let NotificationEvent::Timeline(AnySyncTimelineEvent::MessageLike(event)) = &event {
742+
let content = event.original_content();
743+
if let Some(AnyMessageLikeEventContent::RoomMessage(content)) = content {
744+
if let Some(Relation::Thread(thread)) = content.relates_to {
745+
break 'thread_id Some(thread.event_id.to_string());
746+
}
747+
}
748+
};
749+
None
750+
};
751+
738752
let item = NotificationItem {
739753
event,
740754
raw_event,
@@ -753,6 +767,7 @@ impl NotificationItem {
753767
joined_members_count: room.joined_members_count(),
754768
is_noisy,
755769
has_mention,
770+
thread_id,
756771
};
757772

758773
Ok(item)

0 commit comments

Comments
 (0)