mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Introduce a local mechanism for managing the app's badge count
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user