aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/notification_events.vala
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src/service/notification_events.vala')
-rw-r--r--libdino/src/service/notification_events.vala34
1 files changed, 7 insertions, 27 deletions
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<Account, HashMap<Conversation, ContentItem>> mam_potential_new = new HashMap<Account, HashMap<Conversation, ContentItem>>(Account.hash_func, Account.equals_func);
- private Gee.List<Account> synced_accounts = new ArrayList<Account>(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, ContentItem>(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);