fix: feed card follow ui
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user