List group rooms and public group rooms properly
This commit is contained in:
parent
16e12fab8a
commit
44446b8d47
4 changed files with 69 additions and 7 deletions
8
.env
Normal file
8
.env
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
####
|
||||||
|
# App Config
|
||||||
|
# Environment files are documented here:
|
||||||
|
# https://vitejs.dev/guide/env-and-mode.html#env-files
|
||||||
|
####
|
||||||
|
|
||||||
|
# The room id for the space to use for listing public group call rooms
|
||||||
|
# VITE_PUBLIC_SPACE_ROOM_ID=!hjdfshkdskjdsk:myhomeserver.com
|
|
@ -39,3 +39,7 @@ yarn link matrix-js-sdk
|
||||||
yarn link matrix-react-sdk
|
yarn link matrix-react-sdk
|
||||||
yarn dev
|
yarn dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Config
|
||||||
|
|
||||||
|
Configuration options are documented in the `.env` file.
|
||||||
|
|
|
@ -277,24 +277,45 @@ function sortRooms(client, rooms) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useRooms(client) {
|
export function useGroupCallRooms(client) {
|
||||||
const [rooms, setRooms] = useState([]);
|
const [rooms, setRooms] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function updateRooms() {
|
function updateRooms() {
|
||||||
const visibleRooms = client.getVisibleRooms();
|
const groupCalls = client.groupCallEventHandler.groupCalls.values();
|
||||||
const sortedRooms = sortRooms(client, visibleRooms);
|
const rooms = Array.from(groupCalls).map((groupCall) => groupCall.room);
|
||||||
|
const sortedRooms = sortRooms(client, rooms);
|
||||||
setRooms(sortedRooms);
|
setRooms(sortedRooms);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRooms();
|
updateRooms();
|
||||||
|
|
||||||
client.on("Room", updateRooms);
|
client.on("GroupCall.incoming", updateRooms);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
client.removeListener("Room", updateRooms);
|
client.removeListener("GroupCall.incoming", updateRooms);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return rooms;
|
return rooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function usePublicRooms(client, publicSpaceRoomId, maxRooms = 50) {
|
||||||
|
const [rooms, setRooms] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (publicSpaceRoomId) {
|
||||||
|
client.getRoomHierarchy(publicSpaceRoomId, maxRooms).then(({ rooms }) => {
|
||||||
|
const filteredRooms = rooms.filter(
|
||||||
|
(room) => room.room_type !== "m.space"
|
||||||
|
);
|
||||||
|
|
||||||
|
setRooms(filteredRooms);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setRooms([]);
|
||||||
|
}
|
||||||
|
}, [publicSpaceRoomId]);
|
||||||
|
|
||||||
|
return rooms;
|
||||||
|
}
|
||||||
|
|
33
src/Home.jsx
33
src/Home.jsx
|
@ -16,7 +16,10 @@ limitations under the License.
|
||||||
|
|
||||||
import React, { useCallback, useRef, useState } from "react";
|
import React, { useCallback, useRef, useState } from "react";
|
||||||
import { useHistory, Link } from "react-router-dom";
|
import { useHistory, Link } from "react-router-dom";
|
||||||
import { useRooms } from "./ConferenceCallManagerHooks";
|
import {
|
||||||
|
useGroupCallRooms,
|
||||||
|
usePublicRooms,
|
||||||
|
} from "./ConferenceCallManagerHooks";
|
||||||
import { Header, LeftNav, UserNav } from "./Header";
|
import { Header, LeftNav, UserNav } from "./Header";
|
||||||
import ColorHash from "color-hash";
|
import ColorHash from "color-hash";
|
||||||
import styles from "./Home.module.css";
|
import styles from "./Home.module.css";
|
||||||
|
@ -34,7 +37,11 @@ export function Home({ client, onLogout }) {
|
||||||
const roomNameRef = useRef();
|
const roomNameRef = useRef();
|
||||||
const guestAccessRef = useRef();
|
const guestAccessRef = useRef();
|
||||||
const [createRoomError, setCreateRoomError] = useState();
|
const [createRoomError, setCreateRoomError] = useState();
|
||||||
const rooms = useRooms(client);
|
const rooms = useGroupCallRooms(client);
|
||||||
|
const publicRooms = usePublicRooms(
|
||||||
|
client,
|
||||||
|
import.meta.env.VITE_PUBLIC_SPACE_ROOM_ID
|
||||||
|
);
|
||||||
|
|
||||||
const onCreateRoom = useCallback(
|
const onCreateRoom = useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
|
@ -139,6 +146,28 @@ export function Home({ client, onLogout }) {
|
||||||
</FieldRow>
|
</FieldRow>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
{publicRooms.length > 0 && (
|
||||||
|
<section>
|
||||||
|
<h3>Public Rooms</h3>
|
||||||
|
<div className={styles.roomList}>
|
||||||
|
{publicRooms.map((room) => (
|
||||||
|
<Link
|
||||||
|
className={styles.roomListItem}
|
||||||
|
key={room.room_id}
|
||||||
|
to={`/room/${room.room_id}`}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={styles.roomAvatar}
|
||||||
|
style={{ backgroundColor: colorHash.hex(room.name) }}
|
||||||
|
>
|
||||||
|
<span>{room.name.slice(0, 1)}</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.roomName}>{room.name}</div>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
<section>
|
<section>
|
||||||
<h3>Recent Rooms</h3>
|
<h3>Recent Rooms</h3>
|
||||||
<div className={styles.roomList}>
|
<div className={styles.roomList}>
|
||||||
|
|
Loading…
Reference in a new issue