Add private chat to multiplayer rooms
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
joinRoomSchema,
|
||||
roomRoundSchema,
|
||||
roomGuessSchema,
|
||||
chatMessageSchema,
|
||||
type RoomView,
|
||||
} from "../shared/multiplayer";
|
||||
import {
|
||||
@@ -68,6 +69,29 @@ export async function multiplayerApi(
|
||||
}
|
||||
const id = z.string().uuid().parse(path[1]);
|
||||
const action = path[2] ?? "view";
|
||||
if (
|
||||
action === "chat" &&
|
||||
path.length === 3 &&
|
||||
["GET", "POST"].includes(request.method)
|
||||
) {
|
||||
if (!savedSecret)
|
||||
throw new ServiceError("Chat permission requires joining this room", 403);
|
||||
const body =
|
||||
request.method === "POST"
|
||||
? chatMessageSchema.parse(await jsonBody(request))
|
||||
: null;
|
||||
if (body) await limit("multiplayer:chat:" + accessHash, 60, 60);
|
||||
return respond(
|
||||
required(
|
||||
await client.rpc("multiplayer_chat", {
|
||||
p_room: id,
|
||||
p_access_hash: accessHash,
|
||||
p_text: body?.text ?? null,
|
||||
p_client_id: body?.clientId ?? null,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
let payload: Record<string, string | number> = {};
|
||||
if (request.method === "POST" && path.length === 3) {
|
||||
const input = await jsonBody(request);
|
||||
|
||||
Reference in New Issue
Block a user