mirror of https://github.com/vector-im/riot-web
Merge pull request #5695 from robintown/invite-command-reason
Support sending invite reasons with /invite commandpull/21833/head
commit
89301ca8d9
|
@ -441,15 +441,14 @@ export const Commands = [
|
||||||
}),
|
}),
|
||||||
new Command({
|
new Command({
|
||||||
command: 'invite',
|
command: 'invite',
|
||||||
args: '<user-id>',
|
args: '<user-id> [<reason>]',
|
||||||
description: _td('Invites user with given id to current room'),
|
description: _td('Invites user with given id to current room'),
|
||||||
runFn: function(roomId, args) {
|
runFn: function(roomId, args) {
|
||||||
if (args) {
|
if (args) {
|
||||||
const matches = args.match(/^(\S+)$/);
|
const [address, reason] = args.split(/\s+(.+)/);
|
||||||
if (matches) {
|
if (address) {
|
||||||
// We use a MultiInviter to re-use the invite logic, even though
|
// We use a MultiInviter to re-use the invite logic, even though
|
||||||
// we're only inviting one user.
|
// we're only inviting one user.
|
||||||
const address = matches[1];
|
|
||||||
// If we need an identity server but don't have one, things
|
// If we need an identity server but don't have one, things
|
||||||
// get a bit more complex here, but we try to show something
|
// get a bit more complex here, but we try to show something
|
||||||
// meaningful.
|
// meaningful.
|
||||||
|
@ -490,7 +489,7 @@ export const Commands = [
|
||||||
}
|
}
|
||||||
const inviter = new MultiInviter(roomId);
|
const inviter = new MultiInviter(roomId);
|
||||||
return success(prom.then(() => {
|
return success(prom.then(() => {
|
||||||
return inviter.invite([address]);
|
return inviter.invite([address], reason);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (inviter.getCompletionState(address) !== "invited") {
|
if (inviter.getCompletionState(address) !== "invited") {
|
||||||
throw new Error(inviter.getErrorText(address));
|
throw new Error(inviter.getErrorText(address));
|
||||||
|
|
|
@ -53,13 +53,15 @@ export default class MultiInviter {
|
||||||
* instance of the class.
|
* instance of the class.
|
||||||
*
|
*
|
||||||
* @param {array} addrs Array of addresses to invite
|
* @param {array} addrs Array of addresses to invite
|
||||||
|
* @param {string} reason Reason for inviting (optional)
|
||||||
* @returns {Promise} Resolved when all invitations in the queue are complete
|
* @returns {Promise} Resolved when all invitations in the queue are complete
|
||||||
*/
|
*/
|
||||||
invite(addrs) {
|
invite(addrs, reason) {
|
||||||
if (this.addrs.length > 0) {
|
if (this.addrs.length > 0) {
|
||||||
throw new Error("Already inviting/invited");
|
throw new Error("Already inviting/invited");
|
||||||
}
|
}
|
||||||
this.addrs.push(...addrs);
|
this.addrs.push(...addrs);
|
||||||
|
this.reason = reason;
|
||||||
|
|
||||||
for (const addr of this.addrs) {
|
for (const addr of this.addrs) {
|
||||||
if (getAddressType(addr) === null) {
|
if (getAddressType(addr) === null) {
|
||||||
|
@ -123,7 +125,7 @@ export default class MultiInviter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MatrixClientPeg.get().invite(roomId, addr);
|
return MatrixClientPeg.get().invite(roomId, addr, undefined, this.reason);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unsupported address');
|
throw new Error('Unsupported address');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue