From dd604133943893491868053482152aeab6ac5a57 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 8 Jun 2018 21:32:46 -0600 Subject: [PATCH] Add MentionPipeline --- app/Jobs/MentionPipeline/MentionPipeline.php | 72 ++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 app/Jobs/MentionPipeline/MentionPipeline.php diff --git a/app/Jobs/MentionPipeline/MentionPipeline.php b/app/Jobs/MentionPipeline/MentionPipeline.php new file mode 100644 index 000000000..69b7ebbb2 --- /dev/null +++ b/app/Jobs/MentionPipeline/MentionPipeline.php @@ -0,0 +1,72 @@ +status = $status; + $this->mention = $mention; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + + $status = $this->status; + $mention = $this->mention; + $actor = $this->status->profile; + $target = $this->mention->profile_id; + + $exists = Notification::whereProfileId($target) + ->whereActorId($actor->id) + ->whereAction('mention') + ->whereItemId($status->id) + ->whereItemType('App\Status') + ->count(); + + if($actor->id === $target || $exists !== 0) { + return true; + } + + try { + + $notification = new Notification; + $notification->profile_id = $target; + $notification->actor_id = $actor->id; + $notification->action = 'mention'; + $notification->message = $mention->toText(); + $notification->rendered = $mention->toHtml(); + $notification->item_id = $status->id; + $notification->item_type = "App\Status"; + $notification->save(); + + } catch (Exception $e) { + + } + + } +}