Rejig tab complete to make it faster
Now do a lot less when people speak. Also move more of the tab completion logic into TabComplete.js and out of RoomView.
This commit is contained in:
parent
f1d72296b7
commit
d5bed78a54
5 changed files with 113 additions and 94 deletions
|
@ -69,6 +69,7 @@ class Entry {
|
|||
class CommandEntry extends Entry {
|
||||
constructor(cmd, cmdWithArgs) {
|
||||
super(cmdWithArgs);
|
||||
this.kind = 'command';
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
|
@ -95,6 +96,7 @@ class MemberEntry extends Entry {
|
|||
constructor(member) {
|
||||
super(member.name || member.userId);
|
||||
this.member = member;
|
||||
this.kind = 'member';
|
||||
}
|
||||
|
||||
getImageJsx() {
|
||||
|
@ -113,42 +115,8 @@ class MemberEntry extends Entry {
|
|||
}
|
||||
}
|
||||
|
||||
MemberEntry.fromMemberList = function(room, members) {
|
||||
// build up a dict of when, in the history we have cached,
|
||||
// each member last spoke
|
||||
const lastSpoke = {};
|
||||
const timelineEvents = room.getLiveTimeline().getEvents();
|
||||
for (const ev of room.getLiveTimeline().getEvents()) {
|
||||
lastSpoke[ev.getSender()] = ev.getTs();
|
||||
}
|
||||
|
||||
return members.sort(function(a, b) {
|
||||
const lastSpokeA = lastSpoke[a.userId] || 0;
|
||||
const lastSpokeB = lastSpoke[b.userId] || 0;
|
||||
|
||||
if (lastSpokeA != lastSpokeB) {
|
||||
// B - A here because the highest value
|
||||
// is most recent
|
||||
return lastSpokeB - lastSpokeA;
|
||||
}
|
||||
|
||||
var userA = a.user;
|
||||
var userB = b.user;
|
||||
if (userA && !userB) {
|
||||
return -1; // a comes first
|
||||
}
|
||||
else if (!userA && userB) {
|
||||
return 1; // b comes first
|
||||
}
|
||||
else if (!userA && !userB) {
|
||||
return 0; // don't care
|
||||
}
|
||||
else { // both User objects exist
|
||||
var lastActiveAgoA = userA.lastActiveAgo || Number.MAX_SAFE_INTEGER;
|
||||
var lastActiveAgoB = userB.lastActiveAgo || Number.MAX_SAFE_INTEGER;
|
||||
return lastActiveAgoA - lastActiveAgoB;
|
||||
}
|
||||
}).map(function(m) {
|
||||
MemberEntry.fromMemberList = function(members) {
|
||||
return members.map(function(m) {
|
||||
return new MemberEntry(m);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue