Check if users exist before inviting them and communicate errors

Fixes https://github.com/vector-im/riot-web/issues/3283
Fixes https://github.com/vector-im/riot-web/issues/3968
Fixes https://github.com/vector-im/riot-web/issues/4308
Fixes https://github.com/vector-im/riot-web/issues/1597
Fixes https://github.com/vector-im/riot-web/issues/6790

This does 3 things:
* Makes the `MultiInviter` check for a user profile before attempting an invite. This is to prove the user exists.
* Use the `MultiInviter` everywhere to avoid duplicating the logic. Although a couple places only invite one user, it is still worthwhile.
* Communicate errors from the `MultiInviter` to the user in all cases. This is done through dialogs, where some existed previously but were not invoked.

Specifically to the 403 error not working: What was happening was the `MultiInviter` loop was setting the `fatal` flag, but that didn't resolve the promise it stored. This caused a promise to always be open, therefore never hitting a dialog.
This commit is contained in:
Travis Ralston 2018-11-29 15:05:53 -07:00
parent e3f2e69087
commit 987ad0b0db
5 changed files with 90 additions and 45 deletions

View file

@ -26,6 +26,7 @@ import Modal from './Modal';
import SettingsStore, {SettingLevel} from './settings/SettingsStore';
import {MATRIXTO_URL_PATTERN} from "./linkify-matrix";
import * as querystring from "querystring";
import MultiInviter from './utils/MultiInviter';
class Command {
@ -142,7 +143,14 @@ export const CommandMap = {
if (args) {
const matches = args.match(/^(\S+)$/);
if (matches) {
return success(MatrixClientPeg.get().invite(roomId, matches[1]));
// We use a MultiInviter to re-use the invite logic, even though
// we're only inviting one user.
const userId = matches[1];
const inviter = new MultiInviter(roomId);
return success(inviter.invite([userId]).then(() => {
if (inviter.getCompletionState(userId) !== "invited")
throw new Error(inviter.getErrorText(userId));
}));
}
}
return reject(this.getUsage());