diff --git a/Riot/Modules/StartChat/StartChatViewController.h b/Riot/Modules/StartChat/StartChatViewController.h index 11b4f3ba6..85ce2e83c 100644 --- a/Riot/Modules/StartChat/StartChatViewController.h +++ b/Riot/Modules/StartChat/StartChatViewController.h @@ -19,14 +19,7 @@ /** 'StartChatViewController' instance is used to prepare new room creation. */ -@interface StartChatViewController : ContactsTableViewController - -@property (weak, nonatomic) IBOutlet UIView *searchBarHeader; -@property (weak, nonatomic) IBOutlet UISearchBar *searchBarView; -@property (weak, nonatomic) IBOutlet UIView *searchBarHeaderBorder; - -@property (weak, nonatomic) IBOutlet NSLayoutConstraint *searchBarTopConstraint; -@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewBottomConstraint; +@interface StartChatViewController : ContactsTableViewController /** Tell whether a search session is in progress diff --git a/Riot/Modules/StartChat/StartChatViewController.m b/Riot/Modules/StartChat/StartChatViewController.m index d2c3cd3ae..58ce0f178 100644 --- a/Riot/Modules/StartChat/StartChatViewController.m +++ b/Riot/Modules/StartChat/StartChatViewController.m @@ -20,7 +20,7 @@ #import "AppDelegate.h" #import "Riot-Swift.h" -@interface StartChatViewController () +@interface StartChatViewController () { // The contact used to describe the current user. MXKContact *userContact; @@ -42,6 +42,13 @@ NSMutableDictionary *isMultiUseNameByDisplayName; } +@property (weak, nonatomic) IBOutlet UIView *searchBarHeader; +@property (weak, nonatomic) IBOutlet UISearchBar *searchBarView; +@property (weak, nonatomic) IBOutlet UIView *searchBarHeaderBorder; + +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *searchBarTopConstraint; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewBottomConstraint; + @end @implementation StartChatViewController @@ -522,11 +529,7 @@ // The identity server must be defined if (!self.mainSession.matrixRestClient.identityServer) { - MXError *error = [[MXError alloc] initWithErrorCode:kMXSDKErrCodeStringMissingParameters error:@"No supplied identity server URL"]; NSLog(@"[StartChatViewController] Invite %@ failed", participantId); - // Alert user - [[AppDelegate theDelegate] showErrorAsAlert:[error createNSError]]; - continue; } @@ -681,6 +684,38 @@ - (void)contactsTableViewController:(ContactsTableViewController *)contactsTableViewController didSelectContact:(MXKContact*)contact { + // If contact has only an email the identity server must be defined + if (!self.mainSession.matrixRestClient.identityServer && contact.matrixIdentifiers.count == 0) + { + NSString *participantId; + + if (contact.emailAddresses.count) + { + MXKEmail *email = contact.emailAddresses.firstObject; + participantId = email.emailAddress; + } + else + { + // This is the text filled by the user. + participantId = contact.displayName; + } + + if ([MXTools isEmailAddress:participantId]) + { + NSLog(@"[StartChatViewController] No Identity Server is configured, do not add participant with email"); + + [contactsTableViewController refreshCurrentSelectedCell:YES]; + + UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"] + message:NSLocalizedStringFromTable(@"room_creation_error_invite_user_by_email_without_identity_server", @"Vector", nil) + preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:nil]]; + [self presentViewController:alert animated:YES completion:nil]; + + return; + } + } + if (contact) { // Update here the mutable list of participants