status = $status; $this->comment = $comment; $this->groupPost = $groupPost; } public function handle() { if ($this->status->group_id == null || $this->comment->group_id == null) { return; } $this->updateParentReplyCount(); $this->generateNotification(); if ($this->groupPost) { $this->updateChildReplyCount(); } } protected function updateParentReplyCount() { $parent = $this->status; $parent->reply_count = Status::whereInReplyToId($parent->id)->count(); $parent->save(); StatusService::del($parent->id); } protected function updateChildReplyCount() { $gp = $this->groupPost; if ($gp->reply_child_id) { $parent = GroupPost::whereStatusId($gp->reply_child_id)->first(); if ($parent) { $parent->reply_count++; $parent->save(); } } } protected function generateNotification() { $status = $this->status; $comment = $this->comment; $target = $status->profile; $actor = $comment->profile; if ($actor->id == $target->id || $status->comments_disabled == true) { return; } DB::transaction(function () use ($target, $actor, $comment) { $actorName = $actor->username; $actorUrl = $actor->url(); $text = "{$actorName} commented on your group post."; $html = "{$actorName} commented on your group post."; return NotificationService::createNotification($target->id, $actor->id, 'group:comment', $comment->id, Status::class); }); } }