From 23a4999196f43eee4dc6d37d70dcbe60cf83ec9b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 20 Jan 2023 10:53:30 -0500 Subject: [PATCH] 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 --- Tusker/Preferences/StatusSwipeAction.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tusker/Preferences/StatusSwipeAction.swift b/Tusker/Preferences/StatusSwipeAction.swift index 03a7d701..7b5464ea 100644 --- a/Tusker/Preferences/StatusSwipeAction.swift +++ b/Tusker/Preferences/StatusSwipeAction.swift @@ -99,9 +99,9 @@ private func createFavoriteAction(status: StatusMO, container: StatusSwipeAction } let title = status.favourited ? "Unfavorite" : "Favorite" let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in + completion(true) Task { @MainActor in await FavoriteService(status: status, mastodonController: container.mastodonController, presenter: container.navigationDelegate).toggleFavorite() - completion(true) } } action.image = UIImage(systemName: "star.fill") @@ -116,9 +116,9 @@ private func createReblogAction(status: StatusMO, container: StatusSwipeActionCo } let title = status.reblogged ? "Unreblog" : "Reblog" let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in + completion(true) Task { @MainActor in await ReblogService(status: status, mastodonController: container.mastodonController, presenter: container.navigationDelegate).toggleReblog() - completion(true) } } action.image = UIImage(systemName: "repeat") @@ -145,6 +145,7 @@ private func createBookmarkAction(status: StatusMO, container: StatusSwipeAction let bookmarked = status.bookmarked ?? false let title = bookmarked ? "Unbookmark" : "Bookmark" let action = UIContextualAction(style: .normal, title: title) { [unowned container] _, _, completion in + completion(true) Task { @MainActor in let request = (bookmarked ? Status.unbookmark : Status.bookmark)(status.id) do { @@ -156,7 +157,6 @@ private func createBookmarkAction(status: StatusMO, container: StatusSwipeAction toastable.showToast(configuration: config, animated: true) } } - completion(true) } } action.image = UIImage(systemName: "bookmark.fill")