Skip to content

Commit

Permalink
refactor: flags object in post tools
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Jul 30, 2020
1 parent caa78cc commit fcdbdf6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions install/package.json
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/socket.io/posts/tools.js
Expand Up @@ -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');
Expand All @@ -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(),
Expand All @@ -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;
Expand Down

0 comments on commit fcdbdf6

Please sign in to comment.