Re-do chat history handling
melix99 opened this issue · 3 comments
melix99 commented
Currently the ChatHistory
(the GObject
, to not be confused with the widget) is really bare bone. It's a GListModel
that can load more messages, starting from the last one. It's also the object that caches the messages and updates them with TDLib updates. This object works fine for a basic message list, but it's a limiting factor for a full-fledged Telegram client. For example:
- The fact that it always has to start from the last message means that when we open a chat with lots of unread messages, the chat history will still load only the last sent messages. In telegram clients you usually want to start loading messages from around the last read message instead.
- The cache has no way to shrink. This is because the
ChatHistory
stores fullMessage
objects, and it has no way of knowing when it's time to remove them. - We can't create more
ChatHistory
s for a single chat. This is needed e.g. when pressing on a super old replied message. You don't want to manually load all the chat history messages until that specific message.
These are some of the plans I have to improve things:
- Move message caching and updates to the
Chat
object. This way we don't end up with multiple message caches when creating multipleChatHistory
s. - Remove
history
property from Chat. TheChatHistory
s should be created manually only when needed. - Make the
ChatHistory
store the message ids (or just weak refs of Messages) instead of theMessage
objects. This way if aMessage
is deleted from the cache, it actually gets deallocated. In case those messages are needed, we can callget_message(id)
from tdlib anyway. - Make the messages cache handle the
DeleteMessages
update withfrom_cache=true
, this way we sync our local cache with tdlib's cache. To do that we also need to tell tdlib about opening and closing chats. See discussion in https://t.me/tdlibchat/65304. - Make the
ChatHistory
be able to load chats from a specific message id. - Maybe move
ChatHistory
away from tdlib/ directory? TheChatHistory
seems to be a really custom thing at this point that it's more tied to the chat history'sGtkListView
than the tdlib APIs.
If you have more ideas, feel free to reply here or discuss it in the Telegram group.
melix99 commented
More things to consider: reply threads and group topics.