From a43535e1a0f2b13255d2231d5a95cdd37eb33454 Mon Sep 17 00:00:00 2001 From: J0nathanLai <112527440+J0nathanLai@users.noreply.github.com> Date: Mon, 7 Oct 2024 02:36:52 -0400 Subject: [PATCH 1/3] completed backend logic for anonymous user feature but cannot integrate with frontend button --- public/src/modules/helpers.common.js | 5 +++++ src/posts/create.js | 8 ++++++-- src/posts/summary.js | 1 - src/topics/create.js | 7 ++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js index c5533cf56b..1b8f3179c2 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, + anonChecker, generateWroteReplied, generateRepliedTo, generateWrote, @@ -318,6 +319,10 @@ module.exports = function (utils, Benchpress, relative_path) { return output; } + function anonChecker(anonymousVal) { + return anonymousVal === 'true'; + } + function increment(value, inc) { return String(value + parseInt(inc, 10)); } diff --git a/src/posts/create.js b/src/posts/create.js index f4dbe63939..fff76ba9f5 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -19,7 +19,11 @@ 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 } = data; + + const anonymous = true; + // const anonymous = data.getElementById('anonymousInput').value === 'true'; + console.log('get anon value:', anonymous); if (!uid && parseInt(uid, 10) !== 0) { throw new Error('[[error:invalid-uid]]'); @@ -36,7 +40,7 @@ module.exports = function (Posts) { tid: tid, content: content, timestamp: timestamp, - anonymous: isAnon, + anonymous: anonymous, }; if (data.toPid) { diff --git a/src/posts/summary.js b/src/posts/summary.js index 0356779d6f..9bbbcfb35e 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -1,4 +1,3 @@ - 'use strict'; const validator = require('validator'); diff --git a/src/topics/create.js b/src/topics/create.js index f8bf75cef8..d8d6f73ce4 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -30,7 +30,7 @@ module.exports = function (Topics) { title: data.title, slug: `${tid}/${slugify(data.title) || 'topic'}`, timestamp: timestamp, - // anonymous: data.anonPosts ? data.anonPosts : false, + anonymous: data.anonymousPost ? data.anonymousPost : 'false', lastposttime: 0, postcount: 0, viewcount: 0, @@ -124,10 +124,11 @@ 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.anonymous = data.anonymousPost ? data.anonymousPost : 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 +234,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', 'anonymous']), // add anonymous field Topics.addParentPosts([postData]), Topics.syncBacklinks(postData), posts.parsePost(postData), From a9fb652952e22fb8a891bde4593ac7717d94c981 Mon Sep 17 00:00:00 2001 From: J0nathanLai <112527440+J0nathanLai@users.noreply.github.com> Date: Tue, 8 Oct 2024 23:47:07 -0400 Subject: [PATCH 2/3] cleaned up unnecessary back-end code for the anonymous data field --- public/src/modules/helpers.common.js | 6 ++++-- src/posts/create.js | 11 ++++++----- src/posts/summary.js | 2 +- src/topics/create.js | 4 +--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js index 1b8f3179c2..742d1a3c16 100644 --- a/public/src/modules/helpers.common.js +++ b/public/src/modules/helpers.common.js @@ -25,7 +25,7 @@ module.exports = function (utils, Benchpress, relative_path) { userAgentIcons, buildAvatar, increment, - anonChecker, + anonTrue, generateWroteReplied, generateRepliedTo, generateWrote, @@ -319,7 +319,9 @@ module.exports = function (utils, Benchpress, relative_path) { return output; } - function anonChecker(anonymousVal) { + // 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'; } diff --git a/src/posts/create.js b/src/posts/create.js index fff76ba9f5..dc4bf9e2cf 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -19,11 +19,12 @@ module.exports = function (Posts) { const content = data.content.toString(); const timestamp = data.timestamp || Date.now(); const isMain = data.isMain || false; - // const { anonymous } = data; - - const anonymous = 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'; - console.log('get anon value:', anonymous); + // 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]]'); @@ -40,7 +41,7 @@ module.exports = function (Posts) { tid: tid, content: content, timestamp: timestamp, - anonymous: anonymous, + 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 9bbbcfb35e..b8cbd45e4c 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -51,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 d8d6f73ce4..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.anonymousPost ? data.anonymousPost : 'false', lastposttime: 0, postcount: 0, viewcount: 0, @@ -124,7 +123,6 @@ module.exports = function (Topics) { postData.tid = tid; postData.ip = data.req ? data.req.ip : null; postData.isMain = true; - postData.anonymous = data.anonymousPost ? data.anonymousPost : false; postData = await posts.create(postData); postData = await onNewPost(postData, data); @@ -234,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', 'anonymous']), // add anonymous field + Topics.getTopicFields(tid, ['tid', 'uid', 'title', 'slug', 'cid', 'postcount', 'mainPid', 'scheduled', 'tags']), Topics.addParentPosts([postData]), Topics.syncBacklinks(postData), posts.parsePost(postData), From e8ec92f63bf7bc326272b1d6562035f1085b0234 Mon Sep 17 00:00:00 2001 From: J0nathanLai <112527440+J0nathanLai@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:59:45 -0400 Subject: [PATCH 3/3] removed console logs --- src/meta/themes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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,