From 5daf944384bd57d18f91737f9f3c0fd6459750c9 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Tue, 23 May 2023 12:55:24 +0200 Subject: [PATCH] Dismiss after following all (IOS-157) --- .../SuggestionAccountViewController.swift | 6 ++++- .../SuggestionAccountViewModel.swift | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift index ed0ba0b6b..fa83c2696 100644 --- a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift +++ b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift @@ -122,7 +122,11 @@ extension SuggestionAccountViewController: SuggestionAccountTableViewCellDelegat extension SuggestionAccountViewController: SuggestionAccountTableViewFooterDelegate { func followAll(_ footerView: SuggestionAccountTableViewFooter) { - viewModel.followAllSuggestedAccounts(self) + viewModel.followAllSuggestedAccounts(self) { + OperationQueue.main.addOperation { + self.dismiss(animated: true) + } + } } } diff --git a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift index 038ee887d..f75506f8a 100644 --- a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift +++ b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift @@ -114,20 +114,26 @@ final class SuggestionAccountViewModel: NSObject { .store(in: &disposeBag) } - func followAllSuggestedAccounts(_ dependency: NeedsDependency & AuthContextProvider) { + func followAllSuggestedAccounts(_ dependency: NeedsDependency & AuthContextProvider, completion: (() -> Void)? = nil) { let userRecords = userFetchedResultsController.records.compactMap { $0.object(in: dependency.context.managedObjectContext)?.asRecord } - userRecords.forEach { user in - Task { - try? await DataSourceFacade.responseToUserViewButtonAction( - dependency: dependency, - user: user, - buttonState: .follow - ) - } + Task { + await withTaskGroup(of: Void.self, body: { taskGroup in + for user in userRecords { + taskGroup.addTask { + try? await DataSourceFacade.responseToUserViewButtonAction( + dependency: dependency, + user: user, + buttonState: .follow + ) + } + } + }) + + completion?() } } }