From 8ff0883c2263dd29adc1d5f342ea1815ede7ba84 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 30 Aug 2019 18:29:07 +0100 Subject: [PATCH] Add a dialog when inviting via slash command without IS This adds a dialog to ask how you want to proceed when trying to invite via email when there is no IS configured. Fixes https://github.com/vector-im/riot-web/issues/10619 --- src/SlashCommands.js | 46 +++++++++++++++++++++++++++++++++---- src/i18n/strings/en_EN.json | 3 +++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index 5ed1adb40f..8000d9c2aa 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -31,6 +31,9 @@ import QuestionDialog from "./components/views/dialogs/QuestionDialog"; import WidgetUtils from "./utils/WidgetUtils"; import {textToHtmlRainbow} from "./utils/colour"; import Promise from "bluebird"; +import { getAddressType } from './UserAddress'; +import { abbreviateUrl } from './utils/UrlUtils'; +import { getDefaultIdentityServerUrl, useDefaultIdentityServer } from './utils/IdentityServerUtils'; const singleMxcUpload = async () => { return new Promise((resolve) => { @@ -342,11 +345,46 @@ export const CommandMap = { if (matches) { // We use a MultiInviter to re-use the invite logic, even though // we're only inviting one user. - const userId = matches[1]; + const address = matches[1]; + // If we need an identity server but don't have one, things + // get a bit more complex here, but we try to show something + // meaningful. + let finished = Promise.resolve(); + if ( + getAddressType(address) === 'email' && + !MatrixClientPeg.get().getIdentityServerUrl() + ) { + const defaultIdentityServerUrl = getDefaultIdentityServerUrl(); + if (defaultIdentityServerUrl) { + ({ finished } = Modal.createTrackedDialog('Slash Commands', 'Identity server', + QuestionDialog, { + title: _t("Use an identity server"), + description:

{_t( + "Use an identity server to invite by email. " + + "Click continue to use the default identity server " + + "(%(defaultIdentityServerName)s) or manage in Settings.", + { + defaultIdentityServerName: abbreviateUrl(defaultIdentityServerUrl), + }, + )}

, + button: _t("Continue"), + }, + )); + } else { + return reject(_t("Use an identity server to invite by email. Manage in Settings.")); + } + } const inviter = new MultiInviter(roomId); - return success(inviter.invite([userId]).then(() => { - if (inviter.getCompletionState(userId) !== "invited") { - throw new Error(inviter.getErrorText(userId)); + return success(finished.then(([useDefault] = []) => { + if (useDefault) { + useDefaultIdentityServer(); + } else if (useDefault === false) { + throw new Error(_t("Use an identity server to invite by email. Manage in Settings.")); + } + return inviter.invite([address]); + }).then(() => { + if (inviter.getCompletionState(address) !== "invited") { + throw new Error(inviter.getErrorText(address)); } })); } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index ce4598ed5f..3823b7eb08 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -161,6 +161,9 @@ "This room has no topic.": "This room has no topic.", "Sets the room name": "Sets the room name", "Invites user with given id to current room": "Invites user with given id to current room", + "Use an identity server": "Use an identity server", + "Use an identity server to invite by email. Click continue to use the default identity server (%(defaultIdentityServerName)s) or manage in Settings.": "Use an identity server to invite by email. Click continue to use the default identity server (%(defaultIdentityServerName)s) or manage in Settings.", + "Use an identity server to invite by email. Manage in Settings.": "Use an identity server to invite by email. Manage in Settings.", "Joins room with given alias": "Joins room with given alias", "Leave room": "Leave room", "Unrecognised room alias:": "Unrecognised room alias:",