1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-31 13:44:28 +03:00

Initial work on improving invite dialog

This commit is contained in:
Luke Barnard
2017-02-23 09:03:20 +00:00
parent 2b91b0d9c4
commit b41787c335

View File

@ -167,45 +167,55 @@ module.exports = React.createClass({
const query = ev.target.value; const query = ev.target.value;
let queryList = []; let queryList = [];
// Only do search if there is something to search if (query.length < 2) {
if (query.length > 0 && query != '@') { return;
// filter the known users list }
queryList = this._userList.filter((user) => {
return this._matches(query, user);
}).map((user) => {
// Return objects, structure of which is defined
// by InviteAddressType
return {
addressType: 'mx',
address: user.userId,
displayName: user.displayName,
avatarMxc: user.avatarUrl,
isKnown: true,
}
});
// If the query isn't a user we know about, but is a if (this.queryChangedDebouncer) {
// valid address, add an entry for that clearTimeout(this.queryChangedDebouncer);
if (queryList.length == 0) { }
const addrType = getAddressType(query); this.queryChangedDebouncer = setTimeout(() => {
if (addrType !== null) { // Only do search if there is something to search
queryList[0] = { if (query.length > 0 && query != '@') {
addressType: addrType, // filter the known users list
address: query, queryList = this._userList.filter((user) => {
isKnown: false, return this._matches(query, user);
}; }).sort((userA, userB) => {
if (this._cancelThreepidLookup) this._cancelThreepidLookup(); return this._sortedMatches(query, userA, userB);
if (addrType == 'email') { }).map((user) => {
this._lookupThreepid(addrType, query).done(); // Return objects, structure of which is defined
// by InviteAddressType
return {
addressType: 'mx',
address: user.userId,
displayName: user.displayName,
avatarMxc: user.avatarUrl,
isKnown: true,
}
});
// 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 = getAddressType(query);
if (addrType !== null) {
queryList[0] = {
addressType: addrType,
address: query,
isKnown: false,
};
if (this._cancelThreepidLookup) this._cancelThreepidLookup();
if (addrType == 'email') {
this._lookupThreepid(addrType, query).done();
}
} }
} }
} }
} this.setState({
queryList: queryList,
this.setState({ error: false,
queryList: queryList, });
error: false, }, 200);
});
}, },
onDismissed: function(index) { onDismissed: function(index) {
@ -349,8 +359,8 @@ module.exports = React.createClass({
return false; return false;
} }
// direct prefix matches // positional matches
if (name.indexOf(query) === 0 || uid.indexOf(query) === 0) { if (name.indexOf(query) !== -1 || uid.indexOf(query) !== -1) {
return true; return true;
} }
@ -374,6 +384,16 @@ module.exports = React.createClass({
return false; return false;
}, },
_sortedMatches: function(query, userA, userB) {
if (userA.displayName.startsWith(query) || userA.userId.startsWith(query)) {
return -1;
}
if (userA.displayName.length === query.length) {
return -1;
}
return 0;
},
_isOnInviteList: function(uid) { _isOnInviteList: function(uid) {
for (let i = 0; i < this.state.inviteList.length; i++) { for (let i = 0; i < this.state.inviteList.length; i++) {
if ( if (