@@ -40,7 +40,6 @@ type FullComment struct {
4040 Replies []FullComment `json:"replies"`
4141 ParentCommentId pgtype.Int4 `json:"parent_comment_id"`
4242
43- // this should be omitted
4443 ReplyIds []int32 `db:"reply_ids" json:"-"`
4544}
4645
@@ -51,12 +50,12 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
5150
5251 sql := `
5352 SELECT
54- comment_id as id,
55- parent_comment_id,
56- entity_type,
57- entity_id,
58- user_id,
59- text as message,
53+ comments. comment_id AS id,
54+ comment_threads. parent_comment_id,
55+ comments. entity_type,
56+ comments. entity_id,
57+ comments. user_id,
58+ comments. text AS message,
6059
6160 (
6261 SELECT json_agg(
@@ -72,7 +71,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
7271 ) m
7372 )::jsonb as mentions,
7473
75- track_timestamp_s,
74+ comments. track_timestamp_s,
7675
7776 (
7877 SELECT count(*)
@@ -90,7 +89,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
9089 AND cc.is_delete = false
9190 ) as reply_ids,
9291
93- is_edited,
92+ comments. is_edited,
9493
9594 EXISTS (
9695 SELECT 1
@@ -104,7 +103,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
104103 SELECT 1
105104 FROM comment_reactions
106105 WHERE comment_id = comments.comment_id
107- AND user_id = tracks.owner_id
106+ AND user_id = COALESCE( tracks.owner_id, comments.entity_id)
108107 AND is_delete = false
109108 ) AS is_artist_reacted,
110109
@@ -115,19 +114,22 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
115114 FROM comment_notification_settings mutes
116115 WHERE @my_id > 0
117116 AND mutes.user_id = @my_id
118- AND mutes.entity_type = entity_type
119- AND mutes.entity_id = entity_id
117+ AND mutes.entity_type = comments. entity_type
118+ AND mutes.entity_id = comments. entity_id
120119 LIMIT 1
121120 ), false) as is_muted,
122121
123122 comments.created_at,
124123 comments.updated_at
125124
126125 FROM comments
127- JOIN tracks ON entity_id = track_id
126+ LEFT JOIN tracks ON comments.entity_type = 'Track' AND comments. entity_id = tracks. track_id
128127 LEFT JOIN comment_threads USING (comment_id)
129- WHERE comment_id = ANY(@ids::int[])
130- AND (@include_unlisted = true OR tracks.is_unlisted = false)
128+ WHERE comments.comment_id = ANY(@ids::int[])
129+ AND (
130+ (comments.entity_type = 'Track' AND (@include_unlisted = true OR COALESCE(tracks.is_unlisted, false) = false))
131+ OR comments.entity_type = 'FanClub'
132+ )
131133 ORDER BY comments.created_at DESC
132134 `
133135
@@ -150,7 +152,6 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
150152 commentMap [int32 (comment .Id )] = comment
151153 }
152154
153- // fetch replies
154155 replyIds := []int32 {}
155156 for _ , comment := range comments {
156157 replyIds = append (replyIds , comment .ReplyIds ... )
@@ -170,7 +171,6 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
170171 comment .Replies = append (comment .Replies , reply )
171172 }
172173 }
173- // todo: sort replies?
174174 comment .ReplyCount = len (comment .Replies )
175175
176176 if comment .IsDelete {
0 commit comments