From 143483ec126468726eea395d059bea52fd5b0355 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Nov 2015 17:36:14 +0000 Subject: [PATCH] Support inviting by email address and hit the right API. --- src/controllers/organisms/MemberList.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/controllers/organisms/MemberList.js b/src/controllers/organisms/MemberList.js index 48fef531bb..7d4326ef69 100644 --- a/src/controllers/organisms/MemberList.js +++ b/src/controllers/organisms/MemberList.js @@ -109,9 +109,11 @@ module.exports = { onInvite: function(inputText) { var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); var self = this; - // sanity check the input 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); Modal.createDialog(ErrorDialog, { title: "Invite Error", @@ -119,12 +121,22 @@ module.exports = { }); return; } + + var promise; + if (isEmailAddress) { + promise = MatrixClientPeg.get().inviteByEmail(this.props.roomId, inputText); + } + else { + promise = MatrixClientPeg.get().invite(this.props.roomId, inputText); + } + self.setState({ inviting: true }); - console.log("Invite %s to %s", inputText, this.props.roomId); - MatrixClientPeg.get().invite(this.props.roomId, inputText).done( - function(res) { + console.log( + "Invite %s to %s - isEmail=%s", inputText, this.props.roomId, isEmailAddress + ); + promise.done(function(res) { console.log("Invited"); self.setState({ inviting: false