Skip to content

Commit af6994f

Browse files
committed
Exclude live messages from notifications
Live messages (MSC4357) are now filtered out in the notification handler to prevent notifications for incomplete messages that are still being typed. This fixes the issue where users would receive notifications for messages with just a few letters. Also simplified the worker.rs load_insert logic by clarifying comments and relying on the centralized live detection.
1 parent 42b3784 commit af6994f

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/notifications.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ pub async fn register_notifications(
7676
let room_id = room.room_id().to_owned();
7777
match notification.event {
7878
RawAnySyncOrStrippedTimelineEvent::Sync(e) => {
79+
// Skip notifications for live messages
80+
if crate::message::live_detection::has_live_marker_in_raw(&e) {
81+
tracing::debug!("Skipping notification for live message");
82+
return;
83+
}
84+
7985
match parse_full_notification(e, room, show_message).await {
8086
Ok((summary, body, server_ts)) => {
8187
if server_ts < startup_ts {

src/worker.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn load_insert(
339339

340340
match res {
341341
Ok((fetch_id, msgs)) => {
342-
// First pass: collect all messages and replacements separately
342+
// First pass: collect all messages and categorize them
343343
let mut normal_messages = Vec::new();
344344
let mut replacement_messages = Vec::new();
345345
let mut other_events = Vec::new();
@@ -360,16 +360,15 @@ fn load_insert(
360360
// Check if this is a replacement/edit event
361361
if let RoomMessageEvent::Original(ref orig) = msg {
362362
if let Some(Relation::Replacement(_)) = &orig.content.relates_to {
363-
// This is an edit - save it for later
364-
// We'll process live status only for the LATEST edit
363+
// This is an edit - save it for later processing
364+
// The is_live flag is already determined from the raw event
365365
replacement_messages.push((msg, is_live));
366366
} else {
367-
// Normal message - for history loading, we shouldn't mark as live
368-
// Live messages should always have at least one replacement
367+
// Normal message
369368
normal_messages.push(msg);
370369
}
371370
} else {
372-
// Other message types
371+
// Other message types (redacted, etc.)
373372
normal_messages.push(msg);
374373
}
375374
},
@@ -415,7 +414,7 @@ fn load_insert(
415414
// Group replacements by the event they're replacing and keep only the latest
416415
info!("[LOADING] Processing {} replacement messages", replacement_messages.len());
417416

418-
// Group replacements by target event ID, keeping track of the latest one
417+
// Group replacements by target event ID, keeping only the latest one
419418
let mut latest_replacements: HashMap<OwnedEventId, (MilliSecondsSinceUnixEpoch, RoomMessageEvent, bool)> = HashMap::new();
420419

421420
for (msg, is_live) in replacement_messages {
@@ -424,18 +423,17 @@ fn load_insert(
424423
let target_id = repl.event_id.clone();
425424
let timestamp = orig.origin_server_ts;
426425

427-
// Only keep this replacement if it's newer than what we have
426+
// Keep only the latest replacement for each target
428427
match latest_replacements.get(&target_id) {
429428
Some((existing_ts, _, _)) if existing_ts > &timestamp => {
430-
// We already have a newer replacement, skip this one
429+
// Skip older replacement
431430
info!(
432431
"[M.REPLACE] Skipping older replacement {} -> {} (ts: {:?}, is_live: {})",
433432
msg.event_id(),
434433
target_id,
435434
timestamp,
436435
is_live
437436
);
438-
continue;
439437
}
440438
_ => {
441439
// This is newer or first, keep it
@@ -453,7 +451,7 @@ fn load_insert(
453451
}
454452
}
455453

456-
// Apply only the latest replacement for each message and update live status
454+
// Apply only the latest replacement for each message
457455
info!("[LOADING] Applying {} latest replacements", latest_replacements.len());
458456
for (target_id, (_timestamp, msg, is_live)) in latest_replacements {
459457
if let RoomMessageEvent::Original(ref orig) = msg {
@@ -465,7 +463,8 @@ fn load_insert(
465463
is_live
466464
);
467465

468-
// Update live_message_ids based on the LATEST edit's live status
466+
// Update live status based on the replacement's is_live flag
467+
// The is_live flag comes from centralized detection in load_older_one
469468
if is_live {
470469
info.live_message_ids.insert(target_id.clone());
471470
} else {

0 commit comments

Comments
 (0)