Skip to content

Commit

Permalink
Merge branch 'main' into translation-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ajain-1 authored Feb 28, 2025
2 parents b34bda1 + 6e8ccf0 commit 0a095bb
Show file tree
Hide file tree
Showing 31 changed files with 186 additions and 51 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Team Sunglasses:

Members: Aryan Jain, Eric Due, Emily Xie, Kayo Kuri, Justin Zou


# ![NodeBB](public/images/sm-card.png)

[![Workflow](https://github.com/CMU-313/NodeBB/actions/workflows/test.yaml/badge.svg)](https://github.com/CMU-313/NodeBB/actions/workflows/test.yaml)
Expand Down
Binary file modified dump.rdb
Binary file not shown.
38 changes: 22 additions & 16 deletions nodebb-theme-harmony/scss/topic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,28 @@ body.template-topic {
}

.admin-star {
width: 60px;
height: 60px;
background-color: gold;
clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 10px;
color: black;
text-transform: uppercase;
text-align: right;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
border-radius: 5px;
top: 10px;
left: 10px;
width: 16px; // Tiny but visible
height: 16px;
background: linear-gradient(145deg, #3a8dde, #1e5aa6); // Modern blue gradient
clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%,
50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 6px;
text-align: center;
font-weight: bold;
text-shadow: 0px 0px 2px rgba(255, 255, 255, 0.8);
box-shadow: 0px 2px 5px rgba(0, 0, 255, 0.3), inset 0px -2px 3px rgba(0, 0, 0, 0.2);
border-radius: 3px;
position: relative;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;

&:hover {
transform: scale(1.1);
box-shadow: 0px 3px 8px rgba(0, 0, 255, 0.5);
}
}

[component="post/replies/container"] {
Expand Down
8 changes: 6 additions & 2 deletions nodebb-theme-harmony/templates/partials/topic/post.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</div>
</div>
</div>
{{{ if privileges.isAdminOrMod}}}
<div class="admin-star">Admin</div>
{{{ if posts.user.adminrole }}}
<div class="admin-star"></div>
{{{ end }}}
<div class="post-container d-flex flex-grow-1 flex-column w-100" style="min-width:0;">
<div class="d-flex align-items-center gap-1 flex-wrap w-100 post-header mt-1" itemprop="author" itemscope itemtype="https://schema.org/Person">
Expand All @@ -34,7 +34,11 @@
</a>
</div>

{{{if !posts.anonymous }}}
<a class="fw-bold text-nowrap" href="{{{ if ./user.userslug }}}{config.relative_path}/user/{./user.userslug}{{{ else }}}#{{{ end }}}" data-username="{posts.user.username}" data-uid="{posts.user.uid}">{posts.user.displayname}</a>
{{{ else }}}
<a class="fw-bold text-nowrap" href="{{{ if ./user.userslug }}}{config.relative_path}/user/{./user.userslug}{{{ else }}}#{{{ end }}}" data-username="{posts.user.username}" data-uid="{posts.user.uid}">Anonymous</a>
{{{ end }}}

{{{ each posts.user.selectedGroups }}}
{{{ if posts.user.selectedGroups.slug }}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="d-flex justify-content-end gap-2">
<button type="submit" component="topic/quickreply/expand" class="btn-ghost-sm border" title="[[topic:open-composer]]"><i class="fa fa-expand"></i></button>
<div class="form-group">
<label> <input type="checkbox" id="post-anonymously" /> Post Anonymously </label>
<label> <input type="checkbox" component="topic/quickreply/anonymous" id="post-anonymously" /> Post Anonymously </label>
</div>
<button type="submit" component="topic/quickreply/button" class="btn btn-sm btn-primary">[[topic:post-quick-reply]]</button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/components/schemas/Chats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ MessageObject:
type: number
isOwner:
type: boolean
groupTitle:
type: string
fromUser:
type: object
properties:
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/components/schemas/PostObject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ PostObject:
tid:
type: number
description: A topic identifier
anonymous:
type: number
content:
type: string
uid:
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/components/schemas/TopicObject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ TopicObjectSlim:
tid:
type: number
description: A topic identifier
adminrole:
type: boolean
numThumbs:
type: number
description: The number of thumbnails associated with this topic
Expand Down
4 changes: 4 additions & 0 deletions public/openapi/read/topic/topic_id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ get:
tid:
type: number
description: A topic identifier
anonymous:
type: number
content:
type: string
timestamp:
Expand Down Expand Up @@ -91,6 +93,8 @@ get:
user:
type: object
properties:
adminrole:
type: boolean
uid:
type: number
description: A user identifier
Expand Down
3 changes: 3 additions & 0 deletions public/openapi/read/user/userslug/chats/roomid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ get:
type: number
messageId:
type: number
groupTitle:
type: string
nullable: true
fromUser:
type: object
properties:
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/write/posts/pid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ get:
tid:
type: number
description: A topic identifier
anonymous:
type: number
content:
type: string
english:
Expand Down
5 changes: 4 additions & 1 deletion public/openapi/write/posts/pid/isEndorsed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ get:
application/json:
schema:
type: object
properties: {}
properties:
endorsed:
type: boolean
description: Indicates whether the post is endorsed or not

3 changes: 3 additions & 0 deletions public/src/modules/quickreply.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ define('quickreply', [
}

const replyMsg = components.get('topic/quickreply/text').val();
const anonymousCheckbox = components.get('topic/quickreply/anonymous').get(0).checked;
const replyData = {
tid: ajaxify.data.tid,
handle: undefined,
content: replyMsg,
anonymous: anonymousCheckbox,
};

const replyLen = replyMsg.length;
if (replyLen < parseInt(config.minimumPostLength, 10)) {
return alerts.error('[[error:content-too-short, ' + config.minimumPostLength + ']]');
Expand Down
20 changes: 10 additions & 10 deletions src/api/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ postsAPI.setPostEndorsement = async function (pid, endorsed = true) {
};

postsAPI.getPostEndorsement = async function (pid) {
db.isObjectField(`post:${pid}`, 'endorsed', (err, isField) => {
if (err) {
console.log(err);
}
return isField;
return new Promise((resolve, reject) => {
db.isObjectField(`post:${pid}`, 'endorsed', (err, isField) => {
if (err) reject(err);
else resolve(!!isField);
});
});
};

Expand Down Expand Up @@ -411,13 +411,13 @@ async function canSeeVotes(uid, cids, type) {
const cidToAllowed = _.zipObject(uniqCids, canRead);
const checks = cids.map(
(cid, index) => isAdmin || isMod[index] ||
(
cidToAllowed[cid] &&
(
meta.config[type] === 'all' ||
(meta.config[type] === 'loggedin' && parseInt(uid, 10) > 0)
cidToAllowed[cid] &&
(
meta.config[type] === 'all' ||
(meta.config[type] === 'loggedin' && parseInt(uid, 10) > 0)
)
)
)
);
return isArray ? checks : checks[0];
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ usersAPI.follow = async function (caller, data) {
toUid: data.uid,
});

const userData = await user.getUserFields(caller.uid, ['username', 'userslug']);
const userData = await user.getUserFields(caller.uid, ['username', 'userslug', 'adminrole']);
const { displayname } = userData;

const notifObj = await notifications.create({
Expand Down
2 changes: 1 addition & 1 deletion src/categories/recentreplies.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = function (Categories) {
]);

await batch.processArray(pids, async (pids) => {
const postData = await posts.getPostsFields(pids, ['pid', 'deleted', 'uid', 'timestamp', 'upvotes', 'downvotes']);
const postData = await posts.getPostsFields(pids, ['pid', 'anonymous', 'deleted', 'uid', 'timestamp', 'upvotes', 'downvotes']);

const bulkRemove = [];
const bulkAdd = [];
Expand Down
17 changes: 17 additions & 0 deletions src/categories/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ module.exports = function (Categories) {
const tids = await Categories.getTopicIds(results);
let topicsData = await topics.getTopicsByTids(tids, data.uid);
topicsData = await user.blocks.filter(data.uid, topicsData);

const adminRole = await Promise.all(
topicsData.map(async (topic) => {
const isAdmin = await user.isAdministrator(topic.uid);
if (isAdmin) {
return 'Admin';
}
return 'user';
})
);
topicsData.forEach((topic, index) => {
if (adminRole[index] === 'Admin') {
topic.adminrole = 'Admin';
} else {
topic.adminrole = 'User';
}
});
if (!topicsData.length) {
return { topics: [], uid: data.uid };
}
Expand Down
1 change: 0 additions & 1 deletion src/controllers/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function check3(req, utils, cid) {
}

categoryController.get = async function (req, res, next) {
console.log('Justin Zou');
const cid = req.params.category_id;

let currentPage = parseInt(req.query.page, 10) || 1;
Expand Down
8 changes: 8 additions & 0 deletions src/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ userController.getCurrentUser = async function (req, res) {
}
const userslug = await user.getUserField(req.uid, 'userslug');
const userData = await accountHelpers.getUserDataByUserSlug(userslug, req.uid, req.query);
const isAdmin = await user.isAdministrator(req.uid);
let role = 'None';
if (isAdmin) {
role = 'Admin';
} else {
role = 'User';
}
res.json(userData);
userData.adminrole = role;
};

userController.getUserByUID = async function (req, res, next) {
Expand Down
13 changes: 11 additions & 2 deletions src/messaging/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,26 @@ module.exports = function (Messaging) {
messages = await user.blocks.filter(uid, 'fromuid', messages);
const users = await user.getUsersFields(
messages.map(msg => msg && msg.fromuid),
['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'groupTitle']
['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'groupTitle', 'groupTitleArray']
);

messages.forEach((message, index) => {
message.fromUser = users[index];
message.fromUser.banned = !!message.fromUser.banned;
message.fromUser.deleted = message.fromuid !== message.fromUser.uid && message.fromUser.uid === 0;
message.groupTitle = '';
if (message.fromUser.groupTitle && message.fromUser.groupTitle.length > 0 &&
message.fromUser.groupTitleArray[0] !== undefined) {
const rawTitles = message.fromUser.groupTitleArray.slice(0, 3);
const cleanTitles = rawTitles.map((title) => {
const formattedTitle = title.replace(/"/g, '');
return formattedTitle.charAt(0).toUpperCase() + formattedTitle.slice(1);
});
message.groupTitle = cleanTitles.join(', ');
}

const self = message.fromuid === parseInt(uid, 10);
message.self = self ? 1 : 0;

message.newSet = false;
message.roomId = String(message.roomId || roomId);
});
Expand Down
2 changes: 2 additions & 0 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = function (Posts) {
const { uid } = data;
const { tid } = data;
const content = data.content.toString();
const anonymous = data.anonymous ? 1 : 0;
const timestamp = data.timestamp || Date.now();
const isMain = data.isMain || false;
const [english, translatedTxt] = await translationApi.translate(data);
Expand All @@ -37,6 +38,7 @@ module.exports = function (Posts) {
tid: tid,
english: english,
translation: translatedTxt,
anonymous: anonymous,
content: content,
timestamp: timestamp,
};
Expand Down
2 changes: 1 addition & 1 deletion src/posts/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const plugins = require('../plugins');
const utils = require('../utils');

const intFields = [
'uid', 'pid', 'tid', 'deleted', 'timestamp',
'uid', 'pid', 'tid', 'anonymous', 'deleted', 'timestamp',
'upvotes', 'downvotes', 'deleterUid', 'edited',
'replies', 'bookmarks',
];
Expand Down
2 changes: 1 addition & 1 deletion src/posts/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function (Posts) {
options.parse = options.hasOwnProperty('parse') ? options.parse : true;
options.extraFields = options.hasOwnProperty('extraFields') ? options.extraFields : [];

const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
const fields = ['pid', 'tid', 'content', 'anonymous', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);

let posts = await Posts.getPostsFields(pids, fields);
posts = posts.filter(Boolean);
Expand Down
3 changes: 2 additions & 1 deletion src/topics/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ module.exports = function (Topics) {

await guestHandleValid(data);
data.content = String(data.content || '').trimEnd();

data.content = utils.censorBannedMarkdown(data.content);

data.anonymous = data.anonymous ? 1 : 0;

if (!data.fromQueue && !isAdmin) {
await user.isReadyToPost(uid, data.cid);
Topics.checkContent(data.content);
Expand Down
11 changes: 6 additions & 5 deletions src/topics/posts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict';

const _ = require('lodash');
Expand Down Expand Up @@ -108,10 +107,11 @@ module.exports = function (Topics) {
return [];
}
const pids = postData.map(post => post && post.pid);

let outsideUids = null;
async function getPostUserData(field, method) {
const uids = _.uniq(postData.filter(p => p && parseInt(p[field], 10) >= 0).map(p => p[field]));
const userData = await method(uids);
outsideUids = uids;
return _.zipObject(uids, userData);
}
const [
Expand All @@ -124,7 +124,7 @@ module.exports = function (Topics) {
posts.hasBookmarked(pids, uid),
posts.getVoteStatusByPostIDs(pids, uid),
getPostUserData('uid', async uids => await posts.getUserInfoForPosts(uids, uid)),
getPostUserData('editor', async uids => await user.getUsersFields(uids, ['uid', 'username', 'userslug'])),
getPostUserData('editor', async uids => await user.getUsersFields(uids, ['uid', 'username', 'userslug', 'isAdmin'])),
getPostReplies(postData, uid),
Topics.addParentPosts(postData),
]);
Expand All @@ -139,8 +139,9 @@ module.exports = function (Topics) {
postObj.votes = postObj.votes || 0;
postObj.replies = replies[i];
postObj.selfPost = parseInt(uid, 10) > 0 && parseInt(uid, 10) === postObj.uid;

// Username override for guests, if enabled
outsideUids.forEach((i) => {
userData[String(i)].adminrole = userData[String(i)].groupTitle !== null;
});
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
1 change: 0 additions & 1 deletion src/user/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ module.exports = function (User) {
User.setUserField(postData.uid, 'lastposttime', lastposttime),
User.updateLastOnlineTime(postData.uid),
]);
console.log('jzou was here');
};


Expand Down
Loading

0 comments on commit 0a095bb

Please sign in to comment.