+fn write_frontpage(res: *http.Response, txn: lmdb.Txn) !void {
+ const posts = try Db.posts.open(txn);
+ var counter: u64 = 0;
+ var it = try posts.reverse_iterator();
+ while (it.next()) |p| {
+ if (p.val.parent_id == null and p.val.quote_id == null) {
+ try write_post(res, txn, null, p.key, .{ .recurse = 1 });
+ counter += 1;
+ }
+
+ if (counter >= 10) break;
+ }
+}
+fn write_user(res: *http.Response, txn: lmdb.Txn, user_id: UserId) !void {
+ const users = try Db.users.open(txn);
+ const user = try users.get(user_id);
+ try res.write(
+ \\<a href="/user/{s}">{s}</a>
+ , .{ user.name.constSlice(), user.display_name.constSlice() });
+}
+fn write_votes(res: *http.Response, txn: lmdb.Txn, votes: VoteList, options: struct {
+ show_upvotes: bool = true,
+ show_downvotes: bool = true,
+}) !void {
+ const votes_view = try votes.open(txn);
+
+ var paginate = try Paginate(VoteList).init(res, votes_view, Chirp.UsersPerPage);
+
+ while (paginate.next()) |kv| {
+ const user_id = kv.key;
+ const vote = kv.val;
+
+ if ((options.show_upvotes and vote.kind == .Up) or
+ (options.show_downvotes and vote.kind == .Down))
+ {
+ try write_user(res, txn, user_id);
+ try res.write(" <small>{s}</small><br />", .{time_str(vote.time).constSlice()});
+ }
+ }
+
+ try paginate.write_navigation();
+}