add user signatures

This commit is contained in:
Lera Elvoé 2025-05-24 17:28:07 +03:00
parent fbe582ccbc
commit ccb2819b01
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
10 changed files with 46 additions and 7 deletions

View File

@ -1,6 +1,8 @@
local lapis = require("lapis") local lapis = require("lapis")
local app = lapis.Application() local app = lapis.Application()
local constants = require("constants") local constants = require("constants")
local babycode = require("lib.babycode")
local html_escape = require("lapis.html").escape
local db = require("lapis.db") local db = require("lapis.db")
-- sqlite starts without foreign key enforcement -- sqlite starts without foreign key enforcement
@ -27,6 +29,10 @@ local function inject_methods(req)
return util.infobox_message(s) return util.infobox_message(s)
end end
req.babycode_to_html = function (_, bb)
return babycode.to_html(bb, html_escape)
end
util.pop_infobox(req) util.pop_infobox(req)
end end

View File

@ -1,4 +1,6 @@
local app = require("lapis").Application() local app = require("lapis").Application()
local babycode = require("lib.babycode")
local html_escape = require("lapis.html").escape
local db = require("lapis.db") local db = require("lapis.db")
local constants = require("constants") local constants = require("constants")
@ -225,11 +227,15 @@ app:post("user_settings", "/:username/settings", function(self)
end end
local status = self.params.status:sub(1, 100) local status = self.params.status:sub(1, 100)
local original_sig = self.params.signature or ""
local rendered_sig = babycode.to_html(original_sig, html_escape)
target_user:update({ target_user:update({
status = status, status = status,
signature_original_markup = original_sig,
signature_rendered = rendered_sig,
}) })
util.inject_infobox(self, "Status updated.") util.inject_infobox(self, "Settings updated.")
return {redirect_to = self:url_for("user_settings", {username = self.params.username})} return {redirect_to = self:url_for("user_settings", {username = self.params.username})}
end) end)

View File

@ -10,7 +10,7 @@ Constants.PermissionLevel = {
Constants.FULL_POSTS_QUERY = [[ Constants.FULL_POSTS_QUERY = [[
SELECT SELECT
posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup, users.signature_rendered
FROM FROM
posts posts
JOIN JOIN

View File

@ -107,6 +107,12 @@ body {
grid-area: post-content; grid-area: post-content;
padding: 20px; padding: 20px;
margin-right: 25%; margin-right: 25%;
display: flex;
flex-direction: column;
}
.post-inner {
height: 100%;
} }
pre code { pre code {

View File

@ -68,4 +68,9 @@ return {
schema.add_column("post_history", "original_markup", types.text{null = false}) schema.add_column("post_history", "original_markup", types.text{null = false})
schema.add_column("post_history", "markup_language", types.text{default = "babycode"}) schema.add_column("post_history", "markup_language", types.text{default = "babycode"})
end, end,
[10] = function ()
schema.add_column("users", "signature_original_markup", types.text{default = ""})
schema.add_column("users", "signature_rendered", types.text{default = ""})
end,
} }

View File

@ -143,6 +143,12 @@ body {
grid-area: post-content; grid-area: post-content;
padding: 20px; padding: 20px;
margin-right: 25%; margin-right: 25%;
display: flex;
flex-direction: column;
}
.post-inner {
height: 100%;
} }
pre code { pre code {

View File

@ -4,5 +4,5 @@
<button type=button id="post-editor-strike" title="Insert Strikethrough">S</button> <button type=button id="post-editor-strike" title="Insert Strikethrough">S</button>
<button type=button id="post-editor-code" title="Insert Code block">Code</button> <button type=button id="post-editor-code" title="Insert Code block">Code</button>
</span> </span>
<textarea class="babycode-editor" name="<%= ta_name %>" id="post_content" placeholder="Post body" required><%- prefill or "" %></textarea> <textarea class="babycode-editor" name="<%= ta_name %>" id="<%= ta_id or "post_content" %>" placeholder="<%= ta_placeholder or "Post body"%>" <%= not optional and "required" or "" %>><%- prefill or "" %></textarea>
<script src="/static/js/post-editor.js"></script> <script src="/static/js/post-editor.js"></script>

View File

@ -58,7 +58,15 @@
</div> </div>
<div class="post-content"> <div class="post-content">
<% if not edit then %> <% if not edit then %>
<div class="post-inner">
<%- post.content %> <%- post.content %>
</div>
<% if render_sig and #post.signature_rendered > 0 then %>
<div class="signature-container">
<hr>
<%- post.signature_rendered %>
</div>
<% end %>
<% else %> <% else %>
<% render("views.common.babycode-editor", { <% render("views.common.babycode-editor", {
cancel_url = post_url, cancel_url = post_url,

View File

@ -8,7 +8,7 @@
<span>Posted in <a href="<%= url_for("topic", {slug = topic.slug}) %>"><%= topic.name %></a></span> <span>Posted in <a href="<%= url_for("topic", {slug = topic.slug}) %>"><%= topic.name %></a></span>
</nav> </nav>
<% for i, post in ipairs(posts) do %> <% for i, post in ipairs(posts) do %>
<% render("views.threads.post", {post = post, is_latest = i == #posts}) %> <% render("views.threads.post", {post = post, render_sig = true, is_latest = i == #posts}) %>
<% end %> <% end %>
</main> </main>

View File

@ -8,7 +8,7 @@
<img src="<%= avatar_url(me) %>"> <img src="<%= avatar_url(me) %>">
<input id="file" type="file" name="avatar" accept="image/*" required> <input id="file" type="file" name="avatar" accept="image/*" required>
<div> <div>
<input type="submit" value="Update avatar" <%= disable_avatar and "disabled=disabled" %>> <input type="submit" value="Upload avatar" <%= disable_avatar and "disabled=disabled" %>>
<% if not me:is_default_avatar() then %> <% if not me:is_default_avatar() then %>
<input type="submit" value="Clear avatar" formaction="<%= url_for("user_clear_avatar", {username = me.username}) %>" formnovalidate> <input type="submit" value="Clear avatar" formaction="<%= url_for("user_clear_avatar", {username = me.username}) %>" formnovalidate>
<% end %> <% end %>
@ -16,8 +16,10 @@
</form> </form>
<form method="post" action=""> <form method="post" action="">
<label for="status">Status</label> <label for="status">Status</label>
<input type="text" id="status" name="status" value="<%= me.status %>" maxlength="30"> <input type="text" id="status" name="status" value="<%= me.status %>" maxlength="70" placeholder="Will be shown under your username. Max 70 characters">
<input type="submit" value="Save status"> <label for="signature">Signature</label><br>
<% render("views.common.babycode-editor-component", {ta_name = "signature", ta_id = "signature", prefill = me.signature_original_markup, ta_placeholder = "Will be shown under each of your posts", optional = true}) %>
<input type="submit" value="Save settings">
</form> </form>
<div> <div>
<a class="linkbutton critical" href="<%= url_for("user_delete_confirm", {username = me.username}) %>">Delete account</a> <a class="linkbutton critical" href="<%= url_for("user_delete_confirm", {username = me.username}) %>">Delete account</a>