Skip to content

Node.js based forum software built for the modern web

fix(post-queue): remove socket call for custom reasons by fetching in controller (#14573)

Julian Lamf8d946c85a17
diff --git a/public/src/client/post-queue.js b/public/src/client/post-queue.js
index d8920d2dfb..6c8ea469a9 100644
--- a/public/src/client/post-queue.js
+++ b/public/src/client/post-queue.js
@@ -129,7 +129,7 @@ define('forum/post-queue', [
});
}
- function confirmReject(msg) {
+ function confirmModal(msg) {
return new Promise((resolve) => {
modals.confirm(msg, resolve);
});
@@ -353,12 +353,13 @@ define('forum/post-queue', [
async function handleReject(btn) {
const parent = $(btn).parents('[data-id]');
const id = parent.attr('data-id');
- const translationString = ajaxify.data.canAccept ?
- '[[post-queue:confirm-reject]]' :
- '[[post-queue:confirm-remove]]';
-
- const message = await getMessage(translationString);
- if (message === false) {
+ let message;
+ if (ajaxify.data.canAccept) {
+ message = await getMessage('[[post-queue:confirm-reject]]');
+ if (message === false) {
+ return;
+ }
+ } else if (!await confirmModal('[[post-queue:confirm-remove]]')) {
return;
}
doAction('reject', id, message).then(() => removePostQueueElement(parent)).catch(alerts.error);
@@ -400,7 +401,7 @@ define('forum/post-queue', [
};
});
- const reasons = await socket.emit('user.getCustomReasons', { type: 'post-queue' });
+ const reasons = ajaxify.data.customReasons || [];
const html = await Benchpress.render('partials/custom-reason', { reasons });
const modal = await modals.dialog({
title: title,
@@ -463,7 +464,7 @@ define('forum/post-queue', [
const translationString = ajaxify.data.canAccept ?
`${bulkAction}-confirm` :
`${bulkAction.replace(/^reject/, 'remove')}-confirm`;
- if (!ids.length || (showConfirm && !(await confirmReject(`[[post-queue:${translationString}, ${ids.length}]]`)))) {
+ if (!ids.length || (showConfirm && !(await confirmModal(`[[post-queue:${translationString}, ${ids.length}]]`)))) {
return;
}
const action = bulkAction.split('-')[0];
diff --git a/src/api/posts.js b/src/api/posts.js
index 03c859c7fa..fa79a8da79 100644
--- a/src/api/posts.js
+++ b/src/api/posts.js
@@ -675,7 +675,7 @@ async function sendQueueNotification(type, targetUid, path, notificationText) {
tx.compile(`notifications:${type}`);
const notifData = {
type: type,
- nid: `${type}-${targetUid}-${path}`,
+ nid: `${type}-${targetUid}-${Date.now()}`,
bodyShort: bodyShort,
path: path,
};
diff --git a/src/controllers/mods.js b/src/controllers/mods.js
index b7392c7ff2..433f1d7474 100644
--- a/src/controllers/mods.js
+++ b/src/controllers/mods.js
@@ -225,6 +225,10 @@ modsController.postQueue = async function (req, res, next) {
Promise.all(['global', 'admin'].map(async type => privileges[type].get(req.uid))),
]);
_privileges = { ..._privileges[0], ..._privileges[1] };
+ let customReasons = [];
+ if (isAdmin || isGlobalMod || moderatedCids.length) {
+ customReasons = await user.bans.getCustomReasons({ type: 'post-queue' });
+ }
postData = postData
.filter(p => p &&
@@ -263,5 +267,6 @@ modsController.postQueue = async function (req, res, next) {
enabled: meta.config.postQueue,
singlePost: !!id,
privileges: _privileges,
+ customReasons,
});
};