update
This commit is contained in:
@@ -4,12 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\Achievements\AchievementCheckRequested;
|
||||
use App\Models\Artwork;
|
||||
use App\Jobs\RecComputeSimilarByTagsJob;
|
||||
use App\Jobs\RecComputeSimilarHybridJob;
|
||||
use App\Jobs\Posts\AutoUploadPostJob;
|
||||
use App\Services\ArtworkSearchIndexer;
|
||||
use App\Services\UserStatsService;
|
||||
use App\Services\XPService;
|
||||
|
||||
/**
|
||||
* Syncs artwork documents to Meilisearch on every relevant model event.
|
||||
@@ -22,6 +24,7 @@ class ArtworkObserver
|
||||
public function __construct(
|
||||
private readonly ArtworkSearchIndexer $indexer,
|
||||
private readonly UserStatsService $userStats,
|
||||
private readonly XPService $xp,
|
||||
) {}
|
||||
|
||||
/** New artwork created — index; bump uploadscount + last_upload_at. */
|
||||
@@ -30,6 +33,11 @@ class ArtworkObserver
|
||||
$this->indexer->index($artwork);
|
||||
$this->userStats->incrementUploads($artwork->user_id);
|
||||
$this->userStats->setLastUploadAt($artwork->user_id, $artwork->created_at);
|
||||
|
||||
if ($artwork->published_at !== null) {
|
||||
$this->xp->awardArtworkPublished((int) $artwork->user_id, (int) $artwork->id);
|
||||
event(new AchievementCheckRequested((int) $artwork->user_id));
|
||||
}
|
||||
}
|
||||
|
||||
/** Artwork updated — covers publish, approval, metadata changes. */
|
||||
@@ -52,6 +60,9 @@ class ArtworkObserver
|
||||
|
||||
// Auto-upload post: fire only when artwork transitions to published for the first time
|
||||
if ($artwork->wasChanged('published_at') && $artwork->published_at !== null) {
|
||||
$this->xp->awardArtworkPublished((int) $artwork->user_id, (int) $artwork->id);
|
||||
event(new AchievementCheckRequested((int) $artwork->user_id));
|
||||
|
||||
$user = $artwork->user;
|
||||
$autoPost = $user?->profile?->auto_post_upload ?? true;
|
||||
if ($autoPost) {
|
||||
|
||||
Reference in New Issue
Block a user