messages implemented
This commit is contained in:
@@ -8,9 +8,11 @@ use App\Models\Artwork;
|
||||
use App\Models\ProfileComment;
|
||||
use App\Models\User;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Services\FollowService;
|
||||
use App\Services\ThumbnailPresenter;
|
||||
use App\Services\ThumbnailService;
|
||||
use App\Services\UsernameApprovalService;
|
||||
use App\Services\UserStatsService;
|
||||
use App\Support\AvatarUrl;
|
||||
use App\Support\UsernamePolicy;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -29,6 +31,8 @@ class ProfileController extends Controller
|
||||
public function __construct(
|
||||
private readonly ArtworkService $artworkService,
|
||||
private readonly UsernameApprovalService $usernameApprovalService,
|
||||
private readonly FollowService $followService,
|
||||
private readonly UserStatsService $userStats,
|
||||
)
|
||||
{
|
||||
}
|
||||
@@ -73,35 +77,15 @@ class ProfileController extends Controller
|
||||
public function toggleFollow(Request $request, string $username): JsonResponse
|
||||
{
|
||||
$normalized = UsernamePolicy::normalize($username);
|
||||
$target = User::query()->whereRaw('LOWER(username) = ?', [$normalized])->firstOrFail();
|
||||
$target = User::query()->whereRaw('LOWER(username) = ?', [$normalized])->firstOrFail();
|
||||
$actorId = (int) Auth::id();
|
||||
|
||||
$viewerId = Auth::id();
|
||||
|
||||
if ($viewerId === $target->id) {
|
||||
if ($actorId === $target->id) {
|
||||
return response()->json(['error' => 'Cannot follow yourself.'], 422);
|
||||
}
|
||||
|
||||
$exists = DB::table('user_followers')
|
||||
->where('user_id', $target->id)
|
||||
->where('follower_id', $viewerId)
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
DB::table('user_followers')
|
||||
->where('user_id', $target->id)
|
||||
->where('follower_id', $viewerId)
|
||||
->delete();
|
||||
$following = false;
|
||||
} else {
|
||||
DB::table('user_followers')->insertOrIgnore([
|
||||
'user_id' => $target->id,
|
||||
'follower_id'=> $viewerId,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
$following = true;
|
||||
}
|
||||
|
||||
$count = DB::table('user_followers')->where('user_id', $target->id)->count();
|
||||
$following = $this->followService->toggle($actorId, (int) $target->id);
|
||||
$count = $this->followService->followersCount((int) $target->id);
|
||||
|
||||
return response()->json([
|
||||
'following' => $following,
|
||||
@@ -510,11 +494,7 @@ class ProfileController extends Controller
|
||||
// ── Increment profile views (async-safe, ignore errors) ──────────────
|
||||
if (! $isOwner) {
|
||||
try {
|
||||
DB::table('user_statistics')
|
||||
->updateOrInsert(
|
||||
['user_id' => $user->id],
|
||||
['profile_views' => DB::raw('COALESCE(profile_views, 0) + 1'), 'updated_at' => now()]
|
||||
);
|
||||
$this->userStats->incrementProfileViews($user->id);
|
||||
} catch (\Throwable) {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user