From 50ccd98ab79587bb0e951650771c861ff13ec566 Mon Sep 17 00:00:00 2001 From: boris Date: Thu, 21 Mar 2024 12:58:23 +0200 Subject: [PATCH] feat: Remove notifications on read from another client [WPB-1881] (#2802) --- .../notification/MessageNotificationManager.kt | 16 +++++++++++++++- .../com/wire/android/notification/Models.kt | 7 +++---- kalium | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt b/app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt index a84de5e60ba..99f2de18724 100644 --- a/app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt +++ b/app/src/main/kotlin/com/wire/android/notification/MessageNotificationManager.kt @@ -59,6 +59,7 @@ class MessageNotificationManager addNotifications(newNotifications, userId, userName) updateNotifications(newNotifications, userId) + removeSeenNotifications(newNotifications, userId) appLogger.i("$TAG: handled notifications: newNotifications size ${newNotifications.size}; ") } @@ -90,7 +91,20 @@ class MessageNotificationManager removeSummaryIfNeeded(userId) - appLogger.i("$TAG: added notifications: newNotifications size ${notificationsToUpdate.size}; ") + appLogger.i("$TAG: updated notifications: newNotifications size ${notificationsToUpdate.size}; ") + } + + private fun removeSeenNotifications(newNotifications: List, userId: QualifiedID) { + val notificationsToUpdate: List = newNotifications + .filterIsInstance(LocalNotification.ConversationSeen::class.java) + + notificationsToUpdate.groupBy { it.conversationId }.forEach { (conversationId, _) -> + hideNotification(conversationId, userId) + } + + removeSummaryIfNeeded(userId) + + appLogger.i("$TAG: removed ${notificationsToUpdate.size} notifications, it was seen;") } fun hideNotification(conversationsId: ConversationId, userId: QualifiedID) { diff --git a/app/src/main/kotlin/com/wire/android/notification/Models.kt b/app/src/main/kotlin/com/wire/android/notification/Models.kt index 2f28ed0a032..e5ef79d0c69 100644 --- a/app/src/main/kotlin/com/wire/android/notification/Models.kt +++ b/app/src/main/kotlin/com/wire/android/notification/Models.kt @@ -98,15 +98,13 @@ sealed class NotificationMessage(open val messageId: String, open val author: No override val author: NotificationMessageAuthor, override val time: Long, val authorId: String - ) : - NotificationMessage(messageId, author, time) + ) : NotificationMessage(messageId, author, time) data class ConversationDeleted( override val messageId: String, override val author: NotificationMessageAuthor, override val time: Long - ) : - NotificationMessage(messageId, author, time) + ) : NotificationMessage(messageId, author, time) } data class NotificationMessageAuthor(val name: String, val image: ByteArray?) { @@ -157,6 +155,7 @@ fun LocalNotification.Conversation.intoNotificationConversation(): NotificationC ) } +@Suppress("LongMethod") fun LocalNotificationMessage.intoNotificationMessage(): NotificationMessage { val notificationMessageTime = time.toEpochMilliseconds() diff --git a/kalium b/kalium index 18b7699e312..4be820aa2bb 160000 --- a/kalium +++ b/kalium @@ -1 +1 @@ -Subproject commit 18b7699e312bedf08a441433e25d96fb37dc920f +Subproject commit 4be820aa2bb05ffc40a8ec1709660b16cbe6bfdd