You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: let API clients list mutuals and followers they know - #1542
The web profile has Mutuals and Followers you know lists, and the API's UserResource already returns followed_by_following_count. But there's no API route for either list, so a device client can show the count and not the people behind it.
This adds signed GET api/v1/users/{handle}/mutuals and GET api/v1/users/{handle}/followers-you-know, next to the followers and following routes. They return the same users in the same order as the web, 30 a page with a cursor, with is_followed, follows_you and bio_profiles like the followers list (#1538). Across a block they answer with the followers route's codes.
To share one builder with the web, the mutuals query moves from UserMutualsController into UserConnectionsQuery::mutuals(). FollowersYouKnowQuery::builder() stops sorting, because UserConnectionsQuery::builder() already sorts and adds the flags. Wrapping one in the other sorted twice, which added a duplicate cursor condition to every next page. The web followers-you-know page now uses UserConnectionsQuery::builder() too, so it no longer repeats the flag queries. Both web lists show the same users in the same order as before.
Summary by CodeRabbit
New Features
Added API access to a user’s mutual connections and followers also followed by the signed-in viewer.
Follower and following lists now include profiles linked in each person’s bio.
No actionable comments were generated in the recent review.
Walkthrough
The change adds signed API lists for mutuals and followers known to the viewer. Connection-list responses include profiles mentioned in listed users’ bios. Web connection lists also use shared connection-query logic.
Changes: Connection lists and bio profiles
Layer / File(s)
Summary
Shared connection and profile queries app/Queries/UserConnectionsQuery.php, app/Queries/FollowersYouKnowQuery.php, app/Queries/BioProfilesQuery.php, tests/Unit/Queries/BioProfilesQueryTest.php
The query layer adds mutual connections, removes ordering from the followers-you-know query, and supports batched profile lookups for multiple users.
Shared queries in web and API lists app/Http/Controllers/UserFollowersYouKnowController.php, app/Http/Controllers/UserMutualsController.php, app/Http/Resources/UserConnectionCollection.php, app/Http/Controllers/Api/UserFollowersController.php, app/Http/Controllers/Api/UserFollowingController.php, tests/Feature/Controllers/Api/UserFollowersControllerTest.php, tests/Feature/Controllers/Api/UserFollowingControllerTest.php
Web lists use the shared connection query. API follower and following responses use UserConnectionCollection and include bio profile mappings.
Signed mutuals and followers-you-know endpoints routes/api.php, app/Http/Requests/ListApiUserMutualsRequest.php, app/Http/Requests/ListApiUserFollowersYouKnowRequest.php, app/Http/Controllers/Api/UserMutualsController.php, app/Http/Controllers/Api/UserFollowersYouKnowController.php, tests/Feature/Controllers/Api/UserMutualsControllerTest.php, tests/Feature/Controllers/Api/UserFollowersYouKnowControllerTest.php, KNOWLEDGE_BASE.md
Authenticated routes expose mutuals and followers-you-know lists. Request classes enforce across-block authorization, and feature tests cover response contents, pagination, query counts, blocking, and unknown handles.
sequenceDiagram
actor Client as Signed API client
participant Routes as API routes
participant Request as List API request
participant Controller as API connection controller
participant Queries as Connection queries
participant BioProfilesQuery
participant Collection as UserConnectionCollection
Client->>Routes: Request mutuals or followers-you-know
Routes->>Request: Authorize viewer and target user
Routes->>Controller: Invoke index
alt Followers the viewer knows
Controller->>Queries: Build target followers followed by viewer
else Mutuals
Controller->>Queries: Get reciprocal connections
end
Controller->>BioProfilesQuery: Get profiles for page items
Controller->>Collection: Create collection with page and profiles
Collection-->>Client: Return connection data and pagination
Loading
Possibly related PRs
dev-null-sh/dev-null.sh#1538: Adds bio profile mappings to API follower and following lists using the same collection and batch query.
dev-null-sh/dev-null.sh#1328: Makes API follower and following lists signed-only and requires an authenticated viewer for the shared connection query.
dev-null-sh/dev-null.sh#1354: Applies the shared connection query builder and viewer-relative follow flags to web connection lists.
Suggested reviewers:mnapoli, xheaven, ashkesarmaa
Merge Risk: Minimal · up to addf8
This adds signed API lists for mutuals and followers you know, and adds bio profile data to the existing connection lists. No actionable merge-blocking risk was found in the supplied context.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the primary change: adding API access to mutuals and followers the requesting user knows.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The web profile has Mutuals and Followers you know lists, and the API's
UserResourcealready returnsfollowed_by_following_count. But there's no API route for either list, so a device client can show the count and not the people behind it.This adds signed
GET api/v1/users/{handle}/mutualsandGET api/v1/users/{handle}/followers-you-know, next to the followers and following routes. They return the same users in the same order as the web, 30 a page with a cursor, withis_followed,follows_youandbio_profileslike the followers list (#1538). Across a block they answer with the followers route's codes.To share one builder with the web, the mutuals query moves from
UserMutualsControllerintoUserConnectionsQuery::mutuals().FollowersYouKnowQuery::builder()stops sorting, becauseUserConnectionsQuery::builder()already sorts and adds the flags. Wrapping one in the other sorted twice, which added a duplicate cursor condition to every next page. The web followers-you-know page now usesUserConnectionsQuery::builder()too, so it no longer repeats the flag queries. Both web lists show the same users in the same order as before.Summary by CodeRabbit