From a091ce93dfb40c203447916d5240fa33b4dbe2d9 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Tue, 27 May 2025 21:36:03 +0100 Subject: [PATCH] Allow pre-filling the message dialog Given that send_message_dialog() fills the form with previous inputs if there are any, we can also provide data to pre-fill the first form. This can be useful for preset dialogs, like an "all players" dialog with all players already input. Add an initial data parameter to send_message_dialog() and add it to the message list if it is provided. --- scripts/mills_messages.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/mills_messages.mjs b/scripts/mills_messages.mjs index 2383e79..578841a 100644 --- a/scripts/mills_messages.mjs +++ b/scripts/mills_messages.mjs @@ -71,16 +71,24 @@ async function create_history_journal(user) { * This allows us to populate the form with previous inputs and go back and forth * within the chain, to be able to fix mistakes or send fewer messages. * + * We also use this to pre-fill the first form with data if any is passed. + * * NOTE: The recipients are the same for all the messages of a chain, to simplify * the processing later as we only have to build one array of messages, shared among * the recipients. + * + * @param {MessageFormResponse|null} initial_form_data Data to pre-fill the first form with. * @returns {Promise} The Promise for the processing of the messages. */ -async function send_message_dialog() { +async function send_message_dialog(initial_form_data = null) { /** @type{MessageFormResponse[]} */ let messages = [] let current_message = 0 + if (initial_form_data !== null) { + messages.push(initial_form_data); + } + let chain = false; do { if (chain) {