Repository navigation
feat: show followers you know on profiles #733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nunomaduro
merged 6 commits into
dev-null-sh:production
from
ashkesarmaa:feat/followers-you-know
Oct 26, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c515a3a
feat: show followers you know on profiles
ashkesarmaa e9a6bbb
fix: let long usernames wrap beside the follower avatars
ashkesarmaa 61869a0
Merge remote-tracking branch 'origin/production' into feat/followers-…
ashkesarmaa 464ac96
Merge remote-tracking branch 'origin/production' into feat/followers-…
ashkesarmaa 4143294
Merge remote-tracking branch 'origin/production' into feat/followers-…
ashkesarmaa 4c8201e
Merge remote-tracking branch 'origin/production' into HEAD
ashkesarmaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Http\Requests\ListUserFollowersYouKnowRequest; | ||
| use App\Models\User; | ||
| use App\Queries\FollowersYouKnowQuery; | ||
| use Illuminate\Container\Attributes\CurrentUser; | ||
| use Illuminate\Database\Eloquent\Builder; | ||
| use Inertia\Inertia; | ||
| use Inertia\Response; | ||
|
|
||
| final readonly class UserFollowersYouKnowController | ||
| { | ||
| public function index(ListUserFollowersYouKnowRequest $request, #[CurrentUser] User $currentUser, User $user, FollowersYouKnowQuery $followersYouKnow): Response | ||
| { | ||
| return Inertia::render('user/connections', [ | ||
| 'user' => $user, | ||
| 'type' => 'followers_you_know', | ||
| 'users' => Inertia::scroll(fn () => $followersYouKnow->builder($user, $currentUser) | ||
| ->withExists(['followers as is_followed' => fn (Builder $query): Builder => $query->whereKey($currentUser->id)]) | ||
| ->cursorPaginate(30)), | ||
| ]); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Requests; | ||
|
|
||
| use App\Models\User; | ||
| use Illuminate\Auth\Access\Response; | ||
| use Illuminate\Foundation\Http\FormRequest; | ||
|
|
||
| final class ListUserFollowersYouKnowRequest extends FormRequest | ||
| { | ||
| /** | ||
| * A block hides each one's connections from the other, like the rest of their profile. | ||
| */ | ||
| public function authorize(): Response | ||
| { | ||
| $viewer = $this->user(); | ||
| assert($viewer instanceof User); | ||
|
|
||
| $user = $this->route('user'); | ||
| assert($user instanceof User); | ||
|
|
||
| return $viewer->hasBlockWith($user) ? Response::denyAsNotFound() : Response::allow(); | ||
| } | ||
|
|
||
| /** | ||
| * @return array{} | ||
| */ | ||
| public function rules(): array | ||
| { | ||
| return []; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Queries; | ||
|
|
||
| use App\Models\User; | ||
| use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
| use Illuminate\Support\Collection; | ||
|
|
||
| final readonly class FollowersYouKnowQuery | ||
| { | ||
| public const int PREVIEW_COUNT = 3; | ||
|
|
||
| /** | ||
| * A user's followers whom the viewer follows too, as the web lists them: the newest follow of the user first. | ||
| * | ||
| * @return BelongsToMany<User, User> | ||
| */ | ||
| public function builder(User $user, User $viewer): BelongsToMany | ||
| { | ||
| $following = $viewer->following(); | ||
|
|
||
| return $user->followers() | ||
| ->whereIn('users.id', $following->newPivotQuery()->select($following->getRelatedPivotKeyName())) | ||
| ->latest('follows.created_at') | ||
| ->latest('users.id'); | ||
| } | ||
|
|
||
| /** | ||
| * The few the profile names, the most followed first so the viewer is likelier to recognise them, and how many | ||
| * there are in all. | ||
| * | ||
| * @return array{users: Collection<int, User>, count: int} | ||
| */ | ||
| public function preview(User $user, User $viewer): array | ||
| { | ||
| $following = $viewer->following(); | ||
| $followers = $user->followers(); | ||
|
|
||
| $known = $followers->newPivotQuery() | ||
| ->select($followers->getRelatedPivotKeyName()) | ||
| ->whereIn($followers->getRelatedPivotKeyName(), $following->newPivotQuery()->select($following->getRelatedPivotKeyName())); | ||
|
|
||
| $count = $known->count(); | ||
|
|
||
| if ($count === 0) { | ||
| return ['users' => new Collection(), 'count' => 0]; | ||
| } | ||
|
|
||
| $users = User::query() | ||
| ->whereIn('id', $known) | ||
| ->addSelect(['followers_count' => $following->newPivotStatement() | ||
| ->selectRaw('count(*)') | ||
| ->whereColumn($following->getQualifiedRelatedPivotKeyName(), 'users.id')]) | ||
| ->orderByDesc('followers_count') | ||
| ->orderBy('users.id') | ||
| ->limit(self::PREVIEW_COUNT) | ||
| ->get() | ||
| ->toBase(); | ||
|
|
||
| return ['users' => $users, 'count' => $count]; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { Link } from '@inertiajs/react'; | ||
| import { Fragment } from 'react'; | ||
| import UserFollowersYouKnowController from '@/actions/App/Http/Controllers/UserFollowersYouKnowController'; | ||
| import { UserAvatar } from '@/components/user-avatar'; | ||
| import { show } from '@/routes/user'; | ||
| import type { User } from '@/types'; | ||
|
|
||
| export type FollowersYouKnowPreview = { | ||
| users: User[]; | ||
| count: number; | ||
| }; | ||
|
|
||
| /** | ||
| * Up to two people are named, and the rest are counted, so the line stays one sentence however many there are. | ||
| */ | ||
| const NAMED = 2; | ||
|
|
||
| /** | ||
| * Social proof under a profile's counts: which of the people the viewer follows also follow this user. | ||
| */ | ||
| export function FollowersYouKnow({ | ||
| user, | ||
| preview, | ||
| }: { | ||
| user: Pick<User, 'handle'>; | ||
| preview: FollowersYouKnowPreview; | ||
| }) { | ||
| if (preview.count === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const named = preview.users.slice(0, NAMED); | ||
| const others = preview.count - named.length; | ||
| const list = UserFollowersYouKnowController.index(user); | ||
|
|
||
| return ( | ||
| <div | ||
| className="mt-3 flex items-center gap-2.5 text-sm text-muted-foreground" | ||
| data-test="followers-you-know" | ||
| > | ||
| <Link | ||
| href={list} | ||
| aria-label="Followers you know" | ||
| className="flex shrink-0 -space-x-1.5 rounded-full focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none" | ||
| > | ||
| {preview.users.map((person) => ( | ||
| <UserAvatar | ||
| key={person.id} | ||
| user={person} | ||
| pixels={40} | ||
| className="size-5 text-[10px] ring-2 ring-card" | ||
| /> | ||
| ))} | ||
| </Link> | ||
| <p className="min-w-0 leading-snug"> | ||
| Followed by{' '} | ||
| {named.map((person, index) => ( | ||
| <Fragment key={person.id}> | ||
| {index > 0 && (others > 0 ? ', ' : ' and ')} | ||
| <Link | ||
| href={show(person)} | ||
| className="font-mono text-[13px] font-medium wrap-anywhere text-foreground hover:underline" | ||
| > | ||
| @{person.handle} | ||
| </Link> | ||
| </Fragment> | ||
| ))} | ||
| {others > 0 && ( | ||
| <> | ||
| {' '} | ||
| and{' '} | ||
| <Link href={list} className="hover:underline"> | ||
| {others} {others === 1 ? 'other' : 'others'} you | ||
| follow | ||
| </Link> | ||
| </> | ||
| )} | ||
| </p> | ||
| </div> | ||
| ); | ||
| } |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.