Skip to content

Commit

Permalink
Merge pull request #1872 from vector-im/riot_1871
Browse files Browse the repository at this point in the history
Display the consent tool in case of M_CONSENT_NOT_GIVEN error
  • Loading branch information
SBiOSoftWhare committed May 23, 2018
2 parents d29034e + b8db14d commit 40d0d4e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
83 changes: 83 additions & 0 deletions Riot/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

#include <MatrixSDK/MXUIKitBackgroundModeHandler.h>

#import "WebViewViewController.h"

@import PiwikTracker;

// Calls
Expand Down Expand Up @@ -210,6 +212,9 @@ The current call view controller (if any).

@property (strong, nonatomic) UIAlertController *logoutConfirmation;

@property (weak, nonatomic) UIAlertController *gdprConsentNotGivenAlertController;
@property (weak, nonatomic) UIViewController *gdprConsentViewController;

@property (nonatomic, nullable, copy) void (^registrationForRemoteNotificationsCompletion)(NSError *);


Expand Down Expand Up @@ -596,6 +601,9 @@ - (void)applicationDidBecomeActive:(UIApplication *)application

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

// Register to GDPR consent not given notification
[self registerUserConsentNotGivenNotification];

// Start monitoring reachability
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {

Expand Down Expand Up @@ -3979,4 +3987,79 @@ - (void)checkPendingRoomKeyRequests
}
}

#pragma mark - GDPR consent

// Observe user GDPR consent not given
- (void)registerUserConsentNotGivenNotification
{
[NSNotificationCenter.defaultCenter addObserverForName:kMXHTTPClientUserConsentNotGivenErrorNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *notification)
{
NSString *consentURI = notification.userInfo[kMXHTTPClientUserConsentNotGivenErrorNotificationConsentURIKey];
if (consentURI
&& self.gdprConsentNotGivenAlertController == nil
&& self.gdprConsentViewController == nil)
{
UIViewController *presentingViewController = self.window.rootViewController.presentedViewController ?: self.window.rootViewController;

__weak typeof(self) weakSelf = self;

MXSession *mainSession = self.mxSessions.firstObject;
NSString *homeServerName = mainSession.matrixRestClient.credentials.homeServerName;

NSString *alertMessage = [NSString stringWithFormat:NSLocalizedStringFromTable(@"gdpr_consent_not_given_alert_message", @"Vector", nil), homeServerName];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"settings_term_conditions", @"Vector", nil)
message:alertMessage
preferredStyle:UIAlertControllerStyleAlert];

[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"gdpr_consent_not_given_alert_review_now_action", @"Vector", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {

typeof(weakSelf) strongSelf = weakSelf;

if (strongSelf)
{
[strongSelf presentGDPRConsentFromViewController:presentingViewController consentURI:consentURI];
}
}]];

[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"later", @"Vector", nil)
style:UIAlertActionStyleCancel
handler:nil]];

[presentingViewController presentViewController:alert animated:YES completion:nil];

self.gdprConsentNotGivenAlertController = alert;
}
}];
}

- (void)presentGDPRConsentFromViewController:(UIViewController*)viewController consentURI:(NSString*)consentURI
{
WebViewViewController *webViewViewController = [[WebViewViewController alloc] initWithURL:consentURI];
webViewViewController.title = NSLocalizedStringFromTable(@"settings_term_conditions", @"Vector", nil);

UIBarButtonItem *closeBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSBundle mxk_localizedStringForKey:@"close"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(dismissGDPRConsent)];

webViewViewController.navigationItem.rightBarButtonItem = closeBarButtonItem;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:webViewViewController];

[viewController presentViewController:navigationController animated:YES completion:nil];

self.gdprConsentViewController = navigationController;
}

- (void)dismissGDPRConsent
{
[self.gdprConsentViewController dismissViewControllerAnimated:YES completion:nil];
}

@end
3 changes: 3 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,6 @@
"e2e_room_key_request_share_without_verifying" = "Share without verifying";
"e2e_room_key_request_ignore_request" = "Ignore request";

// GDPR
"gdpr_consent_not_given_alert_message" = "To continue using the %@ homeserver you must review and agree to the terms and conditions.";
"gdpr_consent_not_given_alert_review_now_action" = "Review now";

0 comments on commit 40d0d4e

Please sign in to comment.