Logout of all accounts (IOS-245)

This commit is contained in:
Nathan Mattes 2024-03-18 12:06:54 +01:00
parent 949c22eb4e
commit 7cf8752ff6
3 changed files with 20 additions and 20 deletions

View File

@ -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)
}
}
}

View File

@ -6,12 +6,10 @@
//
import UIKit
import Combine
import MetaTextKit
import MastodonAsset
import MastodonLocalization
import MastodonCore
import MastodonUI
final class LogoutOfAllAccountsCell: UITableViewCell {

View File

@ -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 {