confirmRoom

This commit is contained in:
jusax23 2023-03-29 15:18:15 +02:00
parent f67846ab39
commit c22ca39e3b
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
2 changed files with 53 additions and 4 deletions

View file

@ -467,7 +467,49 @@ export const inviteUser: Act = {
}
};
export const confirmRoom: Act = {
state: STATE.client | STATE.remote,
right: 0,
data: {
room: "name-100",
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, "confirmRoom", data);
if (resp.state == "ok") {
try {
let query = await insert(remoteRooms.accID, remoteRooms.server, remoteRooms.room, remoteRooms.confirmed)
.add(client.accID, resp.server, data.room, true)
.query(db);
if (query.affectedRows == 0) throw new Error("insertion error");
} catch (error) {
await update(remoteRooms)
.set(remoteRooms.confirmed, true)
.where(and(
eq(remoteRooms.server, resp.server),
eq(remoteRooms.room, data.room),
eq(remoteRooms.accID, client.accID)
)).query(db);
}
}
aws(resp.state, resp.data);
return;
}
let roomID = await client.isInRoom(data.room);
if (roomID == -1) return void aws("error", "existence");
let req = await update(roomMembers)
.set(roomMembers.confimed, true)
.where(and(
eq(roomMembers.roomID, roomID),
eq(roomMembers.name, client.name),
eq(roomMembers.server, client.state == STATE.client ? "local" : client.server.tag)
)).query(db);
if (req.affectedRows > 0) aws("ok", "");
else aws("error", "existence");
}
}
export const kickMember: Act = {
state: STATE.client | STATE.remote,

View file

@ -52,11 +52,18 @@ export class Client {
debug("Client", "passing act to remote:", server);
try {
let s = await outbagURLfromTag(server);
return await fetchRemoteAs(s, this.name, act, data);
let resp = await fetchRemoteAs(s, this.name, act, data) as {
state: string,
data: any,
server: string | null
};
resp.server = s.tag;
return resp;
} catch (error) {
return {
state: "error",
data: "remote"
data: "remote",
server: null
}
}
@ -132,7 +139,7 @@ export function checktype(data: any, type: string) {
} else if (type.startsWith("array-") && Array.isArray(data)) {
let ttype = type.substring(6);
for (let i = 0; i < data.length; i++) {
if(!checktype(data[i], ttype)) return false;
if (!checktype(data[i], ttype)) return false;
}
return true;
} else if (type == "any") {