Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Better feedback in invite dialog
Browse files Browse the repository at this point in the history
Show feedback if you enter a valid but unknown email address
or mxid

Fixes element-hq/element-web#2933
  • Loading branch information
dbkr committed Jan 18, 2017
1 parent fcb1d7a commit de62190
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/Invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import MultiInviter from './utils/MultiInviter';

const emailRegex = /^\S+@\S+\.\S+$/;

// We allow localhost for mxids to avoid confusion
const mxidRegex = /^@\S+:(?:\S+\.\S+|localhost)$/

export function getAddressType(inputText) {
const isEmailAddress = /^\S+@\S+\.\S+$/.test(inputText);
const isMatrixId = inputText[0] === '@' && inputText.indexOf(":") > 0;
const isEmailAddress = emailRegex.test(inputText);
const isMatrixId = mxidRegex.test(inputText);

// sanity check the input for user IDs
if (isEmailAddress) {
Expand Down
18 changes: 15 additions & 3 deletions src/components/views/dialogs/ChatInviteDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,26 @@ module.exports = React.createClass({
},

onQueryChanged: function(ev) {
var query = ev.target.value;
var queryList = [];
const query = ev.target.value;
let queryList = [];

// Only do search if there is something to search
if (query.length > 0) {
if (query.length > 0 && query != '@') {
// filter the known users list
queryList = this._userList.filter((user) => {
return this._matches(query, user);
}).map((user) => {
return user.userId;
});

// If the query isn't a user we know about, but is a
// valid address, add an entry for that
if (queryList.length == 0) {
const addrType = Invite.getAddressType(query);
if (addrType !== null) {
queryList.push(query);
}
}
}

this.setState({
Expand Down
4 changes: 3 additions & 1 deletion src/components/views/elements/AddressSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module.exports = React.createClass({

propTypes: {
onSelected: React.PropTypes.func.isRequired,

// List of strings: the addresses to display
addressList: React.PropTypes.array.isRequired,
truncateAt: React.PropTypes.number.isRequired,
selected: React.PropTypes.number,
Expand Down Expand Up @@ -125,7 +127,7 @@ module.exports = React.createClass({
// method, how far to scroll when using the arrow keys
addressList.push(
<div className={classes} onClick={this.onClick(i)} onMouseEnter={this.onMouseEnter(i)} onMouseLeave={this.onMouseLeave} key={i} ref={(ref) => { this.addressListElement = ref; }} >
<AddressTile address={this.props.addressList[i].userId} justified={true} networkName="vector" networkUrl="img/search-icon-vector.svg" />
<AddressTile address={this.props.addressList[i]} justified={true} networkName="vector" networkUrl="img/search-icon-vector.svg" />
</div>
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/views/elements/AddressTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ module.exports = React.createClass({
imgUrl = "img/avatar-error.svg";
}

// Removing networks for now as they're not really supported
/*
var network;
if (this.props.networkUrl !== "") {
network = (
Expand All @@ -79,6 +81,7 @@ module.exports = React.createClass({
</div>
);
}
*/

var info;
var error = false;
Expand Down Expand Up @@ -145,7 +148,6 @@ module.exports = React.createClass({

return (
<div className={classes}>
{ network }
<div className="mx_AddressTile_avatar">
<BaseAvatar width={25} height={25} name={name} title={name} url={imgUrl} />
</div>
Expand Down

0 comments on commit de62190

Please sign in to comment.