forked from shadowfacts/Tusker
Indicate pending follow requests, feedback on successful async menu actions
Closes #265
This commit is contained in:
parent
a97a7e0aea
commit
97f00e9d6f
|
@ -355,6 +355,17 @@ extension MenuActionProvider {
|
|||
}
|
||||
}
|
||||
|
||||
private func handleSuccess(title: String) {
|
||||
if let toastable = self.toastableViewController {
|
||||
var config = ToastConfiguration(title: title)
|
||||
config.systemImageName = "checkmark"
|
||||
config.dismissAutomaticallyAfter = 2
|
||||
DispatchQueue.main.async {
|
||||
toastable.showToast(configuration: config, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func relationshipAction(accountID: String, mastodonController: MastodonController, builder: @escaping @MainActor (RelationshipMO, MastodonController) -> UIMenuElement) -> UIDeferredMenuElement {
|
||||
return UIDeferredMenuElement.uncached({ @MainActor elementHandler in
|
||||
let relationship = Task {
|
||||
|
@ -380,14 +391,26 @@ extension MenuActionProvider {
|
|||
private func followAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement {
|
||||
let accountID = relationship.accountID
|
||||
let following = relationship.following
|
||||
return createAction(identifier: "follow", title: following ? "Unfollow" : "Follow", systemImageName: following ? "person.badge.minus" : "person.badge.plus") { [weak self] _ in
|
||||
let request = (following ? Account.unfollow : Account.follow)(accountID)
|
||||
let requested = relationship.requested
|
||||
let title = following ? "Unfollow" : requested ? "Cancel Request" : "Follow"
|
||||
let imageName = following || requested ? "person.badge.minus" : "person.badge.plus"
|
||||
return createAction(identifier: "follow", title: title, systemImageName: imageName) { [weak self] _ in
|
||||
let request = (following || requested ? Account.unfollow : Account.follow)(accountID)
|
||||
mastodonController.run(request) { response in
|
||||
switch response {
|
||||
case .failure(let error):
|
||||
self?.handleError(error, title: "Error \(following ? "Unf" : "F")ollowing")
|
||||
self?.handleError(error, title: following ? "Error Unfollowing" : requested ? "Error Cancelinng Request" : "Error Following")
|
||||
case .success(let relationship, _):
|
||||
mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
|
||||
if requested { // was requested, now cancelled
|
||||
self?.handleSuccess(title: "Follow Request Cancelled")
|
||||
} else if following { // was following, now unfollowed
|
||||
self?.handleSuccess(title: "Unfollowed")
|
||||
} else if relationship.followRequested { // was not following, now requested
|
||||
self?.handleSuccess(title: "Request Sent")
|
||||
} else { // was not following, not now requested, assume success
|
||||
self?.handleSuccess(title: "Followed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -407,6 +430,7 @@ extension MenuActionProvider {
|
|||
self?.handleError(error, title: "Error \(block ? "B" : "Unb")locking")
|
||||
case .success(let relationship, _):
|
||||
mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
|
||||
self?.handleSuccess(title: "\(block ? "B" : "Unb")locked")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -415,8 +439,11 @@ extension MenuActionProvider {
|
|||
return { [weak self] (_: UIAction) in
|
||||
let req = block ? Client.block(domain: host) : Client.unblock(domain: host)
|
||||
mastodonController.run(req) { response in
|
||||
if case .failure(let error) = response {
|
||||
switch response {
|
||||
case .failure(let error):
|
||||
self?.handleError(error, title: "Error \(block ? "B" : "Unb")locking")
|
||||
case .success(_, _):
|
||||
self?.handleSuccess(title: "Domain \(block ? "B" : "Unb")locked")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -446,6 +473,7 @@ extension MenuActionProvider {
|
|||
self?.handleError(error, title: "Error Unmuting")
|
||||
case .success(let relationship, _):
|
||||
mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
|
||||
self?.handleSuccess(title: "Unmuted")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue