diff --git a/src/Event/WillReactToPost.php b/src/Event/WillReactToPost.php new file mode 100644 index 0000000..d7421ba --- /dev/null +++ b/src/Event/WillReactToPost.php @@ -0,0 +1,54 @@ +post = $post; + $this->user = $user; + $this->reaction = $reaction; + } +} diff --git a/src/Listener/SaveReactionsToDatabase.php b/src/Listener/SaveReactionsToDatabase.php index 691f086..e31819b 100755 --- a/src/Listener/SaveReactionsToDatabase.php +++ b/src/Listener/SaveReactionsToDatabase.php @@ -21,8 +21,10 @@ use FoF\Gamification\Listeners\SaveVotesToDatabase; use FoF\Reactions\Event\PostWasReacted; use FoF\Reactions\Event\PostWasUnreacted; +use FoF\Reactions\Event\WillReactToPost; use FoF\Reactions\PostReaction; use FoF\Reactions\Reaction; +use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Arr; use Pusher; use Symfony\Contracts\Translation\TranslatorInterface; @@ -44,11 +46,17 @@ class SaveReactionsToDatabase */ protected $extensions; - public function __construct(SettingsRepositoryInterface $settings, TranslatorInterface $translator, ExtensionManager $extensions) + /** + * @var Dispatcher + */ + protected $events; + + public function __construct(SettingsRepositoryInterface $settings, TranslatorInterface $translator, ExtensionManager $extensions, Dispatcher $events) { $this->settings = $settings; $this->translator = $translator; $this->extensions = $extensions; + $this->events = $events; } /** @@ -66,12 +74,13 @@ public function handle(Saving $event) $actor = $event->actor; $reactionId = Arr::get($data, 'attributes.reaction'); - $reactionIdentifier = null; $actor->assertCan('react', $post); $reaction = !is_null($reactionId) ? Reaction::where('id', $reactionId)->first() : null; + $this->events->dispatch(new WillReactToPost($post, $actor, $reaction)); + $gamification = $this->extensions->isEnabled('fof-gamification'); $likes = $this->extensions->isEnabled('flarum-likes');