Skip to content

Commit

Permalink
feat: Remove notifications on read from another client
Browse files Browse the repository at this point in the history
  • Loading branch information
borichellow committed Mar 20, 2024
1 parent 01a0da9 commit 701ad06
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}; ")
}
Expand Down Expand Up @@ -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<LocalNotification>, userId: QualifiedID) {
val notificationsToUpdate: List<LocalNotification.ConversationSeen> = 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) {
Expand Down Expand Up @@ -228,6 +242,8 @@ class MessageNotificationManager
setContentIntent(messagePendingIntent(context, conversation.id, userIdString))
}

is NotificationMessage.ConversationSeen -> {}

null -> {
val isAppLocked = lockCodeTimeManager.isAppLocked()
setContentIntent(messagePendingIntent(context, conversation.id, userIdString))
Expand Down Expand Up @@ -409,6 +425,7 @@ class MessageNotificationManager
is NotificationMessage.ConnectionRequest -> italicTextFromResId(R.string.notification_connection_request)
is NotificationMessage.ConversationDeleted -> italicTextFromResId(R.string.notification_conversation_deleted)
is NotificationMessage.Knock -> italicTextFromResId(R.string.notification_knock)
is NotificationMessage.ConversationSeen,
is NotificationMessage.ObfuscatedMessage,
is NotificationMessage.ObfuscatedKnock -> italicTextFromResId(
R.string.notification_obfuscated_message_content
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/kotlin/com/wire/android/notification/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,18 @@ 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 ConversationSeen(
override val messageId: String,
override val time: Long
) : NotificationMessage(messageId, null, time)
}

data class NotificationMessageAuthor(val name: String, val image: ByteArray?) {
Expand Down Expand Up @@ -222,6 +225,9 @@ fun LocalNotificationMessage.intoNotificationMessage(): NotificationMessage {
messageId,
notificationMessageTime
)

is LocalNotificationMessage.ConversationSeen -> NotificationMessage.ConversationSeen(messageId, notificationMessageTime)

}
}

Expand Down

0 comments on commit 701ad06

Please sign in to comment.