branch: externals-release/ement
commit 9845201d3a04cfcb66e220d7f695090b44b487bf
Merge: 84787eda3f 63f30203f3
Author: Adam Porter <a...@alphapapa.net>
Commit: Adam Porter <a...@alphapapa.net>

    Merge: Fixes for redactions of edited messages
    
    See #226, #227, #228.
    
    Reported-by: Phil Sainty <p...@catalyst.net.nz>
---
 README.org    |  2 ++
 ement-room.el | 43 ++++++++++++++++++++++++++++++++-----------
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/README.org b/README.org
index 9f9ea13b3d..c3362ca3cb 100644
--- a/README.org
+++ b/README.org
@@ -306,6 +306,8 @@ Ement.el doesn't support encrypted rooms natively, but it 
can be used transparen
 + Editing a message from the compose buffer would be sent as a reply to the 
edited message.  (Fixes 
[[https://github.com/alphapapa/ement.el/issues/189][#189]].  Thanks to 
[[https://github.com/phil-s][Phil Sainty]] for reporting.)
 + Editing an already-edited message.  
([[https://github.com/alphapapa/ement.el/issues/226][#226]].  Thanks to 
[[https://github.com/phil-s][Phil Sainty]] for reporting.)
 + Replying to an already-edited message.  
([[https://github.com/alphapapa/ement.el/issues/227][#227]].  Thanks to 
[[https://github.com/phil-s][Phil Sainty]] for reporting.)
++ Rendering redactions of edited messages.  
([[https://github.com/alphapapa/ement.el/issues/228][#228]].  Thanks to 
[[https://github.com/phil-s][Phil Sainty]] for reporting.)
++ Redacting an edited message.  
([[https://github.com/alphapapa/ement.el/issues/228][#228]].  Thanks to 
[[https://github.com/phil-s][Phil Sainty]] for reporting.)
 + Command ~ement-room-flush-colors~ maintains point position.
 
 ** 0.12
diff --git a/ement-room.el b/ement-room.el
index 6909beccdc..a5162b9c16 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -1752,7 +1752,7 @@ itself an edit of another event, the original event is 
edited."
                            ement-room ement-session (read-string "Reason 
(optional): " nil nil nil 'inherit-input-method))
                    ;; HACK: This isn't really an error, but is there a cleaner 
way to cancel?
                    (user-error "Message not deleted"))))
-  (ement-redact event room session reason))
+  (ement-redact (ement--original-event-for event session) room session reason))
 
 (defun ement-room-write-reply (event)
   "Write and send a reply to EVENT.
@@ -2490,15 +2490,27 @@ function to `ement-room-event-fns', which see."
   (pcase-let* (((cl-struct ement-event (local (map ('redacts redacted-id)))) 
event)
                ((cl-struct ement-room timeline) ement-room)
                (redacted-event (cl-find redacted-id timeline
-                                        :key #'ement-event-id :test #'equal)))
+                                        :key #'ement-event-id :test #'equal))
+               (redacted-edit-events (cl-remove-if-not (lambda (timeline-event)
+                                                         (pcase-let 
(((cl-struct ement-event
+                                                                               
  (content
+                                                                               
   (map ('m.relates_to
+                                                                               
         (map ('event_id related-id)
+                                                                               
              ('rel_type rel-type))))))
+                                                                      
timeline-event))
+                                                           (and (equal 
redacted-id related-id)
+                                                                (equal 
"m.replace" rel-type))))
+                                                       timeline)))
+    (ement-debug event redacted-event redacted-edit-events)
+    (cl-loop for edit-event in redacted-edit-events
+             do (cl-pushnew event (alist-get 'redacted-by (ement-event-local 
edit-event))))
     (when redacted-event
+      (cl-pushnew event (alist-get 'redacted-by (ement-event-local 
redacted-event)))
       (pcase-let* (((cl-struct ement-event (content
                                             (map ('m.relates_to
                                                   (map ('event_id related-id)
                                                        ('rel_type 
rel-type))))))
                     redacted-event))
-        ;; Record the redaction in the redacted event's local slot.
-        (cl-pushnew event (alist-get 'redacted-by (ement-event-local 
redacted-event)))
         (pcase rel-type
           ("m.annotation"
            ;; Redacted annotation/reaction.  NOTE: Since we link annotations 
in a -room
@@ -2515,13 +2527,22 @@ function to `ement-room-event-fns', which see."
                                (lambda (data)
                                  (and (ement-event-p data)
                                       (equal related-id (ement-event-id 
data))))))
-               (ewoc-invalidate ement-ewoc node)))))
-        ;; Invalidate the redacted event's node.
-        (when-let (node (ement-room--ewoc-last-matching ement-ewoc
-                          (lambda (data)
-                            (and (ement-event-p data)
-                                 (equal redacted-id (ement-event-id data))))))
-          (ewoc-invalidate ement-ewoc node))))))
+               (ewoc-invalidate ement-ewoc node)))))))
+    ;; Invalidate the redacted event's node.
+    (when-let ((node (ement-room--ewoc-last-matching ement-ewoc
+                       (lambda (data)
+                         (and (ement-event-p data)
+                              (pcase-let (((cl-struct ement-event id
+                                                      (content
+                                                       (map ('m.relates_to
+                                                             (map ('event_id 
related-id)
+                                                                  ('rel_type 
rel-type))))))
+                                           data))
+                                (or (equal redacted-id id)
+                                    (and (equal "m.replace" rel-type)
+                                         (equal redacted-id related-id)))))))))
+      (ement-debug node)
+      (ewoc-invalidate ement-ewoc node))))
 
 (ement-room-defevent "m.typing"
   (pcase-let* (((cl-struct ement-session user) ement-session)

Reply via email to