Merge pull request #1104 from vector-im/riot-1058

BF: Unknown devices modal from calling page is different that room page one
This commit is contained in:
manuroe 2017-03-15 17:39:09 +01:00 committed by GitHub
commit 0f5eb4f2bf
6 changed files with 137 additions and 6 deletions

View file

@ -226,6 +226,8 @@
"unknown_devices_alert_title" = "Room contains unknown devices";
"unknown_devices_alert" = "This room contains unknown devices which have not been verified.\nThis means there is no guarantee that the devices belong to the users they claim to.\nWe recommend you go through the verification process for each device before continuing, but you can resend the message without verifying if you prefer.";
"unknown_devices_send_anyway" = "Send Anyway";
"unknown_devices_call_anyway" = "Call Anyway";
"unknown_devices_answer_anyway" = "Answer Anyway";
"unknown_devices_verify" = "Verify...";
"unknown_devices_title" = "Unknown devices";

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="H1p-Uh-vWS">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="H1p-Uh-vWS">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
@ -116,7 +116,7 @@
<!--Users Devices View Controller-->
<scene sceneID="fKQ-Tq-qUc">
<objects>
<viewController id="z83-KC-trJ" customClass="UsersDevicesViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="UsersDevicesViewControllerStoryboardId" id="z83-KC-trJ" customClass="UsersDevicesViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="KBN-JV-gSS"/>
<viewControllerLayoutGuide type="bottom" id="lAN-yJ-zNI"/>
@ -355,7 +355,7 @@
</resources>
<inferredMetricsTieBreakers>
<segue reference="agy-3r-khl"/>
<segue reference="tcD-xb-ae8"/>
<segue reference="f5u-Y1-7nt"/>
<segue reference="cUw-vU-gJq"/>
</inferredMetricsTieBreakers>
</document>

View file

@ -26,10 +26,17 @@
#import "MXRoom+Riot.h"
#import "UsersDevicesViewController.h"
@interface CallViewController ()
{
// Display a gradient view above the screen
CAGradientLayer* gradientMaskLayer;
/**
Current alert (if any).
*/
MXKAlert *currentAlert;
}
@end
@ -160,6 +167,17 @@
self.callerImageView.clipsToBounds = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
if (currentAlert)
{
[currentAlert dismiss:NO];
currentAlert = nil;
}
[super viewWillDisappear:animated];
}
- (void)dealloc
{
}
@ -174,6 +192,99 @@
gradientMaskLayer = nil;
}
#pragma mark - MXCallDelegate
- (void)call:(MXCall *)call didEncounterError:(NSError *)error
{
if ([error.domain isEqualToString:MXEncryptingErrorDomain]
&& error.code == MXEncryptingErrorUnknownDeviceCode)
{
// There are unknown devices, check what the user wants to do
__weak __typeof(self) weakSelf = self;
MXUsersDevicesMap<MXDeviceInfo*> *unknownDevices = error.userInfo[MXEncryptingErrorUnknownDeviceDevicesKey];
[currentAlert dismiss:NO];
currentAlert = [[MXKAlert alloc] initWithTitle:[NSBundle mxk_localizedStringForKey:@"unknown_devices_alert_title"]
message:[NSBundle mxk_localizedStringForKey:@"unknown_devices_alert"]
style:MXKAlertStyleAlert];
[currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"unknown_devices_verify"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
// Get the UsersDevicesViewController from the storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UsersDevicesViewController *usersDevicesViewController = [storyboard instantiateViewControllerWithIdentifier:@"UsersDevicesViewControllerStoryboardId"];
[usersDevicesViewController displayUsersDevices:unknownDevices andMatrixSession:self.mainSession onComplete:^(BOOL doneButtonPressed) {
if (doneButtonPressed)
{
// Retry the call
if (call.isIncoming)
{
[call answer];
}
else
{
[call callWithVideo:call.isVideoCall];
}
}
else
{
// Ignore the call
[call hangup];
}
}];
// Show this screen within a navigation controller
UINavigationController *usersDevicesNavigationController = [[UINavigationController alloc] init];
[usersDevicesNavigationController pushViewController:usersDevicesViewController animated:NO];
[self presentViewController:usersDevicesNavigationController animated:YES completion:nil];
}
}];
[currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:(call.isIncoming ? @"unknown_devices_answer_anyway":@"unknown_devices_call_anyway")]
style:MXKAlertActionStyleDefault
handler:^(MXKAlert *alert) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
// Acknowledge the existence of all devices
[self startActivityIndicator];
[self.mainSession.crypto setDevicesKnown:unknownDevices complete:^{
[self stopActivityIndicator];
// Retry the call
if (call.isIncoming)
{
[call answer];
}
else
{
[call callWithVideo:call.isVideoCall];
}
}];
}
}];
currentAlert.mxkAccessibilityIdentifier = @"CallVCUnknownDevicesAlert";
[currentAlert showInViewController:self];
}
else
{
[super call:call didEncounterError:error];
}
}
#pragma mark - Properties
- (UIImage*)picturePlaceholder

View file

@ -2285,7 +2285,7 @@
if (unknownDevices)
{
UsersDevicesViewController *usersDevicesViewController = (UsersDevicesViewController *)segue.destinationViewController.childViewControllers.firstObject;
[usersDevicesViewController displayUsersDevices:unknownDevices andMatrixSession:self.roomDataSource.mxSession];
[usersDevicesViewController displayUsersDevices:unknownDevices andMatrixSession:self.roomDataSource.mxSession onComplete:nil];
unknownDevices = nil;
}

View file

@ -25,8 +25,13 @@
Display a map of users/devices.
@param usersDevices the map to display.
@param mxSession the Matrix session.
@param onComplete a block called when the user quits the screen
doneButtonPressed is:
- YES if the user clicked the Done button, meaning he acknowledges all unknown devices.
- NO if the user clicked the Cancel button, meaning he prefers to cancel the current request.
*/
- (void)displayUsersDevices:(MXUsersDevicesMap<MXDeviceInfo*>*)usersDevices andMatrixSession:(MXSession*)mxSession;
- (void)displayUsersDevices:(MXUsersDevicesMap<MXDeviceInfo*>*)usersDevices andMatrixSession:(MXSession*)mxSession onComplete:(void (^)(BOOL doneButtonPressed))onComplete;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

View file

@ -26,16 +26,19 @@
{
MXUsersDevicesMap<MXDeviceInfo*> *usersDevices;
MXSession *mxSession;
void (^onCompleteBlock)(BOOL doneButtonPressed);
}
@end
@implementation UsersDevicesViewController
- (void)displayUsersDevices:(MXUsersDevicesMap<MXDeviceInfo*>*)theUsersDevices andMatrixSession:(MXSession*)matrixSession;
- (void)displayUsersDevices:(MXUsersDevicesMap<MXDeviceInfo*>*)theUsersDevices andMatrixSession:(MXSession*)matrixSession onComplete:(void (^)(BOOL doneButtonPressed))onComplete
{
usersDevices = theUsersDevices;
mxSession = matrixSession;
onCompleteBlock = onComplete;
}
- (void)finalizeInit
@ -228,12 +231,22 @@
[self stopActivityIndicator];
[self dismissViewControllerAnimated:YES completion:nil];
if (onCompleteBlock)
{
onCompleteBlock(YES);
}
}];
}
- (IBAction)onCancel:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
if (onCompleteBlock)
{
onCompleteBlock(NO);
}
}
#pragma mark - Private methods