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

End-to-end encryption UI/UX #758

Merged
merged 1 commit into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Vector/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@
"room_details_advanced_room_id"="Room ID:";
"room_details_advanced_enable_e2e_encryption"="Enable encryption (warning: cannot be disabled again!)";
"room_details_advanced_e2e_encryption_enabled"="Encryption is enabled in this room";
"room_details_advanced_e2e_encryption_disabled"="Encryption is not enabled in this room.";
"room_details_advanced_e2e_encryption_prompt_title"="Warning!";
"room_details_advanced_e2e_encryption_prompt_message"="End-to-end encryption is in beta and may not be reliable.\n\nYou should not yet trust it to secure data. File transfers and calls are not yet encrypted.\n\nDevices will not yet be able to decrypt history from before they joined the room.\n\nOnce encryption is enabled for a room it cannot be turned off again (for now).\n\nEncrypted messages will not be visible on clients that do not yet implement encryption.";
"room_details_fail_to_update_avatar" = "Fail to update the room photo";
"room_details_fail_to_update_room_name" = "Fail to update the room name";
"room_details_fail_to_update_topic" = "Fail to update the topic";
Expand Down
122 changes: 99 additions & 23 deletions Vector/ViewController/RoomSettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
{
roomEncryptionSwitch = nil;
}
else if (roomNotifSwitch == directoryVisibilitySwitch)
{
roomNotifSwitch = nil;
}

[directoryVisibilitySwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
directoryVisibilitySwitch.onTintColor = kVectorColorGreen;
Expand Down Expand Up @@ -2331,36 +2335,63 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}

cell.textLabel.font = [UIFont systemFontOfSize:17];
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_enabled", @"Vector", nil);
cell.textLabel.textColor = kVectorTextColorBlack;

cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
MXKTableViewCellWithLabelAndSwitch *roomEncryptionCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier] forIndexPath:indexPath];

roomEncryptionCell.mxkLabelLeadingConstraint.constant = roomEncryptionCell.separatorInset.left;
roomEncryptionCell.mxkSwitchTrailingConstraint.constant = 15;

[roomEncryptionCell.mxkSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
roomEncryptionCell.mxkSwitch.onTintColor = kVectorColorGreen;

roomEncryptionCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_enable_e2e_encryption", @"Vector", nil);
roomEncryptionCell.mxkLabel.textColor = kVectorTextColorBlack;

roomEncryptionSwitch = roomEncryptionCell.mxkSwitch;

// Workaround to avoid mixing between switches
// TODO: this is a design issue with switch within UITableViewCell that must fix everywhere
if (directoryVisibilitySwitch == roomEncryptionSwitch)
// Check user's power level to know whether the user is allowed to turn on the encryption mode
MXRoomPowerLevels *powerLevels = [mxRoom.state powerLevels];
NSInteger oneSelfPowerLevel = [powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId];

if (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomEncryption])
{
directoryVisibilitySwitch = nil;
MXKTableViewCellWithLabelAndSwitch *roomEncryptionCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier] forIndexPath:indexPath];

roomEncryptionCell.mxkLabelLeadingConstraint.constant = roomEncryptionCell.separatorInset.left;
roomEncryptionCell.mxkSwitchTrailingConstraint.constant = 15;

[roomEncryptionCell.mxkSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
roomEncryptionCell.mxkSwitch.onTintColor = kVectorColorGreen;

roomEncryptionCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_enable_e2e_encryption", @"Vector", nil);
roomEncryptionCell.mxkLabel.textColor = kVectorTextColorBlack;

roomEncryptionSwitch = roomEncryptionCell.mxkSwitch;

// Workaround to avoid mixing between switches
// TODO: this is a design issue with switch within UITableViewCell that must fix everywhere
if (directoryVisibilitySwitch == roomEncryptionSwitch)
{
directoryVisibilitySwitch = nil;
}
else if (roomNotifSwitch == roomEncryptionSwitch)
{
roomNotifSwitch = nil;
}

roomEncryptionSwitch.on = ([updatedItemsDict objectForKey:kRoomSettingsEncryptionKey] != nil);

cell = roomEncryptionCell;
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAdvancedE2eEnabledCellViewIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kRoomSettingsAdvancedE2eEnabledCellViewIdentifier];
}

cell.textLabel.font = [UIFont systemFontOfSize:17];
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_disabled", @"Vector", nil);
cell.textLabel.textColor = kVectorTextColorBlack;

cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

roomEncryptionSwitch.on = ([updatedItemsDict objectForKey:kRoomSettingsEncryptionKey] != nil);

cell = roomEncryptionCell;
}
}
}
Expand Down Expand Up @@ -2621,7 +2652,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

[self.parentViewController.navigationController pushViewController:roomMemberDetailsViewController animated:NO];
}
else if (indexPath.section == ROOM_SETTINGS_ADVANCED_SECTION_INDEX)
else if (indexPath.section == ROOM_SETTINGS_ADVANCED_SECTION_INDEX && indexPath.row == 0)
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell)
Expand Down Expand Up @@ -2922,7 +2953,52 @@ - (void)onSwitchUpdate:(UISwitch*)theSwitch
}
else if (theSwitch == roomEncryptionSwitch)
{
[updatedItemsDict setObject:[NSNumber numberWithBool:roomEncryptionSwitch.on] forKey:kRoomSettingsEncryptionKey];
if (roomEncryptionSwitch.on)
{
// Prompt here user before turning on the data encryption
__weak typeof(self) weakSelf = self;

[currentAlert dismiss:NO];

currentAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_prompt_title", @"Vector", nil)
message:NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_prompt_message", @"Vector", nil)
style:MXKAlertStyleAlert];

currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
style:MXKAlertActionStyleDefault
handler:^(MXKAlert *alert) {

if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->currentAlert = nil;
}

// Reset switch change
theSwitch.on = NO;
}];

[currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"]
style:MXKAlertActionStyleDefault
handler:^(MXKAlert *alert) {

if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->currentAlert = nil;

[strongSelf->updatedItemsDict setObject:@(YES) forKey:kRoomSettingsEncryptionKey];

[strongSelf getNavigationItem].rightBarButtonItem.enabled = strongSelf->updatedItemsDict.count;
}
}];

[currentAlert showInViewController:self];
}
else
{
[updatedItemsDict removeObjectForKey:kRoomSettingsEncryptionKey];
}
}

[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
Expand Down