diff --git a/src/inc/routes/notifications.mjs b/src/inc/routes/notifications.mjs index cfdccf7..34d4141 100644 --- a/src/inc/routes/notifications.mjs +++ b/src/inc/routes/notifications.mjs @@ -8,15 +8,10 @@ export default (router, tpl) => { try { const notifications = await db` - SELECT n.id, n.type, n.item_id, n.comment_id, n.reference_id, n.created_at, n.is_read, + SELECT n.id, n.type, n.item_id, n.reference_id, n.created_at, n.is_read, u.user as from_user, u.id as from_user_id FROM notifications n - -- Join on reference_id (which is comment_id) or comment_id. - -- Since we just set both, let's join on comment_id if present, fallback to reference_id? - -- The join was: JOIN comments c ON n.comment_id = c.id - -- If comment_id was null before my fix, this join would fail for old notifs. - -- Let's assume we use reference_id as the ID for now. - JOIN comments c ON (n.comment_id = c.id OR n.reference_id = c.id) + JOIN comments c ON n.reference_id = c.id JOIN "user" u ON c.user_id = u.id WHERE n.user_id = ${req.session.id} AND n.is_read = false ORDER BY n.created_at DESC