mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Cleaning up user data on logout and passing a weak client delegate wrapper to rust.
This commit is contained in:
@@ -64,6 +64,10 @@ class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator {
|
||||
}
|
||||
|
||||
func authenticationCoordinatorDidTearDownUserSession(_ authenticationCoordinator: AuthenticationCoordinator) {
|
||||
if let presentedCoordinator = childCoordinators.first {
|
||||
remove(childCoordinator: presentedCoordinator)
|
||||
}
|
||||
|
||||
mainNavigationController.setViewControllers([splashViewController], animated: false)
|
||||
authenticationCoordinator.start()
|
||||
}
|
||||
|
||||
@@ -74,7 +74,13 @@ class AuthenticationCoordinator: Coordinator {
|
||||
|
||||
func logout() {
|
||||
keychainController.removeAllTokens()
|
||||
|
||||
if let userIdentifier = userSession?.userIdentifier {
|
||||
deleteBaseDirectoryForUsername(userIdentifier)
|
||||
}
|
||||
|
||||
userSession = nil
|
||||
|
||||
delegate?.authenticationCoordinatorDidTearDownUserSession(self)
|
||||
}
|
||||
|
||||
@@ -183,4 +189,14 @@ class AuthenticationCoordinator: Coordinator {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
private class WeakUserSessionWrapper: ClientDelegate {
|
||||
weak var userSession: UserSession?
|
||||
|
||||
init(userSession: UserSession) {
|
||||
self.userSession = userSession
|
||||
}
|
||||
|
||||
func didReceiveSyncUpdate() {
|
||||
userSession?.didReceiveSyncUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
class UserSession: ClientDelegate {
|
||||
|
||||
private let client: Client
|
||||
|
||||
deinit {
|
||||
client.setDelegate(delegate: nil)
|
||||
}
|
||||
|
||||
let callbacks = PassthroughSubject<UserSessionCallback, Never>()
|
||||
|
||||
init(client: Client) {
|
||||
self.client = client
|
||||
|
||||
if !client.hasFirstSynced() {
|
||||
client.startSync(delegate: self)
|
||||
}
|
||||
client.setDelegate(delegate: WeakUserSessionWrapper(userSession: self))
|
||||
client.startSync()
|
||||
}
|
||||
|
||||
var userIdentifier: String {
|
||||
|
||||
Reference in New Issue
Block a user