private function setMessengerModels() { $config = $this->app->make('config'); Models::setMessageModel($config->get('messenger.message_model', Message::class)); Models::setThreadModel($config->get('messenger.thread_model', Thread::class)); Models::setParticipantModel($config->get('messenger.participant_model', Participant::class)); Models::setTables(['messages' => $config->get('messenger.messages_table', Models::message()->getTable()), 'participants' => $config->get('messenger.participants_table', Models::participant()->getTable()), 'threads' => $config->get('messenger.threads_table', Models::thread()->getTable())]); }
/** * Returns all threads with new messages. * * @return array */ public function threadsWithNewMessages() { $threadsWithNewMessages = []; $participants = Models::participant()->where('user_id', $this->id)->lists('last_read', 'thread_id'); /** * @todo: see if we can fix this more in the future. * Illuminate\Foundation is not available through composer, only in laravel/framework which * I don't want to include as a dependency for this package...it's overkill. So let's * exclude this check in the testing environment. */ if (getenv('APP_ENV') == 'testing' || !str_contains(\Illuminate\Foundation\Application::VERSION, '5.0')) { $participants = $participants->all(); } if ($participants) { $threads = Models::thread()->whereIn('id', array_keys($participants))->get(); foreach ($threads as $thread) { if ($thread->updated_at > $participants[$thread->id]) { $threadsWithNewMessages[] = $thread->id; } } } return $threadsWithNewMessages; }