Skip to content

Commit f69ed77

Browse files
committed
change logic to not delete bubbles
instead to use KEY_NOTIFICATION_RESTRICT_DELETION, always check if notification is actually bubbled in cancelNotification Without this commit, bubbled notifications would remain open when the chat was opened in normal mode. With this commit, bubbled notifications will be removed when opening the chat in normal mode.
1 parent 8d659c0 commit f69ed77

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,8 +2708,9 @@ open class ChatActivity :
27082708

27092709
@Suppress("Detekt.TooGenericExceptionCaught")
27102710
protected open fun cancelNotificationsForCurrentConversation() {
2711+
val isBubbleMode = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && isLaunchedFromBubble
27112712
if (conversationUser != null) {
2712-
if (!TextUtils.isEmpty(roomToken)) {
2713+
if (!TextUtils.isEmpty(roomToken) && !isBubbleMode) {
27132714
try {
27142715
NotificationUtils.cancelExistingNotificationsForRoom(
27152716
applicationContext,
@@ -3541,11 +3542,9 @@ open class ChatActivity :
35413542
val messagingStyle = androidx.core.app.NotificationCompat.MessagingStyle(person)
35423543
.setConversationTitle(conversationName)
35433544

3544-
// Create extras bundle to protect bubble from deletion
35453545
val notificationExtras = bundleOf(
3546-
BundleKeys.KEY_ROOM_TOKEN to roomToken,
3547-
BundleKeys.KEY_NOTIFICATION_RESTRICT_DELETION to true,
3548-
BundleKeys.KEY_INTERNAL_USER_ID to conversationUser!!.id!!
3546+
KEY_ROOM_TOKEN to roomToken,
3547+
KEY_INTERNAL_USER_ID to conversationUser!!.id!!
35493548
)
35503549

35513550
val channelId = NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4.name

app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
657657
notificationInfoBundle.putString(KEY_ROOM_TOKEN, pushMessage.id)
658658
notificationInfoBundle.putLong(KEY_NOTIFICATION_ID, pushMessage.notificationId!!)
659659

660-
// Protect bubble notifications from being canceled
661-
if (pushMessage.type == TYPE_RECORDING || pushMessage.type == TYPE_CHAT || pushMessage.type == TYPE_REMINDER) {
660+
if (pushMessage.type == TYPE_RECORDING) {
662661
notificationInfoBundle.putBoolean(KEY_NOTIFICATION_RESTRICT_DELETION, true)
663662
}
664663

app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import android.graphics.drawable.BitmapDrawable
2222
import android.graphics.drawable.Drawable
2323
import android.media.AudioAttributes
2424
import android.net.Uri
25+
import android.os.Build
2526
import android.service.notification.StatusBarNotification
2627
import android.text.TextUtils
2728
import android.util.Log
@@ -241,14 +242,14 @@ object NotificationUtils {
241242

242243
fun cancelNotification(context: Context?, conversationUser: User, notificationId: Long?) {
243244
scanNotifications(context, conversationUser) { notificationManager, statusBarNotification, notification ->
244-
if (notificationId == notification.extras.getLong(BundleKeys.KEY_NOTIFICATION_ID)) {
245-
if (notification.extras.getBoolean(BundleKeys.KEY_NOTIFICATION_RESTRICT_DELETION)) {
246-
if (BuildConfig.DEBUG) {
247-
Log.d(TAG, "Skip cancelling protected notification ${statusBarNotification.id}")
248-
}
249-
} else {
250-
notificationManager.cancel(statusBarNotification.id)
251-
}
245+
val matchesId = notificationId == notification.extras.getLong(BundleKeys.KEY_NOTIFICATION_ID)
246+
247+
val isBubble =
248+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
249+
(notification.flags and Notification.FLAG_BUBBLE) != 0
250+
251+
if (matchesId && !isBubble) {
252+
notificationManager.cancel(statusBarNotification.id)
252253
}
253254
}
254255
}

0 commit comments

Comments
 (0)