/** * Fetch inner comments of facebook * @param datetime $newest * @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'); } } } }
/** * Check if contact exists, if not create a new user * @param string $type * @param string $id * @return collection */ public function getContact($type, $id) { if ($type == 'twitter' && Contact::where('twitter_id', $id)->exists()) { return Contact::findByTwitterId($id); } else { if ($type == 'facebook' && Contact::where('facebook_id', $id)->exists()) { return Contact::findByFbId($id); } } return new Contact(); }