Merge pull request #817 from vector-im/settings_crypto_info

Settings: Add cryptography information
This commit is contained in:
giomfo 2016-11-22 14:32:18 +01:00 committed by GitHub
commit 945b4552d9
4 changed files with 155 additions and 22 deletions

View file

@ -235,6 +235,7 @@
"room_preview_try_join_an_unknown_room_default" = "a room"; "room_preview_try_join_an_unknown_room_default" = "a room";
// Settings // Settings
"settings_title" = "Settings";
"account_logout_all" = "Logout all accounts"; "account_logout_all" = "Logout all accounts";
"settings_config_no_build_info" = "(no build info)"; "settings_config_no_build_info" = "(no build info)";
@ -251,6 +252,8 @@
"settings_advanced" = "ADVANCED"; "settings_advanced" = "ADVANCED";
"settings_other" = "OTHER"; "settings_other" = "OTHER";
"settings_labs" = "LABS"; "settings_labs" = "LABS";
"settings_devices" = "DEVICES";
"settings_cryptography" = "CRYPTOGRAPHY";
"settings_sign_out" = "Sign Out"; "settings_sign_out" = "Sign Out";
"settings_profile_picture" = "Profile Picture"; "settings_profile_picture" = "Profile Picture";
@ -301,6 +304,10 @@
"settings_fail_to_update_password" = "Fail to update password"; "settings_fail_to_update_password" = "Fail to update password";
"settings_password_updated" = "Your password has been updated"; "settings_password_updated" = "Your password has been updated";
"settings_crypto_device_name" = "Device name: ";
"settings_crypto_device_id" = "\nDevice ID: ";
"settings_crypto_device_key" = "\nDevice key: ";
// Room Details // Room Details
"room_details_title" = "Room Details"; "room_details_title" = "Room Details";
"room_details_people" = "Members"; "room_details_people" = "Members";

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="H1p-Uh-vWS"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="H1p-Uh-vWS">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
@ -132,23 +132,41 @@
<point key="canvasLocation" x="414" y="1356"/> <point key="canvasLocation" x="414" y="1356"/>
</scene> </scene>
<!--Settings--> <!--Settings-->
<scene sceneID="4CK-43-kSo"> <scene sceneID="3md-j7-Qex">
<objects> <objects>
<tableViewController id="1TJ-Md-cjN" customClass="SettingsViewController" sceneMemberID="viewController"> <viewController title="Settings" id="BfJ-uC-XeM" customClass="SettingsViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" keyboardDismissMode="interactive" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="24" sectionFooterHeight="24" id="etG-ZU-b2r"> <layoutGuides>
<viewControllerLayoutGuide type="top" id="17C-JB-bS3"/>
<viewControllerLayoutGuide type="bottom" id="x0h-cK-85g"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="hZq-6f-RBH">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.93725490196078431" green="0.93725490196078431" blue="0.95686274509803926" alpha="1" colorSpace="calibratedRGB"/> <subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" keyboardDismissMode="interactive" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="24" sectionFooterHeight="24" translatesAutoresizingMaskIntoConstraints="NO" id="FhP-wT-Bz5">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<connections> <connections>
<outlet property="dataSource" destination="1TJ-Md-cjN" id="Lqt-w3-NjQ"/> <outlet property="dataSource" destination="BfJ-uC-XeM" id="cGQ-We-8Dg"/>
<outlet property="delegate" destination="1TJ-Md-cjN" id="pgx-SX-xgc"/> <outlet property="delegate" destination="BfJ-uC-XeM" id="Yeg-yu-2Od"/>
</connections> </connections>
</tableView> </tableView>
<navigationItem key="navigationItem" title="Settings" id="7NM-zW-wJT"/> </subviews>
</tableViewController> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="ZKJ-22-Asy" userLabel="First Responder" sceneMemberID="firstResponder"/> <constraints>
<constraint firstItem="x0h-cK-85g" firstAttribute="top" secondItem="FhP-wT-Bz5" secondAttribute="bottom" id="Edp-wX-9No"/>
<constraint firstItem="FhP-wT-Bz5" firstAttribute="top" secondItem="hZq-6f-RBH" secondAttribute="top" id="UXv-Vl-XRY"/>
<constraint firstItem="FhP-wT-Bz5" firstAttribute="leading" secondItem="hZq-6f-RBH" secondAttribute="leading" id="uQE-61-tdh"/>
<constraint firstAttribute="trailing" secondItem="FhP-wT-Bz5" secondAttribute="trailing" id="usM-NH-pXB"/>
</constraints>
</view>
<connections>
<outlet property="tableView" destination="FhP-wT-Bz5" id="Uup-02-F3t"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ndh-yC-OwR" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="1404" y="96"/> <point key="canvasLocation" x="1359" y="71"/>
</scene> </scene>
<!--RecentsSplitVC--> <!--RecentsSplitVC-->
<scene sceneID="Nki-YV-4Qg"> <scene sceneID="Nki-YV-4Qg">
@ -199,7 +217,7 @@
<navigationItem key="navigationItem" id="lkL-Yi-y5i"> <navigationItem key="navigationItem" id="lkL-Yi-y5i">
<barButtonItem key="leftBarButtonItem" image="settings_icon.png" id="RwK-LB-3ML"> <barButtonItem key="leftBarButtonItem" image="settings_icon.png" id="RwK-LB-3ML">
<connections> <connections>
<segue destination="1TJ-Md-cjN" kind="show" identifier="showSettings" id="rCU-QE-kdQ"/> <segue destination="BfJ-uC-XeM" kind="show" identifier="showSettings" id="DeP-gh-EmS"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
<barButtonItem key="rightBarButtonItem" image="search_icon.png" id="mxO-nq-rJ1"> <barButtonItem key="rightBarButtonItem" image="search_icon.png" id="mxO-nq-rJ1">

View file

@ -18,8 +18,9 @@
#import "MediaPickerViewController.h" #import "MediaPickerViewController.h"
@interface SettingsViewController : MXKTableViewController<UITextFieldDelegate, MediaPickerViewControllerDelegate> @interface SettingsViewController : MXKViewController<UITextFieldDelegate, MediaPickerViewControllerDelegate, UITableViewDelegate, UITableViewDataSource>
@property (nonatomic) IBOutlet UITableView *tableView;
@end @end

View file

@ -39,6 +39,7 @@ enum {
SETTINGS_SECTION_CONTACTS_INDEX, SETTINGS_SECTION_CONTACTS_INDEX,
#endif #endif
SETTINGS_SECTION_LABS_INDEX, SETTINGS_SECTION_LABS_INDEX,
SETTINGS_SECTION_CRYPTOGRAPHY_INDEX,
SETTINGS_SECTION_COUNT SETTINGS_SECTION_COUNT
}; };
@ -153,12 +154,18 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
self.enableBarTintColorStatusChange = NO; self.enableBarTintColorStatusChange = NO;
self.rageShakeManager = [RageShakeManager sharedManager]; self.rageShakeManager = [RageShakeManager sharedManager];
self.navigationItem.title = NSLocalizedStringFromTable(@"settings_title", @"Vector", nil);
self.tableView.backgroundColor = kVectorColorLightGrey; self.tableView.backgroundColor = kVectorColorLightGrey;
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndTextField defaultReuseIdentifier]]; [self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndTextField defaultReuseIdentifier]];
[self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]]; [self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]];
[self.tableView registerClass:MXKTableViewCellWithLabelAndMXKImageView.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]]; [self.tableView registerClass:MXKTableViewCellWithLabelAndMXKImageView.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]];
// Enable self sizing cells
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 50;
// Add observer to handle removed accounts // Add observer to handle removed accounts
removedAccountObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountManagerDidRemoveAccountNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { removedAccountObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountManagerDidRemoveAccountNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
@ -294,6 +301,9 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
// Refresh linked emails in parallel // Refresh linked emails in parallel
[self loadLinkedEmails]; [self loadLinkedEmails];
// Refresh the current device information in parallel
[self loadCurrentDeviceInformation];
// Observe kAppDelegateDidTapStatusBarNotificationObserver. // Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
@ -345,6 +355,14 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
#pragma mark - Internal methods #pragma mark - Internal methods
- (void)dismissKeyboard
{
[currentPasswordTextField resignFirstResponder];
[newPasswordTextField1 resignFirstResponder];
[newPasswordTextField2 resignFirstResponder];
[newEmailTextField resignFirstResponder];
}
- (void)reset - (void)reset
{ {
// Remove observers // Remove observers
@ -522,6 +540,56 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
}]; }];
} }
- (void)loadCurrentDeviceInformation
{
// Refresh the current device information
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
[account loadDeviceInformation:^{
// Refresh all the table (A slide down animation is observed when we limit the refresh to the concerned section).
// Note: The use of 'reloadData' handles the case where the account has been logged out.
[self.tableView reloadData];
} failure:nil];
}
- (NSAttributedString*)cryptographyInformation
{
// TODO Handle multi accounts
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
// Crypto information
NSMutableAttributedString *cryptoInformationString = [[NSMutableAttributedString alloc]
initWithString:NSLocalizedStringFromTable(@"settings_crypto_device_name", @"Vector", nil)
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
NSFontAttributeName: [UIFont systemFontOfSize:17]}];
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:account.device.displayName ? account.device.displayName : @""
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
NSFontAttributeName: [UIFont systemFontOfSize:17]}]];
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:NSLocalizedStringFromTable(@"settings_crypto_device_id", @"Vector", nil)
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
NSFontAttributeName: [UIFont systemFontOfSize:17]}]];
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:account.device.deviceId ? account.device.deviceId : @""
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
NSFontAttributeName: [UIFont systemFontOfSize:17]}]];
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:NSLocalizedStringFromTable(@"settings_crypto_device_key", @"Vector", nil)
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
NSFontAttributeName: [UIFont systemFontOfSize:17]}]];
NSString *fingerprint = account.mxSession.crypto.olmDevice.deviceEd25519Key;
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
initWithString:fingerprint ? fingerprint : @""
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}]];
return cryptoInformationString;
}
#pragma mark - Segues #pragma mark - Segues
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
@ -601,6 +669,14 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
{ {
count = LABS_COUNT; count = LABS_COUNT;
} }
else if (section == SETTINGS_SECTION_CRYPTOGRAPHY_INDEX)
{
// Check whether this section is visible.
if (self.mainSession.crypto)
{
count = 1;
}
}
return count; return count;
} }
@ -1087,6 +1163,19 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
cell = labelAndSwitchCell; cell = labelAndSwitchCell;
} }
} }
else if (section == SETTINGS_SECTION_CRYPTOGRAPHY_INDEX)
{
MXKTableViewCell *cryptoCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCell defaultReuseIdentifier]];
if (!cryptoCell)
{
cryptoCell = [[MXKTableViewCell alloc] init];
}
cryptoCell.textLabel.attributedText = [self cryptographyInformation];
cryptoCell.textLabel.numberOfLines = 0;
cell = cryptoCell;
}
return cell; return cell;
} }
@ -1103,6 +1192,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
} }
else if (section == SETTINGS_SECTION_IGNORED_USERS_INDEX) else if (section == SETTINGS_SECTION_IGNORED_USERS_INDEX)
{ {
// Check whether this section is visible
if ([AppDelegate theDelegate].mxSessions.count > 0) if ([AppDelegate theDelegate].mxSessions.count > 0)
{ {
MXSession* session = [[AppDelegate theDelegate].mxSessions objectAtIndex:0]; MXSession* session = [[AppDelegate theDelegate].mxSessions objectAtIndex:0];
@ -1111,9 +1201,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
return NSLocalizedStringFromTable(@"settings_ignored_users", @"Vector", nil); return NSLocalizedStringFromTable(@"settings_ignored_users", @"Vector", nil);
} }
} }
// Hide this section
return nil;
} }
else if (section == SETTINGS_SECTION_CONTACTS_INDEX) else if (section == SETTINGS_SECTION_CONTACTS_INDEX)
{ {
@ -1131,6 +1218,14 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
{ {
return NSLocalizedStringFromTable(@"settings_labs", @"Vector", nil); return NSLocalizedStringFromTable(@"settings_labs", @"Vector", nil);
} }
else if (section == SETTINGS_SECTION_CRYPTOGRAPHY_INDEX)
{
// Check whether this section is visible
if (self.mainSession.crypto)
{
return NSLocalizedStringFromTable(@"settings_cryptography", @"Vector", nil);
}
}
return nil; return nil;
} }
@ -1166,6 +1261,15 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
[label sizeToFit]; [label sizeToFit];
return label.frame.size.height + 16; return label.frame.size.height + 16;
} }
else if (indexPath.section == SETTINGS_SECTION_CRYPTOGRAPHY_INDEX)
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];
label.numberOfLines = 0;
label.attributedText = [self cryptographyInformation];
[label sizeToFit];
return label.frame.size.height + 16;
}
return 50; return 50;
} }
@ -1185,7 +1289,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
} }
} }
return [super tableView:tableView heightForHeaderInSection:section]; return 24;
} }
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
@ -1203,7 +1307,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
} }
} }
return [super tableView:tableView heightForFooterInSection:section]; return 24;
} }
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
@ -1496,6 +1600,9 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
[self stopActivityIndicator]; [self stopActivityIndicator];
// Refresh table view to add cryptography information.
[self.tableView reloadData];
} failure:^(NSError *error) { } failure:^(NSError *error) {
[self stopActivityIndicator]; [self stopActivityIndicator];