mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Switch to collator for perf reasons
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
3d4ba20150
commit
86c1550850
@ -1,11 +1,17 @@
|
|||||||
import {PowerLevels} from "../../../matrix/room/timeline/PowerLevels.js";
|
import {PowerLevels} from "../../../matrix/room/timeline/PowerLevels.js";
|
||||||
|
|
||||||
export function createMemberComparator(powerLevels) {
|
export function createMemberComparator(powerLevels) {
|
||||||
|
const collator = new Intl.Collator();
|
||||||
|
//TODO: This is so that all names with @ do not club together; but do we care?
|
||||||
|
const removeCharacter = string => string.charAt(0) === "@"? string.slice(1) : string;
|
||||||
|
|
||||||
return function comparator(member, otherMember) {
|
return function comparator(member, otherMember) {
|
||||||
const p1 = powerLevels.getUserLevel(member.userId);
|
const p1 = powerLevels.getUserLevel(member.userId);
|
||||||
const p2 = powerLevels.getUserLevel(otherMember.userId);
|
const p2 = powerLevels.getUserLevel(otherMember.userId);
|
||||||
if (p1 !== p2) { return p2 - p1; }
|
if (p1 !== p2) { return p2 - p1; }
|
||||||
return member.name?.localeCompare(otherMember.name);
|
const name = removeCharacter(member.name);
|
||||||
|
const otherName = removeCharacter(otherMember.name);
|
||||||
|
return collator.compare(name, otherName);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user