feat: Implement server-side comment preloading for improved performance and introduce new comment features including pinned comments, locked threads, and custom emojis.
This commit is contained in:
@@ -270,9 +270,37 @@ export default {
|
||||
const link = lib.genLink({ user, tag, mime, type: o.fav ? 'favs' : 'f0cks' });
|
||||
|
||||
return {
|
||||
success: true,
|
||||
link: link,
|
||||
itemid: item[0].id
|
||||
};
|
||||
},
|
||||
getComments: async (itemId, sort = 'new') => {
|
||||
if (!itemId) return [];
|
||||
try {
|
||||
const comments = await db`
|
||||
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,
|
||||
(SELECT count(*) FROM comments r WHERE r.parent_id = c.id) as reply_count
|
||||
FROM comments c
|
||||
JOIN "user" u ON c.user_id = u.id
|
||||
LEFT JOIN user_options uo ON uo.user_id = u.id
|
||||
WHERE c.item_id = ${itemId} AND c.is_deleted = false
|
||||
ORDER BY COALESCE(c.is_pinned, false) DESC, c.created_at ${db.unsafe(sort === 'new' ? 'DESC' : 'ASC')}
|
||||
`;
|
||||
return comments;
|
||||
} catch (e) {
|
||||
console.error('[F0CKLIB] Error fetching comments:', e);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
getSubscriptionStatus: async (userId, itemId) => {
|
||||
if (!userId || !itemId) return false;
|
||||
try {
|
||||
const sub = await db`SELECT 1 FROM comment_subscriptions WHERE user_id = ${userId} AND item_id = ${itemId}`;
|
||||
return sub.length > 0;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user