Use a QueryMatcher for forward dialog filtering
This also allows us to filter by room aliases. Signed-off-by: Robin Townsend <robin@robin.town>
This commit is contained in:
parent
4ef69fcbf6
commit
59660df0cb
2 changed files with 14 additions and 5 deletions
|
@ -38,6 +38,7 @@ import {StaticNotificationState} from "../../../stores/notifications/StaticNotif
|
||||||
import NotificationBadge from "../rooms/NotificationBadge";
|
import NotificationBadge from "../rooms/NotificationBadge";
|
||||||
import {RoomPermalinkCreator} from "../../../utils/permalinks/Permalinks";
|
import {RoomPermalinkCreator} from "../../../utils/permalinks/Permalinks";
|
||||||
import {sortRooms} from "../../../stores/room-list/algorithms/tag-sorting/RecentAlgorithm";
|
import {sortRooms} from "../../../stores/room-list/algorithms/tag-sorting/RecentAlgorithm";
|
||||||
|
import QueryMatcher from "../../../autocomplete/QueryMatcher";
|
||||||
|
|
||||||
const AVATAR_SIZE = 30;
|
const AVATAR_SIZE = 30;
|
||||||
|
|
||||||
|
@ -176,14 +177,22 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
|
||||||
|
|
||||||
const spacesEnabled = useFeatureEnabled("feature_spaces");
|
const spacesEnabled = useFeatureEnabled("feature_spaces");
|
||||||
const flairEnabled = useFeatureEnabled(UIFeature.Flair);
|
const flairEnabled = useFeatureEnabled(UIFeature.Flair);
|
||||||
const previewLayout = useSettingValue("layout");
|
const previewLayout = useSettingValue<Layout>("layout");
|
||||||
|
|
||||||
const rooms = useMemo(() => sortRooms(
|
let rooms = useMemo(() => sortRooms(
|
||||||
cli.getVisibleRooms().filter(
|
cli.getVisibleRooms().filter(
|
||||||
room => room.getMyMembership() === "join" &&
|
room => room.getMyMembership() === "join" &&
|
||||||
!(spacesEnabled && room.isSpaceRoom()),
|
!(spacesEnabled && room.isSpaceRoom()),
|
||||||
),
|
),
|
||||||
), [cli, spacesEnabled]).filter(room => room.name.toLowerCase().includes(lcQuery));
|
), [cli, spacesEnabled]);
|
||||||
|
|
||||||
|
if (lcQuery) {
|
||||||
|
rooms = new QueryMatcher<Room>(rooms, {
|
||||||
|
keys: ["name"],
|
||||||
|
funcs: [r => [r.getCanonicalAlias(), ...r.getAltAliases()].filter(Boolean)],
|
||||||
|
shouldMatchWordsOnly: false,
|
||||||
|
}).match(lcQuery);
|
||||||
|
}
|
||||||
|
|
||||||
return <BaseDialog
|
return <BaseDialog
|
||||||
title={_t("Forward message")}
|
title={_t("Forward message")}
|
||||||
|
|
|
@ -35,8 +35,8 @@ export const useSettingValue = <T>(settingName: string, roomId: string = null, e
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hook to fetch whether a feature is enabled and dynamically update when that changes
|
// Hook to fetch whether a feature is enabled and dynamically update when that changes
|
||||||
export const useFeatureEnabled = (featureName: string, roomId: string = null) => {
|
export const useFeatureEnabled = (featureName: string, roomId: string = null): boolean => {
|
||||||
const [enabled, setEnabled] = useState(SettingsStore.getValue(featureName, roomId));
|
const [enabled, setEnabled] = useState(SettingsStore.getValue<boolean>(featureName, roomId));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const ref = SettingsStore.watchSetting(featureName, roomId, () => {
|
const ref = SettingsStore.watchSetting(featureName, roomId, () => {
|
||||||
|
|
Loading…
Reference in a new issue