From c3532bdf3141bcf0cbf9e4ae7a926dcda4f132ef Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 18 Dec 2019 18:53:14 +0100 Subject: Refactor MAM catchup. Fetch from latest to earliest message. --- libdino/src/service/notification_events.vala | 34 ++++++---------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (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 f47b9a0a..dca81af8 100644 --- a/libdino/src/service/notification_events.vala +++ b/libdino/src/service/notification_events.vala @@ -16,9 +16,6 @@ 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(Account.equals_func); - public static void start(StreamInteractor stream_interactor) { NotificationEvents m = new NotificationEvents(stream_interactor); stream_interactor.add_module(m); @@ -31,36 +28,19 @@ public class NotificationEvents : StreamInteractionModule, Object { stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect(on_received_subscription_request); stream_interactor.get_module(MucManager.IDENTITY).invite_received.connect((account, room_jid, from_jid, password, reason) => notify_muc_invite(account, room_jid, from_jid, password, reason)); stream_interactor.connection_manager.connection_error.connect((account, error) => notify_connection_error(account, error)); - 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) { - ContentItem last_mam_item = mam_potential_new[account][c]; - ContentItem last_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_latest(c); - if (last_mam_item == last_item /* && !c.read_up_to.equals(m) */) { - on_content_item_received(last_mam_item, c); - } - } - mam_potential_new[account].clear(); - }); } private void on_content_item_received(ContentItem item, Conversation conversation) { - // Don't wait for MAM sync on servers without MAM - bool mam_available = true; - XmppStream? stream = stream_interactor.get_stream(conversation.account); - if (stream != null) { - mam_available = stream.get_flag(Xep.MessageArchiveManagement.Flag.IDENTITY) != null; - } + ContentItem last_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_latest(conversation); - if (mam_available && !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] = item; - return; + bool not_read_up_to = true; + MessageItem message_item = item as MessageItem; + if (message_item != null) { + not_read_up_to = conversation.read_up_to != null && !conversation.read_up_to.equals(message_item.message); } + if (item.id != last_item.id && not_read_up_to) return; + if (!should_notify(item, conversation)) return; if (stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus()) return; notify_content_item(item, conversation); -- cgit v1.3