Skip to content

Commit

Permalink
Merge pull request #1636 from nextcloud/bugfix/1635/partiipants-not-v…
Browse files Browse the repository at this point in the history
…isible

Wait until all participants have been added before closing "Add Participants" view
  • Loading branch information
SystemKeeper authored May 2, 2024
2 parents 086bd18 + 0c3e33e commit 7c05620
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions NextcloudTalk/AddParticipantsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ @interface AddParticipantsTableViewController () <UISearchBarDelegate, UISearchC
PlaceholderView *_participantsBackgroundView;
NSTimer *_searchTimer;
NSURLSessionTask *_searchParticipantsTask;
UIActivityIndicatorView *_addingParticipantsIndicator;
BOOL _errorAddingParticipants;
}
@end

Expand All @@ -64,7 +66,10 @@ - (instancetype)initForRoom:(NCRoom *)room
_participants = [[NSMutableDictionary alloc] init];
_indexes = [[NSArray alloc] init];
_selectedParticipants = [[NSMutableArray alloc] init];


_addingParticipantsIndicator = [[UIActivityIndicatorView alloc] init];
_addingParticipantsIndicator.color = [NCAppBranding themeTextColor];

return self;
}

Expand Down Expand Up @@ -209,22 +214,34 @@ - (void)close

- (void)addButtonPressed
{
self.tableView.allowsSelection = NO;
_resultTableViewController.tableView.allowsSelection = NO;
if (_room && _selectedParticipants.count > 0) {
dispatch_group_t addParticipantsGroup = dispatch_group_create();

if (_room) {
[self showAddingParticipantsView];
for (NCUser *participant in _selectedParticipants) {
[self addParticipantToRoom:participant];
[self addParticipantToRoom:participant withDispatchGroup:addParticipantsGroup];
}

dispatch_group_notify(addParticipantsGroup, dispatch_get_main_queue(), ^{
[self removeAddingParticipantsView];

if (!self->_errorAddingParticipants) {
[self close];
}

// Reset flag once adding participants process has finished
self->_errorAddingParticipants = NO;
});
} else if ([self.delegate respondsToSelector:@selector(addParticipantsTableViewController:wantsToAdd:)]) {
[self.delegate addParticipantsTableViewController:self wantsToAdd:_selectedParticipants];
[self close];
}

[self close];
}

- (void)addParticipantToRoom:(NCUser *)participant
- (void)addParticipantToRoom:(NCUser *)participant withDispatchGroup:(dispatch_group_t)dispatchGroup
{
dispatch_group_enter(dispatchGroup);

[[NCAPIController sharedInstance] addParticipant:participant.userId ofType:participant.source toRoom:_room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSError *error) {
if (error) {
UIAlertController * alert = [UIAlertController
Expand All @@ -238,9 +255,13 @@ - (void)addParticipantToRoom:(NCUser *)participant
handler:nil];

[alert addAction:okButton];


self->_errorAddingParticipants = YES;

[[NCUserInterfaceController sharedInstance] presentAlertViewController:alert];
}

dispatch_group_leave(dispatchGroup);
}];
}

Expand All @@ -263,6 +284,23 @@ - (void)updateCounter
self.navigationController.navigationBar.topItem.rightBarButtonItem = addButton;
}

- (void)showAddingParticipantsView
{
[_addingParticipantsIndicator startAnimating];
UIBarButtonItem *addingParticipantButton = [[UIBarButtonItem alloc] initWithCustomView:_addingParticipantsIndicator];
self.navigationItem.rightBarButtonItems = @[addingParticipantButton];
self.tableView.allowsSelection = NO;
_resultTableViewController.tableView.allowsSelection = NO;
}

- (void)removeAddingParticipantsView
{
[_addingParticipantsIndicator stopAnimating];
[self updateCounter];
self.tableView.allowsSelection = YES;
_resultTableViewController.tableView.allowsSelection = YES;
}

#pragma mark - Participants actions

- (NSMutableArray *)filterContacts:(NSMutableArray *)contacts
Expand Down

0 comments on commit 7c05620

Please sign in to comment.