From 86c1550850e4ccaef42c408df1857ea11c578af8 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Fri, 25 Jun 2021 23:27:46 +0530 Subject: [PATCH] Switch to collator for perf reasons Signed-off-by: RMidhunSuresh --- src/domain/session/rightpanel/comparator.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/domain/session/rightpanel/comparator.js b/src/domain/session/rightpanel/comparator.js index d4f86176..089ea1ad 100644 --- a/src/domain/session/rightpanel/comparator.js +++ b/src/domain/session/rightpanel/comparator.js @@ -1,11 +1,17 @@ import {PowerLevels} from "../../../matrix/room/timeline/PowerLevels.js"; 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) { const p1 = powerLevels.getUserLevel(member.userId); const p2 = powerLevels.getUserLevel(otherMember.userId); 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); }; }