diff --git a/nodebb-theme-harmony/templates/partials/topic/post.tpl b/nodebb-theme-harmony/templates/partials/topic/post.tpl index 101752d4bf..24b3088846 100644 --- a/nodebb-theme-harmony/templates/partials/topic/post.tpl +++ b/nodebb-theme-harmony/templates/partials/topic/post.tpl @@ -75,11 +75,9 @@ {{{ end }}}
- Flag ID: {posts.flagId} - {{{ if posts.flag }}} - Test post + {{{ if posts.endorsedByStaff }}} + Endorsed by Staff {{{ end }}} - #{increment(./index, "1")}
@@ -150,4 +148,4 @@ {widgets.mainpost-footer.html} {{{ end }}} -{{{ end }}} +{{{ end }}} \ No newline at end of file diff --git a/src/topics/posts.js b/src/topics/posts.js index 42b1551622..9f7d510a83 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -1,4 +1,3 @@ - 'use strict'; const _ = require('lodash'); @@ -130,6 +129,24 @@ module.exports = function (Topics) { Topics.addParentPosts(postData), ]); + // Get flag data for posts with flagId + const flaggedPosts = postData.filter(p => p && p.flagId); + const flagData = await Promise.all( + flaggedPosts.map(async (post) => { + try { + const reports = await require('../flags').getReports(post.flagId); + return { pid: post.pid, reports: reports }; + } catch (err) { + return { pid: post.pid, reports: [] }; + } + }) + ); + // Create a map of pid to flag data for quick lookup + const flagDataMap = {}; + flagData.forEach((data) => { + flagDataMap[data.pid] = data.reports; + }); + postData.forEach((postObj, i) => { if (postObj) { postObj.user = postObj.uid ? userData[postObj.uid] : { ...userData[postObj.uid] }; @@ -141,6 +158,11 @@ module.exports = function (Topics) { postObj.replies = replies[i]; postObj.selfPost = parseInt(uid, 10) > 0 && parseInt(uid, 10) === postObj.uid; + // Check if post has a flag with "Endorsed by Admins" report + if (flagDataMap[postObj.pid]) { + postObj.endorsedByStaff = flagDataMap[postObj.pid].some(report => report.value && report.value.includes('Endorsed by Admins')); + } + // Username override for guests, if enabled if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) { postObj.user.username = validator.escape(String(postObj.handle));