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 {
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)
}
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?()
}
}
}