sort threads in topic by activity by default (bump) and add setting
This commit is contained in:
@ -94,11 +94,15 @@ app:get("topic", "/:slug", function(self)
|
||||
topic_id = topic.id
|
||||
}))
|
||||
self.topic = topic
|
||||
|
||||
self.pages = math.max(math.ceil(threads_count / THREADS_PER_PAGE), 1)
|
||||
self.page = math.max(1, math.min(tonumber(self.params.page) or 1, self.pages))
|
||||
-- self.threads_list = db.query("SELECT * FROM threads WHERE topic_id = ? ORDER BY is_stickied DESC, created_at DESC", topic.id)
|
||||
self.threads_list = db.query([[
|
||||
local sort_by = self.session.sort_by or "activity"
|
||||
local order_clause = ""
|
||||
if sort_by == "thread" then
|
||||
order_clause = "ORDER BY threads.is_stickied DESC, threads.created_at DESC"
|
||||
else
|
||||
order_clause = "ORDER BY threads.is_stickied DESC, latest_post_created_at DESC"
|
||||
end
|
||||
|
||||
local query = [[
|
||||
SELECT
|
||||
threads.title, threads.slug, threads.created_at, threads.is_locked, threads.is_stickied,
|
||||
users.username AS started_by,
|
||||
@ -126,11 +130,11 @@ app:get("topic", "/:slug", function(self)
|
||||
users u ON u.id = posts.user_id
|
||||
WHERE
|
||||
threads.topic_id = ?
|
||||
ORDER BY
|
||||
threads.is_stickied DESC,
|
||||
threads.created_at DESC
|
||||
LIMIT ? OFFSET ?
|
||||
]], topic.id, THREADS_PER_PAGE, (self.page - 1) * THREADS_PER_PAGE)
|
||||
]] .. order_clause .. " LIMIT ? OFFSET ?"
|
||||
|
||||
self.pages = math.max(math.ceil(threads_count / THREADS_PER_PAGE), 1)
|
||||
self.page = math.max(1, math.min(tonumber(self.params.page) or 1, self.pages))
|
||||
self.threads_list = db.query(query, topic.id, THREADS_PER_PAGE, (self.page - 1) * THREADS_PER_PAGE)
|
||||
|
||||
local user = util.get_logged_in_user_or_transient(self)
|
||||
self.me = user
|
||||
|
Reference in New Issue
Block a user