diff options
author | fiaxh <git@mx.ax.lt> | 2017-08-27 23:55:49 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-08-28 00:02:59 +0200 |
commit | 8bc0d107e740be468ee0c9dcd253de36355088d3 (patch) | |
tree | 36858e844d711eb18a68612fd815cb84f4c3a88f /main/src/ui/conversation_summary/message_populator.vala | |
parent | a807ded65cd907e04bab7b8cd27b5702b157e3a2 (diff) | |
download | dino-8bc0d107e740be468ee0c9dcd253de36355088d3.tar.gz dino-8bc0d107e740be468ee0c9dcd253de36355088d3.zip |
Plugins providing conversation items for ConversationView
Diffstat (limited to 'main/src/ui/conversation_summary/message_populator.vala')
-rw-r--r-- | main/src/ui/conversation_summary/message_populator.vala | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/main/src/ui/conversation_summary/message_populator.vala b/main/src/ui/conversation_summary/message_populator.vala new file mode 100644 index 00000000..2c3eccd2 --- /dev/null +++ b/main/src/ui/conversation_summary/message_populator.vala @@ -0,0 +1,66 @@ +using Gee; +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui.ConversationSummary { + +public class MessagePopulator : Object { + + private StreamInteractor? stream_interactor; + private Conversation? current_conversation; + private Plugins.ConversationItemCollection? item_collection; + + public MessagePopulator(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + + Application app = GLib.Application.get_default() as Application; + app.plugin_registry.register_message_display(new DefaultMessageDisplay(stream_interactor)); + app.plugin_registry.register_message_display(new SlashmeMessageDisplay(stream_interactor)); + + + stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect((message, conversation) => { + Idle.add(() => { handle_message(message, conversation); return false; }); + }); + stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect((message, conversation) => { + Idle.add(() => { handle_message(message, conversation); return false; }); + }); + } + + public void init(Conversation conversation, Plugins.ConversationItemCollection item_collection) { + current_conversation = conversation; + this.item_collection = item_collection; + } + + 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); + if (messages != null) { + foreach (Entities.Message message in messages) { + handle_message(message, conversation); + } + } + } + + private void handle_message(Message message, Conversation conversation) { + if (!conversation.equals(current_conversation)) return; + + Plugins.MessageDisplayProvider? best_provider = null; + int priority = -1; + Application app = GLib.Application.get_default() as Application; + foreach (Plugins.MessageDisplayProvider provider in app.plugin_registry.message_displays) { + if (provider.can_display(message) && provider.priority > priority) { + best_provider = provider; + } + } + Plugins.MetaConversationItem meta_item = best_provider.get_item(message, conversation); + meta_item.mark = message.marked; + message.notify["marked"].connect(() => { + meta_item.mark = message.marked; + }); + item_collection.insert_item(meta_item); + } +} + +} |