const ARCHIVFORUMID = 35;
+async function asyncAlert(message) {
+ window.alert(message);
+}
+
+async function asyncConfirm(message) {
+ return window.confirm(message);
+}
+
+async function asyncPrompt(message, defaultValue) {
+ return window.prompt(message, defaultValue);
+}
+
async function banUser(username, reason) {
/* The URL to the ban form does not need any IDs or hidden inputs. We
* hardcode it here.
const thread_title = document.querySelector('.topic-title a').text;
const content = ellipsify(post.querySelector(".content").innerText, 250);
- const splitReason = window.prompt(`Folgenden Beitrag von „${username}“ im Thema „${ellipsify(thread_title, 100)}“ wirklich als Spam archivieren?\n\n„${content}“\n\nGrund:`, "Spam");
+ const splitReason = await asyncPrompt(`Folgenden Beitrag von „${username}“ im Thema „${ellipsify(thread_title, 100)}“ wirklich als Spam archivieren?\n\n„${content}“\n\nGrund:`, "Spam");
if (splitReason === null) {
/* Don't do any of the other actions if splitting was cancelled. */
return;
}
+ const archivingPost = send_mcp_request_archival(post, splitReason);
+
/* Prompting for a separate ban reason in case there is something more
* specific to note here.
*/
const userStillExists = usernameElem.nodeName === "A";
- const banReason = userStillExists &&
- window.prompt(`Benutzer „${username}“ sperren?\n\nGrund:`, "Spam");
- const shouldCloseReport = isPostReported(post) && window.confirm("Meldung zum Beitrag schließen?");
-
- /* Initially, I wanted to use Promise.allSettled() below to trigger and wait
- * for all actions in parallel. But that made at least one of them fail in
- * most cases. Not sure, if there was a mistake in here somewhere (totally
- * not impossible) or if phpBB just does not cope well with parallel mod
- * actions (there are some session IDs and confirm_keys involved when a mod
- * action is executed and confirmed).
+ const banReasonPrompt = userStillExists &&
+ asyncPrompt(`Benutzer „${username}“ sperren?\n\nGrund:`, "Spam");
+
+ /* Mod actions via mcp.php involve a confirm_key which is stored in the
+ * database when an action is requested until it is confirmed. There can only
+ * be one confirm_key stored at a time---meaning there cannot be multiple mcp
+ * actions executed concurrently. See confirm_box() in
+ * phpBB/includes/functions.php.
*
- * So essentially, we do not have any asynchronous execution here,
- * unfortunately.
+ * This means we cannot really execute the actions concurrently here,
+ * unfortunately. User interaction is still done in parallel to one action at
+ * a time, though.
*/
const errors = [];
try {
- await send_mcp_request_archival(post, splitReason);
+ await archivingPost;
} catch (err) {
errors.push(err);
}
+ let banningUser;
+ const banReason = await banReasonPrompt;
if (banReason) {
- try {
- await banUser(username, banReason);
- } catch (err) {
- errors.push(err);
- }
+ banningUser = banUser(username, banReason);
} else if (!userStillExists) {
- window.alert(`Benutzer „${username}“ wurde schon gelöscht und kann nicht mehr gesperrt werden.`);
+ await asyncAlert(`Benutzer „${username}“ wurde schon gelöscht und kann nicht mehr gesperrt werden.`);
+ }
+
+ const shouldCloseReport = isPostReported(post) &&
+ asyncConfirm("Meldung zum Beitrag schließen?");
+
+ try {
+ await banningUser;
+ } catch (err) {
+ errors.push(err);
}
- if (shouldCloseReport) {
+ if (await shouldCloseReport) {
try {
await closeReport(post);
} catch (err) {