aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java20
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java10
-rw-r--r--src/main/res/values/defaults.xml1
-rw-r--r--src/main/res/values/strings.xml2
-rw-r--r--src/main/res/xml/preferences.xml6
5 files changed, 37 insertions, 2 deletions
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;
diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml
index dd0ba1ccb..2b3d62f25 100644
--- a/src/main/res/values/defaults.xml
+++ b/src/main/res/values/defaults.xml
@@ -3,4 +3,5 @@
<string name="default_resource" translatable="false">Phone</string>
<bool name="portrait_only">true</bool>
<bool name="enter_is_send">false</bool>
+ <bool name="notifications_from_strangers">false</bool>
</resources> \ No newline at end of file
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 899f79d49..b569381c3 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -749,4 +749,6 @@
<string name="block_jabber_id">Block Jabber ID</string>
<string name="corresponding_conversations_closed">Corresponding conversations closed.</string>
<string name="contact_blocked_past_tense">Contact blocked.</string>
+ <string name="pref_notifications_from_strangers">Notifications from strangers</string>
+ <string name="pref_notifications_from_strangers_summary">Notify for messages received from strangers.</string>
</resources>
diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml
index ba428aeb3..e3078f1a2 100644
--- a/src/main/res/xml/preferences.xml
+++ b/src/main/res/xml/preferences.xml
@@ -86,6 +86,12 @@
android:ringtoneType="notification"
android:summary="@string/pref_sound_summary"
android:title="@string/pref_sound" />
+ <CheckBoxPreference
+ android:defaultValue="@bool/notifications_from_strangers"
+ android:dependency="show_notification"
+ android:key="notifications_from_strangers"
+ android:summary="@string/pref_notifications_from_strangers_summary"
+ android:title="@string/pref_notifications_from_strangers" />
</PreferenceScreen>
<!--Attachments-->
<PreferenceScreen