do not notify for messages from strangers by default
This commit is contained in:
		
							parent
							
								
									857c761c68
								
							
						
					
					
						commit
						7306e0286f
					
				|  | @ -992,6 +992,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; | ||||
|  |  | |||
|  | @ -59,17 +59,23 @@ 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()) | ||||
| 		; | ||||
| 	} | ||||
| 
 | ||||
| 	public boolean notificationsEnabled() { | ||||
| 		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; | ||||
|  |  | |||
|  | @ -3,4 +3,5 @@ | |||
|     <string name="default_resource">Phone</string> | ||||
|     <bool name="portrait_only">true</bool> | ||||
|     <bool name="enter_is_send">false</bool> | ||||
|     <bool name="notifications_from_strangers">false</bool> | ||||
| </resources> | ||||
|  | @ -736,4 +736,6 @@ | |||
| 	<string name="transcoding_video_progress">Compressing video (%s%% completed)</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> | ||||
|  |  | |||
|  | @ -41,6 +41,12 @@ | |||
|             android:key="show_notification" | ||||
|             android:summary="@string/pref_notifications_summary" | ||||
|             android:title="@string/pref_notifications"/> | ||||
|         <CheckBoxPreference | ||||
|             android:defaultValue="@bool/notifications_from_strangers" | ||||
|             android:key="notifications_from_strangers" | ||||
|             android:dependency="show_notification" | ||||
|             android:title="@string/pref_notifications_from_strangers" | ||||
|             android:summary="@string/pref_notifications_from_strangers_summary"/> | ||||
|         <CheckBoxPreference | ||||
|             android:defaultValue="true" | ||||
|             android:dependency="show_notification" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Daniel Gultsch
						Daniel Gultsch