+ 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) {
+ try res.write(
+ \\<details>
+ \\<summary>Comments</summary>
+ , .{});
+ try res.write("<div style=\"margin: 10px;\">", .{});
+ var it = comments_view.iterator();
+ var count: u8 = 0;
+ while (it.next()) |kv| {
+ try write_post(res, txn, logged_in, kv.key, switch (recurse) {
+ .Yes => .Yes,
+ .Once => .No,
+ else => unreachable,
+ });
+ try res.write("<br />", .{});
+ if (recurse == .Once) {
+ count += 1;
+ if (count >= 3) break;
+ }
+ }
+ try res.write(
+ \\</div>
+ \\</details>
+ , .{});
+ }
+
+ try res.write(
+ \\</div>
+ , .{});
+}
+fn write_posts(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, user: User) !void {
+ const posts_view = try user.posts.open(txn);
+
+ var it = posts_view.reverse_iterator();