diff --git a/src/components/viewmodels/roomlist/useFilteredRooms.tsx b/src/components/viewmodels/roomlist/useFilteredRooms.tsx index 9a1730a7353..f30afd27d9a 100644 --- a/src/components/viewmodels/roomlist/useFilteredRooms.tsx +++ b/src/components/viewmodels/roomlist/useFilteredRooms.tsx @@ -14,9 +14,11 @@ import RoomListStoreV3, { LISTS_UPDATE_EVENT, type RoomsResult, } from "../../../stores/room-list-v3/RoomListStoreV3"; -import { useEventEmitter } from "../../../hooks/useEventEmitter"; +import { useEventEmitter, useEventEmitterState } from "../../../hooks/useEventEmitter"; import SpaceStore from "../../../stores/spaces/SpaceStore"; import { UPDATE_SELECTED_SPACE } from "../../../stores/spaces"; +import { useSettingValue } from "../../../hooks/useSettings"; +import type { Room } from "matrix-js-sdk/src/matrix"; /** * Provides information about a primary filter. @@ -99,6 +101,23 @@ export function useFilteredRooms(): FilteredRooms { setIsLoadingRooms(false); }); + const currentSpace = useEventEmitterState( + SpaceStore.instance, + UPDATE_SELECTED_SPACE, + () => SpaceStore.instance.activeSpaceRoom, + ); + const showPeopleFilter = useSettingValue("Spaces.showPeopleInSpace", currentSpace?.roomId); + + // If the people filter is disabled in the space settings and it is currently active, unset it. + useEffect(() => { + if (primaryFilter === FilterKey.PeopleFilter && !showPeopleFilter) { + setPrimaryFilter(() => { + updateRoomsFromStore(); + return undefined; + }); + } + }, [primaryFilter, updateRoomsFromStore, showPeopleFilter]); + /** * This tells the view which primary filters are available, how to toggle them * and whether a given primary filter is active. @see {@link PrimaryFilter} @@ -120,10 +139,13 @@ export function useFilteredRooms(): FilteredRooms { }; const filters: PrimaryFilter[] = []; for (const [key, name] of filterKeyToNameMap.entries()) { + // Don't render the people filter because it is disabled in space settings + if (key === FilterKey.PeopleFilter && !showPeopleFilter) continue; + filters.push(createPrimaryFilter(key, _t(name))); } return filters; - }, [primaryFilter, updateRoomsFromStore]); + }, [primaryFilter, updateRoomsFromStore, showPeopleFilter]); const activePrimaryFilter = useMemo(() => primaryFilters.find((filter) => filter.active), [primaryFilters]); diff --git a/src/components/views/dialogs/SpacePreferencesDialog.tsx b/src/components/views/dialogs/SpacePreferencesDialog.tsx index 3bb34165243..f73e3c81b0b 100644 --- a/src/components/views/dialogs/SpacePreferencesDialog.tsx +++ b/src/components/views/dialogs/SpacePreferencesDialog.tsx @@ -33,7 +33,7 @@ const SpacePreferencesAppearanceTab: React.FC> = ({ space return ( - + > = ({ space !showPeople, ); }} - description={_t("space|preferences|show_people_in_space", { + description={_t("space|preferences|show_people_filter_in_space", { spaceName: space.name, })} > diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 811edc15905..5a9a1f3100e 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -3237,8 +3237,8 @@ "mark_suggested": "Mark as suggested", "no_search_result_hint": "You may want to try a different search or check for typos.", "preferences": { - "sections_section": "Sections to show", - "show_people_in_space": "This groups your chats with members of this space. Turning this off will hide those chats from your view of %(spaceName)s." + "sections_filter": "Filters to show", + "show_people_filter_in_space": "Show the People filter and DMs related to this Space." }, "room_filter_placeholder": "Search for rooms", "search_children": "Search %(spaceName)s", diff --git a/src/stores/room-list-v3/RoomListStoreV3.ts b/src/stores/room-list-v3/RoomListStoreV3.ts index f5fb48df07a..e71cf03776c 100644 --- a/src/stores/room-list-v3/RoomListStoreV3.ts +++ b/src/stores/room-list-v3/RoomListStoreV3.ts @@ -81,6 +81,11 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient { super(dispatcher); this.msc3946ProcessDynamicPredecessor = SettingsStore.getValue("feature_dynamic_room_predecessors"); SpaceStore.instance.on(UPDATE_SELECTED_SPACE, () => { + SettingsStore.unwatchSetting("Spaces.showPeopleInSpace"); + SettingsStore.watchSetting("Spaces.showPeopleInSpace", SpaceStore.instance.activeSpace, () => + this.onActiveSpaceChanged(), + ); + this.onActiveSpaceChanged(); }); SpaceStore.instance.on(UPDATE_HOME_BEHAVIOUR, () => this.onActiveSpaceChanged());