Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/components/viewmodels/roomlist/useFilteredRooms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -99,6 +101,23 @@ export function useFilteredRooms(): FilteredRooms {
setIsLoadingRooms(false);
});

const currentSpace = useEventEmitterState<Room | null>(
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}
Expand All @@ -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]);

Expand Down
4 changes: 2 additions & 2 deletions src/components/views/dialogs/SpacePreferencesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const SpacePreferencesAppearanceTab: React.FC<Pick<IProps, "space">> = ({ space

return (
<SettingsTab>
<SettingsSection heading={_t("space|preferences|sections_section")}>
<SettingsSection heading={_t("space|preferences|sections_filter")}>
<SettingsSubsection>
<StyledCheckbox
checked={!!showPeople}
Expand All @@ -45,7 +45,7 @@ const SpacePreferencesAppearanceTab: React.FC<Pick<IProps, "space">> = ({ space
!showPeople,
);
}}
description={_t("space|preferences|show_people_in_space", {
description={_t("space|preferences|show_people_filter_in_space", {
spaceName: space.name,
})}
>
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/stores/room-list-v3/RoomListStoreV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
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());
Expand Down
Loading