Skip to content

Commit

Permalink
Merge: Fixes for redactions of edited messages
Browse files Browse the repository at this point in the history
See #226, #227, #228.

Reported-by: Phil Sainty <phil@catalyst.net.nz>
  • Loading branch information
alphapapa committed Oct 3, 2023
2 parents 84787ed + 63f3020 commit 9845201
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 32 additions & 11 deletions ement-room.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 9845201

Please sign in to comment.