paper-plane-developers/paper-plane

Re-do chat history handling

melix99 opened this issue · 3 comments

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 full Message objects, and it has no way of knowing when it's time to remove them.
  • We can't create more ChatHistorys 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 multiple ChatHistorys.
  • Remove history property from Chat. The ChatHistorys should be created manually only when needed.
  • Make the ChatHistory store the message ids (or just weak refs of Messages) instead of the Message objects. This way if a Message is deleted from the cache, it actually gets deallocated. In case those messages are needed, we can call get_message(id) from tdlib anyway.
  • Make the messages cache handle the DeleteMessages update with from_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? The ChatHistory seems to be a really custom thing at this point that it's more tied to the chat history's GtkListView than the tdlib APIs.

If you have more ideas, feel free to reply here or discuss it in the Telegram group.

This is also an opportunity to fix #251.

More things to consider: reply threads and group topics.

This is also an opportunity to fix #335