id: UserId,
name: Username,
display_name: DisplayName,
+ description: UserDescription,
password_hash: PasswordHash,
+
posts: PostList,
+
following: UserList,
followers: UserList,
const Timestamp = i64;
const Username = std.BoundedArray(u8, 32);
const DisplayName = std.BoundedArray(u8, 64);
+const UserDescription = std.BoundedArray(u8, 1024);
const PasswordHash = std.BoundedArray(u8, 128);
const SessionToken = u64;
const CookieValue = std.BoundedArray(u8, 128);
}
// https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding
-fn reencode(text: []const u8) !PostText {
- var result = try PostText.init(0);
+fn reencode(comptime T: type, text: []const u8) !T {
+ var result = try T.init(0);
const len = @min(text.len, 1024); // TODO: PostText length
.id = user_id,
.name = username_array,
.display_name = display_name,
+ .description = try UserDescription.init(0),
.password_hash = try hash_password(password),
.posts = try PostList.init(txn),
.following = try UserList.init(txn),
const posts = try Db.posts(txn);
post_id = try db.Prng.gen(posts.dbi, PostId);
- const decoded_text = try reencode(text);
+ const decoded_text = try reencode(PostText, text);
try posts.put(post_id, Post{
.id = post_id,
.parent_id = parent_id,
it.idx = try parse_enum(T.Base.Key, starting_at_str, 16);
}
- if (it.idx == null) {
- return error.InvalidIterator;
- }
-
return .{
.res = res,
.view = view,
.per_page = per_page,
.it = it,
- .starting_idx = it.idx.?,
+ .starting_idx = it.idx,
};
}
pub fn next(self: *Self) IterateResult {
, .{});
}
+ if (user.description.len > 0) {
+ try res.write(
+ \\<div style="padding-left: 5px; border-left: 1px solid grey;">
+ // \\« {s} »
+ \\<i>{s}</i>
+ \\</div>
+ , .{user.description.constSlice()});
+ }
+
try res.write("<br />", .{});
}
fn write_posts(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, post_list: PostList, options: struct {
.{ "type=\"text\" name=\"display_name\" placeholder=\"{s}\"", .{login.user.display_name.constSlice()} },
"type=\"submit\" value=\"Change\"",
});
+ try self.res.write("<br />Description: ", .{});
+ try html_form(self.res, "/set_description", .{
+ .{ "type=\"text\" name=\"description\" placeholder=\"{s}\"", .{login.user.description.constSlice()} },
+ "type=\"submit\" value=\"Change\"",
+ });
try self.res.write("<br />Password: ", .{});
try html_form(self.res, "/set_password", .{
"type=\"text\" name=\"password\"",
user.display_name = display_name;
try users.put(login.user.id, user);
}
+ pub fn @"/set_description"(self: Self, args: struct { description: []const u8 }) !void {
+ const login = self.logged_in orelse return error.NotLoggedIn;
+ const description = try reencode(UserDescription, args.description);
+
+ const txn = try self.env.txn();
+ defer txn.commit() catch {};
+
+ const users = try Db.users(txn);
+ var user = login.user;
+ user.description = description;
+ try users.put(login.user.id, user);
+ }
pub fn @"/set_password"(self: Self, args: struct { password: []const u8 }) !void {
const login = self.logged_in orelse return error.NotLoggedIn;
server.wait();
while (true) {
const req = (server.next_request(&req_buffer) catch break) orelse break;
- handle_request(env, req) catch {
- try handle_error(env, req);
- };
+ // handle_request(env, req) catch {
+ // try handle_error(env, req);
+ // };
+ try handle_request(env, req);
}
}
// const ThreadCount = 1;