td
td copied to clipboard
Unable to persist fileId through instance recreation
Hello to everyone.
I'm trying to keep a persistent chat feed and stumbled across a unknown behavior. The goal is to retrieve chat content via getChatHistory
, store its content in database, then retrieve and show it. Right now I'm retrieving chat history, then serialize message content and store it in db;
And sometimes later the Invalid file identifier
comes into play. I'm guessing the local fileId
becomes outdated for some reason while still containing file on disk.
But how do you retrieve fileId
without fetching message and it's content again from telegram? I see no functions that can resolve remoteId
to fileId
. And downloadFile
only accepts local id;
Is there a possibility? Or what would be the correct approach?
File identifiers aren't persistent and are valid only until TDLib instance is closed. Apps supposed to save nothing between TDLib restarts.
The correct approach is to fetch the message from TDLib using getMessage
, get file identifier from the message content and download the file using the identifier. There is no way to download the file without having access to the message.
Hm.
Will getMessage
use network request or assemble result from local copy?
Supposedly I've got chat history and stored message ids. And when user will be browsing the history I must getMessage
one by one as they appear? Is this correct? Won't this be a heavy load on telegram?
Will getMessage use network request or assemble result from local copy?
If a request is possible to complete locally, it will be completed locally.
And when user will be browsing the history I must getMessage one by one as they appear?
In fact, ordinary apps almost never need to use getMessage
. See https://core.telegram.org/tdlib/getting-started and https://core.telegram.org/tdlib/getting-started#getting-chat-messages in particular.