fiexes and remoteRoom save

This commit is contained in:
jusax23 2023-03-20 16:51:58 +01:00
parent 42a2642e41
commit 065a693a61
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41

View file

@ -1,4 +1,4 @@
import { alias, and, eq, exists, innerJoinOn, innerJoinUsing, insert, le, minus, naturalJoin, not, or, remove, select, update } from "dblang"; import { alias, and, eq, exists, geq, innerJoinOn, innerJoinUsing, insert, le, minus, naturalJoin, not, or, remove, select, update } from "dblang";
import { checkSelfTag } from "../../server/outbagURL.js"; import { checkSelfTag } from "../../server/outbagURL.js";
import { ROOM_RIGHTS } from "../../server/permissions.js"; import { ROOM_RIGHTS } from "../../server/permissions.js";
import { accounts, db, remoteRooms, roomMembers, roomOTAs, rooms } from "../../sys/db.js"; import { accounts, db, remoteRooms, roomMembers, roomOTAs, rooms } from "../../sys/db.js";
@ -75,6 +75,7 @@ export const getRoomMembers: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "getRoomMembers", data); let resp = await client.pass(data.server, "getRoomMembers", data);
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -117,9 +118,14 @@ export const joinRoom: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "joinRoom", data); let resp = await client.pass(data.server, "joinRoom", data);
if (resp.state == "ok") { if (resp.state == "ok") {
//TODO: add server to personal list try {
await insert(remoteRooms.accID, remoteRooms.server)
.add(client.accID, data.server)
.query(db);
} catch (error) { }
} else if (resp.data == "ota") { } else if (resp.data == "ota") {
client.suspect(); client.suspect();
client.suspect(); client.suspect();
@ -138,7 +144,10 @@ export const joinRoom: Act = {
if (await isRoomFull(roomID)) return void aws("error", "limit"); if (await isRoomFull(roomID)) return void aws("error", "limit");
// TODO: Make Transaktion when possible // TODO: Make Transaktion when possible
await remove(roomOTAs) await remove(roomOTAs)
.where(le(roomOTAs.expires, uts())) .where(and(
le(roomOTAs.expires, uts()),
geq(roomOTAs.expires, 0)
))
.query(db); .query(db);
let req = await update(roomOTAs) let req = await update(roomOTAs)
.set(roomOTAs.usesLeft, minus(roomOTAs.usesLeft, 1)) .set(roomOTAs.usesLeft, minus(roomOTAs.usesLeft, 1))
@ -180,9 +189,14 @@ export const joinPublicRoom: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "joinPublicRoom", data); let resp = await client.pass(data.server, "joinPublicRoom", data);
if (resp.state == "ok") { if (resp.state == "ok") {
//TODO: add server to personal list try {
await insert(remoteRooms.accID, remoteRooms.server)
.add(client.accID, data.server)
.query(db);
} catch (error) { }
} }
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -223,6 +237,7 @@ export const getRoomOTAs: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "getRoomOTAs", data); let resp = await client.pass(data.server, "getRoomOTAs", data);
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -252,6 +267,7 @@ export const addRoomOTA: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "addRoomOTA", data); let resp = await client.pass(data.server, "addRoomOTA", data);
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -285,6 +301,7 @@ export const deleteRoomOTA: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "deleteRoomOTA", data); let resp = await client.pass(data.server, "deleteRoomOTA", data);
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -311,6 +328,7 @@ export const kickMember: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "kickMember", data); let resp = await client.pass(data.server, "kickMember", data);
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -353,6 +371,7 @@ export const setAdminStatus: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.roomServer, "setAdminStatus", data); let resp = await client.pass(data.roomServer, "setAdminStatus", data);
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -383,11 +402,14 @@ export const leaveRoom: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "leaveRoom", data); let resp = await client.pass(data.server, "leaveRoom", data);
if (resp.state == "ok") { if (resp.state == "ok" || resp.data == "existence") {
//TODO: remove server from personal list await remove(remoteRooms)
} else if (resp.data == "ota") { .where(and(
client.suspect(); eq(client.accID, remoteRooms.accID),
eq(data.server, remoteRooms.server)
)).query(db);
} }
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -429,6 +451,7 @@ export const roomSettings: Act = {
}, },
func: async (client, data, aws) => { func: async (client, data, aws) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "roomSettings", data); let resp = await client.pass(data.server, "roomSettings", data);
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;
@ -456,6 +479,7 @@ export const roomMeta: Act = {
}, },
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!checkSelfTag(data.server)) { if (!checkSelfTag(data.server)) {
if (client.state != STATE.client) return void aws("error", "right");
let resp = await client.pass(data.server, "roomMeta", data); let resp = await client.pass(data.server, "roomMeta", data);
aws(resp.state, resp.data); aws(resp.state, resp.data);
return; return;