diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js
index 85aedadf64..d4e390f750 100644
--- a/src/components/views/rooms/RoomHeader.js
+++ b/src/components/views/rooms/RoomHeader.js
@@ -30,6 +30,9 @@ import linkifyElement from 'linkifyjs/element';
import linkifyMatrix from '../../../linkify-matrix';
import AccessibleButton from '../elements/AccessibleButton';
import {CancelButton} from './SimpleRoomHeader';
+import SdkConfig from '../../../SdkConfig';
+import ScalarAuthClient from '../../../ScalarAuthClient';
+import ScalarMessaging from '../../../ScalarMessaging';
linkifyMatrix(linkify);
@@ -57,6 +60,13 @@ module.exports = React.createClass({
};
},
+ getInitialState: function() {
+ return {
+ scalar_error: null,
+ showIntegrationsError: false,
+ };
+ },
+
componentDidMount: function() {
const cli = MatrixClientPeg.get();
cli.on("RoomState.events", this._onRoomStateEvents);
@@ -75,7 +85,23 @@ module.exports = React.createClass({
}
},
+ componentWillMount: function() {
+ ScalarMessaging.startListening();
+ this.scalarClient = null;
+ if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) {
+ this.scalarClient = new ScalarAuthClient();
+ this.scalarClient.connect().done(() => {
+ this.forceUpdate();
+ }, (err) => {
+ this.setState({
+ scalar_error: err,
+ });
+ });
+ }
+ },
+
componentWillUnmount: function() {
+ ScalarMessaging.stopListening();
if (this.props.room) {
this.props.room.removeListener("Room.name", this._onRoomNameChange);
}
@@ -85,6 +111,28 @@ module.exports = React.createClass({
}
},
+ onManageIntegrations(ev) {
+ ev.preventDefault();
+ const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager");
+ Modal.createDialog(IntegrationsManager, {
+ src: (this.scalarClient !== null && this.scalarClient.hasCredentials()) ?
+ this.scalarClient.getScalarInterfaceUrlForRoom(this.props.room.roomId) :
+ null,
+ onFinished: ()=>{
+ if (this._calcSavePromises().length === 0) {
+ this.props.onCancelClick(ev);
+ }
+ },
+ }, "mx_IntegrationsManager");
+ },
+
+ onShowIntegrationsError(ev) {
+ ev.preventDefault();
+ this.setState({
+ showIntegrationsError: !this.state.showIntegrationsError,
+ });
+ },
+
_onRoomStateEvents: function(event, state) {
if (!this.props.room || event.getRoomId() !== this.props.room.roomId) {
return;
@@ -320,10 +368,45 @@ module.exports = React.createClass({
}
let rightRow;
+ let integrationsButton;
+ let integrationsError;
+ if (this.scalarClient !== null) {
+ if (this.state.showIntegrationsError && this.state.scalar_error) {
+ console.error(this.state.scalar_error);
+ integrationsError = (
+
+ { _t('Could not connect to the integration server') }
+
+ );
+ }
+
+ if (this.scalarClient.hasCredentials()) {
+ integrationsButton = (
+