mirror of https://github.com/vector-im/riot-web
Clean up add existing to space dialog and include DMs in it too
parent
ae5b6ef831
commit
e01caba068
|
@ -57,21 +57,22 @@ const AddExistingToSpaceDialog: React.FC<IProps> = ({ matrixClient: cli, space,
|
||||||
|
|
||||||
const existingSubspaces = SpaceStore.instance.getChildSpaces(space.roomId);
|
const existingSubspaces = SpaceStore.instance.getChildSpaces(space.roomId);
|
||||||
const existingSubspacesSet = new Set(existingSubspaces);
|
const existingSubspacesSet = new Set(existingSubspaces);
|
||||||
const spaces = SpaceStore.instance.getSpaces().filter(s => {
|
const existingRoomsSet = new Set(SpaceStore.instance.getChildRooms(space.roomId));
|
||||||
return !existingSubspacesSet.has(s) // not already in space
|
|
||||||
&& space !== s // not the top-level space
|
|
||||||
&& selectedSpace !== s // not the selected space
|
|
||||||
&& s.name.toLowerCase().includes(lcQuery); // contains query
|
|
||||||
});
|
|
||||||
|
|
||||||
const existingRooms = SpaceStore.instance.getChildRooms(space.roomId);
|
const [spaces, rooms, dms] = cli.getVisibleRooms().reduce((arr, room) => {
|
||||||
const existingRoomsSet = new Set(existingRooms);
|
if (room.getMyMembership() !== "join") return arr;
|
||||||
const rooms = cli.getVisibleRooms().filter(room => {
|
if (!room.name.toLowerCase().includes(lcQuery)) return arr;
|
||||||
return !existingRoomsSet.has(room) // not already in space
|
|
||||||
&& !room.isSpaceRoom() // not a space itself
|
if (room.isSpaceRoom()) {
|
||||||
&& room.name.toLowerCase().includes(lcQuery) // contains query
|
if (room !== space && room !== selectedSpace && !existingSubspacesSet.has(room)) {
|
||||||
&& !DMRoomMap.shared().getUserIdForRoomId(room.roomId); // not a DM
|
arr[0].push(room);
|
||||||
});
|
}
|
||||||
|
} else if (!existingRoomsSet.has(room) && selectedSpace.joinRule() !== "public") {
|
||||||
|
// Only show DMs for non-public spaces as they make very little sense in spaces other than "Just Me" ones.
|
||||||
|
arr[DMRoomMap.shared().getUserIdForRoomId(room.roomId) ? 2 : 1].push(room);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}, [[], [], []]);
|
||||||
|
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
@ -172,7 +173,28 @@ const AddExistingToSpaceDialog: React.FC<IProps> = ({ matrixClient: cli, space,
|
||||||
</div>
|
</div>
|
||||||
) : null }
|
) : null }
|
||||||
|
|
||||||
{ spaces.length + rooms.length < 1 ? <span className="mx_AddExistingToSpaceDialog_noResults">
|
{ dms.length > 0 ? (
|
||||||
|
<div className="mx_AddExistingToSpaceDialog_section">
|
||||||
|
<h3>{ _t("Direct Messages") }</h3>
|
||||||
|
{ dms.map(space => {
|
||||||
|
return <Entry
|
||||||
|
key={space.roomId}
|
||||||
|
room={space}
|
||||||
|
checked={selectedToAdd.has(space)}
|
||||||
|
onChange={(checked) => {
|
||||||
|
if (checked) {
|
||||||
|
selectedToAdd.add(space);
|
||||||
|
} else {
|
||||||
|
selectedToAdd.delete(space);
|
||||||
|
}
|
||||||
|
setSelectedToAdd(new Set(selectedToAdd));
|
||||||
|
}}
|
||||||
|
/>;
|
||||||
|
}) }
|
||||||
|
</div>
|
||||||
|
) : null }
|
||||||
|
|
||||||
|
{ spaces.length + rooms.length + dms.length < 1 ? <span className="mx_AddExistingToSpaceDialog_noResults">
|
||||||
{ _t("No results") }
|
{ _t("No results") }
|
||||||
</span> : undefined }
|
</span> : undefined }
|
||||||
</AutoHideScrollbar>
|
</AutoHideScrollbar>
|
||||||
|
|
Loading…
Reference in New Issue