From 0968da1ff76e7443c2590f4182087bb501d9c8f5 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 28 Feb 2018 21:02:39 +0100 Subject: Only notify on last MAM message, only if not read fixes #293 --- libdino/src/service/notification_events.vala | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libdino/src/service/notification_events.vala') diff --git a/libdino/src/service/notification_events.vala b/libdino/src/service/notification_events.vala index 5db581ba..13fef3e3 100644 --- a/libdino/src/service/notification_events.vala +++ b/libdino/src/service/notification_events.vala @@ -14,6 +14,9 @@ public class NotificationEvents : StreamInteractionModule, Object { private StreamInteractor stream_interactor; + private HashMap> mam_potential_new = new HashMap>(Account.hash_func, Account.equals_func); + private Gee.List synced_accounts = new ArrayList(); + public static void start(StreamInteractor stream_interactor) { NotificationEvents m = new NotificationEvents(stream_interactor); stream_interactor.add_module(m); @@ -24,9 +27,29 @@ public class NotificationEvents : StreamInteractionModule, Object { stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received); stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect(on_received_subscription_request); + stream_interactor.get_module(MessageProcessor.IDENTITY).history_synced.connect((account) => { + synced_accounts.add(account); + if (!mam_potential_new.has_key(account)) return; + foreach (Conversation c in mam_potential_new[account].keys) { + Entities.Message m = mam_potential_new[account][c]; + Entities.Message last_message = stream_interactor.get_module(MessageStorage.IDENTITY).get_last_message(c); + if (m.equals(last_message) && !c.read_up_to.equals(m)) { + on_message_received(m, c); + } + } + mam_potential_new[account].clear(); + }); } private void on_message_received(Entities.Message message, Conversation conversation) { + if (!synced_accounts.contains(conversation.account)) { + if (!mam_potential_new.has_key(conversation.account)) { + mam_potential_new[conversation.account] = new HashMap(Conversation.hash_func, Conversation.equals_func); + } + mam_potential_new[conversation.account][conversation] = message; + return; + } + if (!should_notify_message(message, conversation)) return; if (!should_notify_message(message, conversation)) return; if (stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus()) return; notify_message(message, conversation); -- cgit v1.2.3-70-g09d2