From f4711878085ad307029ca24acb7fdb490681d9bb Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 8 Aug 2018 11:28:00 +0200 Subject: [PATCH 01/11] Create GDPRConsentViewController --- Riot.xcodeproj/project.pbxproj | 12 +++++ .../GDPR/GDPRConsentViewController.swift | 53 +++++++++++++++++++ Riot/SupportingFiles/Riot-Bridging-Header.h | 1 + 3 files changed, 66 insertions(+) create mode 100644 Riot/Modules/GDPR/GDPRConsentViewController.swift diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index f5b9e3f66..302045a34 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -60,6 +60,7 @@ B169331520F3CAFC00746532 /* PublicRoomTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B169330F20F3CAFC00746532 /* PublicRoomTableViewCell.xib */; }; B169331620F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = B169331220F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m */; }; B169331720F3CBE000746532 /* RecentCellData.m in Sources */ = {isa = PBXBuildFile; fileRef = B16932F920F3C51900746532 /* RecentCellData.m */; }; + B17982FF2119FED2001FD722 /* GDPRConsentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B17982FE2119FED2001FD722 /* GDPRConsentViewController.swift */; }; B1B5571820EE6C4D00210D55 /* CountryPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567A20EE6C4C00210D55 /* CountryPickerViewController.m */; }; B1B5571920EE6C4D00210D55 /* LanguagePickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567C20EE6C4C00210D55 /* LanguagePickerViewController.m */; }; B1B5571A20EE6C4D00210D55 /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567E20EE6C4C00210D55 /* SettingsViewController.m */; }; @@ -492,6 +493,7 @@ B169331020F3CAFC00746532 /* PublicRoomTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PublicRoomTableViewCell.h; sourceTree = ""; }; B169331220F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PublicRoomsDirectoryDataSource.m; sourceTree = ""; }; B169331320F3CAFC00746532 /* PublicRoomsDirectoryDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PublicRoomsDirectoryDataSource.h; sourceTree = ""; }; + B17982FE2119FED2001FD722 /* GDPRConsentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GDPRConsentViewController.swift; sourceTree = ""; }; B1B5567920EE6C4C00210D55 /* CountryPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CountryPickerViewController.h; sourceTree = ""; }; B1B5567A20EE6C4C00210D55 /* CountryPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CountryPickerViewController.m; sourceTree = ""; }; B1B5567C20EE6C4C00210D55 /* LanguagePickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LanguagePickerViewController.m; sourceTree = ""; }; @@ -1274,12 +1276,21 @@ path = DataSources; sourceTree = ""; }; + B17982FD2119FEA7001FD722 /* GDPR */ = { + isa = PBXGroup; + children = ( + B17982FE2119FED2001FD722 /* GDPRConsentViewController.swift */, + ); + path = GDPR; + sourceTree = ""; + }; B1B5567620EE6C4C00210D55 /* Modules */ = { isa = PBXGroup; children = ( B1B556EA20EE6C4C00210D55 /* Main */, B1B556CA20EE6C4C00210D55 /* TabBar */, B1B556F920EE6C4C00210D55 /* Authentication */, + B17982FD2119FEA7001FD722 /* GDPR */, B1B5568420EE6C4C00210D55 /* Home */, B1B556C720EE6C4C00210D55 /* Favorites */, B1B556E720EE6C4C00210D55 /* People */, @@ -3080,6 +3091,7 @@ B1B558CF20EF768F00210D55 /* RoomIncomingEncryptedTextMsgWithPaginationTitleBubbleCell.m in Sources */, B1B5575120EE6C4D00210D55 /* AuthenticationViewController.m in Sources */, B1B5571820EE6C4D00210D55 /* CountryPickerViewController.m in Sources */, + B17982FF2119FED2001FD722 /* GDPRConsentViewController.swift in Sources */, B1B5575A20EE6C4D00210D55 /* UnifiedSearchViewController.m in Sources */, B1B5572820EE6C4D00210D55 /* RoomViewController.m in Sources */, B1B558C720EF768F00210D55 /* RoomOutgoingEncryptedTextMsgWithPaginationTitleBubbleCell.m in Sources */, diff --git a/Riot/Modules/GDPR/GDPRConsentViewController.swift b/Riot/Modules/GDPR/GDPRConsentViewController.swift new file mode 100644 index 000000000..a60ea8839 --- /dev/null +++ b/Riot/Modules/GDPR/GDPRConsentViewController.swift @@ -0,0 +1,53 @@ +/* + Copyright 2018 New Vector 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 + +@objc protocol GDPRConsentViewControllerDelegate: class { + func gdprConsentViewControllerDidConsentToGDPRWithSucces(_ gdprConsentViewController: GDPRConsentViewController) +} + +/// GPDR consent screen. +final public class GDPRConsentViewController : WebViewViewController { + + // MARK: - Constants + + private static let consentSuccessURLString = "https://matrix.org/_matrix/consent" + + // MARK: - Properties + + @objc weak var delegate: GDPRConsentViewControllerDelegate? + + // MARK: - View life cycle + + public override func viewDidLoad() { + super.viewDidLoad() + + self.title = NSLocalizedString("settings_term_conditions", tableName: "Vector", comment: "") + } + + // MARK: - Superclass Overrides + + override public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + super.webView(webView, didFinish: navigation) + + // When navigation finish on URL `consentSuccessURLString`, it means that user consent to GDPR + if let url = webView.url, url.absoluteString == GDPRConsentViewController.consentSuccessURLString { + NSLog("[GDPRConsentViewController] User consent to GDPR") + self.delegate?.gdprConsentViewControllerDidConsentToGDPRWithSucces(self) + } + } +} diff --git a/Riot/SupportingFiles/Riot-Bridging-Header.h b/Riot/SupportingFiles/Riot-Bridging-Header.h index 1b2cb5d6d..7fed3e175 100644 --- a/Riot/SupportingFiles/Riot-Bridging-Header.h +++ b/Riot/SupportingFiles/Riot-Bridging-Header.h @@ -2,3 +2,4 @@ // Use this file to import your target's public headers that you would like to expose to Swift. // +#import "WebViewViewController.h" From 8b23570ad15de78b8a3d802159cf5774d25a95ea Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 8 Aug 2018 11:30:50 +0200 Subject: [PATCH 02/11] Now use GDPRConsentViewController in AppDelegate in order to present GDPR consent and dismiss controller automatically when accept consent. --- Riot/AppDelegate.m | 28 ++++++++++++------- .../GDPR/GDPRConsentViewController.swift | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index 50acffa9d..186d40b3b 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -81,7 +81,7 @@ NSString *const kAppDelegateDidTapStatusBarNotification = @"kAppDelegateDidTapStatusBarNotification"; NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateNetworkStatusDidChangeNotification"; -@interface AppDelegate () +@interface AppDelegate () { /** Reachability observer @@ -213,7 +213,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN @property (strong, nonatomic) UIAlertController *logoutConfirmation; @property (weak, nonatomic) UIAlertController *gdprConsentNotGivenAlertController; -@property (weak, nonatomic) UIViewController *gdprConsentViewController; +@property (weak, nonatomic) UIViewController *gdprConsentController; @property (nonatomic, nullable, copy) void (^registrationForRemoteNotificationsCompletion)(NSError *); @@ -3979,10 +3979,10 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN NSString *consentURI = notification.userInfo[kMXHTTPClientUserConsentNotGivenErrorNotificationConsentURIKey]; if (consentURI && self.gdprConsentNotGivenAlertController.presentingViewController == nil - && self.gdprConsentViewController.presentingViewController == nil) + && self.gdprConsentController.presentingViewController == nil) { self.gdprConsentNotGivenAlertController = nil; - self.gdprConsentViewController = nil; + self.gdprConsentController = nil; UIViewController *presentingViewController = self.window.rootViewController.presentedViewController ?: self.window.rootViewController; @@ -4022,26 +4022,34 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN - (void)presentGDPRConsentFromViewController:(UIViewController*)viewController consentURI:(NSString*)consentURI { - WebViewViewController *webViewViewController = [[WebViewViewController alloc] initWithURL:consentURI]; - webViewViewController.title = NSLocalizedStringFromTable(@"settings_term_conditions", @"Vector", nil); + GDPRConsentViewController *gdprConsentViewController = [[GDPRConsentViewController alloc] initWithURL:consentURI]; UIBarButtonItem *closeBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSBundle mxk_localizedStringForKey:@"close"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissGDPRConsent)]; - webViewViewController.navigationItem.leftBarButtonItem = closeBarButtonItem; + gdprConsentViewController.navigationItem.leftBarButtonItem = closeBarButtonItem; - UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:webViewViewController]; + UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:gdprConsentViewController]; [viewController presentViewController:navigationController animated:YES completion:nil]; - self.gdprConsentViewController = navigationController; + self.gdprConsentController = navigationController; + + gdprConsentViewController.delegate = self; } - (void)dismissGDPRConsent { - [self.gdprConsentViewController dismissViewControllerAnimated:YES completion:nil]; + [self.gdprConsentController dismissViewControllerAnimated:YES completion:nil]; +} + +#pragma mark - GDPRConsentViewControllerDelegate + +- (void)gdprConsentViewControllerDidConsentToGDPRWithSucces:(GDPRConsentViewController *)gdprConsentViewController +{ + [self dismissGDPRConsent]; } #pragma mark - Settings diff --git a/Riot/Modules/GDPR/GDPRConsentViewController.swift b/Riot/Modules/GDPR/GDPRConsentViewController.swift index a60ea8839..07d7cf07f 100644 --- a/Riot/Modules/GDPR/GDPRConsentViewController.swift +++ b/Riot/Modules/GDPR/GDPRConsentViewController.swift @@ -21,7 +21,7 @@ import Foundation } /// GPDR consent screen. -final public class GDPRConsentViewController : WebViewViewController { +final public class GDPRConsentViewController: WebViewViewController { // MARK: - Constants From 16a84606e1dd9d81426f0d76815dcddd630eba4d Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 8 Aug 2018 18:34:31 +0200 Subject: [PATCH 03/11] Create `OnBoardingManager` in order to manage onboarding steps, like create DM room with riot bot. --- Riot.xcodeproj/project.pbxproj | 12 +++ .../OnBoarding/OnBoardingManager.swift | 82 +++++++++++++++++++ Riot/SupportingFiles/Riot-Bridging-Header.h | 1 + 3 files changed, 95 insertions(+) create mode 100644 Riot/Managers/OnBoarding/OnBoardingManager.swift diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 302045a34..8b21896d1 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -61,6 +61,7 @@ B169331620F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = B169331220F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m */; }; B169331720F3CBE000746532 /* RecentCellData.m in Sources */ = {isa = PBXBuildFile; fileRef = B16932F920F3C51900746532 /* RecentCellData.m */; }; B17982FF2119FED2001FD722 /* GDPRConsentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B17982FE2119FED2001FD722 /* GDPRConsentViewController.swift */; }; + B1798302211B13B3001FD722 /* OnBoardingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1798301211B13B3001FD722 /* OnBoardingManager.swift */; }; B1B5571820EE6C4D00210D55 /* CountryPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567A20EE6C4C00210D55 /* CountryPickerViewController.m */; }; B1B5571920EE6C4D00210D55 /* LanguagePickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567C20EE6C4C00210D55 /* LanguagePickerViewController.m */; }; B1B5571A20EE6C4D00210D55 /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567E20EE6C4C00210D55 /* SettingsViewController.m */; }; @@ -494,6 +495,7 @@ B169331220F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PublicRoomsDirectoryDataSource.m; sourceTree = ""; }; B169331320F3CAFC00746532 /* PublicRoomsDirectoryDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PublicRoomsDirectoryDataSource.h; sourceTree = ""; }; B17982FE2119FED2001FD722 /* GDPRConsentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GDPRConsentViewController.swift; sourceTree = ""; }; + B1798301211B13B3001FD722 /* OnBoardingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnBoardingManager.swift; sourceTree = ""; }; B1B5567920EE6C4C00210D55 /* CountryPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CountryPickerViewController.h; sourceTree = ""; }; B1B5567A20EE6C4C00210D55 /* CountryPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CountryPickerViewController.m; sourceTree = ""; }; B1B5567C20EE6C4C00210D55 /* LanguagePickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LanguagePickerViewController.m; sourceTree = ""; }; @@ -1284,6 +1286,14 @@ path = GDPR; sourceTree = ""; }; + B1798300211B137B001FD722 /* OnBoarding */ = { + isa = PBXGroup; + children = ( + B1798301211B13B3001FD722 /* OnBoardingManager.swift */, + ); + path = OnBoarding; + sourceTree = ""; + }; B1B5567620EE6C4C00210D55 /* Modules */ = { isa = PBXGroup; children = ( @@ -2316,6 +2326,7 @@ B1B5597C20EFC3DF00210D55 /* Managers */ = { isa = PBXGroup; children = ( + B1798300211B137B001FD722 /* OnBoarding */, B1B5598B20EFC5E400210D55 /* Analytics */, B1B5598920EFC41100210D55 /* BugReport */, B1B5598A20EFC42100210D55 /* Settings */, @@ -3081,6 +3092,7 @@ B1B5579920EF575B00210D55 /* AuthInputsView.m in Sources */, B1B5597520EFB02A00210D55 /* InviteRecentTableViewCell.m in Sources */, B1B5571E20EE6C4D00210D55 /* ContactDetailsViewController.m in Sources */, + B1798302211B13B3001FD722 /* OnBoardingManager.swift in Sources */, B1B5573520EE6C4D00210D55 /* GroupDetailsViewController.m in Sources */, B1B5575220EE6C4D00210D55 /* RoomKeyRequestViewController.m in Sources */, F083BD1E1E7009ED00A9B29C /* AppDelegate.m in Sources */, diff --git a/Riot/Managers/OnBoarding/OnBoardingManager.swift b/Riot/Managers/OnBoarding/OnBoardingManager.swift new file mode 100644 index 000000000..5a574c5b5 --- /dev/null +++ b/Riot/Managers/OnBoarding/OnBoardingManager.swift @@ -0,0 +1,82 @@ +/* + Copyright 2018 New Vector 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 + +/// `OnBoardingManager` is used to manage onboarding steps, like create DM room with riot bot. +final public class OnBoardingManager: NSObject { + + // MARK: - Constants + + private enum Constants { + static let riotBotMatrixId = "@riot-bot:matrix.org" + static let createRiotBotDMRequestMaxNumberOfTries: UInt = UInt.max + } + + // MARK: - Properties + + private var session: MXSession + + // MARK: - Setup & Teardown + + @objc init(session: MXSession) { + self.session = session + + super.init() + } + + // MARK: - Public + + @objc func createRiotBotDirectMessageIfNeeded(sucess: (() -> Void)?, failure: ((Error) -> Void)?) { + + // Check user has join no rooms so is a new comer + guard self.isUSerJoinedARoom() == false else { + return + } + + // Create DM room with Riot-bot + + let httpOperation = self.session.createRoom(name: nil, visibility: .private, alias: nil, topic: nil, invite: [Constants.riotBotMatrixId], invite3PID: nil, isDirect: true, preset: .trustedPrivateChat) { (response) in + + switch response { + case .success(_): + sucess?() + case .failure(let error): + NSLog("[OnBoardingManager] Create chat with riot-bot failed with error \(error)"); + failure?(error) + } + + } + + // Make multipe tries, until we get a response + httpOperation.maxNumberOfTries = Constants.createRiotBotDMRequestMaxNumberOfTries + } + + // MARK: - Private + + private func isUSerJoinedARoom() -> Bool { + var isUSerJoinedARoom = false + + for roomSummary in self.session.roomsSummaries() { + if case .join = roomSummary.membership { + isUSerJoinedARoom = true + break + } + } + + return isUSerJoinedARoom + } +} diff --git a/Riot/SupportingFiles/Riot-Bridging-Header.h b/Riot/SupportingFiles/Riot-Bridging-Header.h index 7fed3e175..59026bb56 100644 --- a/Riot/SupportingFiles/Riot-Bridging-Header.h +++ b/Riot/SupportingFiles/Riot-Bridging-Header.h @@ -2,4 +2,5 @@ // Use this file to import your target's public headers that you would like to expose to Swift. // +@import MatrixSDK; #import "WebViewViewController.h" From 283c862692b14f526c72c64e9073e8da72e5e287 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 8 Aug 2018 18:36:24 +0200 Subject: [PATCH 04/11] Now create riot bot direct message room after GDPR consent success. --- Riot/AppDelegate.m | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index 186d40b3b..a8ea968b4 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -215,6 +215,11 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN @property (weak, nonatomic) UIAlertController *gdprConsentNotGivenAlertController; @property (weak, nonatomic) UIViewController *gdprConsentController; +/** + Used to manage on boarding steps, like create DM with riot bot + */ +@property (strong, nonatomic) OnBoardingManager *onBoardingManager; + @property (nonatomic, nullable, copy) void (^registrationForRemoteNotificationsCompletion)(NSError *); @@ -4049,7 +4054,29 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN - (void)gdprConsentViewControllerDidConsentToGDPRWithSucces:(GDPRConsentViewController *)gdprConsentViewController { - [self dismissGDPRConsent]; + MXSession *session = mxSessionArray.firstObject; + + self.onBoardingManager = [[OnBoardingManager alloc] initWithSession:session]; + + MXWeakify(self); + MXWeakify(gdprConsentViewController); + + [gdprConsentViewController startActivityIndicator]; + + void (^createRiotBotDMcompletion)(void) = ^() { + + MXStrongifyAndReturnIfNil(self); + + [weakgdprConsentViewController stopActivityIndicator]; + [self dismissGDPRConsent]; + self.onBoardingManager = nil; + }; + + [self.onBoardingManager createRiotBotDirectMessageIfNeededWithSucess:^{ + createRiotBotDMcompletion(); + } failure:^(NSError * _Nonnull error) { + createRiotBotDMcompletion(); + }]; } #pragma mark - Settings From c2c98311c727521d4bd9a37f733d06000aa2d936 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 9 Aug 2018 12:15:33 +0200 Subject: [PATCH 05/11] Update podfile, now use MatrixSDK/SwiftSupport --- Podfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Podfile b/Podfile index d9d427d94..2ef82b207 100644 --- a/Podfile +++ b/Podfile @@ -22,16 +22,17 @@ $matrixKitVersion = '0.7.15' # Method to import the right MatrixKit flavour def import_MatrixKit if $matrixKitVersion == 'local' - pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' + pod 'MatrixSDK/SwiftSupport', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixSDK/JingleCallStack', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec' else if $matrixKitVersion == 'develop' - pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' + pod 'MatrixSDK/SwiftSupport', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixSDK/JingleCallStack', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixKit', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop' else pod 'MatrixKit', $matrixKitVersion + pod 'MatrixSDK/SwiftSupport' pod 'MatrixSDK/JingleCallStack' end end @@ -40,16 +41,17 @@ end # Method to import the right MatrixKit/AppExtension flavour def import_MatrixKitAppExtension if $matrixKitVersion == 'local' - pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' + pod 'MatrixSDK/SwiftSupport', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixSDK/JingleCallStack', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' else if $matrixKitVersion == 'develop' - pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' + pod 'MatrixSDK/SwiftSupport', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixSDK/JingleCallStack', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixKit/AppExtension', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop' else pod 'MatrixKit/AppExtension', $matrixKitVersion + pod 'MatrixSDK/SwiftSupport' pod 'MatrixSDK/JingleCallStack' end end From 5221012417e70b7e96b4232c67a09ae358500e70 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 9 Aug 2018 12:16:27 +0200 Subject: [PATCH 06/11] Improve OnBoardingManager --- .../Managers/OnBoarding/OnBoardingManager.swift | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Riot/Managers/OnBoarding/OnBoardingManager.swift b/Riot/Managers/OnBoarding/OnBoardingManager.swift index 5a574c5b5..0bfe2429e 100644 --- a/Riot/Managers/OnBoarding/OnBoardingManager.swift +++ b/Riot/Managers/OnBoarding/OnBoardingManager.swift @@ -28,11 +28,11 @@ final public class OnBoardingManager: NSObject { // MARK: - Properties - private var session: MXSession + private let session: MXSession // MARK: - Setup & Teardown - @objc init(session: MXSession) { + @objc public init(session: MXSession) { self.session = session super.init() @@ -40,10 +40,12 @@ final public class OnBoardingManager: NSObject { // MARK: - Public - @objc func createRiotBotDirectMessageIfNeeded(sucess: (() -> Void)?, failure: ((Error) -> Void)?) { + @objc public func createRiotBotDirectMessageIfNeeded(success: (() -> Void)?, failure: ((Error) -> Void)?) { // Check user has join no rooms so is a new comer guard self.isUSerJoinedARoom() == false else { + // riot bot already created + success?() return } @@ -53,12 +55,11 @@ final public class OnBoardingManager: NSObject { switch response { case .success(_): - sucess?() + success?() case .failure(let error): NSLog("[OnBoardingManager] Create chat with riot-bot failed with error \(error)"); failure?(error) } - } // Make multipe tries, until we get a response @@ -68,9 +69,13 @@ final public class OnBoardingManager: NSObject { // MARK: - Private private func isUSerJoinedARoom() -> Bool { + guard let roomSummaries = self.session.roomsSummaries() else { + return false + } + var isUSerJoinedARoom = false - for roomSummary in self.session.roomsSummaries() { + for roomSummary in roomSummaries { if case .join = roomSummary.membership { isUSerJoinedARoom = true break From 19c46023de03c5e63e3aa71eb9907f8154a4c548 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 9 Aug 2018 14:28:45 +0200 Subject: [PATCH 07/11] Update changes --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 922eb3283..0c1ca38be 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,7 @@ Improvements: * Support room versioning (#1938). * Add support of lazy-loading of room members (#1931). * Chat screen: Add "view decrypted source" option on the selected event (#1642). +* Improve GDPR consent webview management (#1952) Changes in 0.6.20 (2018-07-13) =============================================== From f57395092e35391f8b4e375e6f84b51984af9bdd Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 9 Aug 2018 14:47:15 +0200 Subject: [PATCH 08/11] Fix OnBoardingManager method call in AppDelegate --- Riot/AppDelegate.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index a8ea968b4..eac3ef9b0 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -4072,7 +4072,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN self.onBoardingManager = nil; }; - [self.onBoardingManager createRiotBotDirectMessageIfNeededWithSucess:^{ + [self.onBoardingManager createRiotBotDirectMessageIfNeededWithSuccess:^{ createRiotBotDMcompletion(); } failure:^(NSError * _Nonnull error) { createRiotBotDMcompletion(); From dd61bf0c377e588a11d0743d42139cc825aa505e Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 9 Aug 2018 18:56:40 +0200 Subject: [PATCH 09/11] GDPRConsentViewController now do not take into account HS hostname to determine if user consent to GDPR. --- Riot/AppDelegate.m | 2 +- Riot/Modules/GDPR/GDPRConsentViewController.swift | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index eac3ef9b0..8047f6841 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -4052,7 +4052,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN #pragma mark - GDPRConsentViewControllerDelegate -- (void)gdprConsentViewControllerDidConsentToGDPRWithSucces:(GDPRConsentViewController *)gdprConsentViewController +- (void)gdprConsentViewControllerDidConsentToGDPRWithSuccess:(GDPRConsentViewController *)gdprConsentViewController { MXSession *session = mxSessionArray.firstObject; diff --git a/Riot/Modules/GDPR/GDPRConsentViewController.swift b/Riot/Modules/GDPR/GDPRConsentViewController.swift index 07d7cf07f..0723326a1 100644 --- a/Riot/Modules/GDPR/GDPRConsentViewController.swift +++ b/Riot/Modules/GDPR/GDPRConsentViewController.swift @@ -17,7 +17,7 @@ import Foundation @objc protocol GDPRConsentViewControllerDelegate: class { - func gdprConsentViewControllerDidConsentToGDPRWithSucces(_ gdprConsentViewController: GDPRConsentViewController) + func gdprConsentViewControllerDidConsentToGDPRWithSuccess(_ gdprConsentViewController: GDPRConsentViewController) } /// GPDR consent screen. @@ -25,9 +25,9 @@ final public class GDPRConsentViewController: WebViewViewController { // MARK: - Constants - private static let consentSuccessURLString = "https://matrix.org/_matrix/consent" + private static let consentSuccessURLPath = "/_matrix/consent" - // MARK: - Properties + // MARK: - Properties @objc weak var delegate: GDPRConsentViewControllerDelegate? @@ -44,10 +44,10 @@ final public class GDPRConsentViewController: WebViewViewController { override public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { super.webView(webView, didFinish: navigation) - // When navigation finish on URL `consentSuccessURLString`, it means that user consent to GDPR - if let url = webView.url, url.absoluteString == GDPRConsentViewController.consentSuccessURLString { + // When navigation finish on path `consentSuccessURLPath` with no query, it means that user consent to GDPR + if let url = webView.url, url.path == GDPRConsentViewController.consentSuccessURLPath, url.query == nil { NSLog("[GDPRConsentViewController] User consent to GDPR") - self.delegate?.gdprConsentViewControllerDidConsentToGDPRWithSucces(self) + self.delegate?.gdprConsentViewControllerDidConsentToGDPRWithSuccess(self) } } } From 6409dfeceb48e662ddc2b090e9188d5ba41fb074 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 9 Aug 2018 18:57:40 +0200 Subject: [PATCH 10/11] Fix typos in OnBoardingManager --- Riot/Managers/OnBoarding/OnBoardingManager.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Riot/Managers/OnBoarding/OnBoardingManager.swift b/Riot/Managers/OnBoarding/OnBoardingManager.swift index 0bfe2429e..fd17d0028 100644 --- a/Riot/Managers/OnBoarding/OnBoardingManager.swift +++ b/Riot/Managers/OnBoarding/OnBoardingManager.swift @@ -42,9 +42,9 @@ final public class OnBoardingManager: NSObject { @objc public func createRiotBotDirectMessageIfNeeded(success: (() -> Void)?, failure: ((Error) -> Void)?) { - // Check user has join no rooms so is a new comer - guard self.isUSerJoinedARoom() == false else { - // riot bot already created + // Check user has joined no rooms so is a new comer + guard self.isUserJoinedARoom() == false else { + // As the user has already rooms, one of their riot client has already created a room with riot bot success?() return } @@ -57,7 +57,7 @@ final public class OnBoardingManager: NSObject { case .success(_): success?() case .failure(let error): - NSLog("[OnBoardingManager] Create chat with riot-bot failed with error \(error)"); + NSLog("[OnBoardingManager] Create chat with riot-bot failed"); failure?(error) } } @@ -68,7 +68,7 @@ final public class OnBoardingManager: NSObject { // MARK: - Private - private func isUSerJoinedARoom() -> Bool { + private func isUserJoinedARoom() -> Bool { guard let roomSummaries = self.session.roomsSummaries() else { return false } From 956609b01df398b14b09e96c2ff6d3643e1e9532 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 9 Aug 2018 19:04:53 +0200 Subject: [PATCH 11/11] Add reference to 'MatrixSDK' podfile again just for clarity --- Podfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Podfile b/Podfile index 2ef82b207..90d6bd801 100644 --- a/Podfile +++ b/Podfile @@ -22,11 +22,13 @@ $matrixKitVersion = '0.7.15' # Method to import the right MatrixKit flavour def import_MatrixKit if $matrixKitVersion == 'local' + pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixSDK/SwiftSupport', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixSDK/JingleCallStack', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec' else if $matrixKitVersion == 'develop' + pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixSDK/SwiftSupport', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixSDK/JingleCallStack', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixKit', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop' @@ -41,11 +43,13 @@ end # Method to import the right MatrixKit/AppExtension flavour def import_MatrixKitAppExtension if $matrixKitVersion == 'local' + pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixSDK/SwiftSupport', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixSDK/JingleCallStack', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' else if $matrixKitVersion == 'develop' + pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixSDK/SwiftSupport', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixSDK/JingleCallStack', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' pod 'MatrixKit/AppExtension', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop'