mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +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) {
|
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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user