some things

This commit is contained in:
Lera Elvoé 2025-05-19 09:12:59 +03:00
parent 5ec458702a
commit 85b1319c79
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
6 changed files with 20 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -1,7 +1,9 @@
<h1><%= thread.title %></h1>
<p>Posted under <a href="<%= url_for("topic", {slug = topic.slug}) %>"><%= topic.name %></a>
<% for _, post in ipairs(posts) do %>
<div>
<img src="<%= post.avatar_path or "/avatars/default.webp" %>">
<div><%= post.username %></div>
<img src="<%= post.avatar_path or "/avatars/default.webp" %>"><br>
<a href="<%= url_for("user", {username = post.username}) %>"><%= post.username %></a>
<div><p><%- post.content %></p></div>
</div>
<% end %>

View File

@ -2,6 +2,14 @@
<h2><%= topic.description %></h2>
<% if #threads_list == 0 then %>
<p>There are no threads in this topic.</p>
<% else %>
<ul>
<% for _, thread in ipairs(threads_list) do %>
<li>
<a href="<%= url_for("thread", {slug = thread.slug}) %>"><%= thread.title %></a><% if ntob(thread.is_stickied) then %> - pinned<% end %>
</li>
<% end %>
</ul>
<% end %>
<% if thread_create_error == ThreadCreateError.OK then %>

View File

@ -13,6 +13,6 @@
</form>
<form method="post" action="">
<label for="status">Status</label>
<input type="text" id="status" name="status" value="<%= user.status %>" maxlength="10"><br>
<input type="text" id="status" name="status" value="<%= user.status %>" maxlength="30"><br>
<input type="submit" value="Save">
</form>

View File

@ -7,6 +7,7 @@
<h2>You are a guest. An administrator needs to approve your account before you will be able to post.</h2>
<% end %>
<% if user_is_me then %>
<a href="<%= url_for("user_settings", {username = user.username}) %>">Settings</a>
<form method="post" action="<%= url_for("user_logout", {user_id = me.id}) %>">
<input type="submit" value="Log out">
</form>