From 751afadebdbe24ba497fe5f96f29fdb551e5dbf1 Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Wed, 28 Apr 2021 20:49:36 -0400 Subject: [PATCH] Fix notification issues introduced when adding lower API versions. --- .../securesms/notifications/v2/MessageNotifierV2.kt | 2 +- .../notifications/v2/NotificationFactory.kt | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/MessageNotifierV2.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/MessageNotifierV2.kt index a50ff86a8..2f3c401bc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/MessageNotifierV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/MessageNotifierV2.kt @@ -30,7 +30,6 @@ import org.thoughtcrime.securesms.util.ServiceUtil import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.webrtc.CallNotificationBuilder import org.whispersystems.signalservice.internal.util.Util -import java.lang.UnsupportedOperationException import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.Executor import java.util.concurrent.Executors @@ -167,6 +166,7 @@ class MessageNotifierV2(context: Application) : MessageNotifier { targetThreadId = threadId, defaultBubbleState = defaultBubbleState, lastAudibleNotification = lastAudibleNotification, + notificationConfigurationChanged = notificationConfigurationChanged, alertOverrides = alertOverrides ) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationFactory.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationFactory.kt index e28abf0c2..c89f88249 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationFactory.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationFactory.kt @@ -45,6 +45,7 @@ object NotificationFactory { targetThreadId: Long, defaultBubbleState: BubbleUtil.BubbleState, lastAudibleNotification: Long, + notificationConfigurationChanged: Boolean, alertOverrides: Set ): Set { if (state.isEmpty) { @@ -72,6 +73,7 @@ object NotificationFactory { targetThreadId = targetThreadId, defaultBubbleState = defaultBubbleState, lastAudibleNotification = lastAudibleNotification, + notificationConfigurationChanged = notificationConfigurationChanged, alertOverrides = alertOverrides, nonVisibleThreadCount = nonVisibleThreadCount ) @@ -127,6 +129,7 @@ object NotificationFactory { targetThreadId: Long, defaultBubbleState: BubbleUtil.BubbleState, lastAudibleNotification: Long, + notificationConfigurationChanged: Boolean, alertOverrides: Set, nonVisibleThreadCount: Int ): Set { @@ -136,7 +139,7 @@ object NotificationFactory { if (conversation.threadId == visibleThreadId && conversation.hasNewNotifications()) { Log.internal().i(TAG, "Thread is visible, notifying in thread. notificationId: ${conversation.notificationId}") notifyInThread(context, conversation.recipient, lastAudibleNotification) - } else { + } else if (notificationConfigurationChanged || conversation.hasNewNotifications() || alertOverrides.contains(conversation.threadId)) { if (conversation.hasNewNotifications()) { threadsThatNewlyAlerted += conversation.threadId } @@ -165,6 +168,10 @@ object NotificationFactory { defaultBubbleState: BubbleUtil.BubbleState, shouldAlert: Boolean ) { + if (conversation.notificationItems.isEmpty()) { + return + } + val builder: NotificationBuilder = NotificationBuilder.create(context) builder.apply { @@ -205,6 +212,10 @@ object NotificationFactory { } private fun notifySummary(context: Context, state: NotificationStateV2) { + if (state.messageCount == 0) { + return + } + val builder: NotificationBuilder = NotificationBuilder.create(context) builder.apply {