confirmRoom
This commit is contained in:
parent
f67846ab39
commit
c22ca39e3b
2 changed files with 53 additions and 4 deletions
|
@ -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 = {
|
export const kickMember: Act = {
|
||||||
state: STATE.client | STATE.remote,
|
state: STATE.client | STATE.remote,
|
||||||
|
|
|
@ -52,11 +52,18 @@ export class Client {
|
||||||
debug("Client", "passing act to remote:", server);
|
debug("Client", "passing act to remote:", server);
|
||||||
try {
|
try {
|
||||||
let s = await outbagURLfromTag(server);
|
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) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
state: "error",
|
state: "error",
|
||||||
data: "remote"
|
data: "remote",
|
||||||
|
server: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue