Cache normalized room name

pull/21833/head
Germain Souquet 2021-05-20 10:43:57 +01:00
parent aa4984019c
commit 66ffaf945f
1 changed files with 3 additions and 13 deletions

View File

@ -17,7 +17,7 @@ limitations under the License.
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { FILTER_CHANGED, FilterKind, IFilterCondition } from "./IFilterCondition"; import { FILTER_CHANGED, FilterKind, IFilterCondition } from "./IFilterCondition";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { removeHiddenChars } from "matrix-js-sdk/src/utils"; import { normalize } from "matrix-js-sdk/src/utils";
import { throttle } from "lodash"; import { throttle } from "lodash";
/** /**
@ -65,17 +65,7 @@ export class NameFilterCondition extends EventEmitter implements IFilterConditio
return this.matches(room.name); return this.matches(room.name);
} }
private normalize(val: string): string { public matches(normalizedName: string): boolean {
// Note: we have to match the filter with the removeHiddenChars() room name because the return normalizedName.includes(normalize(this.search));
// function strips spaces and other characters (M becomes RN for example, in lowercase).
return removeHiddenChars(val.toLowerCase())
// Strip all punctuation
.replace(/[\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~\u2000-\u206f\u2e00-\u2e7f]/g, "")
// We also doubly convert to lowercase to work around oddities of the library.
.toLowerCase();
}
public matches(val: string): boolean {
return this.normalize(val).includes(this.normalize(this.search));
} }
} }