Dismiss after following all (IOS-157)

This commit is contained in:
Nathan Mattes 2023-05-23 12:55:24 +02:00
parent 9c19bf2985
commit 5daf944384
2 changed files with 20 additions and 10 deletions

View File

@ -122,7 +122,11 @@ extension SuggestionAccountViewController: SuggestionAccountTableViewCellDelegat
extension SuggestionAccountViewController: SuggestionAccountTableViewFooterDelegate { extension SuggestionAccountViewController: SuggestionAccountTableViewFooterDelegate {
func followAll(_ footerView: SuggestionAccountTableViewFooter) { func followAll(_ footerView: SuggestionAccountTableViewFooter) {
viewModel.followAllSuggestedAccounts(self) viewModel.followAllSuggestedAccounts(self) {
OperationQueue.main.addOperation {
self.dismiss(animated: true)
}
}
} }
} }

View File

@ -114,20 +114,26 @@ final class SuggestionAccountViewModel: NSObject {
.store(in: &disposeBag) .store(in: &disposeBag)
} }
func followAllSuggestedAccounts(_ dependency: NeedsDependency & AuthContextProvider) { func followAllSuggestedAccounts(_ dependency: NeedsDependency & AuthContextProvider, completion: (() -> Void)? = nil) {
let userRecords = userFetchedResultsController.records.compactMap { let userRecords = userFetchedResultsController.records.compactMap {
$0.object(in: dependency.context.managedObjectContext)?.asRecord $0.object(in: dependency.context.managedObjectContext)?.asRecord
} }
userRecords.forEach { user in Task {
Task { await withTaskGroup(of: Void.self, body: { taskGroup in
try? await DataSourceFacade.responseToUserViewButtonAction( for user in userRecords {
dependency: dependency, taskGroup.addTask {
user: user, try? await DataSourceFacade.responseToUserViewButtonAction(
buttonState: .follow dependency: dependency,
) user: user,
} buttonState: .follow
)
}
}
})
completion?()
} }
} }
} }