Introduce a local mechanism for managing the app's badge count

This commit is contained in:
Stefan Ceriu
2026-09-08 19:05:44 +03:00
parent 7be93f8da8
commit 58628bd7c5
13 changed files with 164 additions and 6 deletions
@@ -158,6 +158,22 @@ final class NotificationManager: NSObject, NotificationManagerProtocol {
notificationCenter.removeDeliveredNotifications(withIdentifiers: notificationsIdentifiers)
}
func updateAppBadgeCount() async {
guard let userSession, appSettings.roomListNotificationCountEnabled else { return }
let badgeCount = Int(userSession.clientProxy.totalUnreadNotifications)
appSettings.lastKnownBadgeCount = badgeCount
MXLog.debug("Updating app badge count to \(badgeCount)")
do {
try await notificationCenter.setBadgeCount(badgeCount)
} catch {
MXLog.error("Failed updating the app badge count with error: \(error)")
}
}
private func removeReceivedWhileOfflineNotification() {
notificationCenter.removeDeliveredNotifications(withIdentifiers: [NotificationServiceExtensionActor.receivedWhileOfflineNotificationID])
}
@@ -36,4 +36,6 @@ protocol NotificationManagerProtocol: AnyObject {
func removeDeliveredMessageNotifications(for roomID: String) async
func removeDeliveredNotificationsForFullyReadRooms(_ rooms: [RoomSummary]) async
func updateAppBadgeCount() async
}
@@ -15,6 +15,7 @@ protocol UserNotificationCenterProtocol: AnyObject {
func requestAuthorization(options: UNAuthorizationOptions) async throws -> Bool
func deliveredNotifications() async -> [UNNotification]
func removeDeliveredNotifications(withIdentifiers identifiers: [String])
func setBadgeCount(_ newBadgeCount: Int) async throws
func setNotificationCategories(_ categories: Set<UNNotificationCategory>)
func authorizationStatus() async -> UNAuthorizationStatus
func notificationSettings() async -> UNNotificationSettings