Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/Enums/ConnectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Enums;

/**
* The lists of people on a profile: who follows them, who they follow, who of those follow them back, and which of
* their followers the viewer follows too.
*/
enum ConnectionType: string
{
case Followers = 'followers';
case FollowersYouKnow = 'followers_you_know';
case Following = 'following';
case Mutuals = 'mutuals';
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/UserFollowersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Controllers;

use App\Enums\ConnectionType;
use App\Http\Requests\ListUserFollowersRequest;
use App\Models\User;
use App\Services\PageMetadata;
Expand All @@ -23,12 +24,12 @@ public function index(ListUserFollowersRequest $request, #[CurrentUser] ?User $c

return Inertia::render('user/connections', [
'user' => fn (): User => $currentUser instanceof User ? $user : $getCountedUser(),
'type' => 'followers',
'type' => ConnectionType::Followers,
'users' => Inertia::scroll(fn () => $user->followers()
->withExists(['followers as is_followed' => fn (Builder $query): Builder => $currentUser instanceof User ? $query->whereKey($currentUser->id) : $query->whereRaw('1 = 0')])
->latest('follows.created_at')
->latest('users.id')
->cursorPaginate(30)),
])->withViewData(['preview' => $currentUser instanceof User || $request->inertia() ? null : $metadata->connections($getCountedUser(), 'followers')]);
])->withViewData(['preview' => $currentUser instanceof User || $request->inertia() ? null : $metadata->connections($getCountedUser(), ConnectionType::Followers)]);
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/UserFollowersYouKnowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Controllers;

use App\Enums\ConnectionType;
use App\Http\Requests\ListUserFollowersYouKnowRequest;
use App\Models\User;
use App\Queries\FollowersYouKnowQuery;
Expand All @@ -18,7 +19,7 @@ public function index(ListUserFollowersYouKnowRequest $request, #[CurrentUser] U
{
return Inertia::render('user/connections', [
'user' => $user,
'type' => 'followers_you_know',
'type' => ConnectionType::FollowersYouKnow,
'users' => Inertia::scroll(fn () => $followersYouKnow->builder($user, $currentUser)
->withExists(['followers as is_followed' => fn (Builder $query): Builder => $query->whereKey($currentUser->id)])
->cursorPaginate(30)),
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/UserFollowingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Controllers;

use App\Enums\ConnectionType;
use App\Http\Requests\ListUserFollowingRequest;
use App\Models\User;
use App\Services\PageMetadata;
Expand All @@ -23,12 +24,12 @@ public function index(ListUserFollowingRequest $request, #[CurrentUser] ?User $c

return Inertia::render('user/connections', [
'user' => fn (): User => $currentUser instanceof User ? $user : $getCountedUser(),
'type' => 'following',
'type' => ConnectionType::Following,
'users' => Inertia::scroll(fn () => $user->following()
->withExists(['followers as is_followed' => fn (Builder $query): Builder => $currentUser instanceof User ? $query->whereKey($currentUser->id) : $query->whereRaw('1 = 0')])
->latest('follows.created_at')
->latest('users.id')
->cursorPaginate(30)),
])->withViewData(['preview' => $currentUser instanceof User || $request->inertia() ? null : $metadata->connections($getCountedUser(), 'following')]);
])->withViewData(['preview' => $currentUser instanceof User || $request->inertia() ? null : $metadata->connections($getCountedUser(), ConnectionType::Following)]);
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/UserMutualsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Controllers;

use App\Enums\ConnectionType;
use App\Http\Requests\ListUserMutualsRequest;
use App\Models\User;
use App\Queries\UserConnectionsQuery;
Expand All @@ -28,7 +29,7 @@ public function index(ListUserMutualsRequest $request, #[CurrentUser] ?User $cur

return Inertia::render('user/connections', [
'user' => fn (): User => $currentUser instanceof User ? $user : $getCountedUser(),
'type' => 'mutuals',
'type' => ConnectionType::Mutuals,
'users' => Inertia::scroll(function () use ($connections, $currentUser, $user) {
$mutuals = $connections->builder($user->following()
->whereExists(fn (QueryBuilder $query): QueryBuilder => $query->from('follows', 'follows_back')
Expand All @@ -41,6 +42,6 @@ public function index(ListUserMutualsRequest $request, #[CurrentUser] ?User $cur

return $mutuals->cursorPaginate(30);
}),
])->withViewData(['preview' => $currentUser instanceof User || $request->inertia() ? null : $metadata->connections($getCountedUser(), 'mutuals')]);
])->withViewData(['preview' => $currentUser instanceof User || $request->inertia() ? null : $metadata->connections($getCountedUser(), ConnectionType::Mutuals)]);
}
}
19 changes: 10 additions & 9 deletions app/Services/PageMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Services;

use App\Enums\CommitStatus;
use App\Enums\ConnectionType;
use App\Models\Commit;
use App\Models\LinkPreview;
use App\Models\User;
Expand Down Expand Up @@ -300,26 +301,26 @@ public function user(User $user): array
/**
* The link preview of who follows a profile, who it follows, or who of those follow it back. The lists are thin pages, so they are not indexed, though their links are followed.
*
* @param 'followers'|'following'|'mutuals' $type
* @param ConnectionType::Followers|ConnectionType::Following|ConnectionType::Mutuals $type
* @return ConnectionsMetadata
*/
public function connections(User $user, string $type): array
public function connections(User $user, ConnectionType $type): array
{
$title = match ($type) {
'followers' => "People following {$user->nameWithHandle()} on /dev/null",
'following' => "People followed by {$user->nameWithHandle()} on /dev/null",
'mutuals' => "Mutuals of {$user->nameWithHandle()} on /dev/null",
ConnectionType::Followers => "People following {$user->nameWithHandle()} on /dev/null",
ConnectionType::Following => "People followed by {$user->nameWithHandle()} on /dev/null",
ConnectionType::Mutuals => "Mutuals of {$user->nameWithHandle()} on /dev/null",
};

return [
'type' => 'profile',
'title' => $title,
'description' => match ($type) {
'followers' => "See who follows {$user->mention()} on /dev/null, a social network for developers.",
'following' => "See who {$user->mention()} follows on /dev/null, a social network for developers.",
'mutuals' => "See who follows {$user->mention()} back on /dev/null, a social network for developers.",
ConnectionType::Followers => "See who follows {$user->mention()} on /dev/null, a social network for developers.",
ConnectionType::Following => "See who {$user->mention()} follows on /dev/null, a social network for developers.",
ConnectionType::Mutuals => "See who follows {$user->mention()} back on /dev/null, a social network for developers.",
},
'url' => route("user-{$type}.index", $user),
'url' => route("user-{$type->value}.index", $user),
'robots' => self::NOT_INDEXABLE,
'images' => [$this->profileImage($user, $title)],
'handle' => $user->handle,
Expand Down