Skip to content
This repository was archived by the owner on Sep 14, 2025. It is now read-only.

Commit 0bfa6d2

Browse files
committed
Add /rooms API endpoint
1 parent f9f0b64 commit 0bfa6d2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/router/get-rooms.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { getRooms } from '@/room'
2+
import type { SogsRequest, SogsResponse } from '@/router'
3+
import { getRoomDetails } from '@/router/get-room'
4+
import { testPermission } from '@/utils'
5+
6+
export async function getRoomsRoute(req: SogsRequest): Promise<SogsResponse> {
7+
const rooms = getRooms()
8+
const accessibleRooms: any[] = []
9+
10+
for (const room of rooms.values()) {
11+
if (req.user !== null) {
12+
const permissions = await room.getUserPermissions(req.user)
13+
if (!testPermission(permissions, ['accessible'])) {
14+
continue
15+
}
16+
} else if (!room.defaultAccessible) {
17+
continue
18+
}
19+
20+
accessibleRooms.push(await getRoomDetails(room, null))
21+
}
22+
23+
return {
24+
status: 200,
25+
response: accessibleRooms,
26+
contentType: 'application/json'
27+
}
28+
}

src/router/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { User } from '@/user'
22
import { getCapabilities } from '@/router/get-capabilities'
3+
import { getRoomsRoute } from '@/router/get-rooms'
34
import { getRoom } from '@/router/get-room'
45
import { getRoomUpdates } from '@/router/get-room-updates'
56
import { getRoomRecentMessages } from '@/router/get-room-recent-messages'
@@ -48,6 +49,7 @@ type Route = { method: string, route: string, handler: (req: SogsRequest) => Sog
4849
const router: Route[] = []
4950

5051
router.push({ method: 'GET', route: '/capabilities', handler: getCapabilities })
52+
router.push({ method: 'GET', route: '/rooms', handler: getRoomsRoute })
5153
router.push({ method: 'GET', route: '/room/:token', handler: getRoom })
5254
router.push({ method: 'GET', route: '/room/:token/pollInfo/:info_updates', handler: getRoomUpdates })
5355
router.push({ method: 'DELETE', route: '/room/:token/all/:session_id', handler: deleteAllFromUser })

0 commit comments

Comments
 (0)