Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally remove redacted event content from room buffers #300

Open
phil-s opened this issue Sep 21, 2024 · 3 comments
Open

Optionally remove redacted event content from room buffers #300

phil-s opened this issue Sep 21, 2024 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed priority:B
Milestone

Comments

@phil-s
Copy link

phil-s commented Sep 21, 2024

Copying comments from chat

P: After deleting a spam message, what would be a way to remove it (or reduce it to the [redacted] state) from the Ement room buffer? Those telegram spam messages are so big and attention-grabbing, and I'd love to have them just gone from the buffers once they've been dealt with (without having to disconnect and reconnect).

A: Yeah, good point. Well the simplest answer is to C-x C-q and then manually remove it from the buffer. :) But feel free to post an issue or a patch on the repo to discuss more permanent solutions. I decided to just mark redacted messages as strikethrough during a session so that you can still see redacted messages (for the cases where you'd be curious what was redacted; even a room admin might want to know if a user was trying to hide his nasty content to avoid a ban), but obviously in case of spam or bad content, one might not even want to see what's already been redacted. We should probably make an option, e.g. maybe set it to remove content of redacted messages unless you are a mod/admin in the room, something like that.

P: I think the default behaviour is fine and useful generally, but maybe C-u C-k could be a combo to both redact and hide the message -- or just have a separate command to do the hiding.

@alphapapa alphapapa added enhancement New feature or request help wanted Extra attention is needed priority:B labels Sep 21, 2024
@alphapapa alphapapa added this to the v0.17 milestone Sep 21, 2024
@phil-s
Copy link
Author

phil-s commented Sep 22, 2024

Comparing a [redacted] event with one where I can actually see the redacted content, it looked like the notable difference was that the content of the event was simply nil.

The following then works for emptying the content of the redacted event at point and re-displaying it as simply [redacted]:

(defun my-ement-room-hide-message-content ()
  "Hide the content of the message at point."
  (interactive)
  (when-let* ((node (ewoc-locate ement-ewoc (point)))
              (event (ewoc-data node)))
    (setf (ement-event-content event) nil)
    (ement-room--replace-event event)
    (message "Removed content of event.")))

If I try it on a non-redacted message I see: [message has no body content] [unsupported msgtype: nil] (which is fine, and also nice for differentiating from redacted messages in case of accidental use).

@phil-s
Copy link
Author

phil-s commented Sep 22, 2024

It also 'works' in the Notifications buffer, albeit with an error "Wrong type argument: ement-room, nil".

@phil-s
Copy link
Author

phil-s commented Sep 22, 2024

In case anyone else wants this interim solution:

Note that the hidden content is still available by inspecting the event data with ement-room-view-event, as we copy it to a hidden property before clobbering the displayed data, and so it can also be restored.

We may see some errors about ement-room being nil on account of the Notifications and Mentions buffers not being real Room buffers, but we get the desired end result.

(defun my-ement-room-hide-message-content (&optional event)
  "Hide the content of the message at point."
  (interactive)
  (unless event
    (when-let ((node (ewoc-locate ement-ewoc (point))))
      (setq event (ewoc-data node))))
  (when event
    (setf (map-elt (ement-event-local event) 'hidden-content)
          (ement-event-content event))
    (setf (ement-event-content event) nil)
    (ement-room--replace-event event)
    (when-let ((buf (get-buffer "*Ement Notifications*")))
      (with-current-buffer buf
        (ement-room--replace-event event)))
    (when-let ((buf (get-buffer "*Ement Mentions*")))
      (with-current-buffer buf
        (ement-room--replace-event event)))
    (message "Removed content of event.")))

(defun my-ement-room-unhide-message-content (&optional event)
  "Un-hide the content of the message at point."
  (interactive)
  (unless event
    (when-let ((node (ewoc-locate ement-ewoc (point))))
      (setq event (ewoc-data node))))
  (when-let ((content (and event (map-elt (ement-event-local event)
                                          'hidden-content))))
    (setf (ement-event-content event) content
          (map-elt (ement-event-local event) 'hidden-content) nil)
    (ement-room--replace-event event)
    ;; Seems like this doesn't work for Notifications and Mentions,
    ;; but it does the job in the original Room buffer.
    (when-let ((buf (get-buffer "*Ement Notifications*")))
      (with-current-buffer buf
        (ement-room--replace-event event)))
    (when-let ((buf (get-buffer "*Ement Mentions*")))
      (with-current-buffer buf
        (ement-room--replace-event event)))
    (message "Restored content of event.")))

(define-advice ement-room-delete-message
    (:after (event _room _session &optional _reason) my-hide-content)
  "Hide the content of the message after deleting if a prefix arg was given.

This is :after advice for `ement-room-delete-message'.  Remove with:

\(advice-remove \\='ement-room-delete-message
               \\='ement-room-delete-message@my-hide-content)"
  (when current-prefix-arg
    (my-ement-room-hide-message-content event)))

(define-advice ement-room-delete-message
    (:before (&rest _args) my-report-and-ban)
  "Report and ban the user with a double C-u C-u prefix.

This is :before advice for `ement-room-delete-message'.  Remove with:

\(advice-remove \\='ement-room-delete-message
               \\='ement-room-delete-message@my-report-and-ban)"
  (when (equal current-prefix-arg '(16))
    (let ((current-prefix-arg nil))
      (call-interactively #'ement-room-report-content)
      (call-interactively #'ement-room-ban-user))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed priority:B
Projects
None yet
Development

No branches or pull requests

2 participants