mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Enable OIDC token refresh in the NSE. (#1711)
Update the SDK and handle API changes.
This commit is contained in:
@@ -36,7 +36,7 @@ struct NotificationContentBuilder {
|
||||
switch try? event.eventType() {
|
||||
case let .messageLike(content):
|
||||
switch content {
|
||||
case .roomMessage(messageType: let messageType):
|
||||
case .roomMessage(let messageType, _):
|
||||
return try await processRoomMessage(notificationItem: notificationItem, messageType: messageType, mediaProvider: mediaProvider)
|
||||
default:
|
||||
return processEmpty(notificationItem: notificationItem)
|
||||
|
||||
@@ -41,12 +41,6 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
|
||||
// - NotificationID could not be resolved
|
||||
return contentHandler(request.content)
|
||||
}
|
||||
|
||||
if credentials.restorationToken.session.oidcData != nil {
|
||||
// Notification content is disabled for OIDC sessions
|
||||
// until token refresh is multi-process aware.
|
||||
return contentHandler(request.content)
|
||||
}
|
||||
|
||||
handler = contentHandler
|
||||
modifiedContent = request.content.mutableCopy() as? UNMutableNotificationContent
|
||||
@@ -80,8 +74,9 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
|
||||
MXLog.info("\(tag) run with roomId: \(roomId), eventId: \(eventId)")
|
||||
|
||||
do {
|
||||
let userSession = try NSEUserSession(credentials: credentials)
|
||||
let userSession = try NSEUserSession(credentials: credentials, clientSessionDelegate: keychainController)
|
||||
self.userSession = userSession
|
||||
|
||||
guard let itemProxy = await userSession.notificationItemProxy(roomID: roomId, eventID: eventId) else {
|
||||
MXLog.info("\(tag) no notification for the event, discard")
|
||||
return discard()
|
||||
|
||||
@@ -25,27 +25,30 @@ final class NSEUserSession {
|
||||
imageCache: .onlyOnDisk,
|
||||
backgroundTaskService: nil)
|
||||
|
||||
init(credentials: KeychainCredentials) throws {
|
||||
init(credentials: KeychainCredentials, clientSessionDelegate: ClientSessionDelegate) throws {
|
||||
userID = credentials.userID
|
||||
baseClient = try ClientBuilder()
|
||||
.basePath(path: URL.sessionsBaseDirectory.path)
|
||||
.username(username: credentials.userID)
|
||||
.userAgent(userAgent: UserAgentBuilder.makeASCIIUserAgent())
|
||||
.enableCrossProcessRefreshLock(processId: InfoPlistReader.main.bundleIdentifier,
|
||||
sessionDelegate: clientSessionDelegate)
|
||||
.build()
|
||||
|
||||
|
||||
baseClient.setDelegate(delegate: ClientDelegateWrapper())
|
||||
try baseClient.restoreSession(session: credentials.restorationToken.session)
|
||||
|
||||
|
||||
notificationClient = try baseClient
|
||||
.notificationClient(processSetup: .multipleProcesses)
|
||||
.filterByPushRules()
|
||||
.finish()
|
||||
}
|
||||
|
||||
|
||||
func notificationItemProxy(roomID: String, eventID: String) async -> NotificationItemProxyProtocol? {
|
||||
await Task.dispatch(on: .global()) {
|
||||
do {
|
||||
let notification = try self.notificationClient.getNotification(roomId: roomID, eventId: eventID)
|
||||
|
||||
|
||||
guard let notification else {
|
||||
return nil
|
||||
}
|
||||
@@ -60,3 +63,15 @@ final class NSEUserSession {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ClientDelegateWrapper: ClientDelegate {
|
||||
// MARK: - ClientDelegate
|
||||
|
||||
func didReceiveAuthError(isSoftLogout: Bool) {
|
||||
MXLog.error("Received authentication error, the NSE can't handle this.")
|
||||
}
|
||||
|
||||
func didRefreshTokens() {
|
||||
MXLog.info("Delegating session updates to the ClientSessionDelegate.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user