@@ -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