Further simplify usage of integrations

This commit is contained in:
Travis Ralston 2019-06-18 07:55:43 -06:00
parent d5db0077ed
commit be37332bb0
3 changed files with 14 additions and 44 deletions

View file

@ -17,9 +17,12 @@ limitations under the License.
import URL from 'url'; import URL from 'url';
import dis from './dispatcher'; import dis from './dispatcher';
import IntegrationManager from './IntegrationManager';
import WidgetMessagingEndpoint from './WidgetMessagingEndpoint'; import WidgetMessagingEndpoint from './WidgetMessagingEndpoint';
import ActiveWidgetStore from './stores/ActiveWidgetStore'; import ActiveWidgetStore from './stores/ActiveWidgetStore';
import sdk from "./index";
import Modal from "./Modal";
import MatrixClientPeg from "./MatrixClientPeg";
import RoomViewStore from "./stores/RoomViewStore";
const WIDGET_API_VERSION = '0.0.2'; // Current API version const WIDGET_API_VERSION = '0.0.2'; // Current API version
const SUPPORTED_WIDGET_API_VERSIONS = [ const SUPPORTED_WIDGET_API_VERSIONS = [
@ -189,7 +192,14 @@ export default class FromWidgetPostMessageApi {
const data = event.data.data || event.data.widgetData; const data = event.data.data || event.data.widgetData;
const integType = (data && data.integType) ? data.integType : null; const integType = (data && data.integType) ? data.integType : null;
const integId = (data && data.integId) ? data.integId : null; const integId = (data && data.integId) ? data.integId : null;
IntegrationManager.open(integType, integId);
// The dialog will take care of scalar auth for us
const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager");
Modal.createTrackedDialog('Integrations Manager', '', IntegrationsManager, {
room: MatrixClientPeg.get().getRoom(RoomViewStore.getRoomId()),
screen: 'type_' + integType,
integrationId: integId,
}, "mx_IntegrationsManager");
} else if (action === 'set_always_on_screen') { } else if (action === 'set_always_on_screen') {
// This is a new message: there is no reason to support the deprecated widgetData here // This is a new message: there is no reason to support the deprecated widgetData here
const data = event.data.data; const data = event.data.data;

View file

@ -1,40 +0,0 @@
/*
Copyright 2017 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import Modal from './Modal';
import sdk from './index';
import RoomViewStore from './stores/RoomViewStore';
import MatrixClientPeg from "./MatrixClientPeg";
// TODO: We should use this everywhere.
export default class IntegrationManager {
/**
* Launch the integrations manager on the specified integration page
* @param {string} integName integration / widget type
* @param {string} integId integration / widget ID
* @param {function} onFinished Callback to invoke on integration manager close
*/
static async open(integName, integId, onFinished) {
// The dialog will take care of scalar auth for us
const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager");
Modal.createTrackedDialog('Integrations Manager', '', IntegrationsManager, {
room: MatrixClientPeg.get().getRoom(RoomViewStore.getRoomId()),
screen: 'type_' + integName,
integrationId: integId,
onFinished: onFinished,
}, "mx_IntegrationsManager");
}
}

View file

@ -68,7 +68,7 @@ export default class Stickerpicker extends React.Component {
_acquireScalarClient() { _acquireScalarClient() {
if (this.scalarClient) return Promise.resolve(this.scalarClient); if (this.scalarClient) return Promise.resolve(this.scalarClient);
if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) { if (ScalarAuthClient.isPossible()) {
this.scalarClient = new ScalarAuthClient(); this.scalarClient = new ScalarAuthClient();
return this.scalarClient.connect().then(() => { return this.scalarClient.connect().then(() => {
this.forceUpdate(); this.forceUpdate();
@ -348,7 +348,7 @@ 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
*/ */
async _launchManageIntegrations() { _launchManageIntegrations() {
const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager"); const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager");
// The integrations manager will handle scalar auth for us. // The integrations manager will handle scalar auth for us.