Cleanup un/follow menu action

This commit is contained in:
Shadowfacts 2021-06-10 10:36:02 -04:00
parent 7c9287543c
commit 40f5be28f6
1 changed files with 22 additions and 19 deletions

View File

@ -63,13 +63,15 @@ extension MenuPreviewProvider {
let request = Client.getRelationships(accounts: [account.id]) let request = Client.getRelationships(accounts: [account.id])
// talk about callback hell :/ // talk about callback hell :/
mastodonController.run(request) { [weak self] (response) in mastodonController.run(request) { [weak self] (response) in
if let self = self, guard let self = self,
case let .success(results, _) = response, case let .success(results, _) = response,
let relationship = results.first { let relationship = results.first else {
elementHandler([])
return
}
let following = relationship.following let following = relationship.following
DispatchQueue.main.async { DispatchQueue.main.async {
elementHandler([ let action = self.createAction(identifier: "follow", title: following ? "Unfollow" : "Follow", systemImageName: following ? "person.badge.minus" : "person.badge.plus", handler: { (_) in
self.createAction(identifier: "follow", title: following ? "Unfollow" : "Follow", systemImageName: following ? "person.badge.minus" : "person.badge.plus", handler: { (_) in
let request = (following ? Account.unfollow : Account.follow)(accountID) let request = (following ? Account.unfollow : Account.follow)(accountID)
mastodonController.run(request) { (response) in mastodonController.run(request) { (response) in
switch response { switch response {
@ -80,10 +82,11 @@ extension MenuPreviewProvider {
} }
} }
}) })
elementHandler([
action
]) ])
} }
} }
}
})) }))
} }