Skip to content

Commit

Permalink
Displays "Anonymous User" and No Icon when Data Field is Set to True (#…
Browse files Browse the repository at this point in the history
…51)

* completed backend logic for anonymous user feature but cannot integrate with frontend button

* cleaned up unnecessary back-end code for the anonymous data field

* removed console logs
  • Loading branch information
J0nathanLai authored Oct 9, 2024
1 parent c2a080d commit 352ee45
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
7 changes: 7 additions & 0 deletions public/src/modules/helpers.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = function (utils, Benchpress, relative_path) {
userAgentIcons,
buildAvatar,
increment,
anonTrue,
generateWroteReplied,
generateRepliedTo,
generateWrote,
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/meta/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]]');
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/posts/summary.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict';

const validator = require('validator');
Expand Down Expand Up @@ -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]);
Expand Down
5 changes: 2 additions & 3 deletions src/topics/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 352ee45

Please sign in to comment.