╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Comment.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
152 ) !void { 153 if (!fieldsValid(body)) return error.InvalidFields; 154 155 const thread_id_bytes = evt.parseEventId(thread_id) catch return error.NotFound; 156 if (!try evt.threadHolds(repo_kind, repo_opts, io, allocator, repo, thread_kind, &thread_id_bytes, .{ .comment = comment_id })) return error.NotFound; 157 158 var arena = std.heap.ArenaAllocator.init(allocator); 159 defer arena.deinit(); 160 161 const comment = blk: { 162 const DB = evt.EventDB(repo_opts.hash); 163 var event_db_maybe: ?evt.LocalEventDB(repo_opts.hash) = if (repo_kind == .git) try evt.LocalEventDB(repo_opts.hash).openReadOnly(io, allocator, repo.core.repo_dir) else null; 164 defer if (event_db_maybe) |*event_db| event_db.deinit(io, allocator); 165 const moment = (if (event_db_maybe) |*event_db| 166 evt.currentMomentFromDb(repo_opts.hash, event_db.db) 167 else if (repo_kind == .git) 168 return error.NotFound 169 else 170 evt.currentMoment(repo_opts, repo)) catch return error.NotFound; 171 break :blk (try readById(DB, repo_opts.hash, moment, &arena, comment_id)) orelse return error.NotFound; 172 }; 173 if (comment.removed) return error.NotFound; 174 175 var updated = comment.event; 176 updated.body = body; 177 try evt.consume(host, .repo, repo_kind, repo_opts, io, allocator, repo, evt.events_ref, &.{.{ 178 .id = std.fmt.bytesToHex(comment_id.*, .lower), 179 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 180 .author = author, 181 .event = .{ .comment = updated }, 182 }}); 183 } 184 185 // read a comment by event id, or null if the id isn't a known comment. field 186 // byte slices are allocated in `arena`. 187 pub fn readById( 188 comptime DB: type, 189 comptime hash_kind: hash.HashKind, 190 haxy_moment: DB.HashMap(.read_only), 191 arena: *std.heap.ArenaAllocator, 192 comment_id: []const u8, 193 ) !?Record { 194 const records_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, record_map_key)) orelse return null; 195 const records = try DB.HashMap(.read_only).init(records_cursor); 196 const record_cursor = try records.getCursor(hash.hashInt(hash_kind, comment_id)) orelse return null; 197 const record_map = try DB.HashMap(.read_only).init(record_cursor); 198 return try evt.read(Record, DB, hash_kind, arena, record_map); 199 } 200