Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend Code for Displaying "Anonymous User" and No Icon #51

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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