mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Drop support for the legacy session directory and optional store encryption.
Store encryption became mandatory in #2692 Rust's sessionPath replaced the legacy session directory in #2903 Native sliding sync migration resulted in new restoration tokens for new users in #3071 and later for all users by #3801.
This commit is contained in:
@@ -15,7 +15,7 @@ enum RestorationTokenError: Error {
|
||||
struct RestorationToken: Equatable {
|
||||
let session: MatrixRustSDK.Session
|
||||
let sessionDirectories: SessionDirectories
|
||||
let passphrase: String?
|
||||
let passphrase: String
|
||||
let pusherNotificationClientIdentifier: String?
|
||||
|
||||
enum CodingKeys: CodingKey {
|
||||
@@ -32,22 +32,18 @@ extension RestorationToken: Codable {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
let session = try container.decode(Session.self, forKey: .session)
|
||||
let dataDirectory = try container.decodeIfPresent(URL.self, forKey: .sessionDirectory)
|
||||
let dataDirectory = try container.decode(URL.self, forKey: .sessionDirectory)
|
||||
let cacheDirectory = try container.decodeIfPresent(URL.self, forKey: .cacheDirectory)
|
||||
|
||||
let sessionDirectories = if let dataDirectory {
|
||||
if let cacheDirectory {
|
||||
SessionDirectories(dataDirectory: dataDirectory, cacheDirectory: cacheDirectory)
|
||||
} else {
|
||||
SessionDirectories(dataDirectory: dataDirectory)
|
||||
}
|
||||
let sessionDirectories = if let cacheDirectory {
|
||||
SessionDirectories(dataDirectory: dataDirectory, cacheDirectory: cacheDirectory)
|
||||
} else {
|
||||
SessionDirectories(userID: session.userId)
|
||||
SessionDirectories(dataDirectory: dataDirectory)
|
||||
}
|
||||
|
||||
self = try .init(session: session,
|
||||
sessionDirectories: sessionDirectories,
|
||||
passphrase: container.decodeIfPresent(String.self, forKey: .passphrase),
|
||||
passphrase: container.decode(String.self, forKey: .passphrase),
|
||||
pusherNotificationClientIdentifier: container.decodeIfPresent(String.self, forKey: .pusherNotificationClientIdentifier))
|
||||
}
|
||||
|
||||
|
||||
@@ -75,12 +75,6 @@ extension SessionDirectories {
|
||||
cacheDirectory = .sessionCachesBaseDirectory.appending(component: sessionDirectoryName)
|
||||
}
|
||||
|
||||
/// Creates the session directories for a user who signed in before the data directory was stored.
|
||||
init(userID: String) {
|
||||
dataDirectory = .legacySessionDirectory(for: userID)
|
||||
cacheDirectory = .sessionCachesBaseDirectory.appending(component: dataDirectory.lastPathComponent)
|
||||
}
|
||||
|
||||
/// Creates the session directories for a user who has a single session directory stored without a separate caches directory.
|
||||
init(dataDirectory: URL) {
|
||||
self.dataDirectory = dataDirectory
|
||||
@@ -93,18 +87,3 @@ extension SessionDirectories: CustomStringConvertible {
|
||||
"Data: \(dataPath) Caches: \(cachePath)"
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class UserSessionStore: UserSessionStoreProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String?) async -> Result<UserSessionProtocol, UserSessionStoreError> {
|
||||
func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String) async -> Result<UserSessionProtocol, UserSessionStoreError> {
|
||||
do {
|
||||
let session = try client.session()
|
||||
let userID = try client.userId()
|
||||
|
||||
@@ -33,7 +33,7 @@ protocol UserSessionStoreProtocol {
|
||||
func restoreUserSession() async -> Result<UserSessionProtocol, UserSessionStoreError>
|
||||
|
||||
/// Creates a user session for a new client from the SDK along with the passphrase used for the data stores.
|
||||
func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String?) async -> Result<UserSessionProtocol, UserSessionStoreError>
|
||||
func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String) async -> Result<UserSessionProtocol, UserSessionStoreError>
|
||||
|
||||
/// Logs out of the specified session.
|
||||
func logout(userSession: UserSessionProtocol)
|
||||
|
||||
Reference in New Issue
Block a user