Defer sticker picker scalar auth to integration manager dialog

or when needed, instead of up front.
pull/21833/head
Travis Ralston 2019-06-17 15:30:24 -06:00
parent ebabc5238d
commit f699fed720
1 changed files with 40 additions and 38 deletions

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React from 'react'; import React from 'react';
import { _t } from '../../../languageHandler'; import {_t, _td} from '../../../languageHandler';
import AppTile from '../elements/AppTile'; import AppTile from '../elements/AppTile';
import MatrixClientPeg from '../../../MatrixClientPeg'; import MatrixClientPeg from '../../../MatrixClientPeg';
import Modal from '../../../Modal'; import Modal from '../../../Modal';
@ -53,6 +53,9 @@ export default class Stickerpicker extends React.Component {
this.popoverWidth = 300; this.popoverWidth = 300;
this.popoverHeight = 300; this.popoverHeight = 300;
// This is loaded by _acquireScalarClient on an as-needed basis.
this.scalarClient = null;
this.state = { this.state = {
showStickers: false, showStickers: false,
imError: null, imError: null,
@ -63,14 +66,34 @@ export default class Stickerpicker extends React.Component {
}; };
} }
_removeStickerpickerWidgets() { _acquireScalarClient() {
if (this.scalarClient) return Promise.resolve(this.scalarClient);
if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) {
this.scalarClient = new ScalarAuthClient();
return this.scalarClient.connect().then(() => {
this.forceUpdate();
return this.scalarClient;
}).catch((e) => {
this._imError(_td("Failed to connect to integrations server"), e);
});
} else {
this._imError(_td("No integrations server is configured to manage stickers with"));
}
}
async _removeStickerpickerWidgets() {
const scalarClient = await this._acquireScalarClient();
console.warn('Removing Stickerpicker widgets'); console.warn('Removing Stickerpicker widgets');
if (this.state.widgetId) { if (this.state.widgetId) {
this.scalarClient.disableWidgetAssets(widgetType, this.state.widgetId).then(() => { if (scalarClient) {
console.warn('Assets disabled'); scalarClient.disableWidgetAssets(widgetType, this.state.widgetId).then(() => {
}).catch((err) => { console.warn('Assets disabled');
console.error('Failed to disable assets'); }).catch((err) => {
}); console.error('Failed to disable assets');
});
} else {
console.error("Cannot disable assets: no scalar client");
}
} else { } else {
console.warn('No widget ID specified, not disabling assets'); console.warn('No widget ID specified, not disabling assets');
} }
@ -87,19 +110,7 @@ export default class Stickerpicker extends React.Component {
// Close the sticker picker when the window resizes // Close the sticker picker when the window resizes
window.addEventListener('resize', this._onResize); window.addEventListener('resize', this._onResize);
this.scalarClient = null; this.dispatcherRef = dis.register(this._onWidgetAction);
if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) {
this.scalarClient = new ScalarAuthClient();
this.scalarClient.connect().then(() => {
this.forceUpdate();
}).catch((e) => {
this._imError("Failed to connect to integrations server", e);
});
}
if (!this.state.imError) {
this.dispatcherRef = dis.register(this._onWidgetAction);
}
// Track updates to widget state in account data // Track updates to widget state in account data
MatrixClientPeg.get().on('accountData', this._updateWidget); MatrixClientPeg.get().on('accountData', this._updateWidget);
@ -126,7 +137,7 @@ export default class Stickerpicker extends React.Component {
console.error(errorMsg, e); console.error(errorMsg, e);
this.setState({ this.setState({
showStickers: false, showStickers: false,
imError: errorMsg, imError: _t(errorMsg),
}); });
} }
@ -337,24 +348,15 @@ export default class Stickerpicker extends React.Component {
/** /**
* Launch the integrations manager on the stickers integration page * Launch the integrations manager on the stickers integration page
*/ */
_launchManageIntegrations() { async _launchManageIntegrations() {
const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager"); const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager");
this.scalarClient.connect().done(() => {
const src = (this.scalarClient !== null && this.scalarClient.hasCredentials()) ? // The integrations manager will handle scalar auth for us.
this.scalarClient.getScalarInterfaceUrlForRoom( Modal.createTrackedDialog('Integrations Manager', '', IntegrationsManager, {
this.props.room, room: this.props.room,
'type_' + widgetType, screen: `type_${widgetType}`,
this.state.widgetId, integrationId: this.state.widgetId,
) : }, "mx_IntegrationsManager");
null;
Modal.createTrackedDialog('Integrations Manager', '', IntegrationsManager, {
src: src,
}, "mx_IntegrationsManager");
this.setState({showStickers: false});
}, (err) => {
this.setState({imError: err});
console.error('Error ensuring a valid scalar_token exists', err);
});
} }
render() { render() {