Skip to content

Node.js based forum software built for the modern web

refactor: flags object in post tools

Julian Lamfcdbdf63a346
diff --git a/install/package.json b/install/package.json
index 236d66ba37..1b22b13c24 100644
--- a/install/package.json
+++ b/install/package.json
@@ -90,9 +90,9 @@
"nodebb-plugin-spam-be-gone": "0.7.2",
"nodebb-rewards-essentials": "0.1.3",
"nodebb-theme-lavender": "5.0.11",
- "nodebb-theme-persona": "10.2.2",
+ "nodebb-theme-persona": "10.2.3",
"nodebb-theme-slick": "1.2.29",
- "nodebb-theme-vanilla": "11.2.1",
+ "nodebb-theme-vanilla": "11.2.2",
"nodebb-widget-essentials": "4.1.1",
"nodemailer": "^6.4.6",
"passport": "^0.4.1",
diff --git a/src/socket.io/posts/tools.js b/src/socket.io/posts/tools.js
index ded60cd53a..da669de390 100644
--- a/src/socket.io/posts/tools.js
+++ b/src/socket.io/posts/tools.js
@@ -2,6 +2,7 @@
const posts = require('../../posts');
const topics = require('../../topics');
+const flags = require('../../flags');
const events = require('../../events');
const websockets = require('../index');
const socketTopics = require('../topics');
@@ -27,6 +28,7 @@ module.exports = function (SocketPosts) {
canDelete: privileges.posts.canDelete(data.pid, socket.uid),
canPurge: privileges.posts.canPurge(data.pid, socket.uid),
canFlag: privileges.posts.canFlag(data.pid, socket.uid),
+ flagged: flags.exists('post', data.pid, socket.uid), // specifically, whether THIS calling user flagged
bookmarked: posts.hasBookmarked(data.pid, socket.uid),
tools: plugins.fireHook('filter:post.tools', { pid: data.pid, uid: socket.uid, tools: [] }),
postSharing: social.getActivePostSharing(),
@@ -48,6 +50,12 @@ module.exports = function (SocketPosts) {
postData.display_ip_ban = (results.isAdmin || results.isGlobalMod) && !postData.selfPost;
postData.display_history = results.history;
postData.toolsVisible = postData.tools.length || postData.display_moderator_tools;
+ postData.flags = {
+ flagId: parseInt(results.posts.flagId, 10) || null,
+ can: results.canFlag.flag,
+ exists: !!results.posts.flagId,
+ flagged: results.flagged,
+ };
if (!results.isAdmin && !results.canViewInfo) {
postData.ip = undefined;