Skip to content

Commit

Permalink
Edited posts.js file to check for anonymity, if user marks anonymous,…
Browse files Browse the repository at this point in the history
… set username and displayname to anonymous
  • Loading branch information
Nalseaf committed Sep 25, 2024
1 parent d6b4dbc commit 1c7cb2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 2 additions & 9 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ module.exports = function (Posts) {
const timestamp = data.timestamp || Date.now();
const isMain = data.isMain || false;

// Check for anonymous post flag
const isAnonymous = data.anonymous || false;

// Handle anonymous posts
if (isAnonymous) {
// Assign a special anonymous user ID (or clear it if appropriate)
data.uid = 0; // or some anonymous UID, depending on your application
}

if (!uid && parseInt(uid, 10) !== 0) {
throw new Error('[[error:invalid-uid]]');
Expand All @@ -44,7 +36,8 @@ module.exports = function (Posts) {
tid: tid,
content: content,
timestamp: timestamp,
isAnonymous: isAnonymous
// Assign a value to anonymous
anonymous: data.anonymous || true,

};

Expand Down
8 changes: 6 additions & 2 deletions src/topics/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ module.exports = function (Topics) {
postObj.replies = replies[i];
postObj.selfPost = parseInt(uid, 10) > 0 && parseInt(uid, 10) === postObj.uid;

// Username override for guests, if enabled
if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) {
// Handle anonymous posts or guest username override
// Set username and displayname to "Anonymous" if anonymous
if (postObj.anonymous) {
postObj.user.username = 'Anonymous'; // Set username
postObj.user.displayname = 'Anonymous'; // Set displayname
} else if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) {
postObj.user.username = validator.escape(String(postObj.handle));
postObj.user.displayname = postObj.user.username;
}
Expand Down

0 comments on commit 1c7cb2c

Please sign in to comment.