mirror of
https://github.com/vale981/ement.el
synced 2025-03-04 17:01:39 -05:00
Fix: (room-defevent "m.room.message") Replaced messages
When reopening closed room buffers that contain retro-loaded messages that include events that have been replaced by later edits, the original messages were inserted alongside the edits, because the edit events were inserted before the original events, so the original events were not replaced by the edits. This happened because the edits were processed before the originals, because the events were stored out-of-order in the timeline. Now, this shouldn't have been the case, because when retro-loading messages, we store them at the beginning of the timeline, before the newer events. But, for some reason, this isn't always working. The Matrix spec says that the definition of "chronological order" is up to the server, so maybe it's not always returning them in the order we would expect. So this is a mildly hacky workaround: if the event's unsigned data indicates it's been replaced, we just don't insert it. Theoretically, we should already have any such replacing event. If we wanted to be extra careful, we could look up the replacing event in the hash table to ensure we've got it, but we can add that later if necessary; for now, let's not.
This commit is contained in:
parent
8651e480ee
commit
c827e96d62
1 changed files with 8 additions and 4 deletions
|
@ -2198,8 +2198,9 @@ function to `ement-room-event-fns', which see."
|
|||
(ement-room--insert-event event)))
|
||||
|
||||
(ement-room-defevent "m.room.message"
|
||||
(pcase-let* (((cl-struct ement-event content) event)
|
||||
((map ('m.relates_to (map ('rel_type rel-type) ('event_id replaces-event-id)))) content))
|
||||
(pcase-let* (((cl-struct ement-event content unsigned) event)
|
||||
((map ('m.relates_to (map ('rel_type rel-type) ('event_id replaces-event-id)))) content)
|
||||
((map ('m.relations (map ('m.replace (map ('event_id replaced-by-id)))))) unsigned))
|
||||
(if (and ement-room-replace-edited-messages
|
||||
replaces-event-id (equal "m.replace" rel-type))
|
||||
;; Event replaces existing event: find and replace it in buffer if possible, otherwise insert it.
|
||||
|
@ -2207,8 +2208,11 @@ function to `ement-room-event-fns', which see."
|
|||
(progn
|
||||
(ement-debug "Unable to replace event ID: inserting instead." replaces-event-id)
|
||||
(ement-room--insert-event event)))
|
||||
;; New event: insert it.
|
||||
(ement-room--insert-event event))))
|
||||
;; New event.
|
||||
(if replaced-by-id
|
||||
(ement-debug "Event replaced: not inserting." replaced-by-id)
|
||||
;; Not replaced: insert it.
|
||||
(ement-room--insert-event event)))))
|
||||
|
||||
(ement-room-defevent "m.room.tombstone"
|
||||
(pcase-let* (((cl-struct ement-event content) event)
|
||||
|
|
Loading…
Add table
Reference in a new issue