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