fix: feed card follow ui

This commit is contained in:
Krispire Admin
2026-06-18 00:20:52 +05:30
parent be4b1636c0
commit 9235f68402
2 changed files with 15 additions and 2 deletions
+11 -2
View File
@@ -286,8 +286,9 @@ func (r *PostRepo) FeedForViewer(ctx context.Context, viewerID string, limit, of
return posts, err
}
// HydrateViewerRelationships fills ViewerFollowsAuthor / AuthorFollowsViewer
// across a page of feed posts in two batched queries (one per direction).
// HydrateViewerRelationships fills ViewerFollowsAuthor / AuthorFollowsViewer /
// ViewerFollowRequested across a page of feed posts in three batched queries
// (viewer→author accepted, author→viewer accepted, viewer→author pending).
// No-op for anonymous viewers.
func (r *PostRepo) HydrateViewerRelationships(ctx context.Context, viewerID string, posts []model.Post) error {
if viewerID == "" || len(posts) == 0 {
@@ -320,9 +321,17 @@ func (r *PostRepo) HydrateViewerRelationships(ctx context.Context, viewerID stri
if err != nil {
return err
}
requested, err := r.followEdges(ctx,
`SELECT following_id FROM follows
WHERE follower_id = $1 AND status = 'pending' AND following_id = ANY($2)`,
viewerID, authorIDs)
if err != nil {
return err
}
for i := range posts {
posts[i].ViewerFollowsAuthor = following[posts[i].UserID]
posts[i].AuthorFollowsViewer = followers[posts[i].UserID]
posts[i].ViewerFollowRequested = requested[posts[i].UserID]
}
return nil
}