+ const post = posts.get(post_id) catch {
+ res.redirect("/") catch {};
+ return;
+ };
+ const users = try Db.users(txn);
+ const user = try users.get(post.user_id);
+
+ try res.write(
+ \\<div>
+ \\<span><a href="/user/{s}">{s}</a> {s}</span><br />
+ \\<span>{s}</span><br />
+ , .{ user.name.constSlice(), user.display_name.constSlice(), time_str(post.time).constSlice(), post.text.constSlice() });
+
+ if (recurse != .No and post.quote_id != null) {
+ try res.write("<div style=\"border: 1px solid black;\">", .{});
+ try write_post(res, txn, logged_in, post.quote_id.?, .No);
+ try res.write("</div>", .{});
+ }
+
+ const comments_view = try post.comments.open(txn);
+ const quotes_view = try post.quotes.open(txn);
+ const votes_view = try post.votes.open(txn);
+
+ // Votes
+ const vote: ?Vote = if (logged_in != null and try votes_view.has(logged_in.?.user.id)) try votes_view.get(logged_in.?.user.id) else null;
+
+ if (vote != null and vote.?.kind == .Up) {
+ try html_form(res, "/upvote", .{}, .{
+ .{ "type=\"hidden\" value=\"{x}\" name=\"post_id\"", .{@intFromEnum(post.id)} },
+ .{ "type=\"submit\" value=\"⬆ {}\"", .{post.upvotes} },
+ });
+ } else {
+ try html_form(res, "/upvote", .{}, .{
+ .{ "type=\"hidden\" value=\"{x}\" name=\"post_id\"", .{@intFromEnum(post.id)} },
+ .{ "type=\"submit\" value=\"⇧ {}\"", .{post.upvotes} },
+ });
+ }
+ if (vote != null and vote.?.kind == .Down) {
+ try html_form(res, "/downvote", .{}, .{
+ .{ "type=\"hidden\" value=\"{x}\" name=\"post_id\"", .{@intFromEnum(post.id)} },
+ .{ "type=\"submit\" value=\"⬇ {}\"", .{post.downvotes} },
+ });
+ } else {
+ try html_form(res, "/downvote", .{}, .{
+ .{ "type=\"hidden\" value=\"{x}\" name=\"post_id\"", .{@intFromEnum(post.id)} },
+ .{ "type=\"submit\" value=\"⇩ {}\"", .{post.downvotes} },
+ });
+ }
+
+ // Comment Count
+ try res.write(
+ \\<span class="toggle">
+ \\<a href="/post/{x}">💭 {}</a>
+ , .{ @intFromEnum(post.id), comments_view.len() });
+ if (logged_in != null) {
+ try html_form(res, "/comment", .{}, .{
+ .{ "type=\"hidden\" value=\"{x}\" name=\"post_id\"", .{@intFromEnum(post.id)} },
+ "type=\"text\" name=\"text\" placeholder=\"Text\"",
+ "type=\"submit\" value=\"Comment\"",
+ });
+ }
+ try res.write(
+ \\</span>
+ , .{});
+
+ // Quote
+ try res.write(
+ \\<span class="toggle">
+ \\<a href="/quotes/{x}">🔁 {}</a>
+ , .{ @intFromEnum(post.id), quotes_view.len() });
+ try html_form(res, "/quote", .{}, .{
+ .{ "type=\"hidden\" value=\"{x}\" name=\"post_id\"", .{@intFromEnum(post.id)} },
+ "type=\"text\" name=\"text\" placeholder=\"Text\"",
+ "type=\"submit\" value=\"Quote\"",
+ });
+ try res.write(
+ \\</span>
+ \\<br />
+ , .{});
+
+ // Comments
+ if (recurse != .No and comments_view.len() > 0) {