feat: add feed
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prabhupadasays/spsays-bff/internal/model"
|
||||
"github.com/prabhupadasays/spsays-bff/internal/repository"
|
||||
@@ -338,6 +339,13 @@ func (s *SocialGraphService) Followers(ctx context.Context, handle, q string, li
|
||||
return s.follows.ListFollowers(ctx, u.ID, q, limit, offset)
|
||||
}
|
||||
|
||||
// NewUsers returns up to `limit` accounts that joined in the last 24h for the
|
||||
// feed's "new on the platform" discovery strip — excluding the viewer, anyone
|
||||
// they already have a follow edge with, and blocked pairs.
|
||||
func (s *SocialGraphService) NewUsers(ctx context.Context, viewerID string, limit int) ([]model.UserSummary, error) {
|
||||
return s.users.RecentlyJoined(ctx, viewerID, time.Now().Add(-24*time.Hour), limit)
|
||||
}
|
||||
|
||||
func (s *SocialGraphService) Following(ctx context.Context, handle, q string, limit, offset int) ([]model.UserSummary, int, error) {
|
||||
u, err := s.users.FindByHandle(ctx, handle)
|
||||
if err != nil {
|
||||
|
||||
@@ -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