zevlg / telega.el

GNU Emacs telegram client (unofficial)
https://zevlg.github.io/telega.el/
GNU General Public License v3.0
1.09k stars 85 forks source link

Unread messages in a group chat get marked as read when blocked users send a message #314

Closed yangsheng6810 closed 2 years ago

yangsheng6810 commented 3 years ago

Telega Setup

OS: Arch Linux Emacs: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.17.4) Telega: telega v0.7.70 (TDLib v1.7.7) (telega-server v0.7.13)

Current Behavior

I have the following setting in my config to filter out blocked users in group chats:

(add-hook 'telega-msg-ignore-predicates #'telega-msg-from-blocked-sender-p)

Usually, when someone posts a message in a group chat, it is considered as unread before I open that particular chat. With no chat opened, I can see the number of unread messages from *Telega Root*, and while new messages are sent to that chat by other users, the number of unread messages increases. Everything is fine until a message is sent by a user blocked by me. When such a message is sent, all unread messages in that group chat are marked as read, and the number of unread messages resets to zero. I checked with telega and other Telegram clients, and those unread messages are indeed considered as read by the system, i.e. opening up the chat and we will see that the first unread message is the one right after the message sent by the blocked user (note this message by the blocked user is not visible in telega unless you remove telega-msg-from-blocked-sender-p from telega-msg-ignore-predicates).

Steps to Reproduce

  1. Block some user A.
  2. Filter out blocked users with (add-hook 'telega-msg-ignore-predicates #'telega-msg-from-blocked-sender-p)
  3. Pick a group G where A is in, and wait for some unread messages to show up. You can monitor this from *Telega Root* with no chat opened.
  4. Kindly ask A to send a message in group G, and all messages in group G are considered as read.
yangsheng6810 commented 2 years ago

The offending part seems to be in function telega--on-initial-chats-load, where when (telega-msg-run-ignore-predicates last-message 'last-msg) returns t, an update of the chat is called. This seems to mark everything as read.

yangsheng6810 commented 2 years ago

In case anyone finds it useful, here is my workaround:

(define-advice telega--on-updateNewMessage (:around (func event) wrap)
  (define-advice telega-msg-run-ignore-predicates (:filter-return (ret) wrap) nil)
  (funcall func event)
  (advice-remove #'telega-msg-run-ignore-predicates
                 #'telega-msg-run-ignore-predicates@wrap))
zevlg commented 2 years ago

This is actually a "feature", here is a comment about it:

        ;; NOTE: View ignored message, so modeline/appindicator
        ;; won't show there is something important if ignored
        ;; message contains mention

But yeah, you are right, we should not implicitly view ignored message. Better to just delete it for me only in group chats, I'll add customization for this

yangsheng6810 commented 2 years ago

I think the "feature" is that if some ignored message is considered important or contains a mention, then such important/mention shall also be ignored. However, the current implementation achieves this by viewing the ignored message, which causes previously unread messages from other users to also be considered read. I assume an ideal implementation of this feature would achieve the following:

  1. Hide important/mention from ignored messages
  2. Unread messages from un-ignored users stay unread

If this is not achievable, maybe add some customization for this? I am personally OK if I see some phantom mentions which disappear when I view the chat, but maybe not everyone likes this.

zevlg commented 2 years ago

None of 1. or 2. is achievable, unfortunately. The best solution I'm experimenting with right now is to mark all mentions as read if there are no other mentions in the chat and only a single mention exists in the ignored message.

zevlg commented 2 years ago

Should be fixed in the master, please check

And thank you for the report!

yangsheng6810 commented 2 years ago

Seems to work for me. Thanks!