mirror of https://github.com/vector-im/riot-web
Make group invites work
parent
e1ddd3781d
commit
ddf1017799
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
Copyright 2017 New Vector Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import MatrixClientPeg from './MatrixClientPeg';
|
||||||
|
import Modal from './Modal';
|
||||||
|
import sdk from './';
|
||||||
|
import MultiInviter from './utils/MultiInviter';
|
||||||
|
import { _t } from './languageHandler';
|
||||||
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
export function showGroupInviteDialog(groupId) {
|
||||||
|
const UserPickerDialog = sdk.getComponent("dialogs.UserPickerDialog");
|
||||||
|
Modal.createTrackedDialog('Group Invite', '', UserPickerDialog, {
|
||||||
|
title: _t('Invite new group members'),
|
||||||
|
description: _t("Who would you like to add to this group?"),
|
||||||
|
placeholder: _t("Name or matrix ID"),
|
||||||
|
button: _t("Invite to Group"),
|
||||||
|
validAddressTypes: ['mx'],
|
||||||
|
onFinished: (shouldInvite, addrs) => {
|
||||||
|
if (!shouldInvite) return;
|
||||||
|
|
||||||
|
_onGroupInviteFinished(groupId, addrs);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function _onGroupInviteFinished(groupId, addrs) {
|
||||||
|
const multiInviter = new MultiInviter(groupId);
|
||||||
|
|
||||||
|
const addrTexts = addrs.map((addr) => addr.address);
|
||||||
|
|
||||||
|
multiInviter.invite(addrTexts).then((completionStates) => {
|
||||||
|
// Show user any errors
|
||||||
|
const errorList = [];
|
||||||
|
for (const addr of Object.keys(completionStates)) {
|
||||||
|
if (addrs[addr] === "error") {
|
||||||
|
errorList.push(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorList.length > 0) {
|
||||||
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
|
Modal.createTrackedDialog('Failed to invite the following users to the group', '', ErrorDialog, {
|
||||||
|
title: _t("Failed to invite the following users to %(groupId)s:", {groupId: groupId}),
|
||||||
|
description: errorList.join(", "),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
|
Modal.createTrackedDialog('Failed to invite users to group', '', ErrorDialog, {
|
||||||
|
title: _t("Failed to invite users group"),
|
||||||
|
description: _t("Failed to invite users to %(groupId)s", {groupId: groupId}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import dis from "../../dispatcher";
|
||||||
import Modal from "../../Modal";
|
import Modal from "../../Modal";
|
||||||
import Tinter from "../../Tinter";
|
import Tinter from "../../Tinter";
|
||||||
import sdk from '../../index';
|
import sdk from '../../index';
|
||||||
import { showStartChatInviteDialog, showRoomInviteDialog } from '../../Invite';
|
import { showStartChatInviteDialog, showRoomInviteDialog } from '../../RoomInvite';
|
||||||
import * as Rooms from '../../Rooms';
|
import * as Rooms from '../../Rooms';
|
||||||
import linkifyMatrix from "../../linkify-matrix";
|
import linkifyMatrix from "../../linkify-matrix";
|
||||||
import * as Lifecycle from '../../Lifecycle';
|
import * as Lifecycle from '../../Lifecycle';
|
||||||
|
|
|
@ -972,5 +972,9 @@
|
||||||
"Hide avatars in user and room mentions": "Hide avatars in user and room mentions",
|
"Hide avatars in user and room mentions": "Hide avatars in user and room mentions",
|
||||||
"Description": "Description",
|
"Description": "Description",
|
||||||
"Filter group members": "Filter group members",
|
"Filter group members": "Filter group members",
|
||||||
"Remove from group": "Remove from group"
|
"Remove from group": "Remove from group",
|
||||||
|
"Invite new group members": "Invite new group members",
|
||||||
|
"Who would you like to add to this group?": "Who would you like to add to this group?",
|
||||||
|
"Name or matrix ID": "Name or matrix ID",
|
||||||
|
"Invite to Group": "Invite to Group"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2016 OpenMarket Ltd
|
Copyright 2016 OpenMarket Ltd
|
||||||
|
Copyright 2017 New Vector Ltd
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -14,16 +15,26 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import MatrixClientPeg from '../MatrixClientPeg';
|
||||||
import {getAddressType} from '../UserAddress';
|
import {getAddressType} from '../UserAddress';
|
||||||
import {inviteToRoom} from '../Invite';
|
import {inviteToRoom} from '../RoomInvite';
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invites multiple addresses to a room, handling rate limiting from the server
|
* Invites multiple addresses to a room or group, handling rate limiting from the server
|
||||||
*/
|
*/
|
||||||
export default class MultiInviter {
|
export default class MultiInviter {
|
||||||
constructor(roomId) {
|
/**
|
||||||
this.roomId = roomId;
|
* @param {string} targetId The ID of the room or group to invite to
|
||||||
|
*/
|
||||||
|
constructor(targetId) {
|
||||||
|
if (targetId[0] === '+') {
|
||||||
|
this.roomId = null;
|
||||||
|
this.groupId = targetId;
|
||||||
|
} else {
|
||||||
|
this.roomId = targetId;
|
||||||
|
this.groupId = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.canceled = false;
|
this.canceled = false;
|
||||||
this.addrs = [];
|
this.addrs = [];
|
||||||
|
@ -104,7 +115,14 @@ export default class MultiInviter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
inviteToRoom(this.roomId, addr).then(() => {
|
let doInvite;
|
||||||
|
if (this.groupId !== null) {
|
||||||
|
doInvite = MatrixClientPeg.get().inviteUserToGroup(this.groupId, addr);
|
||||||
|
} else {
|
||||||
|
doInvite = inviteToRoom(this.roomId, addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
doInvite.then(() => {
|
||||||
if (this._canceled) { return; }
|
if (this._canceled) { return; }
|
||||||
|
|
||||||
this.completionStates[addr] = 'invited';
|
this.completionStates[addr] = 'invited';
|
||||||
|
|
Loading…
Reference in New Issue