Data Request API helper #10
6 changed files with 38 additions and 32 deletions
|
|
@ -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 { 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 = {
|
const events = {
|
||||||
// Data Request sockets
|
// Data Request sockets
|
||||||
"query.cancel": cancelRequest,
|
"query.cancel": queryCancel,
|
||||||
"query.notify": createNotif,
|
"query.notify": queryNotify,
|
||||||
"query.prompt": dataRequest,
|
"query.prompt": queryPrompt,
|
||||||
"query.submit": submitRequest,
|
"query.submit": querySubmit,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function registerSockets() {
|
export function registerSockets() {
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export function cancelRequest() {};
|
|
||||||
|
|
@ -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,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
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`,
|
||||||
|
Oliver marked this conversation as resolved
|
|||||||
|
content,
|
||||||
|
whisper,
|
||||||
|
style: CONST.CHAT_MESSAGE_STYLES.OOC,
|
||||||
|
});
|
||||||
|
|
||||||
|
respondedToQueries.delete(id);
|
||||||
|
};
|
||||||
|
|
@ -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 {
|
const {
|
||||||
id,
|
id,
|
||||||
users,
|
users,
|
||||||
|
|
@ -40,6 +41,7 @@ export async function dataRequest(payload) {
|
||||||
} else if (result.state === `errored`) {
|
} else if (result.state === `errored`) {
|
||||||
ui.notifications.error(result.error);
|
ui.notifications.error(result.error);
|
||||||
} else if (result.state === `prompted`) {
|
} else if (result.state === `prompted`) {
|
||||||
|
respondedToQueries.add(request.id);
|
||||||
game.socket.emit(`system.taf`, {
|
game.socket.emit(`system.taf`, {
|
||||||
event: `query.submit`,
|
event: `query.submit`,
|
||||||
payload: {
|
payload: {
|
||||||
|
|
@ -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 {
|
const {
|
||||||
id,
|
id,
|
||||||
answers,
|
answers,
|
||||||
Loading…
Add table
Add a link
Reference in a new issue
Localizing this would be nice