mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
IM: Terms modal: Make computation of baseUrl more generic
This commit is contained in:
parent
15154cbaa3
commit
d37017430d
3 changed files with 48 additions and 34 deletions
|
@ -539,19 +539,22 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain";
|
||||||
|
|
||||||
NSString *scalarToken;
|
NSString *scalarToken;
|
||||||
MXJSONModelSetString(scalarToken, JSONResponse[@"scalar_token"])
|
MXJSONModelSetString(scalarToken, JSONResponse[@"scalar_token"])
|
||||||
|
|
||||||
config.scalarToken = scalarToken;
|
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->configs[userId] = config;
|
||||||
[self saveConfigs];
|
[self saveConfigs];
|
||||||
|
|
||||||
|
// Validate it (this mostly checks to see if the IM needs us to agree to some terms)
|
||||||
|
MXHTTPOperation *operation3 = [self validateScalarToken:scalarToken forMXSession:mxSession complete:^(BOOL valid) {
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
success(scalarToken);
|
success(scalarToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} failure:failure];
|
||||||
|
|
||||||
|
[operation mutateTo:operation3];
|
||||||
|
|
||||||
} failure:^(NSError *error) {
|
} failure:^(NSError *error) {
|
||||||
NSLog(@"[WidgetManager] registerForScalarToken: Failed to register. Error: %@", error);
|
NSLog(@"[WidgetManager] registerForScalarToken: Failed to register. Error: %@", error);
|
||||||
|
|
|
@ -36,6 +36,38 @@ class WidgetManagerConfig: NSObject, NSCoding {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var baseUrl: NSString? {
|
||||||
|
// Same comment as https://github.com/matrix-org/matrix-react-sdk/blob/1b0d8510a2ee93beddcd34c2d5770aa9fc76b1d9/src/ScalarAuthClient.js#L108
|
||||||
|
// The terms endpoints are new and so live on standard _matrix prefixes,
|
||||||
|
// but IM rest urls are currently configured with paths, so remove the
|
||||||
|
// path from the base URL before passing it to the js-sdk
|
||||||
|
|
||||||
|
// We continue to use the full URL for the calls done by
|
||||||
|
// Riot-iOS, but the standard terms API called
|
||||||
|
// by the matrix-ios-sdk lives on the standard _matrix path. This means we
|
||||||
|
// don't support running IMs on a non-root path, but it's the only
|
||||||
|
// realistic way of transitioning to _matrix paths since configs in
|
||||||
|
// the wild contain bits of the API path.
|
||||||
|
|
||||||
|
// Once we've fully transitioned to _matrix URLs, we can give people
|
||||||
|
// a grace period to update their configs, then use the rest url as
|
||||||
|
// a regular base url.
|
||||||
|
guard let apiUrl = self.apiUrl as String?, let imApiUrl = URL(string: apiUrl) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
guard var baseUrl = URL(string: "/", relativeTo: imApiUrl)?.absoluteString else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if baseUrl.hasSuffix("/") {
|
||||||
|
// SDK doest not like trailing /
|
||||||
|
baseUrl = String(baseUrl.dropLast())
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseUrl as NSString
|
||||||
|
}
|
||||||
|
|
||||||
init(apiUrl: NSString?, uiUrl: NSString?) {
|
init(apiUrl: NSString?, uiUrl: NSString?) {
|
||||||
self.apiUrl = apiUrl
|
self.apiUrl = apiUrl
|
||||||
self.uiUrl = uiUrl
|
self.uiUrl = uiUrl
|
||||||
|
|
|
@ -695,34 +695,13 @@ NSString *const kIntegrationManagerAddIntegrationScreen = @"add_integ";
|
||||||
#pragma mark - Service terms
|
#pragma mark - Service terms
|
||||||
- (void)presentTerms
|
- (void)presentTerms
|
||||||
{
|
{
|
||||||
// Same comment as https://github.com/matrix-org/matrix-react-sdk/blob/1b0d8510a2ee93beddcd34c2d5770aa9fc76b1d9/src/ScalarAuthClient.js#L108
|
WidgetManagerConfig *config = [[WidgetManager sharedManager] configForUser:mxSession.myUser.userId];
|
||||||
// The terms endpoints are new and so live on standard _matrix prefixes,
|
|
||||||
// but IM rest urls are currently configured with paths, so remove the
|
|
||||||
// path from the base URL before passing it to the js-sdk
|
|
||||||
|
|
||||||
// We continue to use the full URL for the calls done by
|
NSLog(@"[IntegraionManagerVC] presentTerms for %@", config.baseUrl);
|
||||||
// Riot-iOS, but the standard terms API called
|
|
||||||
// by the matrix-ios-sdk lives on the standard _matrix path. This means we
|
|
||||||
// don't support running IMs on a non-root path, but it's the only
|
|
||||||
// realistic way of transitioning to _matrix paths since configs in
|
|
||||||
// the wild contain bits of the API path.
|
|
||||||
|
|
||||||
// Once we've fully transitioned to _matrix URLs, we can give people
|
ServiceTermsModalCoordinatorBridgePresenter *serviceTermsModalCoordinatorBridgePresenter = [[ServiceTermsModalCoordinatorBridgePresenter alloc] initWithSession:mxSession baseUrl:config.baseUrl
|
||||||
// a grace period to update their configs, then use the rest url as
|
|
||||||
// a regular base url.
|
|
||||||
NSURL *imApiUrl = [NSURL URLWithString:[[WidgetManager sharedManager] configForUser:mxSession.myUser.userId].apiUrl];
|
|
||||||
NSString *baseUrl = [NSURL URLWithString:@"/" relativeToURL:imApiUrl].absoluteString;
|
|
||||||
if ([baseUrl hasSuffix:@"/"])
|
|
||||||
{
|
|
||||||
// SDK doest not like trailing /
|
|
||||||
baseUrl = [baseUrl substringToIndex:baseUrl.length - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSLog(@"[IntegraionManagerVC] presentTerms for %@", baseUrl);
|
|
||||||
|
|
||||||
ServiceTermsModalCoordinatorBridgePresenter *serviceTermsModalCoordinatorBridgePresenter = [[ServiceTermsModalCoordinatorBridgePresenter alloc] initWithSession:mxSession baseUrl:baseUrl
|
|
||||||
serviceType:MXServiceTypeIntegrationManager
|
serviceType:MXServiceTypeIntegrationManager
|
||||||
accessToken:scalarToken];
|
accessToken:config.scalarToken];
|
||||||
|
|
||||||
serviceTermsModalCoordinatorBridgePresenter.delegate = self;
|
serviceTermsModalCoordinatorBridgePresenter.delegate = self;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue