Move the query event handlers into a subfolder and name them in a consistent way
This commit is contained in:
parent
6a2cc1170d
commit
c113c326c6
6 changed files with 38 additions and 32 deletions
24
module/sockets/query/notify.mjs
Normal file
24
module/sockets/query/notify.mjs
Normal file
|
|
@ -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);
|
||||
};
|
||||
53
module/sockets/query/prompt.mjs
Normal file
53
module/sockets/query/prompt.mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { DialogManager } from "../../utils/DialogManager.mjs";
|
||||
import { respondedToQueries } from "../../utils/QueryManager.mjs";
|
||||
|
||||
export async function queryPrompt(payload) {
|
||||
const {
|
||||
id,
|
||||
users,
|
||||
config,
|
||||
request,
|
||||
} = payload;
|
||||
|
||||
if (!id) {
|
||||
ui.notifications.error(game.i18n.format(
|
||||
`taf.notifs.error.malformed-socket-payload`,
|
||||
{
|
||||
event: `query.prompt`,
|
||||
details: `A request ID must be provided`,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
// null/undefined is a special case for "all users but me" by default
|
||||
if (users != null && !Array.isArray(users)) {
|
||||
ui.notifications.error(game.i18n.format(
|
||||
`taf.notifs.error.malformed-socket-payload`,
|
||||
{
|
||||
event: `query.prompt`,
|
||||
details: `A list of users must be provided`,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
if (users != null && !users.includes(game.user.id)) { return };
|
||||
|
||||
request.id = id;
|
||||
const result = await DialogManager.ask(request, config);
|
||||
if (result.state === `fronted`) {
|
||||
return;
|
||||
} 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: {
|
||||
id: request.id,
|
||||
answers: result.answers,
|
||||
},
|
||||
});
|
||||
};
|
||||
};
|
||||
22
module/sockets/query/submit.mjs
Normal file
22
module/sockets/query/submit.mjs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { addResponse, has as hasQuery } from "../../utils/QueryManager.mjs";
|
||||
|
||||
export function querySubmit(payload, user) {
|
||||
const {
|
||||
id,
|
||||
answers,
|
||||
} = payload;
|
||||
|
||||
if (!id) {
|
||||
ui.notifications.error(game.i18n.format(
|
||||
`taf.notifs.error.malformed-socket-payload`,
|
||||
{
|
||||
event: `query.submit`,
|
||||
details: `A request ID must be provided`,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
if (!hasQuery(id)) { return };
|
||||
addResponse(id, user.id, answers);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue