room Info

This commit is contained in:
jusax23 2023-03-22 14:28:28 +01:00
parent 3684c69b8a
commit 7acac390aa
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41

View file

@ -66,6 +66,58 @@ export const listRooms: Act = {
}
};
export const getRoomInfo: Act = {
state: STATE.client | STATE.remote,
right: 0,
data: {
room: "name",
server: "string",
},
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "getRoomInfo", data);
aws(resp.state, resp.data);
return;
}
let ownerAlias = alias(
select([accounts.name], accounts)
.where(eq(accounts.accID, rooms.owner)),
"owner") as any;
let req = await select([
rooms.name,
ownerAlias,
rooms.rights,
rooms.visibility,
rooms.title,
rooms.description,
rooms.icon,
roomMembers.admin
], innerJoinUsing(rooms, roomMembers, rooms.roomID, roomMembers.roomID))
.where(and(
eq(roomMembers.name, client.name),
eq(roomMembers.server, client.state == STATE.client ? "local" : client.server.tag),
eq(rooms.name, data.room)
))
.query(db);
if (req.length == 0) return void aws("error", "existence");
aws("ok", {
name: req[0][rooms.name],
server: selfTag.tag,
owner: req[0][ownerAlias],
rights: req[0][rooms.rights],
visibility: req[0][rooms.visibility],
title: req[0][rooms.title],
description: req[0][rooms.description],
icon: req[0][rooms.icon],
isAdmin: req[0][roomMembers.admin] ? true : false,
isOwner: client.state == STATE.client && req[0][ownerAlias] == client.name,
})
}
};
export const getRoomMembers: Act = {
state: STATE.client | STATE.remote,
right: 0,
@ -82,7 +134,6 @@ export const getRoomMembers: Act = {
}
let roomID = await client.isInRoom(data.room);
console.log(data, client.server.tag, client.name, roomID);
if (roomID == -1) {
aws("error", "existence");
return;