diff options
author | fiaxh <git@mx.ax.lt> | 2017-12-06 18:08:20 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-12-13 21:11:33 +0100 |
commit | fc0d7feb5aef16e0024cfeb73286038998e926d2 (patch) | |
tree | 22f7c9a365b6323994dccc52725e936a6ff87f6b /main/src | |
parent | bbbfdf0551fdb03e793944243dcaaf811e8ac027 (diff) | |
download | dino-fc0d7feb5aef16e0024cfeb73286038998e926d2.tar.gz dino-fc0d7feb5aef16e0024cfeb73286038998e926d2.zip |
Load messages for conversation view from cache
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/ui/conversation_summary/conversation_view.vala | 5 | ||||
-rw-r--r-- | main/src/ui/conversation_summary/message_populator.vala | 15 |
2 files changed, 16 insertions, 4 deletions
diff --git a/main/src/ui/conversation_summary/conversation_view.vala b/main/src/ui/conversation_summary/conversation_view.vala index 37412335..7924da57 100644 --- a/main/src/ui/conversation_summary/conversation_view.vala +++ b/main/src/ui/conversation_summary/conversation_view.vala @@ -74,7 +74,8 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { populator.init(conversation, this, Plugins.WidgetType.GTK); } message_item_populator.init(conversation, this); - message_item_populator.populate_number(conversation, new DateTime.now_utc(), 50); + message_item_populator.populate_latest(conversation, 40); + Idle.add(() => { on_value_notify(); return false; }); stack.set_visible_child_name("main"); } @@ -217,7 +218,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { private void load_earlier_messages() { was_value = scrolled.vadjustment.value; if (!reloading_mutex.trylock()) return; - if (meta_items.size > 0) message_item_populator.populate_number(conversation, meta_items.first().sort_time, 20); + if (meta_items.size > 0) message_item_populator.populate_before(conversation, meta_items.first(), 20); } private static int sort_meta_items(Plugins.MetaConversationItem a, Plugins.MetaConversationItem b) { diff --git a/main/src/ui/conversation_summary/message_populator.vala b/main/src/ui/conversation_summary/message_populator.vala index df44a14b..b342306b 100644 --- a/main/src/ui/conversation_summary/message_populator.vala +++ b/main/src/ui/conversation_summary/message_populator.vala @@ -10,6 +10,7 @@ public class MessagePopulator : Object { private StreamInteractor? stream_interactor; private Conversation? current_conversation; private Plugins.ConversationItemCollection? item_collection; + private HashMap<Plugins.MetaConversationItem, Message> meta_message = new HashMap<Plugins.MetaConversationItem, Message>(); public MessagePopulator(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; @@ -30,8 +31,17 @@ public class MessagePopulator : Object { public void close(Conversation conversation) { } - public void populate_number(Conversation conversation, DateTime from, int n) { - Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages_before(conversation, from, n); + public void populate_latest(Conversation conversation, int n) { + Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages(conversation, n); + if (messages != null) { + foreach (Entities.Message message in messages) { + handle_message(message, conversation); + } + } + } + + public void populate_before(Conversation conversation, Plugins.MetaConversationItem item, int n) { + Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages_before_message(conversation, meta_message[item], n); if (messages != null) { foreach (Entities.Message message in messages) { handle_message(message, conversation); @@ -53,6 +63,7 @@ public class MessagePopulator : Object { } Plugins.MetaConversationItem? meta_item = best_provider.get_item(message, conversation); if (meta_item == null) return; + meta_message[meta_item] = message; meta_item.mark = message.marked; WeakRef weak_meta_item = WeakRef(meta_item); |