Tusker/Tusker/API/LogoutService.swift

36 lines
1012 B
Swift

//
// LogoutService.swift
// Tusker
//
// Created by Shadowfacts on 1/27/23.
// Copyright © 2023 Shadowfacts. All rights reserved.
//
import Foundation
@MainActor
class LogoutService {
let accountInfo: LocalData.UserAccountInfo
private let mastodonController: MastodonController
init(accountInfo: LocalData.UserAccountInfo) {
self.accountInfo = accountInfo
self.mastodonController = MastodonController.getForAccount(accountInfo)
}
func run() {
Task.detached {
try? await self.mastodonController.client.revokeAccessToken()
}
MastodonController.removeForAccount(accountInfo)
LocalData.shared.removeAccount(accountInfo)
let psc = mastodonController.persistentContainer.persistentStoreCoordinator
for store in psc.persistentStores {
guard let url = store.url else {
continue
}
try? psc.destroyPersistentStore(at: url, type: .sqlite)
}
}
}