mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 13:37:11 +00:00
Avoid potential app side NSE UserSession races and let the SDK handle them instead
This commit is contained in:
parent
493763b17e
commit
5faa4910b1
@ -44,7 +44,6 @@ private let settings: NSESettingsProtocol = AppSettings()
|
||||
private let notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: RoomMessageEventStringBuilder(attributedStringBuilder: AttributedStringBuilder(mentionBuilder: PlainMentionBuilder())))
|
||||
private let keychainController = KeychainController(service: .sessions,
|
||||
accessGroup: InfoPlistReader.main.keychainAccessGroupIdentifier)
|
||||
private var userSessions = [String: NSEUserSession]()
|
||||
|
||||
class NotificationServiceExtension: UNNotificationServiceExtension {
|
||||
private var handler: ((UNNotificationContent) -> Void)?
|
||||
@ -70,9 +69,8 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
|
||||
|
||||
NSELogger.configure(logLevel: settings.logLevel)
|
||||
|
||||
NSELogger.logMemory(with: tag)
|
||||
|
||||
MXLog.info("\(tag) #########################################")
|
||||
NSELogger.logMemory(with: tag)
|
||||
MXLog.info("\(tag) Payload came: \(request.content.userInfo)")
|
||||
|
||||
Task {
|
||||
@ -97,13 +95,9 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
|
||||
MXLog.info("\(tag) run with roomId: \(roomId), eventId: \(eventId)")
|
||||
|
||||
do {
|
||||
let userSession: NSEUserSession
|
||||
if let existingSession = userSessions[credentials.userID] {
|
||||
userSession = existingSession
|
||||
} else {
|
||||
userSession = try await NSEUserSession(credentials: credentials, clientSessionDelegate: keychainController)
|
||||
userSessions[credentials.userID] = userSession
|
||||
}
|
||||
// This function might be run concurrently and from different processes, let the SDK handle race conditions
|
||||
// on fetching user sessions
|
||||
let userSession = try await NSEUserSession(credentials: credentials, clientSessionDelegate: keychainController)
|
||||
|
||||
guard let itemProxy = await userSession.notificationItemProxy(roomID: roomId, eventID: eventId) else {
|
||||
MXLog.info("\(tag) no notification for the event, discard")
|
||||
|
Loading…
x
Reference in New Issue
Block a user