fix inbox: show badges in inbox

This commit is contained in:
2025-12-19 18:00:41 +03:00
parent 21ace9299f
commit 98bf430604

View File

@@ -645,12 +645,29 @@ def inbox(username):
subscriptions ON subscriptions.thread_id = posts.thread_id subscriptions ON subscriptions.thread_id = posts.thread_id
WHERE subscriptions.user_id = ? AND posts.created_at > subscriptions.last_seen WHERE subscriptions.user_id = ? AND posts.created_at > subscriptions.last_seen
GROUP BY posts.thread_id GROUP BY posts.thread_id
),
user_badges AS (
SELECT
b.user_id,
json_group_array(
json_object(
'label', b.label,
'link', b.link,
'sort_order', b.sort_order,
'file_path', bu.file_path
)
) AS badges_json
FROM badges b
LEFT JOIN badge_uploads bu ON b.upload = bu.id
GROUP BY b.user_id
ORDER BY b.sort_order
) )
SELECT SELECT
tm.thread_id, tm.thread_slug, tm.thread_title, tm.unread_count, tm.newest_post_time, tm.thread_id, tm.thread_slug, tm.thread_title, tm.unread_count, tm.newest_post_time,
posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup, users.signature_rendered posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup, users.signature_rendered,
COALESCE(user_badges.badges_json, '[]') AS badges_json
FROM FROM
thread_metadata tm thread_metadata tm
JOIN JOIN
@@ -665,6 +682,8 @@ def inbox(username):
avatars ON users.avatar_id = avatars.id avatars ON users.avatar_id = avatars.id
LEFT JOIN LEFT JOIN
subscriptions ON subscriptions.thread_id = posts.thread_id subscriptions ON subscriptions.thread_id = posts.thread_id
LEFT JOIN
user_badges ON users.id = user_badges.user_id
WHERE WHERE
subscriptions.user_id = ? AND posts.created_at > subscriptions.last_seen subscriptions.user_id = ? AND posts.created_at > subscriptions.last_seen
ORDER BY ORDER BY
@@ -698,6 +717,7 @@ def inbox(username):
'user_id': row['user_id'], 'user_id': row['user_id'],
'original_markup': row['original_markup'], 'original_markup': row['original_markup'],
'signature_rendered': row['signature_rendered'], 'signature_rendered': row['signature_rendered'],
'badges_json': row['badges_json'],
'thread_slug': row['thread_slug'], 'thread_slug': row['thread_slug'],
}) })