From 4128155189e4d5d96b2ca14eb7cdeb808b3e6ed1 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Sat, 18 Mar 2023 14:45:31 +0100 Subject: [PATCH] listPublicRooms --- src/api/acts/client.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/api/acts/client.ts b/src/api/acts/client.ts index 19c62c6..ca9aabf 100644 --- a/src/api/acts/client.ts +++ b/src/api/acts/client.ts @@ -1,4 +1,4 @@ -import { and, eq, insert, remove, select, update } from "dblang"; +import { and, eq, ge, insert, remove, select, update } from "dblang"; import { PERMISSIONS } from "../../server/permissions.js"; import { sha256, sign } from "../../sys/crypto.js"; import { accounts, db, roomMembers, rooms } from "../../sys/db.js"; @@ -151,4 +151,34 @@ export const deleteRoom = { aws("error", "existence"); } } -} \ No newline at end of file +}; + +export const listPublicRooms = { + state: STATE.client, + right: PERMISSIONS.CAN_USE_API, + data: {}, + func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { + + let req = await select([ + rooms.name, + rooms.public, + rooms.title, + rooms.description, + rooms.icon + ], rooms) + .where(ge(rooms.public, 0)) + .query(db); + let out = req.map(d => { + let name = d[rooms.name]; + let isPublic = d[rooms.public]; + let title = d[rooms.title]; + let description = d[rooms.description]; + let icon = d[rooms.icon]; + if (name != null && isPublic != null && title != null && description != null && icon != null) { + return { name, public: isPublic, title, description, icon }; + } + return null; + }); + aws("ok", out.filter(d => d != null)); + } +};