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

tdlib 1.8.4 Under what conditions does UpdateMessageContent come? #2297

Closed wowka1319 closed 1 year ago

wowka1319 commented 1 year ago

I thought UpdateMessageContent always came if the edited message was last in the chat. But I was wrong. What do guarantees exist for that?

levlam commented 1 year ago

UpdateMessageContent is sent for all messages, received by the application since instance launch, and which weren't unloaded with updateDeleteMessages. For the last chat messages updateChatLastMessage is always sent additionally.

wowka1319 commented 1 year ago

I observe updateDeleteMessages of two types: (is_permanent, not from_cache) and (not is_permanent, from_cache).

  1. (is_permanent, not from_cache) - causes by the server because it's real removing on the server. right?
  2. (not is_permanent, from_cache) - causes by tdlib because it's just unloading from tdlib (removing from local sqlite db) you are talking about above. right?
  3. is_permanent == not from_cache always? I hasn't seen the different case.
levlam commented 1 year ago

is_permanent == not from_cache always? I hasn't seen the different case.

No. If a message is removed from cache, then the action isn't permanent, but not vice versa. Messages can became inaccessible without actual deletion.

wowka1319 commented 1 year ago
  1. Inaccessible without actual deletion? You mean restrictions because of copyright violation, for example? I seem to understand you mean the case when message becomes inaccessible (copyright) and that causes deletion(from_cache=True,is_permanent=False)?
  2. is_permanent == actual deletion always?
  3. from_cache as you say is "unloaded"? i.e. tdlib for some reason clean up message in local db?
levlam commented 1 year ago
  1. No. Messages can become inaccessible if the user clears supergroup history for self or is kicked from a private supergroup. In this case both is_permanent and from_cache will be false.
  2. is_permanent == true means that the message is deleted forever.
  3. TDLib unloads unneeded messages from memory.
wowka1319 commented 1 year ago
  1. Why does TDLib decide a message is unneeded anymore to unload it? What triggers do exist for that?
  2. updateChatLastMessage is sent only when the last message is replaced by another one: a) received new message or b) actual deletion of the last message and the previous one become last ? I.e. updateChatLastMessage is not sent if its content has changed only?
levlam commented 1 year ago
  1. All unneeded messages are unloaded from memory after some time.
  2. updateChatLastMessage is sent whenever last chat message is changed in any way. It must not be used for anything besides last message preview in chat list and handling of situation when last message become unknown.
wowka1319 commented 1 year ago

What does this "some time" depend on? Sometimes deletion from cache happens too early (in 2 minutes for example), before the next updateMessageEdited, that makes updateMessageContent impossible (if i understand correctly TDLib when unloading a message notifies the server not to send updateMessageContent for it anymore). How can I increase this timeout?

levlam commented 1 year ago

TDLib has "message_unload_delay" option. See https://core.telegram.org/tdlib/options.

wowka1319 commented 1 year ago

Thank you! Docs: The maximum time messages are stored in memory before they are unloaded. Does the documentation mean disk or RAM?

AYMENJD commented 1 year ago

It is RAM.

wowka1319 commented 1 year ago

Docs: If updateChatLastMessage.last_message is null, then the last message in the chat became unknown. Some new unknown messages might be added to the chat in this case. What causes a message to become unknown?

levlam commented 1 year ago

The last message can be deleted, or some other unknown messages can be added to the chat.

wowka1319 commented 1 year ago

I am seeing the following case. A new message has been posted. Since then it has been edited 6 times. I got 6 UpdateMessageContent and 6 UpdateMessageEdited (last events ~20 minutes after posting). But I only got one UpdateChatLastMessage (~5 second after posting and with edit_date=0). The message is still the last one. Why aren't UpdateChatLastMessages coming? What could be causing this?

levlam commented 1 year ago

Send TDLib log to https://t.me/tdlib_bot.