mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
setting to disable notifications for new contacts
also mute these notifications between 23:00 and 09:00 fixes #4572 Closes #4926
This commit is contained in:
parent
d238e2bbc5
commit
ed592950c0
5 changed files with 33 additions and 3 deletions
|
@ -947,6 +947,8 @@
|
|||
<string name="preferences__inactivity_timeout_interval">Inactivity timeout interval</string>
|
||||
<string name="preferences__notifications">Notifications</string>
|
||||
<string name="preferences__enable_message_notifications">Enable message notifications</string>
|
||||
<string name="preferences__new_contacts_notifications">New contacts notifications</string>
|
||||
<string name="preferences__show_a_notification_for_new_signal_contacts">Show a notification for new Signal contacts</string>
|
||||
<string name="preferences__led_color">LED color</string>
|
||||
<string name="preferences__led_color_unknown">Unknown</string>
|
||||
<string name="preferences__pref_led_blink_title">LED blink pattern</string>
|
||||
|
|
|
@ -57,4 +57,10 @@
|
|||
android:entries="@array/pref_notification_privacy_entries"
|
||||
android:entryValues="@array/pref_notification_privacy_values"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:key="pref_enable_new_contacts_notifications"
|
||||
android:title="@string/preferences__new_contacts_notifications"
|
||||
android:summary="@string/preferences__show_a_notification_for_new_signal_contacts"
|
||||
android:defaultValue="true" />
|
||||
|
||||
</PreferenceScreen>
|
|
@ -121,6 +121,15 @@ public class MessageNotifier {
|
|||
@Nullable MasterSecret masterSecret,
|
||||
boolean includePushDatabase,
|
||||
long threadId)
|
||||
{
|
||||
updateNotification(context, masterSecret, includePushDatabase, threadId, true);
|
||||
}
|
||||
|
||||
public static void updateNotification(@NonNull Context context,
|
||||
@Nullable MasterSecret masterSecret,
|
||||
boolean includePushDatabase,
|
||||
long threadId,
|
||||
boolean signal)
|
||||
{
|
||||
boolean isVisible = visibleThread == threadId;
|
||||
|
||||
|
@ -141,7 +150,7 @@ public class MessageNotifier {
|
|||
if (isVisible) {
|
||||
sendInThreadNotification(context, threads.getRecipientsForThreadId(threadId));
|
||||
} else {
|
||||
updateNotification(context, masterSecret, true, includePushDatabase, 0);
|
||||
updateNotification(context, masterSecret, signal, includePushDatabase, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.thoughtcrime.securesms.ApplicationContext;
|
|||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.SessionUtil;
|
||||
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.NotInDirectoryException;
|
||||
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
||||
|
@ -32,6 +31,7 @@ import org.whispersystems.textsecure.api.push.ContactTokenDetails;
|
|||
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -213,11 +213,19 @@ public class DirectoryHelper {
|
|||
@Nullable MasterSecret masterSecret,
|
||||
@NonNull List<String> newUsers)
|
||||
{
|
||||
if (!TextSecurePreferences.isNewContactsNotificationEnabled(context)) return;
|
||||
|
||||
for (String newUser : newUsers) {
|
||||
if (!SessionUtil.hasSession(context, masterSecret, newUser)) {
|
||||
IncomingJoinedMessage message = new IncomingJoinedMessage(newUser);
|
||||
Pair<Long, Long> smsAndThreadId = DatabaseFactory.getSmsDatabase(context).insertMessageInbox(message);
|
||||
MessageNotifier.updateNotification(context, masterSecret, smsAndThreadId.second);
|
||||
|
||||
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
||||
if (hour >= 9 && hour < 23) {
|
||||
MessageNotifier.updateNotification(context, masterSecret, false, smsAndThreadId.second, true);
|
||||
} else {
|
||||
MessageNotifier.updateNotification(context, masterSecret, false, smsAndThreadId.second, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ public class TextSecurePreferences {
|
|||
|
||||
public static final String REPEAT_ALERTS_PREF = "pref_repeat_alerts";
|
||||
public static final String NOTIFICATION_PRIVACY_PREF = "pref_notification_privacy";
|
||||
public static final String NEW_CONTACTS_NOTIFICATIONS = "pref_enable_new_contacts_notifications";
|
||||
|
||||
public static final String MEDIA_DOWNLOAD_MOBILE_PREF = "pref_media_download_mobile";
|
||||
public static final String MEDIA_DOWNLOAD_WIFI_PREF = "pref_media_download_wifi";
|
||||
|
@ -116,6 +117,10 @@ public class TextSecurePreferences {
|
|||
return new NotificationPrivacyPreference(getStringPreference(context, NOTIFICATION_PRIVACY_PREF, "all"));
|
||||
}
|
||||
|
||||
public static boolean isNewContactsNotificationEnabled(Context context) {
|
||||
return getBooleanPreference(context, NEW_CONTACTS_NOTIFICATIONS, true);
|
||||
}
|
||||
|
||||
public static long getRatingLaterTimestamp(Context context) {
|
||||
return getLongPreference(context, RATING_LATER_PREF, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue