From 9496f31933dc0bd91e12e82875249cfc5fcd9c3b Mon Sep 17 00:00:00 2001 From: Sandeep Date: Wed, 26 Feb 2025 12:54:35 -0500 Subject: [PATCH 1/2] Was able to add buttons for annonym post and reply that dont dissapear when page is refreshed. They dont work correctly. --- nodebb-plugin-anonymous/library.js | 14 ++++++ nodebb-plugin-anonymous/package.json | 14 ++++++ nodebb-theme-harmony/public/harmony.js | 32 +++++++++++++ .../templates/partials/topic-list-bar.tpl | 26 +++++++++- .../templates/partials/topic/post.tpl | 12 ++++- .../templates/partials/topic/reply-button.tpl | 47 ++++++++++++++----- public/language/en-GB/topic.json | 1 + public/language/en-US/topic.json | 1 + public/src/app.js | 26 ++++++++++ public/src/client/topic/postTools.js | 46 ++++++++++++++++++ src/controllers/composer.js | 7 +++ src/posts/create.js | 1 + src/posts/data.js | 2 +- src/topics/create.js | 2 + src/topics/posts.js | 20 +++++--- 15 files changed, 229 insertions(+), 22 deletions(-) create mode 100644 nodebb-plugin-anonymous/library.js create mode 100644 nodebb-plugin-anonymous/package.json diff --git a/nodebb-plugin-anonymous/library.js b/nodebb-plugin-anonymous/library.js new file mode 100644 index 0000000..8f7771b --- /dev/null +++ b/nodebb-plugin-anonymous/library.js @@ -0,0 +1,14 @@ +'use strict'; + +const hooks = require.main.require('./src/plugins/hooks'); + +hooks.on('filter:composer.postData', async (hookData) => { + if (hookData.data && hookData.data.anonymous) { + console.log('[DEBUG] Anonymizing post data on server...'); + // Override the user data to post anonymously + hookData.data.uid = 0; + hookData.data.username = 'Anonymous'; + hookData.data.picture = '/assets/img/anonymous.png'; // Optional avatar + } + return hookData; +}); \ No newline at end of file diff --git a/nodebb-plugin-anonymous/package.json b/nodebb-plugin-anonymous/package.json new file mode 100644 index 0000000..da73d11 --- /dev/null +++ b/nodebb-plugin-anonymous/package.json @@ -0,0 +1,14 @@ +{ + "name": "nodebb-plugin-anonymous", + "version": "1.0.0", + "description": "Plugin to enable anonymous posting in NodeBB", + "main": "library.js", + "engines": { + "node": ">=18", + "nodebb": ">=3.8.4" + }, + "license": "GPL-3.0", + "nodebb": { + "isPlugin": true + } +} \ No newline at end of file diff --git a/nodebb-theme-harmony/public/harmony.js b/nodebb-theme-harmony/public/harmony.js index 6387055..671e933 100644 --- a/nodebb-theme-harmony/public/harmony.js +++ b/nodebb-theme-harmony/public/harmony.js @@ -285,3 +285,35 @@ $(document).ready(function () { .on('hidden.bs.dropdown', toggleOverflow); } }); + +document.addEventListener('click', function (event) { + // look for clicks on [component="topic/reply-anonymously"] + const el = event.target.closest('[component="topic/reply-anonymously"]'); + if (!el) return; + + event.preventDefault(); + console.log('[DEBUG] Anonymous reply button clicked!'); + + // get the topic ID from ajaxify.data if on a topic page + const tid = ajaxify.data && ajaxify.data.tid; + if (!tid) { + alert('No topic ID found!'); + return; + } + + // call a function that opens the composer with an anonymous flag + app.anonymousReply({ tid: tid }); + }); + + // define the function that sets up an "anonymous" composer + app.anonymousReply = async function (params) { + if (typeof params !== 'object') { + params = { tid: params }; + } + const [hooks, api] = await app.require(['hooks', 'api']); + params.title = ajaxify.data && ajaxify.data.titleRaw || 'Untitled'; + params.anonymous = true; // the important flag + + console.log('[DEBUG] Opening composer with anonymous = true', params); + hooks.fire('action:composer.post.new', params); + }; diff --git a/nodebb-theme-harmony/templates/partials/topic-list-bar.tpl b/nodebb-theme-harmony/templates/partials/topic-list-bar.tpl index 53f558c..c7362a4 100644 --- a/nodebb-theme-harmony/templates/partials/topic-list-bar.tpl +++ b/nodebb-theme-harmony/templates/partials/topic-list-bar.tpl @@ -38,7 +38,31 @@
{{{ if template.category }}} {{{ if privileges.topics:create }}} - [[category:new-topic-button]] + {{{ end }}} {{{ else }}} {{{ if canPost }}} diff --git a/nodebb-theme-harmony/templates/partials/topic/post.tpl b/nodebb-theme-harmony/templates/partials/topic/post.tpl index e2e92ad..ddafa3d 100644 --- a/nodebb-theme-harmony/templates/partials/topic/post.tpl +++ b/nodebb-theme-harmony/templates/partials/topic/post.tpl @@ -8,23 +8,33 @@
+