optimizations

This commit is contained in:
2026-03-28 19:15:39 +01:00
parent 0b25d9570a
commit cab4fbd83e
509 changed files with 1016804 additions and 1605 deletions

View File

@@ -11,6 +11,121 @@ use Illuminate\Support\Collection;
final class NotificationService
{
public function notifyUserFollowed(User $recipient, User $actor): ?Notification
{
if ($recipient->id === $actor->id) {
return null;
}
if ($recipient->profile && $recipient->profile->follower_notifications === false) {
return null;
}
$label = $actor->name ?: $actor->username ?: 'Someone';
return Notification::query()->create([
'user_id' => (int) $recipient->id,
'type' => 'user_followed',
'data' => [
'type' => 'user_followed',
'actor_id' => (int) $actor->id,
'actor_name' => $actor->name,
'actor_username' => $actor->username,
'message' => $label . ' started following you',
'url' => $actor->username ? '/@' . $actor->username : null,
],
]);
}
public function notifyCollectionInvite(User $recipient, User $actor, \App\Models\Collection $collection, string $role): ?Notification
{
if ($recipient->id === $actor->id) {
return null;
}
return Notification::query()->create([
'user_id' => (int) $recipient->id,
'type' => 'collection_invite',
'data' => [
'type' => 'collection_invite',
'actor_id' => (int) $actor->id,
'actor_name' => $actor->name,
'actor_username' => $actor->username,
'message' => ($actor->name ?: $actor->username ?: 'Someone') . ' invited you to collaborate on ' . $collection->title,
'url' => route('settings.collections.show', ['collection' => $collection->id]),
'collection_id' => (int) $collection->id,
'collection_title' => (string) $collection->title,
'role' => $role,
],
]);
}
public function notifyCollectionSubmission(User $recipient, User $actor, \App\Models\Collection $collection, \App\Models\Artwork $artwork): ?Notification
{
if ($recipient->id === $actor->id) {
return null;
}
return Notification::query()->create([
'user_id' => (int) $recipient->id,
'type' => 'collection_submission',
'data' => [
'type' => 'collection_submission',
'actor_id' => (int) $actor->id,
'actor_name' => $actor->name,
'actor_username' => $actor->username,
'message' => ($actor->name ?: $actor->username ?: 'Someone') . ' submitted "' . $artwork->title . '" to ' . $collection->title,
'url' => route('settings.collections.show', ['collection' => $collection->id]),
'collection_id' => (int) $collection->id,
'artwork_id' => (int) $artwork->id,
],
]);
}
public function notifyCollectionComment(User $recipient, User $actor, \App\Models\Collection $collection, \App\Models\CollectionComment $comment): ?Notification
{
if ($recipient->id === $actor->id) {
return null;
}
return Notification::query()->create([
'user_id' => (int) $recipient->id,
'type' => 'collection_comment',
'data' => [
'type' => 'collection_comment',
'actor_id' => (int) $actor->id,
'actor_name' => $actor->name,
'actor_username' => $actor->username,
'message' => ($actor->name ?: $actor->username ?: 'Someone') . ' commented on ' . $collection->title,
'url' => route('profile.collections.show', ['username' => strtolower((string) $collection->user->username), 'slug' => $collection->slug]),
'collection_id' => (int) $collection->id,
'comment_id' => (int) $comment->id,
],
]);
}
public function notifyNovaCardComment(User $recipient, User $actor, \App\Models\NovaCard $card, \App\Models\NovaCardComment $comment): ?Notification
{
if ($recipient->id === $actor->id) {
return null;
}
return Notification::query()->create([
'user_id' => (int) $recipient->id,
'type' => 'nova_card_comment',
'data' => [
'type' => 'nova_card_comment',
'actor_id' => (int) $actor->id,
'actor_name' => $actor->name,
'actor_username' => $actor->username,
'message' => ($actor->name ?: $actor->username ?: 'Someone') . ' commented on ' . $card->title,
'url' => $card->publicUrl() . '#comment-' . $comment->id,
'card_id' => (int) $card->id,
'comment_id' => (int) $comment->id,
],
]);
}
public function listForUser(User $user, int $page = 1, int $perPage = 20): array
{
$resolvedPage = max(1, $page);
@@ -87,4 +202,4 @@ final class NotificationService
] : null,
];
}
}
}