Avoid visual glitch when terms appear for IM

This avoids a visual glitch where the Integration Manager portal would briefly
appear, but then be replaced by a smaller Terms dialog when there's something to
agree to.

To resolve this minimal code churn, this cheats a bit and customises the size of
the terms dialog to match the IM portal modal when terms are shown for IM
purposes.

Fixes https://github.com/vector-im/riot-web/issues/10386
This commit is contained in:
J. Ryan Stinnett 2019-07-23 15:11:38 +01:00
parent 2eb8a8879b
commit 39d5aa7cf4
5 changed files with 49 additions and 19 deletions

View file

@ -18,7 +18,7 @@ limitations under the License.
import url from 'url';
import Promise from 'bluebird';
import SettingsStore from "./settings/SettingsStore";
import { Service, presentTermsForServices, TermsNotSignedError } from './Terms';
import { Service, startTermsFlow, TermsNotSignedError } from './Terms';
const request = require('browser-request');
const SdkConfig = require('./SdkConfig');
@ -32,6 +32,9 @@ const imApiVersion = "1.1";
class ScalarAuthClient {
constructor() {
this.scalarToken = null;
// `undefined` to allow `startTermsFlow` to fallback to a default
// callback if this is unset.
this.termsInteractionCallback = undefined;
}
/**
@ -42,6 +45,10 @@ class ScalarAuthClient {
return SdkConfig.get()['integrations_rest_url'] && SdkConfig.get()['integrations_ui_url'];
}
setTermsInteractionCallback(callback) {
this.termsInteractionCallback = callback;
}
connect() {
return this.getScalarToken().then((tok) => {
this.scalarToken = tok;
@ -122,11 +129,11 @@ class ScalarAuthClient {
const parsedImRestUrl = url.parse(SdkConfig.get().integrations_rest_url);
parsedImRestUrl.path = '';
parsedImRestUrl.pathname = '';
return presentTermsForServices([new Service(
return startTermsFlow([new Service(
Matrix.SERVICE_TYPES.IM,
parsedImRestUrl.format(),
token,
)]).then(() => {
)], this.termsInteractionCallback).then(() => {
return token;
});
} else {