Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable all identity server functionality via the config file #2645

Merged
merged 9 commits into from
Aug 14, 2019
2 changes: 2 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"room_creation_make_private" = "Make private";
"room_creation_wait_for_creation" = "A room is already being created. Please wait.";
"room_creation_invite_another_user" = "Search / invite by User ID, Name or email";
"room_creation_error_invite_user_by_email_without_identity_server" = "No Identity Server is configured so you cannot add a participant with an email.";

// Room recents
"room_recents_directory_section" = "ROOM DIRECTORY";
Expand Down Expand Up @@ -218,6 +219,7 @@
"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_invited_section" = "INVITED";
"room_participants_start_new_chat_error_using_user_email_without_identity_server" = "No Identity Server is configured so you cannot start a chat with a contact using an email.";

"room_participants_online" = "Online";
"room_participants_offline" = "Offline";
Expand Down
8 changes: 8 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,10 @@ internal enum VectorL10n {
internal static var roomCreationAppearancePicture: String {
return VectorL10n.tr("Vector", "room_creation_appearance_picture")
}
/// No Identity Server is configured so you cannot add a participant with an email.
internal static var roomCreationErrorInviteUserByEmailWithoutIdentityServer: String {
return VectorL10n.tr("Vector", "room_creation_error_invite_user_by_email_without_identity_server")
}
/// Search / invite by User ID, Name or email
internal static var roomCreationInviteAnotherUser: String {
return VectorL10n.tr("Vector", "room_creation_invite_another_user")
Expand Down Expand Up @@ -2118,6 +2122,10 @@ internal enum VectorL10n {
internal static var roomParticipantsRemoveThirdPartyInviteMsg: String {
return VectorL10n.tr("Vector", "room_participants_remove_third_party_invite_msg")
}
/// No Identity Server is configured so you cannot start a chat with a contact using an email.
internal static var roomParticipantsStartNewChatErrorUsingUserEmailWithoutIdentityServer: String {
return VectorL10n.tr("Vector", "room_participants_start_new_chat_error_using_user_email_without_identity_server")
}
/// Participants
internal static var roomParticipantsTitle: String {
return VectorL10n.tr("Vector", "room_participants_title")
Expand Down
32 changes: 27 additions & 5 deletions Riot/Modules/Authentication/AuthenticationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ - (void)userInterfaceThemeDidChange
[forgotPasswordTitle addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.tintColor range:NSMakeRange(0, forgotPasswordTitle.length)];
[self.forgotPasswordButton setAttributedTitle:forgotPasswordTitle forState:UIControlStateNormal];
[self.forgotPasswordButton setAttributedTitle:forgotPasswordTitle forState:UIControlStateHighlighted];

NSMutableAttributedString *forgotPasswordTitleDisabled = [[NSMutableAttributedString alloc] initWithAttributedString:forgotPasswordTitle];
[forgotPasswordTitleDisabled addAttribute:NSForegroundColorAttributeName value:[ThemeService.shared.theme.tintColor colorWithAlphaComponent:0.3] range:NSMakeRange(0, forgotPasswordTitle.length)];
[self.forgotPasswordButton setAttributedTitle:forgotPasswordTitleDisabled forState:UIControlStateDisabled];

[self updateForgotPwdButtonVisibility];

NSAttributedString *serverOptionsTitle = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"auth_use_server_options", @"Vector", nil) attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.textSecondaryColor, NSFontAttributeName: [UIFont systemFontOfSize:14]}];
Expand Down Expand Up @@ -609,11 +614,20 @@ - (IBAction)onButtonPressed:(id)sender
else
{
[self.authenticationActivityIndicator stopAnimating];

// Show the supported 3rd party ids which may be added to the account
authInputsview.thirdPartyIdentifiersHidden = NO;

[self updateRegistrationScreenWithThirdPartyIdentifiersHidden:NO];

BOOL isIdentityServerConfigured = self.identityServerTextField.text.length > 0;

if (isIdentityServerConfigured)
{
// Show the supported 3rd party ids which may be added to the account
authInputsview.thirdPartyIdentifiersHidden = NO;
[self updateRegistrationScreenWithThirdPartyIdentifiersHidden:NO];
}
else
{
// Do not propose to add 3rd party ids if there is no configured Identity Server
[super onButtonPressed:sender];
}
}
}];
}
Expand Down Expand Up @@ -785,6 +799,14 @@ - (void)updateForgotPwdButtonVisibility
}
}

- (void)setIdentityServerTextFieldText:(NSString *)identityServerUrl
{
// Disable forgot password button when identity server is not set
self.forgotPasswordButton.enabled = identityServerUrl.length > 0;

[super setIdentityServerTextFieldText:identityServerUrl];
}

#pragma mark -

- (void)updateRegistrationScreenWithThirdPartyIdentifiersHidden:(BOOL)thirdPartyIdentifiersHidden
Expand Down
11 changes: 7 additions & 4 deletions Riot/Modules/Contacts/Details/ContactDetailsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,13 @@ - (void)onActionButtonPressed:(id)sender
// The identity server must be defined
if (!self.mainSession.matrixRestClient.identityServer)
{
MXError *error = [[MXError alloc] initWithErrorCode:kMXSDKErrCodeStringMissingParameters error:@"No supplied identity server URL"];
NSLog(@"[ContactDetailsViewController] Invite %@ failed", participantId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:[error createNSError]];
[self removePendingActionMask];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"]
message:NSLocalizedStringFromTable(@"room_participants_start_new_chat_error_using_user_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;
}
Expand Down
29 changes: 21 additions & 8 deletions Riot/Modules/Settings/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1220,22 +1220,35 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
else if (section == SETTINGS_SECTION_USER_SETTINGS_INDEX)
{
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;

userSettingsProfilePictureIndex = 0;
userSettingsDisplayNameIndex = 1;
userSettingsChangePasswordIndex = 2;
userSettingsEmailStartIndex = 3;
userSettingsNewEmailIndex = userSettingsEmailStartIndex + account.linkedEmails.count;
userSettingsPhoneStartIndex = userSettingsNewEmailIndex + 1;
userSettingsNewPhoneIndex = userSettingsPhoneStartIndex + account.linkedPhoneNumbers.count;


// Hide some unsupported account settings
userSettingsFirstNameIndex = -1;
userSettingsSurnameIndex = -1;
userSettingsNightModeSepIndex = -1;
userSettingsNightModeIndex = -1;

count = userSettingsNewPhoneIndex + 1;

if (self.mainSession.matrixRestClient.identityServer.length)
{
userSettingsEmailStartIndex = 3;
userSettingsNewEmailIndex = userSettingsEmailStartIndex + account.linkedEmails.count;
userSettingsPhoneStartIndex = userSettingsNewEmailIndex + 1;
userSettingsNewPhoneIndex = userSettingsPhoneStartIndex + account.linkedPhoneNumbers.count;

count = userSettingsNewPhoneIndex + 1;
}
else
{
userSettingsEmailStartIndex = -1;
userSettingsNewEmailIndex = -1;
userSettingsPhoneStartIndex = -1;
userSettingsNewPhoneIndex = -1;

count = userSettingsChangePasswordIndex + 1;
}
}
else if (section == SETTINGS_SECTION_NOTIFICATIONS_SETTINGS_INDEX)
{
Expand Down
9 changes: 1 addition & 8 deletions Riot/Modules/StartChat/StartChatViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@
/**
'StartChatViewController' instance is used to prepare new room creation.
*/
@interface StartChatViewController : ContactsTableViewController <UITableViewDataSource, UISearchBarDelegate, ContactsTableViewControllerDelegate>

@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
Expand Down
45 changes: 40 additions & 5 deletions Riot/Modules/StartChat/StartChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import "AppDelegate.h"
#import "Riot-Swift.h"

@interface StartChatViewController ()
@interface StartChatViewController () <UITableViewDataSource, UISearchBarDelegate, ContactsTableViewControllerDelegate>
{
// The contact used to describe the current user.
MXKContact *userContact;
Expand All @@ -42,6 +42,13 @@ @interface StartChatViewController ()
NSMutableDictionary <NSString*, NSNumber*> *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
Expand Down Expand Up @@ -522,11 +529,7 @@ - (IBAction)onButtonPressed:(id)sender
// 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;
}

Expand Down Expand Up @@ -681,6 +684,38 @@ - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

- (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
Expand Down