ios: fix notification badge count (#903)

This commit is contained in:
Evgeny Poberezkin
2022-08-04 22:25:52 +01:00
committed by GitHub
parent afbc7dd2c1
commit e8749debec
3 changed files with 12 additions and 3 deletions

View File

@@ -162,7 +162,10 @@ final class ChatModel: ObservableObject {
if case .rcvNew = cItem.meta.itemStatus {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if self.chatId == cInfo.id {
Task { await apiMarkChatItemRead(cInfo, cItem) }
Task {
await apiMarkChatItemRead(cInfo, cItem)
NtfManager.shared.decNtfBadgeCount()
}
}
}
}

View File

@@ -58,6 +58,7 @@ struct SimpleXApp: App {
enteredBackground = ProcessInfo.processInfo.systemUptime
}
doAuthenticate = false
NtfManager.shared.setNtfBadgeCount(chatModel.totalUnreadCount())
case .active:
if chatModel.chatRunning == true {
ChatReceiver.shared.start()

View File

@@ -63,8 +63,6 @@ class NotificationService: UNNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
logger.debug("NotificationService.didReceive")
badgeCount = ntfBadgeCountGroupDefault.get() + 1
ntfBadgeCountGroupDefault.set(badgeCount)
setBestAttemptNtf(request.content.mutableCopy() as? UNMutableNotificationContent)
self.contentHandler = contentHandler
registerGroupDefaults()
@@ -72,9 +70,11 @@ class NotificationService: UNNotificationServiceExtension {
switch appState {
case .suspended:
logger.debug("NotificationService: app is suspended")
setBadgeCount()
receiveNtfMessages(request, contentHandler)
case .suspending:
logger.debug("NotificationService: app is suspending")
setBadgeCount()
Task {
var state = appState
for _ in 1...5 {
@@ -131,6 +131,11 @@ class NotificationService: UNNotificationServiceExtension {
deliverBestAttemptNtf()
}
func setBadgeCount() {
badgeCount = ntfBadgeCountGroupDefault.get() + 1
ntfBadgeCountGroupDefault.set(badgeCount)
}
func setBestAttemptNtf(_ ntf: UNMutableNotificationContent?) {
logger.debug("NotificationService.setBestAttemptNtf")
bestAttemptNtf = ntf