fix(notification): set badge count via setNumber() for multi-sender notifications

This commit is contained in:
Jens Reinemann 2026-05-18 22:05:28 +02:00
parent 22112e7978
commit ab2cbff8ba

View file

@ -111,19 +111,22 @@ internal class NotificationHelper @Inject constructor(
if (shouldSuppressNotification(senderId)) return false
val senderNotificationId = senderId.hashCode()
val (contentText, pendingIntent) = synchronized(activeSenderNotificationIds) {
val (contentText, pendingIntent, senderCount) = synchronized(activeSenderNotificationIds) {
activeSenderNotificationIds.add(senderNotificationId)
activeSenderNamesById[senderNotificationId] = senderUsername
val names = activeSenderNamesById.values.toList()
if (activeSenderNotificationIds.size == 1) {
Pair(
val count = activeSenderNotificationIds.size
if (count == 1) {
Triple(
"Neue Nachricht von $senderUsername",
buildChatPendingIntent(senderId, senderUsername)
buildChatPendingIntent(senderId, senderUsername),
count
)
} else {
Pair(
Triple(
buildSummaryText(names),
buildMessagesPendingIntent()
buildMessagesPendingIntent(),
count
)
}
}
@ -133,6 +136,7 @@ internal class NotificationHelper @Inject constructor(
.setContentTitle("Bollwerk")
.setContentText(contentText)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setNumber(senderCount)
.setAutoCancel(false)
.setOngoing(true)
.setContentIntent(pendingIntent)
@ -175,11 +179,13 @@ internal class NotificationHelper @Inject constructor(
if (remainingText == null) {
notificationManager.notify(MessagingService.NOTIFICATION_ID, buildIdleNotification())
} else {
val remainingCount = activeSenderNotificationIds.size
val updatedNotification = NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_message)
.setContentTitle("Bollwerk")
.setContentText(remainingText)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setNumber(remainingCount)
.setAutoCancel(false)
.setOngoing(true)
.setContentIntent(buildMessagesPendingIntent())