mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00
Some consolidation of logout logic
This commit is contained in:
parent
8153c16932
commit
ac30d4a3dc
@ -599,7 +599,7 @@ extension SceneCoordinator: MastodonLoginViewControllerDelegate {
|
||||
|
||||
//MARK: - SettingsCoordinatorDelegate
|
||||
extension SceneCoordinator: SettingsCoordinatorDelegate {
|
||||
func logout(_ settingsCoordinator: SettingsCoordinator) {
|
||||
func logout(_ user: MastodonAuthentication, presentingFrom viewController: UIViewController) {
|
||||
|
||||
let preferredStyle: UIAlertController.Style
|
||||
|
||||
@ -617,17 +617,17 @@ extension SceneCoordinator: SettingsCoordinatorDelegate {
|
||||
|
||||
let cancelAction = UIAlertAction(title: L10n.Common.Controls.Actions.cancel, style: .cancel)
|
||||
let signOutAction = UIAlertAction(title: L10n.Common.Alerts.SignOut.confirm, style: .destructive) { [weak self] _ in
|
||||
guard let self, let authenticationBox = self.authenticationBox else { return }
|
||||
guard let self else { return }
|
||||
|
||||
NotificationService.shared.clearNotificationCountForActiveUser()
|
||||
|
||||
Task { @MainActor in
|
||||
try await AuthenticationServiceProvider.shared.signOutMastodonUser(
|
||||
authentication: authenticationBox.authentication
|
||||
authentication: user
|
||||
)
|
||||
let userIdentifier = authenticationBox
|
||||
PersistenceManager.shared.removeAllCaches(forUser: userIdentifier)
|
||||
self.setup()
|
||||
PersistenceManager.shared.removeAllCaches(forUser: user)
|
||||
try await BodegaPersistence.removeUser(user)
|
||||
}
|
||||
|
||||
}
|
||||
@ -635,7 +635,7 @@ extension SceneCoordinator: SettingsCoordinatorDelegate {
|
||||
alertController.addAction(cancelAction)
|
||||
alertController.addAction(signOutAction)
|
||||
|
||||
settingsCoordinator.navigationController.present(alertController, animated: true)
|
||||
(viewController.navigationController ?? viewController).present(alertController, animated: true)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -103,20 +103,7 @@ extension AccountListViewController: UITableViewDelegate {
|
||||
guard let self else { return }
|
||||
|
||||
UserDefaults.shared.setNotificationCountWithAccessToken(accessToken: record.userAccessToken, value: 0)
|
||||
|
||||
Task { @MainActor in
|
||||
do {
|
||||
let userIdentifier = record
|
||||
try await AuthenticationServiceProvider.shared.signOutMastodonUser(authentication: record)
|
||||
PersistenceManager.shared.removeAllCaches(forUser: userIdentifier)
|
||||
|
||||
self.sceneCoordinator?.setup()
|
||||
|
||||
} catch {
|
||||
assertionFailure("Failed to delete Authentication: \(error)")
|
||||
}
|
||||
|
||||
}
|
||||
self.sceneCoordinator?.logout(record, presentingFrom: self)
|
||||
})
|
||||
logoutAction.image = UIImage(systemName: "rectangle.portrait.and.arrow.forward")
|
||||
|
||||
@ -153,10 +140,15 @@ extension AccountListViewController: UITableViewDelegate {
|
||||
Task { @MainActor in
|
||||
self.sceneCoordinator?.showLoading()
|
||||
for authenticationBox in AuthenticationServiceProvider.shared.mastodonAuthenticationBoxes {
|
||||
try? await AuthenticationServiceProvider.shared.signOutMastodonUser(authentication: authenticationBox.authentication)
|
||||
let userIdentifier = authenticationBox.authentication.userIdentifier()
|
||||
PersistenceManager.shared.removeAllCaches(forUser: userIdentifier)
|
||||
self.sceneCoordinator?.setup()
|
||||
do {
|
||||
try await AuthenticationServiceProvider.shared.signOutMastodonUser(authentication: authenticationBox.authentication)
|
||||
let userIdentifier = authenticationBox.authentication.userIdentifier()
|
||||
self.sceneCoordinator?.setup()
|
||||
PersistenceManager.shared.removeAllCaches(forUser: userIdentifier)
|
||||
try await BodegaPersistence.removeUser(userIdentifier)
|
||||
} catch {
|
||||
assertionFailure("failed to sign out")
|
||||
}
|
||||
}
|
||||
self.sceneCoordinator?.hideLoading()
|
||||
|
||||
|
@ -645,17 +645,6 @@ extension HomeTimelineViewController {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@objc func signOutAction(_ sender: UIAction) {
|
||||
|
||||
Task { @MainActor in
|
||||
try await AuthenticationServiceProvider.shared.signOutMastodonUser(authentication: authenticationBox.authentication)
|
||||
let userIdentifier = authenticationBox
|
||||
PersistenceManager.shared.removeAllCaches(forUser: userIdentifier)
|
||||
self.sceneCoordinator?.setup()
|
||||
self.sceneCoordinator?.setup()
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func timelinePillTouched(_ sender: TimelineStatusPill) {
|
||||
UIView.animate(withDuration: 0.05) {
|
||||
|
@ -10,7 +10,7 @@ import MetaTextKit
|
||||
import MastodonUI
|
||||
|
||||
protocol SettingsCoordinatorDelegate: AnyObject {
|
||||
func logout(_ settingsCoordinator: SettingsCoordinator)
|
||||
func logout(_ user: MastodonAuthentication, presentingFrom viewController: UIViewController)
|
||||
func openGithubURL(_ settingsCoordinator: SettingsCoordinator)
|
||||
func openPrivacyURL(_ settingsCoordinator: SettingsCoordinator)
|
||||
func openProfileSettingsURL(_ settingsCoordinator: SettingsCoordinator)
|
||||
@ -142,7 +142,8 @@ extension SettingsCoordinator: SettingsViewControllerDelegate {
|
||||
|
||||
navigationController.pushViewController(aboutViewController, animated: true)
|
||||
case .logout(_):
|
||||
delegate?.logout(self)
|
||||
guard let user = AuthenticationServiceProvider.shared.currentActiveUser.value?.authentication else { return }
|
||||
delegate?.logout(user, presentingFrom: self.navigationController)
|
||||
case .manageBetaFeatures:
|
||||
let betaTestSettingsViewController = BetaTestSettingsViewController()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user