Logout of all accounts (IOS-245)
This commit is contained in:
parent
949c22eb4e
commit
7cf8752ff6
|
@ -174,8 +174,26 @@ extension AccountListViewController: UITableViewDelegate {
|
|||
// TODO: add dismiss entry for welcome scene
|
||||
_ = coordinator.present(scene: .welcome, from: self, transition: .modal(animated: true, completion: nil))
|
||||
case .logoutOfAllAccounts:
|
||||
//TODO: Show alert with "Logout of all Accounts", "Cancel"
|
||||
break
|
||||
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
|
||||
|
||||
//TODO: Localization
|
||||
let logoutAction = UIAlertAction(title: "Log Out Of All Accounts", style: .destructive) { _ in
|
||||
Task { @MainActor in
|
||||
self.coordinator.showLoading()
|
||||
for authenticationBox in self.context.authenticationService.mastodonAuthenticationBoxes {
|
||||
try? await self.context.authenticationService.signOutMastodonUser(authenticationBox: authenticationBox)
|
||||
}
|
||||
self.coordinator.hideLoading()
|
||||
|
||||
self.coordinator.setup()
|
||||
}
|
||||
}
|
||||
|
||||
alert.addAction(logoutAction)
|
||||
|
||||
let cancelAction = UIAlertAction(title: "Cancel", style: .default)
|
||||
alert.addAction(cancelAction)
|
||||
present(alert, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,10 @@
|
|||
//
|
||||
|
||||
import UIKit
|
||||
import Combine
|
||||
import MetaTextKit
|
||||
import MastodonAsset
|
||||
import MastodonLocalization
|
||||
import MastodonCore
|
||||
import MastodonUI
|
||||
|
||||
final class LogoutOfAllAccountsCell: UITableViewCell {
|
||||
|
||||
|
|
|
@ -137,22 +137,6 @@ extension AuthenticationService {
|
|||
}
|
||||
|
||||
public func signOutMastodonUser(authenticationBox: MastodonAuthenticationBox) async throws {
|
||||
let managedObjectContext = backgroundManagedObjectContext
|
||||
try await managedObjectContext.performChanges {
|
||||
// remove Feed
|
||||
let request = Feed.sortedFetchRequest
|
||||
request.predicate = Feed.predicate(
|
||||
acct: .mastodon(
|
||||
domain: authenticationBox.domain,
|
||||
userID: authenticationBox.userID
|
||||
)
|
||||
)
|
||||
let feeds = managedObjectContext.safeFetch(request)
|
||||
for feed in feeds {
|
||||
managedObjectContext.delete(feed)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
try AuthenticationServiceProvider.shared.delete(authentication: authenticationBox.authentication)
|
||||
} catch {
|
||||
|
|
Loading…
Reference in New Issue