feat: add feed
This commit is contained in:
@@ -212,6 +212,40 @@ func (s *PostService) ListByHandle(ctx context.Context, handle, viewerID string,
|
||||
return posts, total, nil
|
||||
}
|
||||
|
||||
// Feed is the global, personalised home feed: posts from across the platform,
|
||||
// prioritising not-yet-liked posts from people the viewer follows. Fully
|
||||
// hydrated (reshare/like/mention/comment state) plus the viewer↔author
|
||||
// relationship so the card can show Follow / Follow Back. Returns at most
|
||||
// `limit` posts; the caller infers "more" from a full page.
|
||||
func (s *PostService) Feed(ctx context.Context, viewerID string, limit, offset int) ([]model.Post, error) {
|
||||
if limit <= 0 || limit > 50 {
|
||||
limit = 10
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
posts, err := s.posts.FeedForViewer(ctx, viewerID, limit, offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.hydrateReshareStatesSlice(ctx, viewerID, posts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.hydrateLikesSlice(ctx, viewerID, posts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.hydrateMentionsSlice(ctx, posts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.hydratePinnedSlice(ctx, viewerID, posts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.posts.HydrateViewerRelationships(ctx, viewerID, posts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
// hydratePinnedSlice fills PinnedComment on a value slice.
|
||||
func (s *PostService) hydratePinnedSlice(ctx context.Context, viewerID string, posts []model.Post) error {
|
||||
if len(posts) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user