tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

How does tdlib know when to update reactions? #2312

Closed vincentneo closed 1 year ago

vincentneo commented 1 year ago

According to #2214,

Reactions are updated only for recently viewed messages.

But how exactly does tdlib know which message is 'recently viewed'?

I assumed that it would be via the calling of the viewMessages function, but sometimes even after calling that, I still don't receive reactions.

levlam commented 1 year ago

Yes, if you view messages in an opened chat, their reactions will be eventually updated. But this doesn't mean that you can call viewMessages for thousands messages and receive updated reactions for all of them. Only a few messages can be viewed in a time.

vincentneo commented 1 year ago

Understood with thanks. Since you've mentioned 'opened chat', looked at it and I think there's a race condition in my code. Maybe that's why it wasn't receiving the updates. (get chat history before opening chat)

Will see if things improve, and will close if proven that that's the reason.

vincentneo commented 1 year ago

Anyways, I observed that getChatHistory only return populated reactions in interaction_info some of the times, not always, even if on the same chat & message. Why is that so?

levlam commented 1 year ago

getChatHistory returns messages, which state is consistent with all other updates and request responses. If the message was recently viewed and its reactions were updated, then getChatHistory will return the updated data.

vincentneo commented 1 year ago

Thanks for the clarification on the getChatHistory part.

From my end, my observation is still that updateMessageInteractionInfo for the last message does not seem to send for the initial reactions, until when someone in the same channel/group sends a reaction for a particular message. (to clarify, it's sometimes, not always, seems pretty flaky?)

For context, this is how my sequence of calls are like:

  1. openChat
  2. getChatHistory, recursively until recent 50 messages are retrieved.
  3. viewMessages is called, with message id(s) of the most recent message, or most recent messages of same media album id.

By the way, another question: when someone adds a reaction to a message associated with some other messages with the same media_album_id, which exact message id will updateMessageInteractionInfo consider towards?

Also, apologies if I'm asking too many questions.

levlam commented 1 year ago

when someone adds a reaction to a message associated with some other messages with the same media_album_id, which exact message id will updateMessageInteractionInfo consider towards?

Only the first message in an album can receive reactions. Apps aren't supposed to send reactions for other album messages.