From a095fc4a4d02b52a86590b25b4b044e686a5ff7f Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 21 Aug 2020 13:18:53 +0300 Subject: [PATCH 1/7] Wait for the first sync to complete loading --- Riot/Modules/Authentication/AuthenticationViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/Modules/Authentication/AuthenticationViewController.m b/Riot/Modules/Authentication/AuthenticationViewController.m index 907dfaac79..f9c2a071be 100644 --- a/Riot/Modules/Authentication/AuthenticationViewController.m +++ b/Riot/Modules/Authentication/AuthenticationViewController.m @@ -1218,7 +1218,7 @@ - (void)sessionStateDidChangeNotification:(NSNotification*)notification { MXSession *session = (MXSession*)notification.object; - if (session.state >= MXSessionStateStoreDataReady) + if (session.state >= MXSessionStateRunning) { [self unregisterSessionStateChangeNotification]; From 4548d3641212cbcbdbc2509a65bbcc872852dc27 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 21 Aug 2020 13:19:46 +0300 Subject: [PATCH 2/7] Update CHANGES.rst --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 9b384bf257..08f1078396 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,7 @@ Improvements: Bugfix: * Fix biometry name null case (#3551). * Avoid email validation link to redirect to web app (#3513). + * Wait for first sync complete before stopping loading screen (#3336). API Change: * From 266204b5f4814250c544542fb20b06a7db78c562 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 21 Aug 2020 13:24:17 +0300 Subject: [PATCH 3/7] Revert session state --- Riot/Modules/Authentication/AuthenticationViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/Modules/Authentication/AuthenticationViewController.m b/Riot/Modules/Authentication/AuthenticationViewController.m index f9c2a071be..907dfaac79 100644 --- a/Riot/Modules/Authentication/AuthenticationViewController.m +++ b/Riot/Modules/Authentication/AuthenticationViewController.m @@ -1218,7 +1218,7 @@ - (void)sessionStateDidChangeNotification:(NSNotification*)notification { MXSession *session = (MXSession*)notification.object; - if (session.state >= MXSessionStateRunning) + if (session.state >= MXSessionStateStoreDataReady) { [self unregisterSessionStateChangeNotification]; From 80891db6c2fd224cdb97a203f4f1377011b4ca8c Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 21 Aug 2020 14:06:12 +0300 Subject: [PATCH 4/7] Make MXSessionState comparable --- Riot.xcodeproj/project.pbxproj | 4 ++++ Riot/Categories/MXSessionState.swift | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 Riot/Categories/MXSessionState.swift diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 3a7157da30..da794c940c 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -848,6 +848,7 @@ ECAE7AE524EC0E01002FA813 /* TableViewSections.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECAE7AE424EC0E01002FA813 /* TableViewSections.swift */; }; ECAE7AE724EC15F7002FA813 /* Section.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECAE7AE624EC15F7002FA813 /* Section.swift */; }; ECAE7AE924EC1888002FA813 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECAE7AE824EC1888002FA813 /* Row.swift */; }; + ECAE7AEE24EFDD1F002FA813 /* MXSessionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECAE7AED24EFDD1F002FA813 /* MXSessionState.swift */; }; ECB101302477CFDB00CF8C11 /* UITableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB1012C2477CFDB00CF8C11 /* UITableView.swift */; }; ECB101312477CFDB00CF8C11 /* UILabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB1012D2477CFDB00CF8C11 /* UILabel.swift */; }; ECB101322477CFDB00CF8C11 /* UIDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB1012E2477CFDB00CF8C11 /* UIDevice.swift */; }; @@ -1976,6 +1977,7 @@ ECAE7AE424EC0E01002FA813 /* TableViewSections.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewSections.swift; sourceTree = ""; }; ECAE7AE624EC15F7002FA813 /* Section.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Section.swift; sourceTree = ""; }; ECAE7AE824EC1888002FA813 /* Row.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = ""; }; + ECAE7AED24EFDD1F002FA813 /* MXSessionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSessionState.swift; sourceTree = ""; }; ECB1012C2477CFDB00CF8C11 /* UITableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableView.swift; sourceTree = ""; }; ECB1012D2477CFDB00CF8C11 /* UILabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UILabel.swift; sourceTree = ""; }; ECB1012E2477CFDB00CF8C11 /* UIDevice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIDevice.swift; sourceTree = ""; }; @@ -4964,6 +4966,7 @@ B1DCC63322E72C1B00625807 /* UISearchBar.swift */, B11291EB238D704C0077B478 /* FloatingPoint.swift */, 32FD757524D2C9BA00BA7B37 /* Bundle.swift */, + ECAE7AED24EFDD1F002FA813 /* MXSessionState.swift */, ); path = Categories; sourceTree = ""; @@ -5897,6 +5900,7 @@ F05927C91FDED836009F2A68 /* MXGroup+Riot.m in Sources */, B1B5594520EF7BD000210D55 /* TableViewCellWithCollectionView.m in Sources */, B1A6C109238828A6002882FD /* SlidingModalPresentationDelegate.swift in Sources */, + ECAE7AEE24EFDD1F002FA813 /* MXSessionState.swift in Sources */, 32DB557722FDADE50016329E /* ServiceTermsModalCoordinator.swift in Sources */, B185145B24B8C98200EE19EA /* MajorUpdateViewController.swift in Sources */, 32DB557922FDADE50016329E /* ServiceTermsModalScreenViewModel.swift in Sources */, diff --git a/Riot/Categories/MXSessionState.swift b/Riot/Categories/MXSessionState.swift new file mode 100644 index 0000000000..9f43992a80 --- /dev/null +++ b/Riot/Categories/MXSessionState.swift @@ -0,0 +1,25 @@ +// +// Copyright 2020 Vector Creations Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation + +extension MXSessionState: Comparable { + + public static func < (lhs: MXSessionState, rhs: MXSessionState) -> Bool { + return lhs.rawValue < rhs.rawValue + } + +} From 4caf2602cd2b6c5b678b0fa1f606ffe5a44346e2 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 21 Aug 2020 14:07:43 +0300 Subject: [PATCH 5/7] Wait for session sync complete --- ...yVerificationSelfVerifyWaitViewModel.swift | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewModel.swift b/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewModel.swift index 702e7fc830..e84c39604f 100644 --- a/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewModel.swift +++ b/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewModel.swift @@ -28,7 +28,7 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai private let keyVerificationService: KeyVerificationService private let verificationManager: MXKeyVerificationManager private let isNewSignIn: Bool - private let secretsRecoveryAvailability: SecretsRecoveryAvailability + private var secretsRecoveryAvailability: SecretsRecoveryAvailability private var keyVerificationRequest: MXKeyVerificationRequest? // MARK: Public @@ -62,7 +62,8 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai switch self.secretsRecoveryAvailability { case .notAvailable: fatalError("Should not happen: When recovery is not available button is hidden") - case .available(let secretsRecoveryMode): self.coordinatorDelegate?.keyVerificationSelfVerifyWaitViewModel(self, wantsToRecoverSecretsWith: secretsRecoveryMode) + case .available(let secretsRecoveryMode): + self.coordinatorDelegate?.keyVerificationSelfVerifyWaitViewModel(self, wantsToRecoverSecretsWith: secretsRecoveryMode) } } } @@ -85,7 +86,31 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai }, failure: { [weak self] error in self?.update(viewState: .error(error)) }) + + continueLoadData() + } else { + // be sure that session has completed its first sync + if session.state >= MXSessionStateRunning { + continueLoadData() + } else { + // show loader + self.update(viewState: .loading) + NotificationCenter.default.addObserver(self, selector: #selector(sessionStateChanged), name: .mxSessionStateDidChange, object: session) + } + } + } + + @objc + private func sessionStateChanged() { + if session.state >= MXSessionStateRunning { + NotificationCenter.default.removeObserver(self, name: .mxSessionStateDidChange, object: session) + continueLoadData() } + } + + private func continueLoadData() { + // update availability again + self.secretsRecoveryAvailability = session.crypto.recoveryService.vc_availability let viewData = KeyVerificationSelfVerifyWaitViewData(isNewSignIn: self.isNewSignIn, secretsRecoveryAvailability: self.secretsRecoveryAvailability) From b4ff819000058aa7506dc5d3014ab27a103c9dfb Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 21 Aug 2020 16:29:07 +0300 Subject: [PATCH 6/7] Add string value for loading --- Riot/Assets/en.lproj/Vector.strings | 1 + Riot/Generated/Strings.swift | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 07aba72e56..463b8c0031 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -1121,6 +1121,7 @@ "device_verification_self_verify_wait_recover_secrets_without_passphrase" = "Use Recovery Key"; "device_verification_self_verify_wait_recover_secrets_with_passphrase" = "Use Recovery Passphrase or Key"; "device_verification_self_verify_wait_recover_secrets_additional_information" = "If you can't accessing an existing session"; +"device_verification_self_verify_wait_recover_secrets_checking_availability" = "Checking for other verification capabilities ..."; // MARK: Verify diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index ffdd4d08c3..34a325d639 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -926,6 +926,10 @@ internal enum VectorL10n { internal static var deviceVerificationSelfVerifyWaitRecoverSecretsAdditionalInformation: String { return VectorL10n.tr("Vector", "device_verification_self_verify_wait_recover_secrets_additional_information") } + /// Checking for other verification capabilities ... + internal static var deviceVerificationSelfVerifyWaitRecoverSecretsCheckingAvailability: String { + return VectorL10n.tr("Vector", "device_verification_self_verify_wait_recover_secrets_checking_availability") + } /// Use Recovery Passphrase or Key internal static var deviceVerificationSelfVerifyWaitRecoverSecretsWithPassphrase: String { return VectorL10n.tr("Vector", "device_verification_self_verify_wait_recover_secrets_with_passphrase") From cae2c36ad889a157dc1b33bcb5b608fa15382923 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 21 Aug 2020 16:31:22 +0300 Subject: [PATCH 7/7] Add new loading state, add a label and activity indicator for loading state --- ...ionSelfVerifyWaitViewController.storyboard | 55 ++++++++++++++----- ...ficationSelfVerifyWaitViewController.swift | 17 +++++- ...yVerificationSelfVerifyWaitViewModel.swift | 2 +- ...yVerificationSelfVerifyWaitViewState.swift | 1 + 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewController.storyboard b/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewController.storyboard index a854f88783..d3db75f1f1 100644 --- a/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewController.storyboard +++ b/Riot/Modules/KeyVerification/Device/SelfVerifyWait/KeyVerificationSelfVerifyWaitViewController.storyboard @@ -1,11 +1,9 @@ - - - - + + - + @@ -19,16 +17,16 @@ - + - + - + - + @@ -85,19 +83,43 @@ Riot X for Android - + + + + + + + + + + + + + + + + + + + + - +