diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index bc1a72684..449807afe 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -89,6 +89,8 @@ "room_participants_remove_prompt_msg" = "Are you sure you want to remove %@ from this chat?"; "room_participants_admin_name" = "%@ (admin)"; "room_participants_invite_another_user" = "Invite another user"; +"room_participants_invite_malformed_id_title" = "Invite Error"; +"room_participants_invite_malformed_id" = "Malformed ID. Should be an email address or a Matrix ID like '@localpart:domain'"; "room_participants_active" = "Active"; "room_participants_invite" = "Invite"; diff --git a/Vector/ViewController/RoomParticipantsViewController.m b/Vector/ViewController/RoomParticipantsViewController.m index 5d11d7f53..192134643 100644 --- a/Vector/ViewController/RoomParticipantsViewController.m +++ b/Vector/ViewController/RoomParticipantsViewController.m @@ -675,7 +675,84 @@ if (indexPath.section == searchResultSection) { - if (row < filteredParticipants.count) + if (row == 0) + { + // This is the text entered by the user + // Try to invite what he typed + MXKContact *contact = filteredParticipants[row]; + + // Invite this user if a room is defined + if (self.mxRoom) + { + NSString *participantId = contact.displayName; + + // Is it an email or a Matrix user ID? + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^\\S+@\\S+\\.\\S+$" options:NSRegularExpressionCaseInsensitive error:nil]; + BOOL isEmailAddress = (nil != [regex firstMatchInString:participantId options:0 range:NSMakeRange(0, participantId.length)]); + + // Sanity check the input + if (!isEmailAddress && + ([participantId characterAtIndex:0] != '@' || [participantId containsString:@":"] == NO)) + { + __weak typeof(self) weakSelf = self; + currentAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"room_participants_invite_malformed_id_title", @"Vector", nil) + message:NSLocalizedStringFromTable(@"room_participants_invite_malformed_id", @"Vector", nil) + style:MXKAlertStyleAlert]; + + currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] + style:MXKAlertActionStyleCancel + handler:^(MXKAlert *alert) { + + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + + }]; + [currentAlert showInViewController:self]; + } + else + { + if (isEmailAddress) + { + [self addPendingActionMask]; + [self.mxRoom inviteUserByEmail:participantId success:^{ + + [self removePendingActionMask]; + + // Refresh display by leaving search session + [self searchBarCancelButtonClicked:addParticipantsSearchBarCell.mxkSearchBar]; + + } failure:^(NSError *error) { + + [self removePendingActionMask]; + + NSLog(@"[RoomParticipantsVC] Invite be email %@ failed: %@", participantId, error); + // Alert user + [[AppDelegate theDelegate] showErrorAsAlert:error]; + }]; + } + else + { + [self addPendingActionMask]; + [self.mxRoom inviteUser:participantId success:^{ + + [self removePendingActionMask]; + + // Refresh display by leaving search session + [self searchBarCancelButtonClicked:addParticipantsSearchBarCell.mxkSearchBar]; + + } failure:^(NSError *error) { + + [self removePendingActionMask]; + + NSLog(@"[RoomParticipantsVC] Invite %@ failed: %@", participantId, error); + // Alert user + [[AppDelegate theDelegate] showErrorAsAlert:error]; + }]; + } + } + } + } + else if (row < filteredParticipants.count) { MXKContact *contact = filteredParticipants[row];