/** * Renders a thread. * * @param Board $board * @param integer|null $thread * @return Response */ public function getThread(Board $board, $thread_id = null) { if (is_null($thread_id)) { return redirect($board->board_uri); } // Pull the thread. $thread = $board->getThreadByBoardId($thread_id); if (!$thread) { return abort(404); } return $this->view(static::VIEW_THREAD, ['board' => &$board, 'posts' => [$thread], 'reply_to' => $thread]); }
/** * Returns a thread and its replies to the client. * * @var Board $board * @var integer|null $thread * @return Response */ public function getThread(Request $request, Board $board, $thread) { if (is_null($thread)) { return abort(404); } $input = $request->only('updatesOnly', 'updateHtml', 'updatedSince'); if (isset($input['updatesOnly'])) { $updatedSince = Carbon::createFromTimestamp($request->input('updatedSince', 0)); $posts = Post::where('posts.board_uri', $board->board_uri)->withEverything()->where(function ($query) use($thread) { $query->where('posts.reply_to_board_id', $thread); $query->orWhere('posts.board_id', $thread); })->where(function ($query) use($updatedSince) { $query->where('posts.updated_at', '>=', $updatedSince); $query->orWhere('posts.deleted_at', '>=', $updatedSince); })->withTrashed()->orderBy('posts.created_at', 'asc')->get(); if (isset($input['updateHtml'])) { foreach ($posts as $post) { $appends = $post->getAppends(); $appends[] = "html"; $post->setAppends($appends); } } return $posts; } else { // Pull the thread. $thread = $board->getThreadByBoardId($thread); if (!$thread) { return abort(404); } } return $thread; }