╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
240 // the user doesn't exist. field byte slices are allocated in `arena`. 241 pub fn readByName( 242 io: std.Io, 243 allocator: std.mem.Allocator, 244 admin_repo_path: []const u8, 245 arena: *std.heap.ArenaAllocator, 246 name: []const u8, 247 ) !?Record { 248 var repo = rp.Repo(.xit, evt.admin_repo_opts).open(io, allocator, .{ .path = admin_repo_path }) catch |err| switch (err) { 249 error.RepoNotFound => return null, 250 else => |e| return e, 251 }; 252 defer repo.deinit(io, allocator); 253 254 const moment = try evt.currentMoment(evt.admin_repo_opts, &repo); 255 256 const name_to_user_id_cursor = try moment.getCursor(hash.hashInt(evt.admin_repo_opts.hash, "name->user-id")) orelse return null; 257 const name_to_user_id = try evt.AdminDB.HashMap(.read_only).init(name_to_user_id_cursor); 258 const user_id_cursor = try name_to_user_id.getCursor(hash.hashInt(evt.admin_repo_opts.hash, name)) orelse return null; 259 var user_id: [evt.event_id_size]u8 = undefined; 260 _ = try user_id_cursor.readBytes(&user_id); 261 262 return try readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, &user_id); 263 } 264 265 // flip a user's ANSI-art preference by re-emitting their User event with 266 // enable_ansi negated. a no-op for an unknown user. `repo` must be writable. 267 pub fn toggleAnsi( 268 comptime repo_opts: rp.RepoOpts(.xit), 269 io: std.Io, 270 allocator: std.mem.Allocator, 271 repo: *rp.Repo(.xit, repo_opts), 272 user_id: []const u8, 273 ) !void { 274 const DB = rp.Repo(.xit, repo_opts).DB; 275 var arena = std.heap.ArenaAllocator.init(allocator); 276 defer arena.deinit(); 277 278 const moment = try evt.currentMoment(repo_opts, repo); 279 const user = (try readById(DB, repo_opts.hash, moment, &arena, user_id)) orelse return; 280 281 var updated = user.event; 282 updated.enable_ansi = !updated.enable_ansi; 283 try evt.consume(.xit, repo_opts, io, allocator, repo, evt.events_ref, &[_]evt.EventWithId{.{ 284 .id = std.fmt.bytesToHex(user_id[0..evt.event_id_size].*, .lower), 285 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 286 .author_email = user.event.email, 287 .event = .{ .user = updated }, 288 }}); 289 } 290