mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-30 18:35:49 +00:00
ios: fix notification badge count (#903)
This commit is contained in:
committed by
GitHub
parent
afbc7dd2c1
commit
e8749debec
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user