Rubenwouters\CrmLauncher\Updates\UpdateAllCases::fetchInnerComments PHP Method

fetchInnerComments() private method

Fetch inner comments of facebook
private fetchInnerComments ( datetime $newest ) : void
$newest datetime
return void
    private function fetchInnerComments($newest)
    {
        $messages = $this->getComments();
        foreach ($messages as $key => $message) {
            $comments = $this->facebookContent->fetchInnerComments($newest, $message['fb_post_id']);
            if ($comments == null) {
                continue;
            }
            foreach ($comments->data as $key => $comment) {
                if ($comment->from->id != config('crm-launcher.facebook_credentials.facebook_page_id') && new Datetime(changeFbDateFormat($comment->created_time)) > new Datetime($newest)) {
                    if (!$this->contact->findByFbId($comment->from->id)->exists()) {
                        $contact = $this->contact->createContact('facebook', $comment);
                    } else {
                        $contact = $this->contact->where('facebook_id', $comment->from->id)->first();
                    }
                    $innerComment = new InnerComment();
                    $innerComment->fb_reply_id = $message['fb_post_id'];
                    $innerComment->post_date = changeFbDateFormat($comment->created_time);
                    $innerComment->contact_id = $contact->id;
                    if (is_a($message, "Rubenwouters\\CrmLauncher\\Models\\Answer")) {
                        $innerComment->answer_id = $message['id'];
                    } else {
                        if (is_a($message, "Rubenwouters\\CrmLauncher\\Models\\Reaction")) {
                            $innerComment->reaction_id = $message['id'];
                        } else {
                            $innerComment->message_id = $message['id'];
                        }
                    }
                    $innerComment->fb_post_id = $comment->id;
                    $innerComment->message = $comment->message;
                    $innerComment->save();
                    $this->media->handleMedia($innerComment->id, $comment, 'facebook_innerComment');
                }
            }
        }
    }