fix(notification): set badge count via setNumber() for multi-sender notifications
This commit is contained in:
parent
22112e7978
commit
ab2cbff8ba
1 changed files with 12 additions and 6 deletions
|
|
@ -111,19 +111,22 @@ internal class NotificationHelper @Inject constructor(
|
||||||
if (shouldSuppressNotification(senderId)) return false
|
if (shouldSuppressNotification(senderId)) return false
|
||||||
|
|
||||||
val senderNotificationId = senderId.hashCode()
|
val senderNotificationId = senderId.hashCode()
|
||||||
val (contentText, pendingIntent) = synchronized(activeSenderNotificationIds) {
|
val (contentText, pendingIntent, senderCount) = synchronized(activeSenderNotificationIds) {
|
||||||
activeSenderNotificationIds.add(senderNotificationId)
|
activeSenderNotificationIds.add(senderNotificationId)
|
||||||
activeSenderNamesById[senderNotificationId] = senderUsername
|
activeSenderNamesById[senderNotificationId] = senderUsername
|
||||||
val names = activeSenderNamesById.values.toList()
|
val names = activeSenderNamesById.values.toList()
|
||||||
if (activeSenderNotificationIds.size == 1) {
|
val count = activeSenderNotificationIds.size
|
||||||
Pair(
|
if (count == 1) {
|
||||||
|
Triple(
|
||||||
"Neue Nachricht von $senderUsername",
|
"Neue Nachricht von $senderUsername",
|
||||||
buildChatPendingIntent(senderId, senderUsername)
|
buildChatPendingIntent(senderId, senderUsername),
|
||||||
|
count
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Pair(
|
Triple(
|
||||||
buildSummaryText(names),
|
buildSummaryText(names),
|
||||||
buildMessagesPendingIntent()
|
buildMessagesPendingIntent(),
|
||||||
|
count
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -133,6 +136,7 @@ internal class NotificationHelper @Inject constructor(
|
||||||
.setContentTitle("Bollwerk")
|
.setContentTitle("Bollwerk")
|
||||||
.setContentText(contentText)
|
.setContentText(contentText)
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
.setNumber(senderCount)
|
||||||
.setAutoCancel(false)
|
.setAutoCancel(false)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
|
|
@ -175,11 +179,13 @@ internal class NotificationHelper @Inject constructor(
|
||||||
if (remainingText == null) {
|
if (remainingText == null) {
|
||||||
notificationManager.notify(MessagingService.NOTIFICATION_ID, buildIdleNotification())
|
notificationManager.notify(MessagingService.NOTIFICATION_ID, buildIdleNotification())
|
||||||
} else {
|
} else {
|
||||||
|
val remainingCount = activeSenderNotificationIds.size
|
||||||
val updatedNotification = NotificationCompat.Builder(context, CHANNEL_ID)
|
val updatedNotification = NotificationCompat.Builder(context, CHANNEL_ID)
|
||||||
.setSmallIcon(R.drawable.ic_notification_message)
|
.setSmallIcon(R.drawable.ic_notification_message)
|
||||||
.setContentTitle("Bollwerk")
|
.setContentTitle("Bollwerk")
|
||||||
.setContentText(remainingText)
|
.setContentText(remainingText)
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
.setNumber(remainingCount)
|
||||||
.setAutoCancel(false)
|
.setAutoCancel(false)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setContentIntent(buildMessagesPendingIntent())
|
.setContentIntent(buildMessagesPendingIntent())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue