X-Git-Url: https://gitweb.ps.run/chirp/blobdiff_plain/12f0f2f8e72e933531b0ac6865265461d97e2312..d4496703a509fb5ad5352787ae277ebe204195c8:/src/main.zig
diff --git a/src/main.zig b/src/main.zig
index 74070d6..0b22dbb 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -31,7 +31,6 @@ const User = struct {
display_name: DisplayName,
password_hash: PasswordHash,
posts: PostList,
- replies: PostList,
following: UserList,
followers: UserList,
@@ -223,7 +222,6 @@ const Chirp = struct {
.display_name = display_name,
.password_hash = try hash_password(password),
.posts = try PostList.init(txn),
- .replies = try PostList.init(txn),
.following = try UserList.init(txn),
.followers = try UserList.init(txn),
.post_lists = try PostListList.init(txn),
@@ -328,11 +326,7 @@ const Chirp = struct {
txn.abort();
const post_id = try append_post(env, user_id, user.posts, null, null, text);
-
- txn = try env.txn();
- var replies_view = try user.replies.open(txn);
- try replies_view.append(post_id);
- try txn.commit();
+ _ = post_id;
}
fn comment(env: lmdb.Env, user_id: UserId, parent_post_id: PostId, text: []const u8) !void {
@@ -347,7 +341,7 @@ const Chirp = struct {
const post_id = try append_post(env, user_id, parent_post.comments, parent_post_id, null, text);
txn = try env.txn();
- var replies_view = try user.replies.open(txn);
+ var replies_view = try user.posts.open(txn);
try replies_view.append(post_id);
try txn.commit();
}
@@ -359,11 +353,7 @@ const Chirp = struct {
txn.abort();
const post_id = try append_post(env, user_id, user.posts, null, quote_post_id, text);
-
- txn = try env.txn();
- var replies_view = try user.replies.open(txn);
- try replies_view.append(post_id);
- try txn.commit();
+ _ = post_id;
}
fn vote(env: lmdb.Env, post_id: PostId, user_id: UserId, kind: Vote.Kind) !void {
@@ -521,17 +511,13 @@ fn write_header(res: *http.Response, logged_in: ?Login) !void {
\\
\\
\\
- \\
+ \\
\\
User not found [{}]
, .{err}); } } - pub fn @"/replies/"(self: Self, args: struct { username: []const u8 }) !void { + pub fn @"/comments/"(self: Self, args: struct { username: []const u8 }) !void { const user_ids = try Db.user_ids(self.txn); if (user_ids.get(try Username.fromSlice(args.username))) |user_id| { const users = try Db.users(self.txn); @@ -906,7 +911,49 @@ const GET = struct { try write_profile(self.res, self.txn, self.logged_in, user); - try write_posts(self.res, self.txn, self.logged_in, user.replies); + try write_posts(self.res, self.txn, self.logged_in, user.posts, .{ + .show_posts = false, + .show_quotes = false, + .show_comments = true, + }); + } else |err| { + try self.res.write( + \\User not found [{}]
+ , .{err}); + } + } + pub fn @"/quotes/"(self: Self, args: struct { username: []const u8 }) !void { + const user_ids = try Db.user_ids(self.txn); + if (user_ids.get(try Username.fromSlice(args.username))) |user_id| { + const users = try Db.users(self.txn); + const user = try users.get(user_id); + + try write_profile(self.res, self.txn, self.logged_in, user); + + try write_posts(self.res, self.txn, self.logged_in, user.posts, .{ + .show_posts = false, + .show_quotes = true, + .show_comments = false, + }); + } else |err| { + try self.res.write( + \\User not found [{}]
+ , .{err}); + } + } + pub fn @"/all/"(self: Self, args: struct { username: []const u8 }) !void { + const user_ids = try Db.user_ids(self.txn); + if (user_ids.get(try Username.fromSlice(args.username))) |user_id| { + const users = try Db.users(self.txn); + const user = try users.get(user_id); + + try write_profile(self.res, self.txn, self.logged_in, user); + + try write_posts(self.res, self.txn, self.logged_in, user.posts, .{ + .show_posts = true, + .show_quotes = true, + .show_comments = true, + }); } else |err| { try self.res.write( \\User not found [{}]
@@ -971,7 +1018,7 @@ const GET = struct { .show_comment_field = true, }); } - pub fn @"/quotes/"(self: Self, args: struct { post_id: PostId }) !void { + pub fn @"/quoted/"(self: Self, args: struct { post_id: PostId }) !void { const posts = try Db.posts(self.txn); const post = try posts.get(args.post_id); @@ -995,7 +1042,11 @@ const GET = struct { } } pub fn @"/list/"(self: Self, args: struct { list_id: PostList.Index }) !void { - try write_posts(self.res, self.txn, self.logged_in, PostList{ .idx = args.list_id }); + try write_posts(self.res, self.txn, self.logged_in, PostList{ .idx = args.list_id }, .{ + .show_posts = true, + .show_quotes = true, + .show_comments = true, + }); } pub fn @"/lists"(self: Self) !void { if (self.logged_in) |login| {