fix: feed card follow ui
This commit is contained in:
@@ -71,6 +71,10 @@ type Post struct {
|
||||
// author follows the caller. Both false for anonymous viewers / own posts.
|
||||
ViewerFollowsAuthor bool `json:"viewer_follows_author"`
|
||||
AuthorFollowsViewer bool `json:"author_follows_viewer"`
|
||||
|
||||
// ViewerFollowRequested: the caller has a pending (unaccepted) follow
|
||||
// request to this post's author. Drives the "Requested" feed affordance.
|
||||
ViewerFollowRequested bool `json:"viewer_follow_requested"`
|
||||
}
|
||||
|
||||
// Comment is one comment (or reply) on a post. Threading is one level deep:
|
||||
|
||||
@@ -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