diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index 7721add5cf..e1928e15d4 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -82,6 +82,10 @@ class ScalarAuthClient { url += "&room_id=" + encodeURIComponent(roomId); return url; } + + getStarterLink(starterLinkUrl) { + return starterLinkUrl + "?scalar_token=" + encodeURIComponent(this.scalarToken); + } } module.exports = ScalarAuthClient; diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 47e69d9d29..e6ed354f29 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -23,6 +23,10 @@ var linkify = require('linkifyjs'); var linkifyElement = require('linkifyjs/element'); var linkifyMatrix = require('../../../linkify-matrix'); var sdk = require('../../../index'); +var ScalarAuthClient = require("../../../ScalarAuthClient"); +var Modal = require("../../../Modal"); +var SdkConfig = require('../../../SdkConfig'); +var UserSettingsStore = require('../../../UserSettingsStore'); linkifyMatrix(linkify); @@ -176,7 +180,50 @@ module.exports = React.createClass({ } }, - onStarterLinkClick: function() { + onStarterLinkClick: function(starterLink) { + // We need to add on our scalar token to the starter link, but we may not have one! + // In addition, we can't fetch one on click and then go to it immediately as that + // is then treated as a popup! + // We can get around this by fetching one now and showing a "confirmation dialog" (hurr hurr) + // which requires the user to click through and THEN we can open the link in a new tab because + // the window.open command occurs in the same stack frame as the onClick callback. + + let integrationsEnabled = UserSettingsStore.isFeatureEnabled("integration_management"); + if (!integrationsEnabled) { + var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + Modal.createDialog(ErrorDialog, { + title: "Integrations disabled", + description: "You need to enable the Labs option 'Integrations Management' in your Vector user settings first.", + }); + return; + } + + // Go fetch a scalar token + let scalarClient = new ScalarAuthClient(); + scalarClient.connect().then(() => { + let completeUrl = scalarClient.getStarterLink(starterLink); + let QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + let integrationsUrl = SdkConfig.get().integrations_ui_url; + Modal.createDialog(QuestionDialog, { + title: "Add an Integration", + description: +