mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Avoid race and duplication conditions between local and remote notifications (#848)
* added timestamp control of the local notification * improved the code, and implemented the solution, just needs some testing * sdk bump * UserPreference init with initialValue instead of defaultValue * pr suggestions * changelog * notifications sliding sync view added
This commit is contained in:
@@ -101,12 +101,19 @@ class NotificationManager: NSObject, NotificationManagerProtocol {
|
||||
}
|
||||
|
||||
private func showLocalNotification(_ notification: NotificationItemProxyProtocol) async {
|
||||
guard let userSession else { return }
|
||||
guard let userSession,
|
||||
notification.event.timestamp > ServiceLocator.shared.settings.lastLaunchDate else { return }
|
||||
do {
|
||||
guard let content = try await notification.process(receiverId: userSession.userID, roomId: notification.roomID, mediaProvider: userSession.mediaProvider) else {
|
||||
guard let content = try await notification.process(mediaProvider: userSession.mediaProvider),
|
||||
let identifier = notification.id else {
|
||||
return
|
||||
}
|
||||
let request = UNNotificationRequest(identifier: ProcessInfo.processInfo.globallyUniqueString, content: content, trigger: nil)
|
||||
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: nil)
|
||||
guard !ServiceLocator.shared.settings.servedNotificationIdentifiers.contains(identifier) else {
|
||||
MXLog.info("NotificationManager] local notification discarded because it has already been served")
|
||||
return
|
||||
}
|
||||
ServiceLocator.shared.settings.servedNotificationIdentifiers.insert(identifier)
|
||||
try await notificationCenter.add(request)
|
||||
} catch {
|
||||
MXLog.error("[NotificationManager] show local notification item failed: \(error)")
|
||||
|
||||
Reference in New Issue
Block a user