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:
Mauro
2023-05-03 16:28:07 +02:00
committed by GitHub
parent 60c2692a26
commit 95492d7e10
15 changed files with 251 additions and 108 deletions
@@ -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)")