forked from shadowfacts/Tusker
40 lines
1.3 KiB
Swift
40 lines
1.3 KiB
Swift
//
|
|
// RemoveProfileSuggestionService.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 6/1/24.
|
|
// Copyright © 2024 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Pachyderm
|
|
|
|
@MainActor
|
|
class RemoveProfileSuggestionService {
|
|
private let accountID: String
|
|
private let mastodonController: MastodonController
|
|
private let presenter: any TuskerNavigationDelegate
|
|
private let completionHandler: @MainActor () -> Void
|
|
|
|
init(accountID: String, mastodonController: MastodonController, presenter: any TuskerNavigationDelegate, completionHandler: @MainActor @escaping () -> Void) {
|
|
self.accountID = accountID
|
|
self.mastodonController = mastodonController
|
|
self.presenter = presenter
|
|
self.completionHandler = completionHandler
|
|
}
|
|
|
|
func run() async {
|
|
let req = Suggestion.remove(accountID: accountID)
|
|
do {
|
|
_ = try await mastodonController.run(req)
|
|
completionHandler()
|
|
} catch {
|
|
let config = ToastConfiguration(from: error, with: "Error Removing Suggestion", in: presenter) { toast in
|
|
toast.dismissToast(animated: true)
|
|
await self.run()
|
|
}
|
|
self.presenter.showToast(configuration: config, animated: true)
|
|
}
|
|
}
|
|
}
|