feat: Introduce custom emojis, pinned comments, and comment thread locking, making comments require user login.
This commit is contained in:
@@ -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) => {
|
||||
const itemId = req.params.itemid;
|
||||
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 {
|
||||
// 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`
|
||||
SELECT
|
||||
SELECT
|
||||
c.id, c.parent_id, c.content, c.created_at, c.vote_score, c.is_deleted,
|
||||
COALESCE(c.is_pinned, false) as is_pinned,
|
||||
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;
|
||||
}
|
||||
|
||||
// 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
|
||||
return res.reply({
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
Reference in New Issue
Block a user