Cleaning up user data on logout and passing a weak client delegate wrapper to rust.

This commit is contained in:
Stefan Ceriu
2022-03-01 14:05:35 +02:00
parent e50f0257d2
commit 0d33e1e4ab
3 changed files with 38 additions and 3 deletions
+4
View File
@@ -64,6 +64,10 @@ class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator {
} }
func authenticationCoordinatorDidTearDownUserSession(_ authenticationCoordinator: AuthenticationCoordinator) { func authenticationCoordinatorDidTearDownUserSession(_ authenticationCoordinator: AuthenticationCoordinator) {
if let presentedCoordinator = childCoordinators.first {
remove(childCoordinator: presentedCoordinator)
}
mainNavigationController.setViewControllers([splashViewController], animated: false) mainNavigationController.setViewControllers([splashViewController], animated: false)
authenticationCoordinator.start() authenticationCoordinator.start()
} }
@@ -74,7 +74,13 @@ class AuthenticationCoordinator: Coordinator {
func logout() { func logout() {
keychainController.removeAllTokens() keychainController.removeAllTokens()
if let userIdentifier = userSession?.userIdentifier {
deleteBaseDirectoryForUsername(userIdentifier)
}
userSession = nil userSession = nil
delegate?.authenticationCoordinatorDidTearDownUserSession(self) delegate?.authenticationCoordinatorDidTearDownUserSession(self)
} }
@@ -183,4 +189,14 @@ class AuthenticationCoordinator: Coordinator {
return url.path return url.path
} }
private func deleteBaseDirectoryForUsername(_ username: String) {
guard var url = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {
fatalError("Should always be able to retrieve the caches directory")
}
url = url.appendingPathComponent(username)
try? FileManager.default.removeItem(at: url)
}
} }
@@ -18,18 +18,33 @@ enum UserSessionError: Error {
case failedRetrievingAvatar case failedRetrievingAvatar
} }
private class WeakUserSessionWrapper: ClientDelegate {
weak var userSession: UserSession?
init(userSession: UserSession) {
self.userSession = userSession
}
func didReceiveSyncUpdate() {
userSession?.didReceiveSyncUpdate()
}
}
class UserSession: ClientDelegate { class UserSession: ClientDelegate {
private let client: Client private let client: Client
deinit {
client.setDelegate(delegate: nil)
}
let callbacks = PassthroughSubject<UserSessionCallback, Never>() let callbacks = PassthroughSubject<UserSessionCallback, Never>()
init(client: Client) { init(client: Client) {
self.client = client self.client = client
if !client.hasFirstSynced() { client.setDelegate(delegate: WeakUserSessionWrapper(userSession: self))
client.startSync(delegate: self) client.startSync()
}
} }
var userIdentifier: String { var userIdentifier: String {