diff --git a/CHANGES.rst b/CHANGES.rst index f6d72cbeb..2fd18c99c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,7 +8,7 @@ Changes to be released in next version * 🐛 Bugfix - * + * Self-verification: Fix compatibility with Element-Web (#4217). ⚠️ API Changes * diff --git a/Riot/Modules/Application/LegacyAppDelegate.m b/Riot/Modules/Application/LegacyAppDelegate.m index 501021ddc..ef261c069 100644 --- a/Riot/Modules/Application/LegacyAppDelegate.m +++ b/Riot/Modules/Application/LegacyAppDelegate.m @@ -2274,21 +2274,29 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni if (mainSession.crypto.crossSigning) { - NSLog(@"[AppDelegate] handleAppState: crossSigning.state: %@", @(mainSession.crypto.crossSigning.state)); - - switch (mainSession.crypto.crossSigning.state) - { - case MXCrossSigningStateCrossSigningExists: - NSLog(@"[AppDelegate] handleAppState: presentVerifyCurrentSessionAlertIfNeededWithSession"); - [_masterTabBarController presentVerifyCurrentSessionAlertIfNeededWithSession:mainSession]; - break; - case MXCrossSigningStateCanCrossSign: - NSLog(@"[AppDelegate] handleAppState: presentReviewUnverifiedSessionsAlertIfNeededWithSession"); - [_masterTabBarController presentReviewUnverifiedSessionsAlertIfNeededWithSession:mainSession]; - break; - default: - break; - } + // Get the up-to-date cross-signing state + MXWeakify(self); + [mainSession.crypto.crossSigning refreshStateWithSuccess:^(BOOL stateUpdated) { + MXStrongifyAndReturnIfNil(self); + + NSLog(@"[AppDelegate] handleAppState: crossSigning.state: %@", @(mainSession.crypto.crossSigning.state)); + + switch (mainSession.crypto.crossSigning.state) + { + case MXCrossSigningStateCrossSigningExists: + NSLog(@"[AppDelegate] handleAppState: presentVerifyCurrentSessionAlertIfNeededWithSession"); + [self.masterTabBarController presentVerifyCurrentSessionAlertIfNeededWithSession:mainSession]; + break; + case MXCrossSigningStateCanCrossSign: + NSLog(@"[AppDelegate] handleAppState: presentReviewUnverifiedSessionsAlertIfNeededWithSession"); + [self.masterTabBarController presentReviewUnverifiedSessionsAlertIfNeededWithSession:mainSession]; + break; + default: + break; + } + } failure:^(NSError * _Nonnull error) { + NSLog(@"[AppDelegate] handleAppState: crossSigning.state: %@. Error: %@", @(mainSession.crypto.crossSigning.state), error); + }]; } // TODO: We should wait that cross-signing screens are done before going further but it seems fine. Those screens @@ -3934,6 +3942,18 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni [self.incomingKeyVerificationRequestAlertController dismissViewControllerAnimated:NO completion:nil]; } + if (self.userNewSignInAlertController + && [session.myUserId isEqualToString:senderId]) + { + // If it is a self verification for my device, we can discard the new signin alert. + // Note: It will not work well with several devices to verify at the same time. + NSLog(@"[AppDelegate] presentNewKeyVerificationRequest: Remove the alert for new sign in detected"); + [self.userNewSignInAlertController dismissViewControllerAnimated:NO completion:^{ + self.userNewSignInAlertController = nil; + [self presentNewKeyVerificationRequestAlertForSession:session senderName:senderName senderId:senderId request:keyVerificationRequest]; + }]; + } + NSString *senderInfo; if (senderName) @@ -3955,7 +3975,6 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni } }; - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"key_verification_tile_request_incoming_title", @"Vector", nil) message:senderInfo preferredStyle:UIAlertControllerStyleAlert]; diff --git a/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewModel.swift b/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewModel.swift index badcf9dcf..6da9e3ccf 100644 --- a/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewModel.swift +++ b/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewModel.swift @@ -91,6 +91,21 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai } else { // be sure that session has completed its first sync if session.state >= MXSessionStateRunning { + + // Always send request instead of waiting for an incoming one as per recent EW changes + print("[KeyVerificationSelfVerifyWaitViewModel] loadData: Send a verification request to all devices instead of waiting") + + let keyVerificationService = KeyVerificationService() + self.verificationManager.requestVerificationByToDevice(withUserId: self.session.myUserId, deviceIds: nil, methods: keyVerificationService.supportedKeyVerificationMethods(), success: { [weak self] (keyVerificationRequest) in + guard let self = self else { + return + } + + self.keyVerificationRequest = keyVerificationRequest + + }, failure: { [weak self] error in + self?.update(viewState: .error(error)) + }) continueLoadData() } else { // show loader