forked from mystiq/hydrogen-web
Switch to collator for perf reasons
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
3d4ba20150
commit
86c1550850
1 changed files with 7 additions and 1 deletions
|
@ -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 a new issue