Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions extensions/tags/src/Listener/UpdateTagMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,29 @@ public function subscribe(Dispatcher $events): void
$events->listen(PostDeleted::class, $this->whenPostIsDeleted(...));
$events->listen(PostHidden::class, $this->whenPostIsHidden(...));
$events->listen(PostRestored::class, $this->whenPostIsRestored(...));

// Refresh metadata skipped while a post was pending approval.
$events->listen('Flarum\Approval\Event\PostWasApproved', $this->whenPostIsApproved(...));
}

public function whenDiscussionIsStarted(Started $event): void
{
$this->updateTags($event->discussion, 1);
}

public function whenPostIsApproved(object $event): void
{
$discussion = $event->post->discussion;
$delta = $event->post->number === 1 ? 1 : 0;

// The visibility change may not be persisted yet; if so, defer to its save.
if ($discussion->is_private) {
$discussion->afterSave(fn (Discussion $discussion) => $this->updateTags($discussion, $delta));
} else {
$this->updateTags($discussion, $delta);
}
}

public function whenDiscussionWasTagged(DiscussionWasTagged $event): void
{
$oldTags = Tag::whereIn('id', Arr::pluck($event->oldTags, 'id'))->get();
Expand Down
Loading