+fn write_profile(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, user: User) !void {
+ const following = try user.following.open(txn);
+ const followers = try user.followers.open(txn);
+
+ try res.write(
+ \\<h2 style="display: inline;"><a href="/user/{s}">{s}</a></h2>
+ , .{
+ user.name.constSlice(), user.display_name.constSlice(),
+ });
+ if (logged_in != null and user.id != logged_in.?.user.id) {
+ const login = logged_in.?;
+
+ // follow/unfollow
+ if (try followers.has(login.user.id)) {
+ try html_form(res, "/follow", .{
+ .{ "type=\"hidden\" name=\"user.id\" value=\"{x}\"", .{@intFromEnum(user.id)} },
+ \\type="submit" value="Unfollow"
+ });
+ } else {
+ try html_form(res, "/follow", .{
+ .{ "type=\"hidden\" name=\"user.id\" value=\"{x}\"", .{@intFromEnum(user.id)} },
+ \\type="submit" value="Follow"
+ });
+ }
+
+ // add to feed
+ const feeds_view = try login.user.feeds.open(txn);
+ try res.write("<form action=\"/feed_add\" method=\"post\">", .{});
+ try res.write("<select name=\"feed_id\">", .{});
+ var it = feeds_view.iterator();
+ while (it.next()) |kv| {
+ const name = kv.val.name;
+ const id = kv.val.list.idx.?;
+ try res.write("<option value=\"{x}\">{s}</option>", .{ id, name.constSlice() });
+ }
+ try res.write("</select>", .{});
+ try res.write("<input type=\"hidden\" name=\"user.id\" value=\"{x}\"></input>", .{@intFromEnum(user.id)});
+ try res.write("<input type=\"submit\" value=\"Add to feed\"></input>", .{});
+ try res.write("</form>", .{});
+ }
+ try res.write(
+ \\ <a href="/following/{s}">{} following</a>
+ \\ <a href="/followers/{s}">{} followers</a>
+ \\<br />
+ , .{
+ user.name.constSlice(), following.len(),
+ user.name.constSlice(), followers.len(),
+ });
+
+ try res.write(
+ \\<a href="/all/{0s}">All Posts</a>
+ \\ <a href="/comments/{0s}">Comments</a>
+ \\ <a href="/quotes/{0s}">Quotes</a><br />
+ , .{
+ user.name.constSlice(),
+ });
+
+ if (logged_in != null and user.id == logged_in.?.user.id) {
+ try res.write(
+ \\<a href="/lists">Lists</a>
+ \\<a href="/feeds">Feeds</a>
+ \\<a href="/edit">Edit</a><br />
+ \\<br />
+ , .{});
+ }
+
+ try res.write("<br />", .{});
+}
+fn write_posts(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, post_list: PostList, options: struct {
+ show_posts: bool,
+ show_quotes: bool,
+ show_comments: bool,
+}) !void {