diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js index c5533cf56b..742d1a3c16 100644 --- a/public/src/modules/helpers.common.js +++ b/public/src/modules/helpers.common.js @@ -25,6 +25,7 @@ module.exports = function (utils, Benchpress, relative_path) { userAgentIcons, buildAvatar, increment, + anonTrue, generateWroteReplied, generateRepliedTo, generateWrote, @@ -318,6 +319,12 @@ module.exports = function (utils, Benchpress, relative_path) { return output; } + // this help function is used inside node_modules/nodebb-theme-harmony/templates/partials/topic/post.tpl + // to check whether to indicate objects depending on the anonymous data field value + function anonTrue(anonymousVal) { + return anonymousVal === 'true'; + } + function increment(value, inc) { return String(value + parseInt(inc, 10)); } diff --git a/src/meta/themes.js b/src/meta/themes.js index 5113b916f2..43a82cdf4a 100644 --- a/src/meta/themes.js +++ b/src/meta/themes.js @@ -115,7 +115,7 @@ Themes.set = async (data) => { // Re-set the themes path (for when NodeBB is reloaded) Themes.setPath(config); - console.log('jonathan lai'); + // console.log('jonathan lai'); await Meta.configs.setMultiple({ 'theme:type': data.type, diff --git a/src/posts/create.js b/src/posts/create.js index f4dbe63939..dc4bf9e2cf 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -19,7 +19,12 @@ module.exports = function (Posts) { const content = data.content.toString(); const timestamp = data.timestamp || Date.now(); const isMain = data.isMain || false; - const isAnon = true; + // const anonymous = false; // hard code anonymous to become false + const anonymous = true; // hard code anonymous to become true + // attempted to get id from the tpl but we don't know how to do it + // const anonymous = data.getElementById('anonymousInput').value === 'true'; + // log anonymous field to see which variable it is + // console.log('get anon value:', anonymous); if (!uid && parseInt(uid, 10) !== 0) { throw new Error('[[error:invalid-uid]]'); @@ -36,7 +41,7 @@ module.exports = function (Posts) { tid: tid, content: content, timestamp: timestamp, - anonymous: isAnon, + anonymous: anonymous, // set anonymous datafield to be anonymous value }; if (data.toPid) { diff --git a/src/posts/summary.js b/src/posts/summary.js index 0356779d6f..b8cbd45e4c 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -1,4 +1,3 @@ - 'use strict'; const validator = require('validator'); @@ -52,7 +51,7 @@ module.exports = function (Posts) { post.isMainPost = post.topic && post.pid === post.topic.mainPid; post.deleted = post.deleted === 1; post.timestampISO = utils.toISOString(post.timestamp); - post.anonymous = post.anonymous ? post.anonymous : 'false'; // checks if anonymous is true if not then false + post.anonymous = post.anonymous ? post.anonymous : 'false'; // makes sure anonymous is a required field for every post, false if anonymous field is undefined }); posts = posts.filter(post => tidToTopic[post.tid]); diff --git a/src/topics/create.js b/src/topics/create.js index f8bf75cef8..a584b47208 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -30,7 +30,6 @@ module.exports = function (Topics) { title: data.title, slug: `${tid}/${slugify(data.title) || 'topic'}`, timestamp: timestamp, - // anonymous: data.anonPosts ? data.anonPosts : false, lastposttime: 0, postcount: 0, viewcount: 0, @@ -124,10 +123,10 @@ module.exports = function (Topics) { postData.tid = tid; postData.ip = data.req ? data.req.ip : null; postData.isMain = true; - // postData.anonymous = data.anonPosts ? data.anonPosts : false; postData = await posts.create(postData); postData = await onNewPost(postData, data); + const [settings, topics] = await Promise.all([ user.getSettings(uid), Topics.getTopicsByTids([postData.tid], uid), @@ -233,7 +232,7 @@ module.exports = function (Topics) { topicInfo, ] = await Promise.all([ posts.getUserInfoForPosts([postData.uid], uid), - Topics.getTopicFields(tid, ['tid', 'uid', 'title', 'slug', 'cid', 'postcount', 'mainPid', 'scheduled', 'tags']), // add anonymous field + Topics.getTopicFields(tid, ['tid', 'uid', 'title', 'slug', 'cid', 'postcount', 'mainPid', 'scheduled', 'tags']), Topics.addParentPosts([postData]), Topics.syncBacklinks(postData), posts.parsePost(postData),