tdlib / td

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

Disable useMessageDatabase affect other databases! #699

Closed aghasi closed 5 years ago

aghasi commented 5 years ago

This is the official description of useMessageDatabase:

If set to true, the library will maintain a cache of chats and messages. Implies useChatInfoDatabase.

I'm using following parameter to initialize TDLib:

TdApi.TdlibParameters parameters = new TdApi.TdlibParameters();
parameters.databaseDirectory = this.getApplicationContext().getFilesDir().toString() + "/" + index;
parameters.useFileDatabase = true;
parameters.useChatInfoDatabase = true;
parameters.useMessageDatabase = false; 
parameters.useSecretChats = false; 
parameters.apiId = ...;
parameters.apiHash = "...";
parameters.systemLanguageCode = "en";
parameters.deviceModel = deviceModel;
parameters.systemVersion = systemVersion;
parameters.applicationVersion = "1.0";
parameters.enableStorageOptimizer = false; 

I except that TDLib stores chat info in database. But it does not. After restarting the program database of chat info is empty. It is surprising that it stores chat info is i set useMessageDatabase to true. The problem exists with both Android PreBuild and Compiled source code cloned from your GitHub repository!

levlam commented 5 years ago

This is the official description of useChatInfoDatabase:

If set to true, the library will maintain a cache of users, basic groups, supergroups, channels and secret chats. Implies useFileDatabase.

You can ensure that all that data is persisted by successfully calling GetUser/GetBasicGroup/GetSupergroup/GetSecretChat. If you want to create a corresponding Chat then you need to call CreatePrivateChat/CreateBasicGroupChat/CreateSupergroupChat/CreateSecretChat.

aghasi commented 5 years ago

useChatInfoDatabase is enabled as you can see in my code.

I'm working with channels. GetSupergroup works great, but GetChatHistory and OpenChat not work at all. The response of calling them is

Error {
  code = 6
  message = "Chat not found"
}

It is interesting that chat data is not persisted when useMessageDatabase is disabled while useChatInfoDatabase is enabled. I know that useMessageDatabase is irrelevant but it seems that it affect storing info of chats. So i think that it is a bug.

levlam commented 5 years ago

This is exactly as written in the documentation. useMessageDatabase - "a cache of chats and messages.". useChatInfoDatabase - "a cache of users, basic groups, supergroups, channels and secret chats".

So, without message database, you need to use CreatePrivateChat/CreateBasicGroupChat/CreateSupergroupChat/CreateSecretChat to recreate the chat from a corresponding user_id, basic_group_id, supergroup_id or secret_chat_id before you can use it.