mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Adopt Rust's new sessionPath that replaces the basePath (#2903)
This commit is contained in:
@@ -17,12 +17,27 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
struct RestorationToken: Codable, Equatable {
|
||||
struct RestorationToken: Equatable {
|
||||
let session: MatrixRustSDK.Session
|
||||
let sessionDirectory: URL
|
||||
let passphrase: String?
|
||||
let pusherNotificationClientIdentifier: String?
|
||||
}
|
||||
|
||||
extension RestorationToken: Codable {
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
let session = try container.decode(MatrixRustSDK.Session.self, forKey: .session)
|
||||
let sessionDirectory = try container.decodeIfPresent(URL.self, forKey: .sessionDirectory)
|
||||
|
||||
self = try .init(session: session,
|
||||
sessionDirectory: sessionDirectory ?? .legacySessionDirectory(for: session.userId),
|
||||
passphrase: container.decodeIfPresent(String.self, forKey: .passphrase),
|
||||
pusherNotificationClientIdentifier: container.decodeIfPresent(String.self, forKey: .pusherNotificationClientIdentifier))
|
||||
}
|
||||
}
|
||||
|
||||
extension MatrixRustSDK.Session: Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
@@ -50,3 +65,18 @@ extension MatrixRustSDK.Session: Codable {
|
||||
case accessToken, refreshToken, userId, deviceId, homeserverUrl, oidcData, slidingSyncProxy
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Migrations
|
||||
|
||||
private extension URL {
|
||||
/// Gets the store directory of a legacy session that hasn't been migrated to the new token format.
|
||||
///
|
||||
/// This should only be used to fill in the missing value when restoring a token as older versions of
|
||||
/// the SDK set the session directory for us, based on the user's ID. Newer sessions now use a UUID,
|
||||
/// which is generated app side during authentication.
|
||||
static func legacySessionDirectory(for userID: String) -> URL {
|
||||
// Rust sanitises the user ID replacing invalid characters with an _
|
||||
let sanitisedUserID = userID.replacingOccurrences(of: ":", with: "_")
|
||||
return .sessionsBaseDirectory.appendingPathComponent(sanitisedUserID)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user