Fixes cache cleaning behavior after sdk change

This commit is contained in:
Stefan Ceriu 2023-05-12 18:24:20 +03:00 committed by Stefan Ceriu
parent 1981270840
commit a2b38f7656
3 changed files with 18 additions and 18 deletions

View File

@ -458,20 +458,21 @@ class AppCoordinator: AppCoordinatorProtocol {
private func clearCache() {
showLoadingIndicator()
defer {
hideLoadingIndicator()
}
navigationRootCoordinator.setRootCoordinator(SplashScreenCoordinator())
userSession.clientProxy.stopSync()
userSessionFlowCoordinator?.stop()
userSessionStore.clearCacheFor(userSession: userSession)
let userID = userSession.userID
tearDownUserSession()
stateMachine.processEvent(.startWithExistingSession)
// Allow for everything to deallocate properly
Task {
try await Task.sleep(for: .seconds(2))
userSessionStore.clearCache(for: userID)
stateMachine.processEvent(.startWithExistingSession)
hideLoadingIndicator()
}
}
}

View File

@ -21,7 +21,7 @@ import MatrixRustSDK
class UserSessionStore: UserSessionStoreProtocol {
private let keychainController: KeychainControllerProtocol
private let backgroundTaskService: BackgroundTaskServiceProtocol
private let cachesFolderName = "matrix-sdk-state"
private let matrixSDKStateKey = "matrix-sdk-state"
/// Whether or not there are sessions in the store.
var hasSessions: Bool { !keychainController.restorationTokens().isEmpty }
@ -91,9 +91,8 @@ class UserSessionStore: UserSessionStoreProtocol {
deleteSessionDirectory(for: userID)
}
func clearCacheFor(userSession: UserSessionProtocol) {
let userID = userSession.clientProxy.userID
deleteCachesFolder(for: userID)
func clearCache(for userID: String) {
deleteCaches(for: userID)
}
// MARK: - Private
@ -153,17 +152,17 @@ class UserSessionStore: UserSessionStoreProtocol {
}
}
private func deleteCachesFolder(for userID: String) {
let url = basePath(for: userID).appendingPathComponent(cachesFolderName)
private func deleteCaches(for userID: String) {
do {
try FileManager.default.removeItem(at: url)
for url in try FileManager.default.contentsOfDirectory(at: basePath(for: userID), includingPropertiesForKeys: nil) where url.path.contains(matrixSDKStateKey) {
try FileManager.default.removeItem(at: url)
}
} catch {
MXLog.failure("Failed deleting the session data: \(error)")
}
}
#warning("We should move this and the caches folder path to the rust side")
#warning("We should move this and the caches cleanup to the rust side")
private func basePath(for userID: String) -> URL {
// Rust sanitises the user ID replacing invalid characters with an _
let sanitisedUserID = userID.replacingOccurrences(of: ":", with: "_")

View File

@ -47,5 +47,5 @@ protocol UserSessionStoreProtocol {
func logout(userSession: UserSessionProtocol)
/// Clears our all the matrix sdk state data for the specified session
func clearCacheFor(userSession: UserSessionProtocol)
func clearCache(for userID: String)
}