Prefer canonical aliases over non-canonical ones

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-06-20 10:41:36 +02:00
parent d0ea842f1e
commit 7bf230e665
No known key found for this signature in database
GPG key ID: 9760693FDD98A790

View file

@ -32,6 +32,11 @@ import SettingsStore from "../settings/SettingsStore";
const ROOM_REGEX = /\B#\S*/g;
// Prefer canonical aliases over non-canonical ones
function canonicalScore(displayedAlias: string, room: Room): number {
return displayedAlias === room.getCanonicalAlias() ? 0 : 1;
}
function matcherObject(room: Room, displayedAlias: string, matchName = "") {
return {
room,
@ -97,6 +102,7 @@ export default class RoomProvider extends AutocompleteProvider {
const matchedString = command[0];
completions = this.matcher.match(matchedString, limit);
completions = sortBy(completions, [
(c) => canonicalScore(c.displayedAlias, c.room),
(c) => c.displayedAlias.length,
]);
completions = uniqBy(completions, (match) => match.room);