diff --git a/apps/threads.lua b/apps/threads.lua index 6aa84be..dca112a 100644 --- a/apps/threads.lua +++ b/apps/threads.lua @@ -64,6 +64,10 @@ app:get("thread", "/:slug", function(self) return {status = 404} end self.thread = thread + local post_count = Posts:count(db.clause({ + thread_id = thread.id + })) + local pages = math.floor(post_count / 20) local posts = db.query([[ SELECT posts.id, post_history.content, users.username, avatars.file_path AS avatar_path @@ -81,6 +85,7 @@ app:get("thread", "/:slug", function(self) posts.created_at ASC LIMIT 20 ]], thread.id, tonumber(self.params.cursor or 0)) + self.topic = Topics:find(thread.topic_id) self.user = util.get_logged_in_user_or_transient(self) self.posts = posts self.next_cursor = #posts > 0 and posts[#posts].id or nil diff --git a/apps/topics.lua b/apps/topics.lua index b093749..12f6332 100644 --- a/apps/topics.lua +++ b/apps/topics.lua @@ -62,9 +62,7 @@ app:get("topic", "/:slug", function(self) return {status = 404} end self.topic = topic - self.threads_list = Threads:select(db.clause({ - topic_id = topic.id - })) + self.threads_list = db.query("SELECT * FROM threads WHERE topic_id = ? ORDER BY is_stickied DESC, created_at DESC", topic.id) local user = util.get_logged_in_user_or_transient(self) print(topic.is_locked, type(topic.is_locked)) self.user = user diff --git a/views/threads/thread.etlua b/views/threads/thread.etlua index 4e56839..72acfc3 100644 --- a/views/threads/thread.etlua +++ b/views/threads/thread.etlua @@ -1,7 +1,9 @@ +
Posted under "><%= topic.name %> <% for _, post in ipairs(posts) do %>
<% end %> diff --git a/views/topics/topic.etlua b/views/topics/topic.etlua index 553dbcd..68fb769 100644 --- a/views/topics/topic.etlua +++ b/views/topics/topic.etlua @@ -2,6 +2,14 @@There are no threads in this topic.
+<% else %> +