add user page markup

This commit is contained in:
2025-05-20 17:05:45 +03:00
parent 3bd474d7fe
commit 2eddb70d63
7 changed files with 186 additions and 42 deletions

View File

@ -68,11 +68,23 @@ app:get("thread", "/:slug", function(self)
return {status = 404}
end
self.thread = thread
if self.params.after then
local after_id = tonumber(self.params.after)
local post_position = Posts:count(db.clause({
thread_id = thread.id,
{"id <= ?", after_id},
}))
self.page = math.floor((post_position - 1) / POSTS_PER_PAGE) + 1
else
self.page = tonumber(self.params.page) or 1
end
local post_count = Posts:count(db.clause({
thread_id = thread.id
}))
self.pages = math.ceil(post_count / POSTS_PER_PAGE)
self.page = tonumber(self.params.page) or 1
-- self.page = math.max(1, math.min(self.page, self.pages))
local posts = db.query([[
SELECT
posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path
@ -93,9 +105,9 @@ app:get("thread", "/:slug", function(self)
self.topic = Topics:find(thread.topic_id)
self.me = util.get_logged_in_user_or_transient(self)
self.posts = posts
self.page_title = thread.title
return {render = "threads.thread"}
end)

View File

@ -71,8 +71,7 @@ app:get("user", "/:username", function(self)
self.session.flash = {}
end
-- local me = validate_session(self.session.session_key) or TransientUser
local me = util.get_logged_in_user(self) or util.TransientUser
local me = util.get_logged_in_user_or_transient(self)
self.user = user
self.me = me
@ -84,7 +83,24 @@ app:get("user", "/:username", function(self)
end
end
self.page_title = user.username
self.latest_posts = db.query([[
SELECT
posts.id, posts.created_at, post_history.content, post_history.edited_at, threads.title AS thread_title, topics.name as topic_name, threads.slug as thread_slug
FROM
posts
JOIN
post_history ON posts.current_revision_id = post_history.id
JOIN
threads ON posts.thread_id = threads.id
JOIN
topics ON threads.topic_id = topics.id
WHERE
posts.user_id = ?
ORDER BY posts.created_at DESC
LIMIT 10
]], user.id)
self.page_title = user.username .. "'s profile"
return {render = "user.user"}
end)