From ca2ba5528863ed5ed2eee7be88033c0eaaeddbb7 Mon Sep 17 00:00:00 2001 From: wmwragg Date: Tue, 13 Sep 2016 11:02:59 +0100 Subject: [PATCH] Added error checking, and UI --- .../views/dialogs/ChatInviteDialog.js | 59 +++++++++++++++---- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/src/components/views/dialogs/ChatInviteDialog.js b/src/components/views/dialogs/ChatInviteDialog.js index be878aa670..5946f143d8 100644 --- a/src/components/views/dialogs/ChatInviteDialog.js +++ b/src/components/views/dialogs/ChatInviteDialog.js @@ -56,6 +56,7 @@ module.exports = React.createClass({ getInitialState: function() { return { + error: false, inviteList: [], queryList: [], }; @@ -123,12 +124,16 @@ module.exports = React.createClass({ } else if (e.keyCode === 32 || e.keyCode === 188) { // space or comma e.stopPropagation(); e.preventDefault(); - var inviteList = this.state.inviteList.slice(); - inviteList.push(this.refs.textinput.value); - this.setState({ - inviteList: inviteList, - queryList: [], - }); + if (this._isValidAddress(this.refs.textinput.value)) { + var inviteList = this.state.inviteList.slice(); + inviteList.push(this.refs.textinput.value); + this.setState({ + inviteList: inviteList, + queryList: [], + }); + } else { + this.setState({ error: true }); + } } }, @@ -143,7 +148,10 @@ module.exports = React.createClass({ }); } - this.setState({ queryList: queryList }); + this.setState({ + queryList: queryList, + error: false, + }); }, onDismissed: function(index) { @@ -265,6 +273,23 @@ module.exports = React.createClass({ return false; }, + _isValidAddress: function(addr) { + // Check if the addr is a valid type + var addrType = Invite.getAddressType(addr); + if (addrType === "mx") { + let user = MatrixClientPeg.get().getUser(addr); + if (user) { + return true; + } else { + return false; + } + } else if (addrType === "email") { + return true; + } else { + return false; + } + }, + render: function() { var TintableSvg = sdk.getComponent("elements.TintableSvg"); var AddressSelector = sdk.getComponent("elements.AddressSelector"); @@ -280,6 +305,7 @@ module.exports = React.createClass({ ); } } + // Add the query at the end query.push(