From b6dc14971f5918ba796c0fe4d38e1957c47b52a8 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 4 Sep 2022 10:21:52 +1000 Subject: [PATCH] Listener code tidyup - consistent use of slack queue "slack" --- src/Listeners/AppHomeOpenedListener.php | 4 ++-- src/Listeners/BlockActionListener.php | 10 +++++++--- src/Listeners/BlockSuggestionListener.php | 4 +++- src/Listeners/ChannelJoinListener.php | 2 +- src/Listeners/ChannelLeftListener.php | 2 +- src/Listeners/InteractiveMessageListener.php | 2 +- src/Listeners/MessageListener.php | 2 +- src/Listeners/PinAddedListener.php | 2 +- src/Listeners/PinRemovedListener.php | 2 +- src/Listeners/ReactionAddedListener.php | 2 +- src/Listeners/ShortcutListener.php | 17 ++++++----------- src/Listeners/ViewClosedListener.php | 2 +- src/Listeners/ViewSubmissionListener.php | 2 +- 13 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/Listeners/AppHomeOpenedListener.php b/src/Listeners/AppHomeOpenedListener.php index 179dd84..912acc1 100644 --- a/src/Listeners/AppHomeOpenedListener.php +++ b/src/Listeners/AppHomeOpenedListener.php @@ -20,11 +20,11 @@ class AppHomeOpenedListener implements ShouldQueue * @param AppHomeOpened $event * @return void */ - public function handle(AppHomeOpened $event) + public function handle(AppHomeOpened $event): void { // Do some magic with event data Log::info(sprintf('%s:App Home Page open for [%s] in team [%s]',self::LOGKEY,$event->user_id,$event->team_id),['m'=>__METHOD__]); - dispatch((new SlackHomeTabUpdate($event->user(),$event->team(TRUE),$event->tab,$event->view))->onQueue('high')); + dispatch((new SlackHomeTabUpdate($event->user(),$event->team(TRUE),$event->tab,$event->view))->onQueue('slack')); } } \ No newline at end of file diff --git a/src/Listeners/BlockActionListener.php b/src/Listeners/BlockActionListener.php index 5b8be49..4e81794 100644 --- a/src/Listeners/BlockActionListener.php +++ b/src/Listeners/BlockActionListener.php @@ -2,6 +2,7 @@ namespace Slack\Listeners; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Log; use Slack\Jobs\DeleteChat; @@ -10,9 +11,12 @@ use Slack\Interactive\BlockActions; /** * This class handles BlockActions events. * It's expected that the local application would implement this class completely, rather than using this - * modules implementation. + * module's implementation. + * + * @note Since block actions contain a trigger_id, we shouldnt queue this as the trigger_id may have expired by the time + * the queue runs the job. (trigger_id's only last 3 seconds) */ -class BlockActionListener +class BlockActionListener //implements ShouldQueue { protected const LOGKEY = 'LBA'; @@ -60,7 +64,7 @@ class BlockActionListener switch ($event->action_id) { case 'self_destruct': // Queue the delete of the message - dispatch((new DeleteChat($event->user(),$event->message_ts))->onQueue('low')); + dispatch((new DeleteChat($event->user(),$event->message_ts))->onQueue('slack')); // @todo If this message is on integrations messages channel, which is not the user_id() - need to use the user's integration direct channel ID break; diff --git a/src/Listeners/BlockSuggestionListener.php b/src/Listeners/BlockSuggestionListener.php index c9217f0..0b1a280 100644 --- a/src/Listeners/BlockSuggestionListener.php +++ b/src/Listeners/BlockSuggestionListener.php @@ -2,10 +2,12 @@ namespace Slack\Listeners; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Log; + use Slack\Options\BlockSuggestion; -class BlockSuggestionListener +class BlockSuggestionListener implements ShouldQueue { private const LOGKEY = 'LBS'; diff --git a/src/Listeners/ChannelJoinListener.php b/src/Listeners/ChannelJoinListener.php index b7519a0..36c2a78 100644 --- a/src/Listeners/ChannelJoinListener.php +++ b/src/Listeners/ChannelJoinListener.php @@ -19,7 +19,7 @@ class ChannelJoinListener implements ShouldQueue * @param MemberJoinedChannel $event * @return void */ - public function handle(MemberJoinedChannel $event) + public function handle(MemberJoinedChannel $event): void { // Do some magic with event data Log::info(sprintf('%s:User [%s] joined Channel [%s]',self::LOGKEY,$event->invited,$event->channel_id),['m'=>__METHOD__]); diff --git a/src/Listeners/ChannelLeftListener.php b/src/Listeners/ChannelLeftListener.php index 3e3a11c..2303aad 100644 --- a/src/Listeners/ChannelLeftListener.php +++ b/src/Listeners/ChannelLeftListener.php @@ -19,7 +19,7 @@ class ChannelLeftListener implements ShouldQueue * @param Base $event * @return void */ - public function handle(Base $event) + public function handle(Base $event): void { if (! $event instanceof ChannelLeft AND ! $event instanceof GroupLeft) abort(500,'Wrong class calling this listener? '.get_class($event)); diff --git a/src/Listeners/InteractiveMessageListener.php b/src/Listeners/InteractiveMessageListener.php index 0732788..9e385a5 100644 --- a/src/Listeners/InteractiveMessageListener.php +++ b/src/Listeners/InteractiveMessageListener.php @@ -19,7 +19,7 @@ class InteractiveMessageListener implements ShouldQueue * @param InteractiveMessage $event * @return void */ - public function handle(InteractiveMessage $event) + public function handle(InteractiveMessage $event): void { // Do some magic with event data Log::info(sprintf('%s:Interactive Message for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]); diff --git a/src/Listeners/MessageListener.php b/src/Listeners/MessageListener.php index b3e0d13..a9d62a9 100644 --- a/src/Listeners/MessageListener.php +++ b/src/Listeners/MessageListener.php @@ -19,7 +19,7 @@ class MessageListener implements ShouldQueue * @param Message $event * @return void */ - public function handle(Message $event) + public function handle(Message $event): void { // Do some magic with event data Log::info(sprintf('%s:Message event [%s] - subtype [%s]',self::LOGKEY,$event->ts,$event->type),['m'=>__METHOD__]); diff --git a/src/Listeners/PinAddedListener.php b/src/Listeners/PinAddedListener.php index 401a343..ead17f1 100644 --- a/src/Listeners/PinAddedListener.php +++ b/src/Listeners/PinAddedListener.php @@ -19,7 +19,7 @@ class PinAddedListener implements ShouldQueue * @param PinAdded $event * @return void */ - public function handle(PinAdded $event) + public function handle(PinAdded $event): void { // Do some magic with event data Log::info(sprintf('%s:Pin Added to message [%s] in [%s]',self::LOGKEY,$event->ts,$event->channel_id),['m'=>__METHOD__]); diff --git a/src/Listeners/PinRemovedListener.php b/src/Listeners/PinRemovedListener.php index 7c12227..e8bdd03 100644 --- a/src/Listeners/PinRemovedListener.php +++ b/src/Listeners/PinRemovedListener.php @@ -19,7 +19,7 @@ class PinRemovedListener implements ShouldQueue * @param PinRemoved $event * @return void */ - public function handle(PinRemoved $event) + public function handle(PinRemoved $event): void { // Do some magic with event data Log::info(sprintf('%s:Pin Removed from message [%s] in [%s]',self::LOGKEY,$event->ts,$event->channel_id),['m'=>__METHOD__]); diff --git a/src/Listeners/ReactionAddedListener.php b/src/Listeners/ReactionAddedListener.php index d7a0f1e..b1106fc 100644 --- a/src/Listeners/ReactionAddedListener.php +++ b/src/Listeners/ReactionAddedListener.php @@ -19,7 +19,7 @@ class ReactionAddedListener implements ShouldQueue * @param ReactionAdded $event * @return void */ - public function handle(ReactionAdded $event) + public function handle(ReactionAdded $event): void { // Do some magic with event data Log::info(sprintf('%s:Reaction [%s] added to message in [%s]',self::LOGKEY,$event->reaction,$event->team_id),['m'=>__METHOD__]); diff --git a/src/Listeners/ShortcutListener.php b/src/Listeners/ShortcutListener.php index 9bc844c..66ced06 100644 --- a/src/Listeners/ShortcutListener.php +++ b/src/Listeners/ShortcutListener.php @@ -2,6 +2,7 @@ namespace Slack\Listeners; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Log; use Slack\Blockkit\Blocks\Elements\Text; @@ -20,30 +21,24 @@ class ShortcutListener //implements ShouldQueue * Handle the event. * * @param Shortcut $event - * @return Message|null + * @return void * @throws \Exception * @todo To Test */ - public function handle(Shortcut $event): ?Message + public function handle(Shortcut $event): void { if (! $event->channel() || ! $event->channel()->active) { $modal = new Modal(Text::item(config('app.name'),'plain_text')); - $modal->addBlock( - Header::item(Text::item(':robot_face: Bot not in this channel','plain_text')) - ) - ->addBlock( - Section::item(Text::item('Please add the BOT to this channel and try this again.')) - ); + $modal->addBlock(Header::item(Text::item(':robot_face: Bot not in this channel','plain_text'))) + ->addBlock(Section::item(Text::item('Please add the BOT to this channel and try this again.'))); try { - $event->team()->slackAPI()->viewOpen($event->trigger_id,json_encode($modal)); + $event->team()->slackAPI()->viewOpen($event->trigger_id,$modal); } catch (\Exception $e) { Log::error(sprintf('%s:Got an error posting view to slack: %s',static::LOGKEY,$e->getMessage()),['m'=>__METHOD__]); } - - return (new Message)->blank(); } // Do some magic with event data diff --git a/src/Listeners/ViewClosedListener.php b/src/Listeners/ViewClosedListener.php index 1d84b8c..eb8e3f7 100644 --- a/src/Listeners/ViewClosedListener.php +++ b/src/Listeners/ViewClosedListener.php @@ -19,7 +19,7 @@ class ViewClosedListener implements ShouldQueue * @param ViewClosed $event * @return void */ - public function handle(ViewClosed $event) + public function handle(ViewClosed $event): void { // Do some magic with event data Log::info(sprintf('%s:Block Action for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]); diff --git a/src/Listeners/ViewSubmissionListener.php b/src/Listeners/ViewSubmissionListener.php index 8c2f4e2..a954bf2 100644 --- a/src/Listeners/ViewSubmissionListener.php +++ b/src/Listeners/ViewSubmissionListener.php @@ -19,7 +19,7 @@ class ViewSubmissionListener implements ShouldQueue * @param ViewSubmission $event * @return void */ - public function handle(ViewSubmission $event) + public function handle(ViewSubmission $event): void { // Do some magic with event data Log::info(sprintf('%s:View Submission for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]);