Open maximbaz opened 1 year ago
This would be great! This feature has long been needed. Now that signal-cli has the dbus support for it (had it for while by now, actually) this really needs to be implemented in scli.
The biggest challenge is, as you say, detecting the user's "focus" (similar to #109), so that we only send read receipts for the likely-to-have-actually-been-seen messages. I think Signal-desktop has a leg-up with this: Electron probably makes available such information as whether its window is currently in focus, etc.
For the purposes of sending read receipts in scli though, I think we can just send them after any keyboard activity from the user, while the newly received messages are in view. Does that sound reasonable?
This will require writing some code for urwid
's keyevent
s. I should be able to help with that, or point to the relevant documentation.
Another relevant issue (but a less important one) is that scli currently focuses the view on every newly received message. When there are many messages received in a chat, this results in some of the earlier ones scrolling out of the top of the view (since the latest message will always be made visible). So the last received message might be seen by the user before the first (unread) message. And so the RR will be sent for all the new messages in chat, even when the first one hasn't been seen yet.
The official clients handle this properly, by not allowing any of the unread messages to scroll out of view.
Fixing this would again require dealing with urwid
's specifics (how items are focused in the corresponding ListBox
object). This might be tricky, and probably not strictly necessary for implementing a good-enough read-receipt functionality.
I seem to remember that when Signal Desktop is open (but not focused, or focused but on a different contact), notifications on the phone arrive with a delay, seemingly giving the user a few seconds to check them out on desktop, before "spamming" their phone
This might be just the phone being slower to receive the messages. Perhaps because of power saving, when it polls / gets pushes less frequently. I don't think Signal clients exchange such info as which clients are concurrently opened. They just each receive new messages from the server.
Finally, some general notes on the sending-read-receipts functionality:
Let me know if I can help with anything else related! I haven't had much time to devote to this lately, but will try to be of assistance.
Thank you, very insightful and helpful! I actually made a rough proof of concept, just of sending read receipts as soon as scli receives them, and stumbled upon the fact that the phone still receives the notifications, contrary to Signal Desktop behavior....
I asked upstream, but if you also have any thoughts, it's very appreciated 😊
Can you reliably reproduce the delayed-notifications-on-phone behavior? Either way, it's probably not related to read receipts. Since as you say it happens when Signal Desktop is "not focused, or focused but on a different contact". In which case, read receipts for the relevant conversation wouldn't be sent from signal-desktop.
P.S. for sending read receipts automatically on every incoming message, signal-cli has a --send-read-receipts
option.
I can reliably reproduce this:
--send-read-receipts
does NOT add this 5 seconds delay, yes messages are instantly marked as "read", but every message still gets instantly vibrating on the phone / smartwatch.So there has to be something else at play, something that Signal Desktop is doing to introduce this delay, in addition to just marking messages as "read" :thinking:
Interesting..
I suppose it's possible for signal-desktop to send "sync" messages reporting that it's running. Signal on the phone, after receiving such messages would delay showing notifications for a few seconds. Don't know if that's what's actually happening.
Maybe in addition to signal-cli's disucssions (https://github.com/AsamK/signal-cli/discussions/1163), this could also be asked on the official clients discussions somewhere (don't know which repo/forum would be most appropriate though). Searching through the signal-desktop's code might yield something (assuming one knows what to look for..)
Anyway, this seems to be a different kind of sync message, that is sent in addition to the read receipts.
I think you are onto something!
Here is a snippet of Signal Desktop's debug logs when I received a message while Signal was open and focused on this contact (so the phone never vibrated):
I think these snippets are relevant:
You have a lot more knowledge about signal-cli, from a first glance it doesn't seem like it implements readSync
, do you think it's something we could ask for?
And what do you think about it all in general, does it all sound plausible?
Nice find!
I haven't fully studied the code, but the readSync
events look like they might be responsible for this behavior.
Signal-cli doesn't have readSync
s AFAIK. Probably wouldn't hurt requesting this. Would be good to first understand what exactly it does though, so that to know what exactly to ask for :). But if it's not clear from the code, maybe AsamK could help figuring it out..
If you can determine what those read-syncs do from reading the code, that would definitely make implementing it in signal-cli easier. But feel free to ask in signal-cli tracker and to link to this discussion. I don't know whether it's possible to ask upstream someone who's familiar with signal-desktop code though: their repo does not even have Discussions; and the signal forums are mostly for feature requests (maybe worth a try?)..
I'd like to implement sending read receipts, and I want to run it by you first, to discuss some architectural decisions :smile:
The primary goal: I don't want to receive signal notifications on phone/smartwatch, if I'm actively chatting in
scli
.The main challenges, as I currently see them, are:
signal-cli
to actually send read receipt.scli
is currently focused.The first item seems possible, although I haven't worked with
signal-cli
before, I can see sendReadReceipt in the docs. Do you see any challenges here, missing APIs or some other problems? I haven't used Signal Desktop for a while, but I seem to remember that when Signal Desktop is open (but not focused, or focused but on a different contact), notifications on the phone arrive with a delay, seemingly giving the user a few seconds to check them out on desktop, before "spamming" their phone. I don't know if that's just "magically" works via their backend, or there's a special API to use, to activate such "delayed" mode. Do you know, perhaps?Detecting whether a user is currently looking at
scli
is both difficult to implement for everyone, but at the same time is easy to do when you know the particulars of user's setup. Just to give you a concrete example, I am running Hyprland, which comes with both a CLI tool that can detect the currently focused window, and a Unix socket where you can subscribe for events of changing the active window. Identifyingscli
process specifically within a terminal window is also possible, e.g. by running a dedicated terminal instance with a custom app_id / class (e.g.kitty --class=scli scli
).So it sounds like it should be left to the user, to tell
scli
if it's currently focused, andscli
should send read receipts if it has such information.Here are the two different ways I thought such integration could potentially be implemented:
scli
a command, which it periodically runs, say every second or two, to detect ifscli
is currently focused or not (say it outputs a boolean). Maybe also runs it additionally after every received message.scli
a couple of Unix signals (saySIGUSR1
andSIGUSR2
), which would tellsci
that it got focused and unfocused respectively. We leave it up to users to send those signals (either precisely when these events occur, if they can e.g. subscribe to a socket like me, or just sending these signals in an infinite loop).The latter seems a lot more robust and battery-friendly, but also requires users to implement more glue.
What are your thoughts on it?