╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ notify.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
594 } 595 } 596 597 // a failure leaves the cursor, so the repo's next round redelivers 598 var failed = false; 599 for (inboxes.by_user.keys(), inboxes.by_user.values()) |*user_id, notifs| { 600 deliver(io, allocator, users_dir, user_id, notifs.items) catch |err| { 601 std.log.warn("failed to deliver notifications: {s}", .{@errorName(err)}); 602 failed = true; 603 }; 604 } 605 if (failed) return error.DeliveryFailed; 606 } 607 608 try writeLastNotified(io, &owner_repo, &location.repo_id, current); 609 } 610 611 fn readLastNotified(owner_repo: *rp.Repo(.xit, evt.user_repo_opts), repo_id: *const [evt.event_id_size]u8) !?u64 { 612 const map_cursor = try (try owner_repo.core.latestMoment()).getCursor(hash.hashInt(hash_kind, last_notified_map_key)) orelse return null; 613 const map = try UserDB.HashMap(.read_only).init(map_cursor); 614 const cursor = try map.getCursor(hash.hashInt(hash_kind, repo_id)) orelse return null; 615 return try cursor.readUint(); 616 } 617 618 fn writeLastNotified(io: std.Io, owner_repo: *rp.Repo(.xit, evt.user_repo_opts), repo_id: *const [evt.event_id_size]u8, moment_index: u64) !void { 619 const Ctx = struct { 620 repo_id: *const [evt.event_id_size]u8, 621 moment_index: u64, 622 623 pub fn run(ctx: @This(), cursor: *UserDB.Cursor(.read_write)) !void { 624 const moment = try UserDB.HashMap(.read_write).init(cursor.*); 625 const map = try UserDB.HashMap(.read_write).init(try moment.putCursor(hash.hashInt(hash_kind, last_notified_map_key))); 626 try map.put(hash.hashInt(hash_kind, ctx.repo_id), .{ .uint = ctx.moment_index }); 627 } 628 }; 629 630 try transactIn(io, owner_repo, Ctx{ .repo_id = repo_id, .moment_index = moment_index }); 631 } 632