Commit b9c187b893

b9c187b8930d8e64fbba7cbfc1ad839aaa216740

parent: ddadde6e4c

Unregistered key

Tayfur Yıldız <yildiztayfur668@gmail.com> · 2026-09-26 10:39 UTC
committer: <noreply@github.com>

Indicate thread messages in notifications (#747)

Layout: unified · split

src/notifications.rs +22 −1
@@ -8,6 +8,7 @@ use matrix_sdk::notification_settings::{
88 NotificationSettings,
99 RoomNotificationMode,
1010};
11use matrix_sdk::ruma::events::room::message::Relation;
1112use matrix_sdk::ruma::events::{AnyMessageLikeEventContent, AnySyncTimelineEvent};
1213use matrix_sdk::ruma::serde::Raw;
1314
@@ -277,6 +278,7 @@ pub fn event_notification_body(event: &AnySyncTimelineEvent, sender_name: &str)
277278
278279 match event.original_content()? {
279280 AnyMessageLikeEventContent::RoomMessage(message) => {
281 let is_thread = matches!(message.relates_to, Some(Relation::Thread(_)));
280282 let body = match message.msgtype {
281283 MessageType::Audio(_) => {
282284 format!("{sender_name} sent an audio file.")
@@ -304,7 +306,7 @@ pub fn event_notification_body(event: &AnySyncTimelineEvent, sender_name: &str)
304306 format!("[Unknown message type: {:?}]", &message.msgtype)
305307 },
306308 };
307 Some(body)
309 Some(thread_notification_body(body, is_thread))
308310 },
309311 AnyMessageLikeEventContent::Sticker(_) => Some(format!("{sender_name} sent a sticker.")),
310312 AnyMessageLikeEventContent::PollStart(_) |
@@ -318,6 +320,25 @@ pub fn event_notification_body(event: &AnySyncTimelineEvent, sender_name: &str)
318320 }
319321}
320322
323fn thread_notification_body(body: String, is_thread: bool) -> String {
324 if is_thread {
325 format!("Thread: {body}")
326 } else {
327 body
328 }
329}
330
331#[cfg(test)]
332mod tests {
333 use super::thread_notification_body;
334
335 #[test]
336 fn thread_messages_are_identified_in_notifications() {
337 assert_eq!(thread_notification_body("hello".into(), true), "Thread: hello");
338 assert_eq!(thread_notification_body("hello".into(), false), "hello");
339 }
340}
341
321342fn truncate(s: String) -> String {
322343 static MAX_LENGTH: usize = 5000;
323344 if s.graphemes(true).count() > MAX_LENGTH {