Added multi invite functionality
This commit is contained in:
parent
f7f907a0c7
commit
272dd82b9d
2 changed files with 49 additions and 27 deletions
|
@ -56,7 +56,7 @@ export function inviteToRoom(roomId, addr) {
|
||||||
*/
|
*/
|
||||||
export function inviteMultipleToRoom(roomId, addrs) {
|
export function inviteMultipleToRoom(roomId, addrs) {
|
||||||
this.inviter = new MultiInviter(roomId);
|
this.inviter = new MultiInviter(roomId);
|
||||||
return inviter.invite(addrs);
|
return this.inviter.invite(addrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isValidAddress(addr) {
|
export function isValidAddress(addr) {
|
||||||
|
|
|
@ -71,16 +71,10 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onButtonClick: function() {
|
onButtonClick: function() {
|
||||||
var addr;
|
if (this.state.inviteList.length > 0) {
|
||||||
|
if (this._isDmChat()) {
|
||||||
// Either an address tile was created, or text input is being used
|
|
||||||
if (this.state.inviteList[0]) {
|
|
||||||
addr = this.state.inviteList[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.state.inviteList.length === 1 && Invite.getAddressType(addr) === "mx" && !this.props.roomId) {
|
|
||||||
// Direct Message chat
|
// Direct Message chat
|
||||||
var room = this._getDirectMessageRoom(addr);
|
var room = this._getDirectMessageRoom(this.state.inviteList[0]);
|
||||||
if (room) {
|
if (room) {
|
||||||
// A Direct Message room already exists for this user and you
|
// A Direct Message room already exists for this user and you
|
||||||
// so go straight to that room
|
// so go straight to that room
|
||||||
|
@ -88,13 +82,17 @@ module.exports = React.createClass({
|
||||||
action: 'view_room',
|
action: 'view_room',
|
||||||
room_id: room.roomId,
|
room_id: room.roomId,
|
||||||
});
|
});
|
||||||
this.props.onFinished(true, addr);
|
this.props.onFinished(true, this.state.inviteList[0]);
|
||||||
} else {
|
} else {
|
||||||
this._startChat(addr);
|
this._startChat(this.state.inviteList);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Multi invite chat
|
// Multi invite chat
|
||||||
this._startChat(addr);
|
this._startChat(this.state.inviteList);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// No addresses supplied
|
||||||
|
this.setState({ error: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -198,9 +196,22 @@ module.exports = React.createClass({
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
_startChat: function(addr) {
|
_startChat: function(addrs) {
|
||||||
if (this.props.roomId) {
|
if (this.props.roomId) {
|
||||||
Invite.inviteToRoom(this.props.roomId, addr)
|
// Invite new user to a room
|
||||||
|
Invite.inviteMultipleToRoom(this.props.roomId, addrs)
|
||||||
|
.catch(function(err) {
|
||||||
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
|
Modal.createDialog(ErrorDialog, {
|
||||||
|
title: "Failure to invite user",
|
||||||
|
description: err.toString()
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
.done();
|
||||||
|
} else if (this._isDmChat()) {
|
||||||
|
// Start the DM chat
|
||||||
|
createRoom({dmUserId: addrs[0]})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
Modal.createDialog(ErrorDialog, {
|
Modal.createDialog(ErrorDialog, {
|
||||||
|
@ -211,8 +222,11 @@ module.exports = React.createClass({
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
} else {
|
} else {
|
||||||
// Start the chat
|
// Start multi user chat
|
||||||
createRoom({dmUserId: addr})
|
var self = this;
|
||||||
|
createRoom().then(function(roomId) {
|
||||||
|
return Invite.inviteMultipleToRoom(self.props.roomId, addrs);
|
||||||
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
Modal.createDialog(ErrorDialog, {
|
Modal.createDialog(ErrorDialog, {
|
||||||
|
@ -225,7 +239,7 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close - this will happen before the above, as that is async
|
// Close - this will happen before the above, as that is async
|
||||||
this.props.onFinished(true, addr);
|
this.props.onFinished(true, addrs);
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateUserList: new rate_limited_func(function() {
|
_updateUserList: new rate_limited_func(function() {
|
||||||
|
@ -273,6 +287,14 @@ module.exports = React.createClass({
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_isDmChat: function() {
|
||||||
|
if (this.state.inviteList.length === 1 && Invite.getAddressType(this.state.inviteList[0]) === "mx" && !this.props.roomId) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var TintableSvg = sdk.getComponent("elements.TintableSvg");
|
var TintableSvg = sdk.getComponent("elements.TintableSvg");
|
||||||
var AddressSelector = sdk.getComponent("elements.AddressSelector");
|
var AddressSelector = sdk.getComponent("elements.AddressSelector");
|
||||||
|
|
Loading…
Reference in a new issue