Support inviting by email address and hit the right API.

This commit is contained in:
Kegan Dougal 2015-11-09 17:36:14 +00:00
parent b556eff492
commit 143483ec12

View file

@ -109,9 +109,11 @@ module.exports = {
onInvite: function(inputText) { onInvite: function(inputText) {
var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); var ErrorDialog = sdk.getComponent("organisms.ErrorDialog");
var self = this; var self = this;
// sanity check the input
inputText = inputText.trim(); // react requires es5-shim so we know trim() exists inputText = inputText.trim(); // react requires es5-shim so we know trim() exists
if (inputText[0] !== '@' || inputText.indexOf(":") === -1) { var isEmailAddress = /^\S+@\S+\.\S+$/.test(inputText);
// sanity check the input for user IDs
if (!isEmailAddress && (inputText[0] !== '@' || inputText.indexOf(":") === -1)) {
console.error("Bad user ID to invite: %s", inputText); console.error("Bad user ID to invite: %s", inputText);
Modal.createDialog(ErrorDialog, { Modal.createDialog(ErrorDialog, {
title: "Invite Error", title: "Invite Error",
@ -119,12 +121,22 @@ module.exports = {
}); });
return; return;
} }
var promise;
if (isEmailAddress) {
promise = MatrixClientPeg.get().inviteByEmail(this.props.roomId, inputText);
}
else {
promise = MatrixClientPeg.get().invite(this.props.roomId, inputText);
}
self.setState({ self.setState({
inviting: true inviting: true
}); });
console.log("Invite %s to %s", inputText, this.props.roomId); console.log(
MatrixClientPeg.get().invite(this.props.roomId, inputText).done( "Invite %s to %s - isEmail=%s", inputText, this.props.roomId, isEmailAddress
function(res) { );
promise.done(function(res) {
console.log("Invited"); console.log("Invited");
self.setState({ self.setState({
inviting: false inviting: false