feat: add community activity feed and mentions

This commit is contained in:
2026-03-17 18:26:57 +01:00
parent 2728644477
commit 2119741ba7
15 changed files with 1280 additions and 112 deletions

View File

@@ -6,6 +6,7 @@ namespace App\Observers;
use App\Models\ArtworkComment;
use App\Services\UserStatsService;
use App\Services\UserMentionSyncService;
use Illuminate\Support\Facades\DB;
/**
@@ -16,6 +17,7 @@ class ArtworkCommentObserver
{
public function __construct(
private readonly UserStatsService $userStats,
private readonly UserMentionSyncService $mentionSync,
) {}
public function created(ArtworkComment $comment): void
@@ -28,6 +30,14 @@ class ArtworkCommentObserver
// The commenter is "active"
$this->userStats->ensureRow($comment->user_id);
$this->userStats->setLastActiveAt($comment->user_id);
$this->mentionSync->syncForComment($comment);
}
public function updated(ArtworkComment $comment): void
{
if ($comment->wasChanged(['content', 'raw_content', 'rendered_content', 'parent_id'])) {
$this->mentionSync->syncForComment($comment);
}
}
/** Soft delete. */
@@ -37,6 +47,8 @@ class ArtworkCommentObserver
if ($creatorId) {
$this->userStats->decrementCommentsReceived($creatorId);
}
$this->mentionSync->deleteForComment((int) $comment->id);
}
/** Hard delete after soft delete — already decremented; nothing to do. */
@@ -50,6 +62,13 @@ class ArtworkCommentObserver
$this->userStats->decrementCommentsReceived($creatorId);
}
}
$this->mentionSync->deleteForComment((int) $comment->id);
}
public function restored(ArtworkComment $comment): void
{
$this->mentionSync->syncForComment($comment);
}
private function creatorId(int $artworkId): ?int