/**
* Gets all public mentions on Twitter
* @return void
*/
public function collectMentions()
{
$mentions = array_reverse($this->twitterContent->fetchMentions());
foreach ($mentions as $key => $mention) {
$date = changeDateFormat($mention['created_at']);
$inReplyTo = $mention['in_reply_to_status_id_str'];
$message = new Message();
if ($inReplyTo == null) {
$contact = $this->contact->createContact('twitter_mention', $mention);
$case = $this->case->createCase('twitter_mention', $mention, $contact);
}
if (($this->answer->where('tweet_id', $inReplyTo)->exists() || $this->message->where('tweet_id', $inReplyTo)->exists()) && $inReplyTo != null) {
$contact = $this->contact->createContact('twitter_mention', $mention);
$message->contact_id = $contact->id;
if ($this->answer->where('tweet_id', $inReplyTo)->exists()) {
$post = $this->answer->where('tweet_id', $inReplyTo)->first();
} else {
$post = $this->message->where('tweet_id', $inReplyTo)->first();
}
$message->case_id = $post->case_id;
$case = $this->case->find($post->case_id);
} else {
if ($inReplyTo != null && $this->publishment->where('tweet_id', $inReplyTo)->exists()) {
$this->fetchSpecificMention($mention);
continue;
} else {
if ($inReplyTo != null) {
$message->tweet_reply_id = $inReplyTo;
} else {
$message->case_id = $case->id;
}
}
}
$message->contact_id = $contact->id;
$message->tweet_id = $mention['id_str'];
$message->message = filterUrl($mention['text']);
$message->post_date = $date;
$message->save();
$this->media->handleMedia($message->id, $mention, 'twitter');
$this->updateCase($case->id, 'twitter', $mention['id_str']);
}
}