SettingsVC: Use CrossSigningSetupCoordinatorBridgePresenter to setup cross signing.

This commit is contained in:
SBiOSoftWhare
2021-02-03 12:08:26 +01:00
parent 6bb5d2eade
commit de9e236edb
+37 -51
View File
@@ -249,6 +249,8 @@ TableViewSectionsDelegate>
@property (nonatomic, strong) InviteFriendsPresenter *inviteFriendsPresenter;
@property (nonatomic, strong) CrossSigningSetupCoordinatorBridgePresenter *crossSigningSetupCoordinatorBridgePresenter;
@end
@implementation SettingsViewController
@@ -4029,58 +4031,42 @@ TableViewSectionsDelegate>
message:(NSString*)message
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure
{
__block UIViewController *viewController;
[self startActivityIndicator];
// Get credentials to set up cross-signing
NSString *path = [NSString stringWithFormat:@"%@/keys/device_signing/upload", kMXAPIPrefixPathUnstable];
_authenticatedSessionViewControllerFactory = [[AuthenticatedSessionViewControllerFactory alloc] initWithSession:self.mainSession];
[_authenticatedSessionViewControllerFactory viewControllerForPath:path
httpMethod:@"POST"
title:title
message:message
onViewController:^(UIViewController * _Nonnull theViewController)
{
viewController = theViewController;
[self presentViewController:viewController animated:YES completion:nil];
} onAuthenticated:^(NSDictionary * _Nonnull authParams) {
[viewController dismissViewControllerAnimated:NO completion:nil];
viewController = nil;
MXCrossSigning *crossSigning = self.mainSession.crypto.crossSigning;
if (crossSigning)
{
[crossSigning setupWithAuthParams:authParams success:^{
[self stopActivityIndicator];
success();
} failure:^(NSError * _Nonnull error) {
[self stopActivityIndicator];
[[AppDelegate theDelegate] showErrorAsAlert:error];
failure(error);
}];
}
} onCancelled:^{
[self stopActivityIndicator];
[viewController dismissViewControllerAnimated:NO completion:nil];
viewController = nil;
failure(nil);
} onFailure:^(NSError * _Nonnull error) {
[self stopActivityIndicator];
[[AppDelegate theDelegate] showErrorAsAlert:error];
[viewController dismissViewControllerAnimated:NO completion:nil];
viewController = nil;
failure(error);
}];
}
{
[self startActivityIndicator];
self.view.userInteractionEnabled = NO;
MXWeakify(self);
void (^animationCompletion)(void) = ^void () {
MXStrongifyAndReturnIfNil(self);
[self stopActivityIndicator];
self.view.userInteractionEnabled = YES;
[self.crossSigningSetupCoordinatorBridgePresenter dismissWithAnimated:YES completion:^{}];
self.crossSigningSetupCoordinatorBridgePresenter = nil;
};
CrossSigningSetupCoordinatorBridgePresenter *crossSigningSetupCoordinatorBridgePresenter = [[CrossSigningSetupCoordinatorBridgePresenter alloc] initWithSession:self.mainSession];
[crossSigningSetupCoordinatorBridgePresenter presentWith:title
message:message
from:self
animated:YES
success:^{
animationCompletion();
success();
} cancel:^{
animationCompletion();
failure(nil);
} failure:^(NSError * _Nonnull error) {
animationCompletion();
[[AppDelegate theDelegate] showErrorAsAlert:error];
failure(error);
}];
self.crossSigningSetupCoordinatorBridgePresenter = crossSigningSetupCoordinatorBridgePresenter;
}
#pragma mark - SingleImagePickerPresenterDelegate