mirror of https://github.com/vector-im/riot-web
avoid unneeded lookups in memberDict
have members be an array of RoomMember instead of userId, so we can avoid multiple lookups when sorting, rendering, ...pull/21833/head
parent
50de22fb51
commit
8500a7131f
|
@ -196,12 +196,12 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
const all_members = room.currentState.members;
|
const all_members = room.currentState.members;
|
||||||
|
|
||||||
Object.keys(all_members).map(function(userId) {
|
Object.values(all_members).forEach(function(member) {
|
||||||
// work around a race where you might have a room member object
|
// work around a race where you might have a room member object
|
||||||
// before the user object exists. This may or may not cause
|
// before the user object exists. This may or may not cause
|
||||||
// https://github.com/vector-im/vector-web/issues/186
|
// https://github.com/vector-im/vector-web/issues/186
|
||||||
if (all_members[userId].user === null) {
|
if (member.user === null) {
|
||||||
all_members[userId].user = MatrixClientPeg.get().getUser(userId);
|
member.user = cli.getUser(member.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: this user may have no lastPresenceTs value!
|
// XXX: this user may have no lastPresenceTs value!
|
||||||
|
@ -212,26 +212,20 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
roomMembers: function() {
|
roomMembers: function() {
|
||||||
const all_members = this.memberDict || {};
|
|
||||||
const all_user_ids = Object.keys(all_members);
|
|
||||||
const ConferenceHandler = CallHandler.getConferenceHandler();
|
const ConferenceHandler = CallHandler.getConferenceHandler();
|
||||||
|
|
||||||
all_user_ids.sort(this.memberSort);
|
const allMembersDict = this.memberDict || {};
|
||||||
|
const allMembers = Object.values(allMembersDict);
|
||||||
const to_display = [];
|
const filteredAndSortedMembers = allMembers.filter((m) => {
|
||||||
let count = 0;
|
return (
|
||||||
for (let i = 0; i < all_user_ids.length; ++i) {
|
m.membership === 'join' || m.membership === 'invite'
|
||||||
const user_id = all_user_ids[i];
|
) && (
|
||||||
const m = all_members[user_id];
|
!ConferenceHandler ||
|
||||||
|
(ConferenceHandler && !ConferenceHandler.isConferenceUser(m.userId))
|
||||||
if (m.membership === 'join' || m.membership === 'invite') {
|
);
|
||||||
if ((ConferenceHandler && !ConferenceHandler.isConferenceUser(user_id)) || !ConferenceHandler) {
|
});
|
||||||
to_display.push(user_id);
|
filteredAndSortedMembers.sort(this.memberSort);
|
||||||
++count;
|
return filteredAndSortedMembers;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return to_display;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_createOverflowTileJoined: function(overflowCount, totalCount) {
|
_createOverflowTileJoined: function(overflowCount, totalCount) {
|
||||||
|
@ -278,14 +272,12 @@ module.exports = React.createClass({
|
||||||
// returns negative if a comes before b,
|
// returns negative if a comes before b,
|
||||||
// returns 0 if a and b are equivalent in ordering
|
// returns 0 if a and b are equivalent in ordering
|
||||||
// returns positive if a comes after b.
|
// returns positive if a comes after b.
|
||||||
memberSort: function(userIdA, userIdB) {
|
memberSort: function(memberA, memberB) {
|
||||||
// order by last active, with "active now" first.
|
// order by last active, with "active now" first.
|
||||||
// ...and then by power
|
// ...and then by power
|
||||||
// ...and then alphabetically.
|
// ...and then alphabetically.
|
||||||
// We could tiebreak instead by "last recently spoken in this room" if we wanted to.
|
// We could tiebreak instead by "last recently spoken in this room" if we wanted to.
|
||||||
|
|
||||||
const memberA = this.memberDict[userIdA];
|
|
||||||
const memberB = this.memberDict[userIdB];
|
|
||||||
const userA = memberA.user;
|
const userA = memberA.user;
|
||||||
const userB = memberB.user;
|
const userB = memberB.user;
|
||||||
|
|
||||||
|
@ -335,9 +327,7 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_filterMembers: function(members, membership, query) {
|
_filterMembers: function(members, membership, query) {
|
||||||
return members.filter((userId) => {
|
return members.filter((m) => {
|
||||||
const m = this.memberDict[userId];
|
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
query = query.toLowerCase();
|
query = query.toLowerCase();
|
||||||
const matchesName = m.name.toLowerCase().indexOf(query) !== -1;
|
const matchesName = m.name.toLowerCase().indexOf(query) !== -1;
|
||||||
|
@ -379,10 +369,9 @@ module.exports = React.createClass({
|
||||||
_makeMemberTiles: function(members, membership) {
|
_makeMemberTiles: function(members, membership) {
|
||||||
const MemberTile = sdk.getComponent("rooms.MemberTile");
|
const MemberTile = sdk.getComponent("rooms.MemberTile");
|
||||||
|
|
||||||
const memberList = members.map((userId) => {
|
const memberList = members.map((m) => {
|
||||||
const m = this.memberDict[userId];
|
|
||||||
return (
|
return (
|
||||||
<MemberTile key={userId} member={m} ref={userId} showPresence={this._showPresence} />
|
<MemberTile key={m.userId} member={m} ref={m.userId} showPresence={this._showPresence} />
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue