feat: Introduce custom emojis, pinned comments, and comment thread locking, making comments require user login.
This commit is contained in:
@@ -47,6 +47,14 @@ class CommentSystem {
|
|||||||
|
|
||||||
async loadComments(scrollToId = null) {
|
async loadComments(scrollToId = null) {
|
||||||
if (!this.container) return;
|
if (!this.container) return;
|
||||||
|
|
||||||
|
// If guest, hide completely and don't fetch
|
||||||
|
if (!this.user) {
|
||||||
|
this.container.innerHTML = '';
|
||||||
|
this.container.style.display = 'none';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!scrollToId) this.container.innerHTML = '<div class="loading">Loading comments...</div>';
|
if (!scrollToId) this.container.innerHTML = '<div class="loading">Loading comments...</div>';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -54,6 +62,12 @@ class CommentSystem {
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
|
if (data.require_login) {
|
||||||
|
this.container.innerHTML = '';
|
||||||
|
this.container.style.display = 'none'; // Ensure it takes no space
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.isAdmin = data.is_admin || false;
|
this.isAdmin = data.is_admin || false;
|
||||||
this.isLocked = data.is_locked || false;
|
this.isLocked = data.is_locked || false;
|
||||||
this.render(data.comments, data.user_id, data.is_subscribed);
|
this.render(data.comments, data.user_id, data.is_subscribed);
|
||||||
|
|||||||
@@ -5,14 +5,32 @@ export default (router, tpl) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Fetch comments for an item
|
// Get comments for an item
|
||||||
router.get(/\/api\/comments\/(?<itemid>\d+)/, async (req, res) => {
|
router.get(/\/api\/comments\/(?<itemid>\d+)/, async (req, res) => {
|
||||||
const itemId = req.params.itemid;
|
const itemId = req.params.itemid;
|
||||||
const sort = req.url.qs?.sort || 'new'; // 'new' or 'old'
|
const sort = req.url.qs?.sort || 'new'; // 'new' or 'old'
|
||||||
|
|
||||||
|
// Require login
|
||||||
|
if (!req.session) {
|
||||||
|
return res.reply({
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
success: true,
|
||||||
|
comments: [],
|
||||||
|
require_login: true,
|
||||||
|
user_id: null,
|
||||||
|
is_admin: false
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Check locked status
|
||||||
|
const item = await db`SELECT is_comments_locked FROM items WHERE id = ${itemId}`;
|
||||||
|
const is_locked = item.length > 0 ? item[0].is_comments_locked : false;
|
||||||
|
|
||||||
const comments = await db`
|
const comments = await db`
|
||||||
SELECT
|
SELECT
|
||||||
c.id, c.parent_id, c.content, c.created_at, c.vote_score, c.is_deleted,
|
c.id, c.parent_id, c.content, c.created_at, c.vote_score, c.is_deleted,
|
||||||
COALESCE(c.is_pinned, false) as is_pinned,
|
COALESCE(c.is_pinned, false) as is_pinned,
|
||||||
u.user as username, u.id as user_id, uo.avatar,
|
u.user as username, u.id as user_id, uo.avatar,
|
||||||
@@ -30,10 +48,6 @@ export default (router, tpl) => {
|
|||||||
if (sub.length > 0) is_subscribed = true;
|
if (sub.length > 0) is_subscribed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if thread is locked
|
|
||||||
const itemInfo = await db`SELECT COALESCE(is_comments_locked, false) as is_locked FROM items WHERE id = ${itemId}`;
|
|
||||||
const is_locked = itemInfo.length > 0 ? itemInfo[0].is_locked : false;
|
|
||||||
|
|
||||||
// Transform for frontend if needed, or send as is
|
// Transform for frontend if needed, or send as is
|
||||||
return res.reply({
|
return res.reply({
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
|||||||
Reference in New Issue
Block a user