From 8d00dc4fda0830056dff4daefa4d0da497f70cb7 Mon Sep 17 00:00:00 2001 From: Patrick Britton Date: Sat, 7 Feb 2026 18:12:35 -0600 Subject: [PATCH] fix: add is_nsfw/nsfw_reason to all post queries (profile, detail, saved, liked, chain, focus context) --- .../internal/repository/post_repository.go | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/go-backend/internal/repository/post_repository.go b/go-backend/internal/repository/post_repository.go index a866053..73e2f04 100644 --- a/go-backend/internal/repository/post_repository.go +++ b/go-backend/internal/repository/post_repository.go @@ -251,7 +251,9 @@ func (r *PostRepository) GetPostsByAuthor(ctx context.Context, authorID string, CASE WHEN $4 != '' THEN EXISTS(SELECT 1 FROM public.post_likes WHERE post_id = p.id AND user_id = $4::uuid) ELSE FALSE END as is_liked, p.allow_chain, p.visibility, COALESCE((SELECT jsonb_object_agg(emoji, count) FROM (SELECT emoji, COUNT(*) as count FROM public.post_reactions WHERE post_id = p.id GROUP BY emoji) r), '{}'::jsonb) as reaction_counts, - CASE WHEN ($4::text) != '' THEN COALESCE((SELECT jsonb_agg(emoji) FROM public.post_reactions WHERE post_id = p.id AND user_id = $4::text::uuid), '[]'::jsonb) ELSE '[]'::jsonb END as my_reactions + CASE WHEN ($4::text) != '' THEN COALESCE((SELECT jsonb_agg(emoji) FROM public.post_reactions WHERE post_id = p.id AND user_id = $4::text::uuid), '[]'::jsonb) ELSE '[]'::jsonb END as my_reactions, + COALESCE(p.is_nsfw, FALSE) as is_nsfw, + COALESCE(p.nsfw_reason, '') as nsfw_reason FROM public.posts p JOIN public.profiles pr ON p.author_id = pr.id LEFT JOIN public.post_metrics m ON p.id = m.post_id @@ -282,6 +284,7 @@ func (r *PostRepository) GetPostsByAuthor(ctx context.Context, authorID string, &p.ID, &p.AuthorID, &p.CategoryID, &p.Body, &p.ImageURL, &p.VideoURL, &p.ThumbnailURL, &p.DurationMS, &p.Tags, &p.CreatedAt, &p.AuthorHandle, &p.AuthorDisplayName, &p.AuthorAvatarURL, &p.LikeCount, &p.CommentCount, &p.IsLiked, &p.AllowChain, &p.Visibility, &p.Reactions, &p.MyReactions, + &p.IsNSFW, &p.NSFWReason, ) if err != nil { return nil, err @@ -319,7 +322,9 @@ func (r *PostRepository) GetPostByID(ctx context.Context, postID string, userID pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, COALESCE(m.like_count, 0) as like_count, COALESCE(m.comment_count, 0) as comment_count, CASE WHEN $2 != '' THEN EXISTS(SELECT 1 FROM public.post_likes WHERE post_id = p.id AND user_id = $2::uuid) ELSE FALSE END as is_liked, - p.allow_chain, p.visibility + p.allow_chain, p.visibility, + COALESCE(p.is_nsfw, FALSE) as is_nsfw, + COALESCE(p.nsfw_reason, '') as nsfw_reason FROM public.posts p JOIN public.profiles pr ON p.author_id = pr.id LEFT JOIN public.post_metrics m ON p.id = m.post_id @@ -341,6 +346,7 @@ func (r *PostRepository) GetPostByID(ctx context.Context, postID string, userID &p.AuthorHandle, &p.AuthorDisplayName, &p.AuthorAvatarURL, &p.LikeCount, &p.CommentCount, &p.IsLiked, &p.AllowChain, &p.Visibility, + &p.IsNSFW, &p.NSFWReason, ) if err != nil { return nil, err @@ -555,7 +561,9 @@ func (r *PostRepository) GetSavedPosts(ctx context.Context, userID string, limit p.created_at, pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, COALESCE(m.like_count, 0) as like_count, COALESCE(m.comment_count, 0) as comment_count, - EXISTS(SELECT 1 FROM public.post_likes WHERE post_id = p.id AND user_id = $1::uuid) as is_liked + EXISTS(SELECT 1 FROM public.post_likes WHERE post_id = p.id AND user_id = $1::uuid) as is_liked, + COALESCE(p.is_nsfw, FALSE) as is_nsfw, + COALESCE(p.nsfw_reason, '') as nsfw_reason FROM public.post_saves ps JOIN public.posts p ON ps.post_id = p.id JOIN public.profiles pr ON p.author_id = pr.id @@ -577,6 +585,7 @@ func (r *PostRepository) GetSavedPosts(ctx context.Context, userID string, limit &p.ID, &p.AuthorID, &p.CategoryID, &p.Body, &p.ImageURL, &p.VideoURL, &p.ThumbnailURL, &p.DurationMS, &p.Tags, &p.CreatedAt, &p.AuthorHandle, &p.AuthorDisplayName, &p.AuthorAvatarURL, &p.LikeCount, &p.CommentCount, &p.IsLiked, + &p.IsNSFW, &p.NSFWReason, ) if err != nil { return nil, err @@ -604,7 +613,9 @@ func (r *PostRepository) GetLikedPosts(ctx context.Context, userID string, limit p.created_at, pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, COALESCE(m.like_count, 0) as like_count, COALESCE(m.comment_count, 0) as comment_count, - TRUE as is_liked + TRUE as is_liked, + COALESCE(p.is_nsfw, FALSE) as is_nsfw, + COALESCE(p.nsfw_reason, '') as nsfw_reason FROM public.post_likes pl JOIN public.posts p ON pl.post_id = p.id JOIN public.profiles pr ON p.author_id = pr.id @@ -626,6 +637,7 @@ func (r *PostRepository) GetLikedPosts(ctx context.Context, userID string, limit &p.ID, &p.AuthorID, &p.CategoryID, &p.Body, &p.ImageURL, &p.VideoURL, &p.ThumbnailURL, &p.DurationMS, &p.Tags, &p.CreatedAt, &p.AuthorHandle, &p.AuthorDisplayName, &p.AuthorAvatarURL, &p.LikeCount, &p.CommentCount, &p.IsLiked, + &p.IsNSFW, &p.NSFWReason, ) if err != nil { return nil, err @@ -656,6 +668,7 @@ func (r *PostRepository) GetPostChain(ctx context.Context, rootID string) ([]mod p.created_at, p.chain_parent_id, pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, COALESCE(m.like_count, 0) as like_count, COALESCE(m.comment_count, 0) as comment_count, + COALESCE(p.is_nsfw, FALSE) as is_nsfw, COALESCE(p.nsfw_reason, '') as nsfw_reason, 1 as level FROM public.posts p JOIN public.profiles pr ON p.author_id = pr.id @@ -675,6 +688,7 @@ func (r *PostRepository) GetPostChain(ctx context.Context, rootID string) ([]mod p.created_at, p.chain_parent_id, pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, COALESCE(m.like_count, 0) as like_count, COALESCE(m.comment_count, 0) as comment_count, + COALESCE(p.is_nsfw, FALSE) as is_nsfw, COALESCE(p.nsfw_reason, '') as nsfw_reason, oc.level + 1 FROM public.posts p JOIN public.profiles pr ON p.author_id = pr.id @@ -700,6 +714,7 @@ func (r *PostRepository) GetPostChain(ctx context.Context, rootID string) ([]mod COALESCE(pr.avatar_url, '') as author_avatar_url, 0 as like_count, 0 as comment_count, + FALSE as is_nsfw, '' as nsfw_reason, 2 as level FROM public.comments c JOIN public.profiles pr ON c.author_id = pr.id @@ -709,13 +724,13 @@ func (r *PostRepository) GetPostChain(ctx context.Context, rootID string) ([]mod SELECT id, author_id, category_id, body, image_url, video_url, thumbnail_url, duration_ms, tags, created_at, chain_parent_id, level, author_handle, author_display_name, author_avatar_url, - like_count, comment_count, FALSE as is_liked + like_count, comment_count, is_nsfw, nsfw_reason, FALSE as is_liked FROM object_chain UNION ALL SELECT id, author_id, category_id, body, image_url, video_url, thumbnail_url, duration_ms, tags, created_at, chain_parent_id, level, author_handle, author_display_name, author_avatar_url, - like_count, comment_count, FALSE as is_liked + like_count, comment_count, is_nsfw, nsfw_reason, FALSE as is_liked FROM comments_chain ORDER BY level ASC, created_at ASC; ` @@ -733,7 +748,7 @@ func (r *PostRepository) GetPostChain(ctx context.Context, rootID string) ([]mod err := rows.Scan( &p.ID, &p.AuthorID, &p.CategoryID, &p.Body, &p.ImageURL, &p.VideoURL, &p.ThumbnailURL, &p.DurationMS, &p.Tags, &p.CreatedAt, &p.ChainParentID, &level, &p.AuthorHandle, &p.AuthorDisplayName, &p.AuthorAvatarURL, - &p.LikeCount, &p.CommentCount, &p.IsLiked, + &p.LikeCount, &p.CommentCount, &p.IsNSFW, &p.NSFWReason, &p.IsLiked, ) if err != nil { return nil, err @@ -996,7 +1011,9 @@ func (r *PostRepository) GetPostFocusContext(ctx context.Context, postID string, pr.handle as author_handle, pr.display_name as author_display_name, COALESCE(pr.avatar_url, '') as author_avatar_url, COALESCE(m.like_count, 0) as like_count, COALESCE(m.comment_count, 0) as comment_count, CASE WHEN $2 != '' THEN EXISTS(SELECT 1 FROM public.post_likes WHERE post_id = p.id AND user_id = $2::uuid) ELSE FALSE END as is_liked, - p.allow_chain, p.visibility + p.allow_chain, p.visibility, + COALESCE(p.is_nsfw, FALSE) as is_nsfw, + COALESCE(p.nsfw_reason, '') as nsfw_reason FROM public.posts p JOIN public.profiles pr ON p.author_id = pr.id LEFT JOIN public.post_metrics m ON p.id = m.post_id @@ -1025,6 +1042,7 @@ func (r *PostRepository) GetPostFocusContext(ctx context.Context, postID string, &p.AuthorHandle, &p.AuthorDisplayName, &p.AuthorAvatarURL, &p.LikeCount, &p.CommentCount, &p.IsLiked, &p.AllowChain, &p.Visibility, + &p.IsNSFW, &p.NSFWReason, ) if err != nil { return nil, fmt.Errorf("failed to scan child post: %w", err) @@ -1065,6 +1083,7 @@ func (r *PostRepository) GetPostFocusContext(ctx context.Context, postID string, &p.AuthorHandle, &p.AuthorDisplayName, &p.AuthorAvatarURL, &p.LikeCount, &p.CommentCount, &p.IsLiked, &p.AllowChain, &p.Visibility, + &p.IsNSFW, &p.NSFWReason, ) if err != nil { return nil, fmt.Errorf("failed to scan parent child post: %w", err)