Skip to content

Commit

Permalink
Add a dialog when inviting via slash command without IS
Browse files Browse the repository at this point in the history
This adds a dialog to ask how you want to proceed when trying to invite via
email when there is no IS configured.

Fixes element-hq/element-web#10619
  • Loading branch information
jryans committed Aug 30, 2019
1 parent 27fdef5 commit 8ff0883
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
46 changes: 42 additions & 4 deletions src/SlashCommands.js
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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: <p>{_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),
},
)}</p>,
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));
}
}));
}
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/strings/en_EN.json
Expand Up @@ -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:",
Expand Down

0 comments on commit 8ff0883

Please sign in to comment.