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

TdApi.GetChatHistory returns inconsistent results #2485

Closed rufatagayev closed 1 year ago

rufatagayev commented 1 year ago

I'm trying to fetch the list of messages from a chat and this is what is happening (I'm using Kotlin):

This code returns all messages except the last one: client?.send(TdApi.GetChatHistory(chat.id, chat.lastMessage?.id!!, 0, 100, false)) {}

These lines all return only the last message: client?.send(TdApi.GetChatHistory(chat.id, chat.lastMessage?.id!!, -1, 100, false)) {} client?.send(TdApi.GetChatHistory(chat.id, 0, 0, 100, false)) {} client?.send(TdApi.GetChatHistory(chat.id, 0, -99, 100, false)) {} client?.send(TdApi.GetChatHistory(chat.id, 0, -1, 100, false)) {}

What is going on here? Is this a bug? Or is there a way I can get all messages including the last one?

levlam commented 1 year ago

The behavior is intended. See https://core.telegram.org/tdlib/getting-started#getting-chat-messages for more details. Also, note that for optimal performance, the number of returned messages is chosen by TDLib, so app must repeat the request with adjusted from_message_id if appropriate.