feat: friend request notifications
This commit is contained in:
@@ -98,22 +98,29 @@ func (r *FollowRepo) Status(ctx context.Context, followerID, followingID string)
|
||||
// them), newest first, optionally filtered by a name/handle search `q`.
|
||||
// Returns the page plus the total matching count (for pagination).
|
||||
func (r *FollowRepo) ListFollowers(ctx context.Context, userID, q string, limit, offset int) ([]model.UserSummary, int, error) {
|
||||
return r.listRelations(ctx, "f.following_id = $1", "f.follower_id", userID, q, limit, offset)
|
||||
return r.listRelations(ctx, "f.following_id = $1", "f.follower_id", "accepted", userID, q, limit, offset)
|
||||
}
|
||||
|
||||
// ListIncomingRequests returns the users with a pending request to follow
|
||||
// userID (newest first), optionally filtered by `q`, plus the total count.
|
||||
func (r *FollowRepo) ListIncomingRequests(ctx context.Context, userID, q string, limit, offset int) ([]model.UserSummary, int, error) {
|
||||
return r.listRelations(ctx, "f.following_id = $1", "f.follower_id", "pending", userID, q, limit, offset)
|
||||
}
|
||||
|
||||
// ListFollowing returns the users userID follows (accepted), newest first,
|
||||
// optionally filtered by `q`. Returns the page plus the total count.
|
||||
func (r *FollowRepo) ListFollowing(ctx context.Context, userID, q string, limit, offset int) ([]model.UserSummary, int, error) {
|
||||
return r.listRelations(ctx, "f.follower_id = $1", "f.following_id", userID, q, limit, offset)
|
||||
return r.listRelations(ctx, "f.follower_id = $1", "f.following_id", "accepted", userID, q, limit, offset)
|
||||
}
|
||||
|
||||
// listRelations powers both directions: `whereOwn` pins the row to userID on
|
||||
// one side, `joinCol` is the follows column holding the *other* user (the one
|
||||
// we join to users and return). `q` filters by name/handle (ILIKE); empty `q`
|
||||
// disables the filter. The column expressions are fixed internal constants —
|
||||
// never user input — so this stays injection-safe.
|
||||
// listRelations powers follower/following/pending-request listings: `whereOwn`
|
||||
// pins the row to userID on one side, `joinCol` is the follows column holding
|
||||
// the *other* user (the one we join to users and return), `status` is the edge
|
||||
// status to match ('accepted' or 'pending'). `q` filters by name/handle
|
||||
// (ILIKE); empty `q` disables the filter. The column/status expressions are
|
||||
// fixed internal constants — never user input — so this stays injection-safe.
|
||||
func (r *FollowRepo) listRelations(
|
||||
ctx context.Context, whereOwn, joinCol, userID, q string, limit, offset int,
|
||||
ctx context.Context, whereOwn, joinCol, status, userID, q string, limit, offset int,
|
||||
) ([]model.UserSummary, int, error) {
|
||||
like := "%" + q + "%"
|
||||
|
||||
@@ -121,7 +128,7 @@ func (r *FollowRepo) listRelations(
|
||||
countSQL := `
|
||||
SELECT count(*)
|
||||
FROM follows f JOIN users u ON u.id = ` + joinCol + `
|
||||
WHERE ` + whereOwn + ` AND f.status = 'accepted'
|
||||
WHERE ` + whereOwn + ` AND f.status = '` + status + `'
|
||||
AND ($2 = '' OR u.name ILIKE $3 OR u.handle ILIKE $3)`
|
||||
if err := r.pg.Pool.QueryRow(ctx, countSQL, userID, q, like).Scan(&total); err != nil {
|
||||
return nil, 0, fmt.Errorf("count relations: %w", err)
|
||||
@@ -133,7 +140,7 @@ func (r *FollowRepo) listRelations(
|
||||
listSQL := `
|
||||
SELECT u.handle, u.name, u.avatar_url
|
||||
FROM follows f JOIN users u ON u.id = ` + joinCol + `
|
||||
WHERE ` + whereOwn + ` AND f.status = 'accepted'
|
||||
WHERE ` + whereOwn + ` AND f.status = '` + status + `'
|
||||
AND ($2 = '' OR u.name ILIKE $3 OR u.handle ILIKE $3)
|
||||
ORDER BY f.created_at DESC, u.handle ASC
|
||||
LIMIT $4 OFFSET $5`
|
||||
|
||||
Reference in New Issue
Block a user