messages implemented

This commit is contained in:
2026-02-26 21:12:32 +01:00
parent d0aefc5ddc
commit 15b7b77d20
168 changed files with 14728 additions and 6786 deletions

View File

@@ -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) {}
}