╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Comment.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
171 else 172 evt.currentMoment(repo_opts, repo)) catch return error.NotFound; 173 break :blk (try readById(DB, repo_opts.hash, moment, &arena, comment_id)) orelse return error.NotFound; 174 }; 175 if (comment.removed) return error.NotFound; 176 177 var updated = comment.event; 178 updated.body = body; 179 try evt.consume(host, .repo, repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{.{ 180 .id = std.fmt.bytesToHex(comment_id.*, .lower), 181 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 182 .author = author, 183 .event = .{ .comment = updated }, 184 }}); 185 } 186 187 // read a comment by event id, or null if the id isn't a known comment. field 188 // byte slices are allocated in `arena`. 189 pub fn readById( 190 comptime DB: type, 191 comptime hash_kind: hash.HashKind, 192 haxy_moment: DB.HashMap(.read_only), 193 arena: *std.heap.ArenaAllocator, 194 comment_id: []const u8, 195 ) !?Record { 196 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 197 const records = try DB.HashMap(.read_only).init(records_cursor); 198 const record_cursor = try records.getCursor(hash.hashInt(hash_kind, comment_id)) orelse return null; 199 const record_map = try DB.HashMap(.read_only).init(record_cursor); 200 return try evt.read(Record, DB, hash_kind, arena, record_map); 201 } 202