From 132b27adeef3ab4d305facda7dd035015b00766f Mon Sep 17 00:00:00 2001 From: steckbrief Date: Sat, 5 May 2018 20:28:04 +0200 Subject: introduces new message state model --- .../services/NotificationService.java | 48 ++++++++++++---------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java') diff --git a/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java b/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java index c21c90d1..c5ada873 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/NotificationService.java @@ -29,9 +29,12 @@ import java.util.List; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.ConversationsPlusColors; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; +import de.thedevstack.conversationsplus.enums.MessageDirection; import de.thedevstack.conversationsplus.services.avatar.AvatarCache; import de.thedevstack.conversationsplus.utils.ImageUtil; import de.thedevstack.conversationsplus.utils.MessageUtil; +import de.thedevstack.conversationsplus.utils.XmppSendUtil; +import de.thedevstack.conversationsplus.xmpp.stanzas.MessagePacket; import de.tzur.conversations.Settings; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.R; @@ -62,7 +65,7 @@ public class NotificationService { } public boolean notify(final Message message) { - return (message.getStatus() == Message.STATUS_RECEIVED) + return MessageUtil.isIncomingMessage(message) && !message.isRead() && ConversationsPlusPreferences.showNotification() && !message.getConversation().isMuted() @@ -133,25 +136,28 @@ public class NotificationService { } public void push(final Message message) { - if (!notify(message)) { - return; - } - mXmppConnectionService.updateUnreadCountBadge(); - final boolean isScreenOn = mXmppConnectionService.isInteractive(); - if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { - return; - } - synchronized (notifications) { - pushToStack(message); - final Account account = message.getConversation().getAccount(); - final boolean doNotify = (!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) - && !account.inGracePeriod() - && !this.inMiniGracePeriod(account); - updateNotification(doNotify); - if (doNotify) { - notifyPebble(message); + if (message.isMamReceived()) { + return; + } + if (notify(message)) { + mXmppConnectionService.updateUnreadCountBadge(); + final boolean isScreenOn = mXmppConnectionService.isInteractive(); + if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { + return; + } + synchronized (notifications) { + pushToStack(message); + final Account account = message.getConversation().getAccount(); + final boolean doNotify = (!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) + && !account.inGracePeriod() + && !this.inMiniGracePeriod(account); + updateNotification(doNotify); + if (doNotify) { + notifyPebble(message); + } } } + } public void clear() { @@ -354,11 +360,9 @@ public class NotificationService { private Message getImage(final Iterable messages) { for (final Message message : messages) { - if (message.getType() != Message.TYPE_TEXT - && message.getTransferable() == null + if (message.getTransferable() == null && message.getEncryption() != Message.ENCRYPTION_PGP - && message.getFileParams() != null - && message.getFileParams().getHeight() > 0) { // TODO Use FileParams.getMimeType() + && MessageUtil.isAttachedFileAnImage(message)) { // TODO Use FileParams.getMimeType() return message; } } -- cgit v1.2.3