diff --git a/Riot/Managers/Widgets/WidgetManager.h b/Riot/Managers/Widgets/WidgetManager.h index a15928789..f8d027185 100644 --- a/Riot/Managers/Widgets/WidgetManager.h +++ b/Riot/Managers/Widgets/WidgetManager.h @@ -56,10 +56,12 @@ typedef enum : NSUInteger WidgetManagerErrorCodeNotEnoughPower, WidgetManagerErrorCodeCreationFailed, WidgetManagerErrorCodeNoIntegrationsServerConfigured, - WidgetManagerErrorCodeFailedToConnectToIntegrationsServer + WidgetManagerErrorCodeFailedToConnectToIntegrationsServer, + WidgetManagerErrorCodeTermsNotSigned } WidgetManagerErrorCode; +FOUNDATION_EXPORT NSString *const WidgetManagerErrorOpenIdTokenKey; /** The `WidgetManager` helps to handle modular widgets. diff --git a/Riot/Managers/Widgets/WidgetManager.m b/Riot/Managers/Widgets/WidgetManager.m index a6d2bdec1..2505f7bd2 100644 --- a/Riot/Managers/Widgets/WidgetManager.m +++ b/Riot/Managers/Widgets/WidgetManager.m @@ -513,6 +513,8 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; MXHTTPOperation *operation; NSString *userId = mxSession.myUser.userId; + NSLog(@"[WidgetManager] registerForScalarToken"); + WidgetManagerConfig *config = [self configForUser:userId]; if (!config.hasUrls) { @@ -539,6 +541,10 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; MXJSONModelSetString(scalarToken, JSONResponse[@"scalar_token"]) config.scalarToken = scalarToken; + // Validate it (this mostly checks to see if the IM needs us to agree to some terms) + // TODO + // return this._checkToken(tokenObject); + self->configs[userId] = config; [self saveConfigs]; @@ -622,7 +628,22 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; } else if (failure) { - failure(error); + MXError *mxError = [[MXError alloc] initWithNSError:error]; + if ([mxError.errcode isEqualToString:kMXErrCodeStringTermsNotSigned]) + { + NSLog(@"[WidgetManager] validateScalarToke. Error: Need to accept terms"); + NSError *termsNotSignedError = [NSError errorWithDomain:WidgetManagerErrorDomain + code:WidgetManagerErrorCodeTermsNotSigned + userInfo:@{ + NSLocalizedDescriptionKey:error.userInfo[NSLocalizedDescriptionKey] + }]; + + failure(termsNotSignedError); + } + else + { + failure(error); + } } }]; }