Merge pull request #3925 from matrix-org/travis/invite-polish

Last bit of polish for user lists
This commit is contained in:
Travis Ralston 2020-01-24 08:57:18 -07:00 committed by GitHub
commit ddafd010ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 9 deletions

View file

@ -338,19 +338,31 @@ export default class InviteDialog extends React.PureComponent {
const recents = []; const recents = [];
for (const userId in rooms) { for (const userId in rooms) {
// Filter out user IDs that are already in the room / should be excluded // Filter out user IDs that are already in the room / should be excluded
if (excludedTargetIds.includes(userId)) continue; if (excludedTargetIds.includes(userId)) {
console.warn(`[Invite:Recents] Excluding ${userId} from recents`);
continue;
}
const room = rooms[userId]; const room = rooms[userId];
const member = room.getMember(userId); const member = room.getMember(userId);
if (!member) continue; // just skip people who don't have memberships for some reason if (!member) {
// just skip people who don't have memberships for some reason
console.warn(`[Invite:Recents] ${userId} is missing a member object in their own DM (${room.roomId})`);
continue;
}
const lastEventTs = room.timeline && room.timeline.length const lastEventTs = room.timeline && room.timeline.length
? room.timeline[room.timeline.length - 1].getTs() ? room.timeline[room.timeline.length - 1].getTs()
: 0; : 0;
if (!lastEventTs) continue; // something weird is going on with this room if (!lastEventTs) {
// something weird is going on with this room
console.warn(`[Invite:Recents] ${userId} (${room.roomId}) has a weird last timestamp: ${lastEventTs}`);
continue;
}
recents.push({userId, user: member, lastActive: lastEventTs}); recents.push({userId, user: member, lastActive: lastEventTs});
} }
if (!recents) console.warn("[Invite:Recents] No recents to suggest!");
// Sort the recents by last active to save us time later // Sort the recents by last active to save us time later
recents.sort((a, b) => b.lastActive - a.lastActive); recents.sort((a, b) => b.lastActive - a.lastActive);
@ -713,11 +725,16 @@ export default class InviteDialog extends React.PureComponent {
}; };
_toggleMember = (member: Member) => { _toggleMember = (member: Member) => {
let filterText = this.state.filterText;
const targets = this.state.targets.map(t => t); // cheap clone for mutation const targets = this.state.targets.map(t => t); // cheap clone for mutation
const idx = targets.indexOf(member); const idx = targets.indexOf(member);
if (idx >= 0) targets.splice(idx, 1); if (idx >= 0) {
else targets.push(member); targets.splice(idx, 1);
this.setState({targets}); } else {
targets.push(member);
filterText = ""; // clear the filter when the user accepts a suggestion
}
this.setState({targets, filterText});
}; };
_removeMember = (member: Member) => { _removeMember = (member: Member) => {
@ -917,7 +934,7 @@ export default class InviteDialog extends React.PureComponent {
key={"input"} key={"input"}
rows={1} rows={1}
onChange={this._updateFilter} onChange={this._updateFilter}
defaultValue={this.state.filterText} value={this.state.filterText}
ref={this._editorRef} ref={this._editorRef}
onPaste={this._onPaste} onPaste={this._onPaste}
/> />
@ -985,7 +1002,7 @@ export default class InviteDialog extends React.PureComponent {
title = _t("Direct Messages"); title = _t("Direct Messages");
helpText = _t( helpText = _t(
"If you can't find someone, ask them for their username, or share your " + "If you can't find someone, ask them for their username, share your " +
"username (%(userId)s) or <a>profile link</a>.", "username (%(userId)s) or <a>profile link</a>.",
{userId}, {userId},
{a: (sub) => <a href={makeUserPermalink(userId)} rel="noopener" target="_blank">{sub}</a>}, {a: (sub) => <a href={makeUserPermalink(userId)} rel="noopener" target="_blank">{sub}</a>},

View file

@ -1475,7 +1475,7 @@
"Suggestions": "Suggestions", "Suggestions": "Suggestions",
"Recently Direct Messaged": "Recently Direct Messaged", "Recently Direct Messaged": "Recently Direct Messaged",
"Show more": "Show more", "Show more": "Show more",
"If you can't find someone, ask them for their username, or share your username (%(userId)s) or <a>profile link</a>.": "If you can't find someone, ask them for their username, or share your username (%(userId)s) or <a>profile link</a>.", "If you can't find someone, ask them for their username, share your username (%(userId)s) or <a>profile link</a>.": "If you can't find someone, ask them for their username, share your username (%(userId)s) or <a>profile link</a>.",
"Go": "Go", "Go": "Go",
"If you can't find someone, ask them for their username (e.g. @user:server.com) or <a>share this room</a>.": "If you can't find someone, ask them for their username (e.g. @user:server.com) or <a>share this room</a>.", "If you can't find someone, ask them for their username (e.g. @user:server.com) or <a>share this room</a>.": "If you can't find someone, ask them for their username (e.g. @user:server.com) or <a>share this room</a>.",
"You added a new device '%(displayName)s', which is requesting encryption keys.": "You added a new device '%(displayName)s', which is requesting encryption keys.", "You added a new device '%(displayName)s', which is requesting encryption keys.": "You added a new device '%(displayName)s', which is requesting encryption keys.",