X-Git-Url: https://gitweb.ps.run/chirp/blobdiff_plain/e439c64e7489a392a0debce2dbf4a87ee05e367c..6a5bd646d03ad9796f00b639881c3b3e25ee35f2:/src/main.zig diff --git a/src/main.zig b/src/main.zig index 2ccb16b..2f7fd4c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -447,20 +447,20 @@ pub fn Paginate(comptime T: type) type { return struct { const Self = @This(); - const IterateResult = @typeInfo(@TypeOf(T.View.Iterator.next)).Fn.return_type.?; + const IterateResult = T.Base.View.Iterator.Result; res: *http.Response, view: T.View, per_page: u64, - it: T.View.Iterator, - starting_idx: ?T.Key, + it: T.Base.View.Iterator, + starting_idx: ?T.Base.Key, count: u64 = 0, pub fn init(res: *http.Response, view: T.View, per_page: u64) !Self { var it = view.reverse_iterator(); if (res.req.get_param("starting_at")) |starting_at_str| { - it.idx = try parse_enum(T.Key, starting_at_str, 16); + it.idx = try parse_enum(T.Base.Key, starting_at_str, 16); } if (it.idx == null) { @@ -487,7 +487,7 @@ pub fn Paginate(comptime T: type) type { pub fn write_navigation(self: *Self) !void { const next_idx = self.it.next(); - if (self.view.head.last != self.starting_idx) { + if (self.view.base.head.last != self.starting_idx) { var prev_it = self.view.iterator(); prev_it.idx = self.starting_idx.?; var oldest_idx = self.starting_idx.?; @@ -702,7 +702,7 @@ fn write_post(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, post_id: Po // TODO: mark lists that already contain post while (it.next()) |kv| { const name = kv.val.name; - const id = kv.val.list.idx.?; + const id = kv.val.list.base.idx.?; const list_view = try kv.val.list.open(txn); try res.write("", .{ id, name.constSlice(), if (list_view.has(post_id) catch false) " *" else "" }); } @@ -783,7 +783,7 @@ fn write_profile(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, user: Us var it = feeds_view.iterator(); while (it.next()) |kv| { const name = kv.val.name; - const id = kv.val.list.idx.?; + const id = kv.val.list.base.idx.?; const list_view = try kv.val.list.open(txn); try res.write("", .{ id, name.constSlice(), if (list_view.has(user.id) catch false) " *" else "" }); } @@ -1170,8 +1170,8 @@ const GET = struct { .show_comments = false, }); } - 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 }, .{ + pub fn @"/list/"(self: Self, args: struct { list_id: PostList.Base.Index }) !void { + try write_posts(self.res, self.txn, self.logged_in, PostList{ .base = .{ .idx = args.list_id } }, .{ .show_posts = true, .show_quotes = true, .show_comments = true, @@ -1194,7 +1194,7 @@ const GET = struct { const post_list = kv.val.list; try self.res.write( \\{s} - , .{ post_list.idx.?, name.constSlice() }); + , .{ post_list.base.idx.?, name.constSlice() }); try html_form(self.res, "/delete_list", .{ .{ "type=\"hidden\" name=\"list_id\" value=\"{x}\"", .{kv.key} }, "type=\"submit\" value=\"Delete\"", @@ -1205,8 +1205,8 @@ const GET = struct { try self.res.write("not logged in", .{}); } } - pub fn @"/feed/"(self: Self, args: struct { feed_id: UserList.Index }) !void { - try write_timeline(self.res, self.txn, self.logged_in, UserList{ .idx = args.feed_id }); + pub fn @"/feed/"(self: Self, args: struct { feed_id: UserList.Base.Index }) !void { + try write_timeline(self.res, self.txn, self.logged_in, UserList{ .base = .{ .idx = args.feed_id } }); } pub fn @"/feeds"(self: Self) !void { if (self.logged_in) |login| { @@ -1225,7 +1225,7 @@ const GET = struct { const user_list = kv.val.list; try self.res.write( \\{s} - , .{ user_list.idx.?, name.constSlice() }); + , .{ user_list.base.idx.?, name.constSlice() }); try html_form(self.res, "/delete_feed", .{ .{ "type=\"hidden\" name=\"list_id\" value=\"{x}\"", .{kv.key} }, "type=\"submit\" value=\"Delete\"", @@ -1451,7 +1451,7 @@ const POST = struct { try txn.commit(); } } - pub fn @"/delete_list"(self: Self, args: struct { list_id: PostList.Index }) !void { + pub fn @"/delete_list"(self: Self, args: struct { list_id: PostList.Base.Index }) !void { if (self.logged_in) |login| { var post_list: ?PostList = null; { @@ -1469,14 +1469,14 @@ const POST = struct { } } } - pub fn @"/list_add"(self: Self, args: struct { list_id: PostList.Index, post_id: PostId }) !void { + pub fn @"/list_add"(self: Self, args: struct { list_id: PostList.Base.Index, post_id: PostId }) !void { if (self.logged_in) |login| { _ = login; const txn = try self.env.txn(); defer txn.commit() catch {}; - const post_list = PostList{ .idx = args.list_id }; + const post_list = PostList{ .base = .{ .idx = args.list_id } }; var post_list_view = try post_list.open(txn); if (try post_list_view.has(args.post_id)) { try post_list_view.del(args.post_id); @@ -1500,7 +1500,7 @@ const POST = struct { try txn.commit(); } } - pub fn @"/delete_feed"(self: Self, args: struct { list_id: UserList.Index }) !void { + pub fn @"/delete_feed"(self: Self, args: struct { list_id: UserList.Base.Index }) !void { if (self.logged_in) |login| { var user_list: ?UserList = null; @@ -1519,14 +1519,14 @@ const POST = struct { } } } - pub fn @"/feed_add"(self: Self, args: struct { feed_id: UserList.Index, user_id: UserId }) !void { + pub fn @"/feed_add"(self: Self, args: struct { feed_id: UserList.Base.Index, user_id: UserId }) !void { if (self.logged_in) |login| { _ = login; const txn = try self.env.txn(); defer txn.commit() catch {}; - const user_list = UserList{ .idx = args.feed_id }; + const user_list = UserList{ .base = .{ .idx = args.feed_id } }; var user_list_view = try user_list.open(txn); if (try user_list_view.has(args.user_id)) { try user_list_view.del(args.user_id);