Forum: - TipTap WYSIWYG editor with full toolbar - @emoji-mart/react emoji picker (consistent with tweets) - @mention autocomplete with user search API - Fix PHP 8.4 parse errors in Blade templates - Fix thread data display (paginator items) - Align forum page widths to max-w-5xl Discover: - Extract shared _nav.blade.php partial - Add missing nav links to for-you page - Add Following link for authenticated users Feed/Posts: - Post model, controllers, policies, migrations - Feed page components (PostComposer, FeedCard, etc) - Post reactions, comments, saves, reports, sharing - Scheduled publishing support - Link preview controller Profile: - Profile page components (ProfileHero, ProfileTabs) - Profile API controller Uploads: - Upload wizard enhancements - Scheduled publish picker - Studio status bar and readiness checklist
91 lines
3.3 KiB
PHP
91 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Observers;
|
|
|
|
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;
|
|
|
|
/**
|
|
* Syncs artwork documents to Meilisearch on every relevant model event.
|
|
* Also keeps user_statistics.uploads_count and last_upload_at in sync.
|
|
*
|
|
* All operations are dispatched to the queue — no blocking calls.
|
|
*/
|
|
class ArtworkObserver
|
|
{
|
|
public function __construct(
|
|
private readonly ArtworkSearchIndexer $indexer,
|
|
private readonly UserStatsService $userStats,
|
|
) {}
|
|
|
|
/** New artwork created — index; bump uploadscount + last_upload_at. */
|
|
public function created(Artwork $artwork): void
|
|
{
|
|
$this->indexer->index($artwork);
|
|
$this->userStats->incrementUploads($artwork->user_id);
|
|
$this->userStats->setLastUploadAt($artwork->user_id, $artwork->created_at);
|
|
}
|
|
|
|
/** Artwork updated — covers publish, approval, metadata changes. */
|
|
public function updated(Artwork $artwork): void
|
|
{
|
|
// When soft-deleted, remove from index immediately.
|
|
if ($artwork->isDirty('deleted_at') && $artwork->deleted_at !== null) {
|
|
$this->indexer->delete($artwork->id);
|
|
return;
|
|
}
|
|
|
|
$this->indexer->update($artwork);
|
|
|
|
// §7.5 On-demand: recompute similarity when tags/categories could have changed.
|
|
// The pivot sync happens outside this observer, so we dispatch on every
|
|
// meaningful update and let the job be idempotent (cheap if nothing changed).
|
|
if ($artwork->is_public && $artwork->published_at) {
|
|
RecComputeSimilarByTagsJob::dispatch($artwork->id)->delay(now()->addSeconds(30));
|
|
RecComputeSimilarHybridJob::dispatch($artwork->id)->delay(now()->addMinutes(1));
|
|
|
|
// Auto-upload post: fire only when artwork transitions to published for the first time
|
|
if ($artwork->wasChanged('published_at') && $artwork->published_at !== null) {
|
|
$user = $artwork->user;
|
|
$autoPost = $user?->profile?->auto_post_upload ?? true;
|
|
if ($autoPost) {
|
|
AutoUploadPostJob::dispatch($artwork->id, $artwork->user_id)
|
|
->delay(now()->addSeconds(5));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Soft delete — remove from search and decrement uploads_count. */
|
|
public function deleted(Artwork $artwork): void
|
|
{
|
|
$this->indexer->delete($artwork->id);
|
|
$this->userStats->decrementUploads($artwork->user_id);
|
|
}
|
|
|
|
/** Force delete — ensure removal from index; only decrement if NOT already soft-deleted. */
|
|
public function forceDeleted(Artwork $artwork): void
|
|
{
|
|
$this->indexer->delete($artwork->id);
|
|
|
|
// If deleted_at was null the artwork was not soft-deleted before;
|
|
// the deleted() event did NOT fire, so we decrement here.
|
|
if ($artwork->deleted_at === null) {
|
|
$this->userStats->decrementUploads($artwork->user_id);
|
|
}
|
|
}
|
|
|
|
/** Restored from soft-delete — re-index and re-increment uploads_count. */
|
|
public function restored(Artwork $artwork): void
|
|
{
|
|
$this->indexer->index($artwork);
|
|
$this->userStats->incrementUploads($artwork->user_id);
|
|
}
|
|
}
|