-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display the consent tool in case of M_CONSENT_NOT_GIVEN error #498
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c564035
MXError: Add userInfo property and add consent not given constant
SBiOSoftWhare e7d671e
MXHTTPClient: Handle MXError creation from JSON response
SBiOSoftWhare 790185d
MXHTTPClient: Post a notification if user have not yet consent to GDPR
SBiOSoftWhare d0c2679
MXHTTPClient: Remove comments in .m already present in .h
SBiOSoftWhare 282f42e
MXError: Add \n at the end of - (id)initWithErrorCode:error:userInfo:…
SBiOSoftWhare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,24 @@ | |
*/ | ||
NSString * const MXHTTPClientErrorResponseDataKey = @"com.matrixsdk.httpclient.error.response.data"; | ||
|
||
/** | ||
Posted when the user did not consent to GDPR. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually, we do not comment symbols that already commented in .h |
||
*/ | ||
NSString* const kMXHTTPClientUserConsentNotGivenErrorNotification = @"kMXHTTPClientUserConsentNotGivenErrorNotification"; | ||
/** | ||
kMXHTTPClientUserConsentNotGivenErrorNotification userInfo key for consent URI | ||
*/ | ||
NSString* const kMXHTTPClientUserConsentNotGivenErrorNotificationConsentURIKey = @"kMXHTTPClientUserConsentNotGivenErrorNotificationConsentURIKey"; | ||
|
||
/** | ||
Matrix error API JSON Keys | ||
*/ | ||
static NSString* const kMXErrorCodeJSONKey = @"errcode"; | ||
static NSString* const kMXErrorMessageJSONKey = @"error"; | ||
|
||
static NSString* const kMXErrorConsentNotGivenConsentURIJSONKey = @"consent_uri"; | ||
|
||
|
||
@interface MXHTTPClient () | ||
{ | ||
/** | ||
|
@@ -285,11 +303,10 @@ - (void)tryRequest:(MXHTTPOperation*)mxHTTPOperation | |
{ | ||
NSLog(@"[MXHTTPClient] Error JSONResponse: %@", JSONResponse); | ||
|
||
if (JSONResponse[@"errcode"] || JSONResponse[@"error"]) | ||
if (JSONResponse[kMXErrorCodeJSONKey] || JSONResponse[kMXErrorMessageJSONKey]) | ||
{ | ||
// Extract values from the home server JSON response | ||
MXError *mxError = [[MXError alloc] initWithErrorCode:JSONResponse[@"errcode"] | ||
error:JSONResponse[@"error"]]; | ||
MXError *mxError = [self mxErrorFromJSON:JSONResponse]; | ||
|
||
if ([mxError.errcode isEqualToString:kMXErrCodeStringLimitExceeded]) | ||
{ | ||
|
@@ -325,6 +342,24 @@ - (void)tryRequest:(MXHTTPOperation*)mxHTTPOperation | |
NSLog(@"[MXHTTPClient] Giving up rate limited request %p: spent too long retrying.", mxHTTPOperation); | ||
} | ||
} | ||
if ([mxError.errcode isEqualToString:kMXErrCodeStringConsentNotGiven]) | ||
{ | ||
NSString* consentURI = mxError.userInfo[kMXErrorConsentNotGivenConsentURIJSONKey]; | ||
|
||
if (consentURI.length > 0) | ||
{ | ||
NSLog(@"[MXHTTPClient] User did not consent to GDPR"); | ||
|
||
// Send a notification if user did not consent to GDPR | ||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXHTTPClientUserConsentNotGivenErrorNotification | ||
object:self | ||
userInfo:@{ kMXHTTPClientUserConsentNotGivenErrorNotificationConsentURIKey: consentURI }]; | ||
} | ||
else | ||
{ | ||
NSLog(@"[MXHTTPClient] User did not consent to GDPR but fail to retrieve consent uri"); | ||
} | ||
} | ||
else | ||
{ | ||
error = [mxError createNSError]; | ||
|
@@ -721,4 +756,22 @@ - (void)setDefaultSecurityPolicy | |
} | ||
} | ||
|
||
- (MXError*)mxErrorFromJSON:(NSDictionary*)json | ||
{ | ||
// Add key/values other than error code and error message in user info | ||
NSMutableDictionary *userInfo = [json mutableCopy]; | ||
[userInfo removeObjectForKey:kMXErrorCodeJSONKey]; | ||
[userInfo removeObjectForKey:kMXErrorMessageJSONKey]; | ||
|
||
NSDictionary *mxErrorUserInfo = nil; | ||
|
||
if (userInfo.allKeys.count > 0) { | ||
mxErrorUserInfo = [NSDictionary dictionaryWithDictionary:userInfo]; | ||
} | ||
|
||
return [[MXError alloc] initWithErrorCode:json[kMXErrorCodeJSONKey] | ||
error:json[kMXErrorMessageJSONKey] | ||
userInfo:mxErrorUserInfo]; | ||
} | ||
|
||
@end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing \n