From 9a4bf42b5d92fa74bbbed37b24a7b1fd777c9317 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Tue, 3 Oct 2023 00:13:34 -0500 Subject: [PATCH 1/4] Fix: ("m.room.redaction") Redacting edited events Fixes #228. Reported-by: Phil Sainty --- ement-room.el | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/ement-room.el b/ement-room.el index 6909becc..a522d867 100644 --- a/ement-room.el +++ b/ement-room.el @@ -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) From 5d12e083abcf176d57ef3f2b37c122dc37eb919d Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Tue, 3 Oct 2023 00:14:15 -0500 Subject: [PATCH 2/4] Docs: Update changelog --- README.org | 1 + 1 file changed, 1 insertion(+) diff --git a/README.org b/README.org index 9f9ea13b..2ed83aac 100644 --- a/README.org +++ b/README.org @@ -306,6 +306,7 @@ 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.) ++ Redactions of edited messages. ([[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 From cb24ae6a2785489746185fff3805b38c54766a0e Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Tue, 3 Oct 2023 00:17:46 -0500 Subject: [PATCH 3/4] Fix: (ement-room-delete-message) Redact original messages Seems like the correct thing to do. See . Fixes #228. Reported-by: Phil Sainty --- ement-room.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ement-room.el b/ement-room.el index a522d867..a5162b9c 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. From 63f30203f379d2f51d8162e0c59d2e7e440c7d39 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Tue, 3 Oct 2023 00:18:28 -0500 Subject: [PATCH 4/4] Docs: Update changelog --- README.org | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 2ed83aac..c3362ca3 100644 --- a/README.org +++ b/README.org @@ -306,7 +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.) -+ Redactions of edited messages. ([[https://github.com/alphapapa/ement.el/issues/228][#228]]. 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