feat: add feed
This commit is contained in:
@@ -379,6 +379,47 @@ func (r *UserRepo) Search(ctx context.Context, q string, limit, offset int) ([]m
|
||||
return out, total, rows.Err()
|
||||
}
|
||||
|
||||
// RecentlyJoined returns up to `limit` users who registered on/after `since`,
|
||||
// newest first, as a discovery list for the feed's "new on the platform"
|
||||
// strip. Excludes the viewer, anyone the viewer already has a follow edge with
|
||||
// (pending or accepted), and anyone involved in a block either direction — so
|
||||
// every suggestion is a fresh account the viewer can actually follow.
|
||||
func (r *UserRepo) RecentlyJoined(ctx context.Context, viewerID string, since time.Time, limit int) ([]model.UserSummary, error) {
|
||||
if limit <= 0 || limit > 20 {
|
||||
limit = 5
|
||||
}
|
||||
const q = `
|
||||
SELECT u.id, u.handle, u.name, u.avatar_url
|
||||
FROM users u
|
||||
WHERE u.created_at >= $2
|
||||
AND u.id <> $1
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM follows f
|
||||
WHERE f.follower_id = $1 AND f.following_id = u.id
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM user_blocks b
|
||||
WHERE (b.blocker_id = $1 AND b.blocked_id = u.id)
|
||||
OR (b.blocker_id = u.id AND b.blocked_id = $1)
|
||||
)
|
||||
ORDER BY u.created_at DESC
|
||||
LIMIT $3`
|
||||
rows, err := r.pg.Pool.Query(ctx, q, viewerID, since, limit)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("recently joined: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []model.UserSummary{}
|
||||
for rows.Next() {
|
||||
var u model.UserSummary
|
||||
if err := rows.Scan(&u.ID, &u.Handle, &u.Name, &u.AvatarURL); err != nil {
|
||||
return nil, fmt.Errorf("scan recently joined: %w", err)
|
||||
}
|
||||
out = append(out, u)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// GetReadingPrefs returns the raw JSONB bytes for the user's reading
|
||||
// prefs (empty object when never set). The frontend owns the shape, so
|
||||
// we round-trip the payload verbatim — no server-side schema enforced.
|
||||
|
||||
Reference in New Issue
Block a user