mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Update the app badge after receiving a notification by reading and using the unreadCount from the request payload
This commit is contained in:
parent
e9a945cfe4
commit
3bc474fb70
@ -60,7 +60,8 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
|
|||||||
Task {
|
Task {
|
||||||
await run(with: credentials,
|
await run(with: credentials,
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
eventId: eventId)
|
eventId: eventId,
|
||||||
|
unreadCount: request.unreadCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,8 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
|
|||||||
|
|
||||||
private func run(with credentials: KeychainCredentials,
|
private func run(with credentials: KeychainCredentials,
|
||||||
roomId: String,
|
roomId: String,
|
||||||
eventId: String) async {
|
eventId: String,
|
||||||
|
unreadCount: Int?) async {
|
||||||
MXLog.info("\(tag) run with roomId: \(roomId), eventId: \(eventId)")
|
MXLog.info("\(tag) run with roomId: \(roomId), eventId: \(eventId)")
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -102,6 +104,12 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
|
|||||||
modifiedContent = latestContent
|
modifiedContent = latestContent
|
||||||
}
|
}
|
||||||
// We still notify, but without the media attachment if it fails to load
|
// We still notify, but without the media attachment if it fails to load
|
||||||
|
|
||||||
|
// Finally update the app badge
|
||||||
|
if let unreadCount {
|
||||||
|
modifiedContent?.badge = NSNumber(value: unreadCount)
|
||||||
|
}
|
||||||
|
|
||||||
return notify()
|
return notify()
|
||||||
} catch {
|
} catch {
|
||||||
MXLog.error("NSE run error: \(error)")
|
MXLog.error("NSE run error: \(error)")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user