From c113c326c66eeba6f93eb602e562973e8c1621a0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 20 Nov 2025 22:14:43 -0700 Subject: [PATCH] Move the query event handlers into a subfolder and name them in a consistent way --- module/sockets/_index.mjs | 16 ++++++------- module/sockets/cancelRequest.mjs | 1 - module/sockets/createNotif.mjs | 19 --------------- module/sockets/query/notify.mjs | 24 +++++++++++++++++++ .../{dataRequest.mjs => query/prompt.mjs} | 6 +++-- .../{submitRequest.mjs => query/submit.mjs} | 4 ++-- 6 files changed, 38 insertions(+), 32 deletions(-) delete mode 100644 module/sockets/cancelRequest.mjs delete mode 100644 module/sockets/createNotif.mjs create mode 100644 module/sockets/query/notify.mjs rename module/sockets/{dataRequest.mjs => query/prompt.mjs} (83%) rename module/sockets/{submitRequest.mjs => query/submit.mjs} (72%) diff --git a/module/sockets/_index.mjs b/module/sockets/_index.mjs index a133c06..f824c9e 100644 --- a/module/sockets/_index.mjs +++ b/module/sockets/_index.mjs @@ -1,15 +1,15 @@ -import { cancelRequest } from "./cancelRequest.mjs"; -import { createNotif } from "./createNotif.mjs"; -import { dataRequest } from "./dataRequest.mjs"; import { Logger } from "../utils/Logger.mjs"; -import { submitRequest } from "./submitRequest.mjs"; +import { queryCancel } from "./query/cancel.mjs"; +import { queryNotify } from "./query/notify.mjs"; +import { queryPrompt } from "./query/prompt.mjs"; +import { querySubmit } from "./query/submit.mjs"; const events = { // Data Request sockets - "query.cancel": cancelRequest, - "query.notify": createNotif, - "query.prompt": dataRequest, - "query.submit": submitRequest, + "query.cancel": queryCancel, + "query.notify": queryNotify, + "query.prompt": queryPrompt, + "query.submit": querySubmit, }; export function registerSockets() { diff --git a/module/sockets/cancelRequest.mjs b/module/sockets/cancelRequest.mjs deleted file mode 100644 index 865071a..0000000 --- a/module/sockets/cancelRequest.mjs +++ /dev/null @@ -1 +0,0 @@ -export function cancelRequest() {}; diff --git a/module/sockets/createNotif.mjs b/module/sockets/createNotif.mjs deleted file mode 100644 index 8ec4c2f..0000000 --- a/module/sockets/createNotif.mjs +++ /dev/null @@ -1,19 +0,0 @@ -export function createNotif(payload) { - const { userID, content, includeGM } = payload; - - if (userID !== game.user.id) { return }; - - // TODO: prevent this from working if the user hasn't submitted a query response - - let whisper = [game.user.id]; - if (includeGM) { - whisper = game.users.filter(u => u.isGM).map(u => u.id); - }; - - ChatMessage.implementation.create({ - flavor: `Data Query Notification`, - content, - whisper, - style: CONST.CHAT_MESSAGE_STYLES.OOC, - }); -}; diff --git a/module/sockets/query/notify.mjs b/module/sockets/query/notify.mjs new file mode 100644 index 0000000..7974d63 --- /dev/null +++ b/module/sockets/query/notify.mjs @@ -0,0 +1,24 @@ +import { respondedToQueries } from "../../utils/QueryManager.mjs"; + +export function queryNotify(payload) { + const { id, userID, content, includeGM } = payload; + + if (userID !== game.user.id) { return }; + + // Ensure that each user can only get one notification about a query + if (!respondedToQueries.has(id)) { return }; + + let whisper = [game.user.id]; + if (includeGM) { + whisper = game.users.filter(u => u.isGM).map(u => u.id); + }; + + ChatMessage.implementation.create({ + flavor: `Data Query Notification`, + content, + whisper, + style: CONST.CHAT_MESSAGE_STYLES.OOC, + }); + + respondedToQueries.delete(id); +}; diff --git a/module/sockets/dataRequest.mjs b/module/sockets/query/prompt.mjs similarity index 83% rename from module/sockets/dataRequest.mjs rename to module/sockets/query/prompt.mjs index 34cd39f..aef9d72 100644 --- a/module/sockets/dataRequest.mjs +++ b/module/sockets/query/prompt.mjs @@ -1,6 +1,7 @@ -import { DialogManager } from "../utils/DialogManager.mjs"; +import { DialogManager } from "../../utils/DialogManager.mjs"; +import { respondedToQueries } from "../../utils/QueryManager.mjs"; -export async function dataRequest(payload) { +export async function queryPrompt(payload) { const { id, users, @@ -40,6 +41,7 @@ export async function dataRequest(payload) { } else if (result.state === `errored`) { ui.notifications.error(result.error); } else if (result.state === `prompted`) { + respondedToQueries.add(request.id); game.socket.emit(`system.taf`, { event: `query.submit`, payload: { diff --git a/module/sockets/submitRequest.mjs b/module/sockets/query/submit.mjs similarity index 72% rename from module/sockets/submitRequest.mjs rename to module/sockets/query/submit.mjs index 1d4ef0c..a4c9d6d 100644 --- a/module/sockets/submitRequest.mjs +++ b/module/sockets/query/submit.mjs @@ -1,6 +1,6 @@ -import { addResponse, has as hasQuery } from "../utils/QueryManager.mjs"; +import { addResponse, has as hasQuery } from "../../utils/QueryManager.mjs"; -export function submitRequest(payload, user) { +export function querySubmit(payload, user) { const { id, answers,