From 2764f04c14bdc19ee1d267e43bafbffb29257c64 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 9 Mar 2017 20:32:19 +0100 Subject: do not notify for messages from strangers by default --- .../de/pixart/messenger/entities/Conversation.java | 20 ++++++++++++++++++++ .../messenger/services/NotificationService.java | 10 ++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index e4e138ec2..260678728 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -1036,6 +1036,26 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } + private int sentMessagesCount() { + int count = 0; + synchronized (this.messages) { + for (Message message : messages) { + if (message.getStatus() != Message.STATUS_RECEIVED) { + ++count; + } + } + } + return count; + } + + public boolean isWithStranger() { + if (mode == MODE_SINGLE) { + return !getContact().mutualPresenceSubscription() && sentMessagesCount() == 0; + } else { + return false; + } + } + public class Smp { public static final int STATUS_NONE = 0; public static final int STATUS_CONTACT_REQUESTED = 1; diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index 3a29275ea..e042d76db 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -65,10 +65,11 @@ public class NotificationService { } public boolean notify(final Message message) { - return (message.getStatus() == Message.STATUS_RECEIVED) + return message.getStatus() == Message.STATUS_RECEIVED && notificationsEnabled() && !message.getConversation().isMuted() - && (message.getConversation().alwaysNotify() || wasHighlightedOrPrivate(message) + && (message.getConversation().alwaysNotify() || wasHighlightedOrPrivate(message)) + && (!message.getConversation().isWithStranger() || notificationsFromStrangers() ); } @@ -76,6 +77,11 @@ public class NotificationService { return mXmppConnectionService.getPreferences().getBoolean("show_notification", true); } + private boolean notificationsFromStrangers() { + return mXmppConnectionService.getPreferences().getBoolean("notifications_from_strangers", + mXmppConnectionService.getResources().getBoolean(R.bool.notifications_from_strangers)); + } + public boolean isQuietHours() { if (!mXmppConnectionService.getPreferences().getBoolean("enable_quiet_hours", false)) { return false; -- cgit v1.2.3