Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid potential app side NSE UserSession races and let the SDK handle… #2695

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions NSE/Sources/NotificationServiceExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand All @@ -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 {
Expand All @@ -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")
Expand Down
Loading