You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to understand the details of how the libtdjson library works. Below is a piece of code that attempts to retrieve messages for a specified chat with limit number of messages. When the requests are made, the only_local flag is set to true to ensure that the data is read only from the local database without making any requests to the server. For the sake of the experiment, the database is wiped before the first run, and it is reinitialized afterwards.
It is expected that when the getHistory function is executed for the first time, the result will be empty because there are no messages in the database, as it is recreated from scratch. However, after the first run, it turns out that when limit=1000, the function returns 1 message. This is likely because the library loads a small part of the history into the local storage during the first run. In this case, it’s just 1 message.
Then, I restart the program. Now, after executing the function, I can read 51 messages. This is strange, given that the only_local flag is applied. Because if, during the previous run, the function fetched an additional 50 messages from the server just in case, it means that, first of all, it made a request to the server, fetched a batch of messages to respond to user queries, but did not return those messages in the function result. On the other hand, if the function requested 50 new messages after the restart, why didn’t it do that the previous time? I’m a bit confused here.
If I restart the program again, the function returns 50 more messages than the previous run.
Could you please help answer the following questions?
Why, despite setting only_local == true, does the number of messages returned by the getHistory function increase by 50 after each restart compared to the previous run?
Does the libtdjson library automatically load the chat history or part of it into the local storage during the first run, without any explicit command from the user like getHistoryChat? Does this depend on the settings used when initializing the library? Does it do this every time the program is restarted if the local database already exists?
In the Messages class, it is mentioned that the list of messages can be null. In what case is the message list null when retrieving chat history, and in what case is it simply an empty list?
Future<void> getHistory(Int53 chatId, int limit) async {
var fromMessageId =Int53(0);
int left = limit;
int receivedMessagesCount =0;
while (left >0) {
Messages messages =await client.getChatHistory(
chat_id: chatId,
from_message_id: fromMessageId,
limit:Int32(left),
offset:Int32(0),
only_local:true,
);
if (messages.messages ==null|| messages.messages!.isEmpty) {
break;
}
for (Message m in messages.messages!) {
receivedMessagesCount++;
}
fromMessageId = messages.messages!.last.id;
left -= messages.messages!.length;
}
log.i(receivedMessagesCount, "receivedMessagesCount");
}
TDLib has message history preloading strategies to provide smooth scrollback experience.
No, TDLib doesn't load data without app request. You run a request that required loading of the chat, and the last message is maintained for all chats from a chat list.
Individual messages in the list can be null, but not the list itself. You can just skip null messages in the response.
I will do that, I’ll skip the null messages, but my curiosity is getting the best of me. Why can a message even be null? Is it some kind of deleted message?
Actually, getChatHistory will never return null messages in the recent TDLib versions, but previously null could have been returned in place of just deleted messages, which were deleted right before the response was returned to the app.
I'm trying to understand the details of how the libtdjson library works. Below is a piece of code that attempts to retrieve messages for a specified chat with
limit
number of messages. When the requests are made, theonly_local
flag is set to true to ensure that the data is read only from the local database without making any requests to the server. For the sake of the experiment, the database is wiped before the first run, and it is reinitialized afterwards.It is expected that when the getHistory function is executed for the first time, the result will be empty because there are no messages in the database, as it is recreated from scratch. However, after the first run, it turns out that when limit=1000, the function returns 1 message. This is likely because the library loads a small part of the history into the local storage during the first run. In this case, it’s just 1 message.
Then, I restart the program. Now, after executing the function, I can read 51 messages. This is strange, given that the
only_local
flag is applied. Because if, during the previous run, the function fetched an additional 50 messages from the server just in case, it means that, first of all, it made a request to the server, fetched a batch of messages to respond to user queries, but did not return those messages in the function result. On the other hand, if the function requested 50 new messages after the restart, why didn’t it do that the previous time? I’m a bit confused here.If I restart the program again, the function returns 50 more messages than the previous run.
Could you please help answer the following questions?
Why, despite setting
only_local == true
, does the number of messages returned by the getHistory function increase by 50 after each restart compared to the previous run?Does the libtdjson library automatically load the chat history or part of it into the local storage during the first run, without any explicit command from the user like getHistoryChat? Does this depend on the settings used when initializing the library? Does it do this every time the program is restarted if the local database already exists?
In the
Messages
class, it is mentioned that the list of messages can be null. In what case is the message list null when retrieving chat history, and in what case is it simply an empty list?Настройки библиотеки применяются такие:
The text was updated successfully, but these errors were encountered: