From 55c1129a651b1191273bbf8e49783a4798580375 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 10 Dec 2015 23:05:11 +0100 Subject: notify on mam catchup messages --- .../eu/siacs/conversations/parser/MessageParser.java | 20 +++++++++++++++----- .../services/MessageArchiveService.java | 3 +++ .../conversations/services/NotificationService.java | 4 ++-- .../services/XmppConnectionService.java | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 2c536f69..80886f7f 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -397,15 +397,21 @@ public class MessageParser extends AbstractParser implements } conversation.add(message); - if (query != null) { - query.incrementMessageCount(); - } else { + + if (query == null || query.getWith() == null) { //either no mam or catchup if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) { mXmppConnectionService.markRead(conversation); - account.activateGracePeriod(); + if (query == null) { + account.activateGracePeriod(); + } } else { message.markUnread(); } + } + + if (query != null) { + query.incrementMessageCount(); + } else { mXmppConnectionService.updateConversationUi(); } @@ -445,7 +451,11 @@ public class MessageParser extends AbstractParser implements if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) { manager.createNewDownloadConnection(message); } else if (!message.isRead()) { - mXmppConnectionService.getNotificationService().push(message); + if (query == null) { + mXmppConnectionService.getNotificationService().push(message); + } else if (query.getWith() == null) { // mam catchup + mXmppConnectionService.getNotificationService().pushFromBacklog(message); + } } } else { //no body if (isTypeGroupChat) { diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index f6d3a2fa..8847cfcd 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -218,6 +218,9 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { if (complete || relevant == null || abort) { this.finalizeQuery(query); Log.d(Config.LOGTAG,query.getAccount().getJid().toBareJid().toString()+": finished mam after "+query.getTotalCount()+" messages"); + if (query.getWith() == null && query.getTotalCount() > 0) { + mXmppConnectionService.getNotificationService().finishBacklog(true); + } } else { final Query nextQuery; if (query.getPagingOrder() == PagingOrder.NORMAL) { diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 03ab6f63..e8dec815 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -119,10 +119,10 @@ public class NotificationService { } } - public void finishBacklog() { + public void finishBacklog(boolean notify) { synchronized (notifications) { mXmppConnectionService.updateUnreadCountBadge(); - updateNotification(false); + updateNotification(notify); } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 790e035c..1a0153e5 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1107,7 +1107,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } }); } - mNotificationService.finishBacklog(); + mNotificationService.finishBacklog(false); mRestoredFromDatabase = true; Log.d(Config.LOGTAG, "restored all messages"); updateConversationUi(); -- cgit v1.2.3