Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Support adding space-restricted joins on rooms not members of those spaces #9017

Merged
merged 9 commits into from
Aug 3, 2023
38 changes: 34 additions & 4 deletions src/components/views/dialogs/ManageRestrictedJoinRuleDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,20 @@ const ManageRestrictedJoinRuleDialog: React.FC<IProps> = ({ room, selected = [],
const [query, setQuery] = useState("");
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
const lcQuery = query.toLowerCase().trim();

const [spacesContainingRoom, otherEntries] = useMemo(() => {
const [spacesContainingRoom, otherJoinedSpaces, otherEntries] = useMemo(() => {
const parents = new Set<Room>();

// Add the known parents first so the user can see them more easily
addAllParents(parents, room);

// Add all the other known spaces second. We cheat and rely on the Set not
// allowing duplicates here, which should maintain our insertion order from
// above.
// SpaceStore.instance.spacePanelSpaces.forEach(s => parents.add(s));

return [
Array.from(parents),
SpaceStore.instance.spacePanelSpaces.filter(s => !parents.has(s)),
selected.map(roomId => {
const room = cli.getRoom(roomId);
if (!room) {
Expand All @@ -100,10 +109,11 @@ const ManageRestrictedJoinRuleDialog: React.FC<IProps> = ({ room, selected = [],
];
}, [cli, selected, room]);

const [filteredSpacesContainingRoom, filteredOtherEntries] = useMemo(() => [
const [filteredSpacesContainingRoom, filteredOtherJoinedSpaces, filteredOtherEntries] = useMemo(() => [
spacesContainingRoom.filter(r => r.name.toLowerCase().includes(lcQuery)),
otherJoinedSpaces.filter(r => r.name.toLowerCase().includes(lcQuery)),
otherEntries.filter(r => r.name.toLowerCase().includes(lcQuery)),
], [spacesContainingRoom, otherEntries, lcQuery]);
], [spacesContainingRoom, otherJoinedSpaces, otherEntries, lcQuery]);

const onChange = (checked: boolean, room: Room): void => {
if (checked) {
Expand All @@ -121,6 +131,10 @@ const ManageRestrictedJoinRuleDialog: React.FC<IProps> = ({ room, selected = [],
</div>;
}

const totalResults =
filteredSpacesContainingRoom.length
+ filteredOtherJoinedSpaces.length
+ filteredOtherEntries.length;
return <BaseDialog
title={_t("Select spaces")}
className="mx_ManageRestrictedJoinRuleDialog"
Expand Down Expand Up @@ -180,7 +194,23 @@ const ManageRestrictedJoinRuleDialog: React.FC<IProps> = ({ room, selected = [],
</div>
) : null }

{ filteredSpacesContainingRoom.length + filteredOtherEntries.length < 1
{ filteredOtherJoinedSpaces.length > 0 ? (
<div className="mx_ManageRestrictedJoinRuleDialog_section">
<h3>{ _t("Other spaces you know") }</h3>
{ filteredOtherJoinedSpaces.map(space => {
return <Entry
key={space.roomId}
room={space}
checked={newSelected.has(space.roomId)}
onChange={(checked: boolean) => {
onChange(checked, space);
}}
/>;
}) }
</div>
) : null }

{ totalResults < 1
? <span className="mx_ManageRestrictedJoinRuleDialog_noResults">
{ _t("No results") }
</span>
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,7 @@
"Spaces you know that contain this room": "Spaces you know that contain this room",
"Other spaces or rooms you might not know": "Other spaces or rooms you might not know",
"These are likely ones other room admins are a part of.": "These are likely ones other room admins are a part of.",
"Other spaces you know": "Other spaces you know",
"Confirm by comparing the following with the User Settings in your other session:": "Confirm by comparing the following with the User Settings in your other session:",
"Confirm this user's session by comparing the following with their User Settings:": "Confirm this user's session by comparing the following with their User Settings:",
"Session name": "Session name",
Expand Down