forked from shadowfacts/Tusker
Complete asynchronous swipe actions immediately
Fixes crash when the user things the action has failed and taps it again, which results in an invalid completion handler later being called
This commit is contained in:
parent
3e0feba273
commit
23a4999196
|
@ -99,9 +99,9 @@ private func createFavoriteAction(status: StatusMO, container: StatusSwipeAction
|
||||||
}
|
}
|
||||||
let title = status.favourited ? "Unfavorite" : "Favorite"
|
let title = status.favourited ? "Unfavorite" : "Favorite"
|
||||||
let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in
|
let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in
|
||||||
|
completion(true)
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
await FavoriteService(status: status, mastodonController: container.mastodonController, presenter: container.navigationDelegate).toggleFavorite()
|
await FavoriteService(status: status, mastodonController: container.mastodonController, presenter: container.navigationDelegate).toggleFavorite()
|
||||||
completion(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action.image = UIImage(systemName: "star.fill")
|
action.image = UIImage(systemName: "star.fill")
|
||||||
|
@ -116,9 +116,9 @@ private func createReblogAction(status: StatusMO, container: StatusSwipeActionCo
|
||||||
}
|
}
|
||||||
let title = status.reblogged ? "Unreblog" : "Reblog"
|
let title = status.reblogged ? "Unreblog" : "Reblog"
|
||||||
let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in
|
let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in
|
||||||
|
completion(true)
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
await ReblogService(status: status, mastodonController: container.mastodonController, presenter: container.navigationDelegate).toggleReblog()
|
await ReblogService(status: status, mastodonController: container.mastodonController, presenter: container.navigationDelegate).toggleReblog()
|
||||||
completion(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action.image = UIImage(systemName: "repeat")
|
action.image = UIImage(systemName: "repeat")
|
||||||
|
@ -145,6 +145,7 @@ private func createBookmarkAction(status: StatusMO, container: StatusSwipeAction
|
||||||
let bookmarked = status.bookmarked ?? false
|
let bookmarked = status.bookmarked ?? false
|
||||||
let title = bookmarked ? "Unbookmark" : "Bookmark"
|
let title = bookmarked ? "Unbookmark" : "Bookmark"
|
||||||
let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in
|
let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in
|
||||||
|
completion(true)
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
let request = (bookmarked ? Status.unbookmark : Status.bookmark)(status.id)
|
let request = (bookmarked ? Status.unbookmark : Status.bookmark)(status.id)
|
||||||
do {
|
do {
|
||||||
|
@ -156,7 +157,6 @@ private func createBookmarkAction(status: StatusMO, container: StatusSwipeAction
|
||||||
toastable.showToast(configuration: config, animated: true)
|
toastable.showToast(configuration: config, animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
completion(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action.image = UIImage(systemName: "bookmark.fill")
|
action.image = UIImage(systemName: "bookmark.fill")
|
||||||
|
|
Loading…
Reference in New Issue