╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ notify.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
118 // notify records 119 // 120 121 // muting a thread drops its notif 122 try notify.mute(io, allocator, users_dir, &recipient_id, location, &thread_b, author); 123 try std.testing.expectEqual(0, (try readRecent(io, allocator, &arena, users_dir, &recipient_id)).len); 124 125 // subscribing replaces the mute record and indexes the subscriber in the owner's repo 126 const id_b = notify.idOf(&location.repo_id, &thread_b); 127 try std.testing.expectEqual(.mute, try readMode(io, allocator, &arena, users_dir, &recipient_id, &location.repo_id, &thread_b)); 128 try notify.subscribe(io, allocator, users_dir, &recipient_id, location, &thread_b, author); 129 try std.testing.expectEqual(.subscribe, try readMode(io, allocator, &arena, users_dir, &recipient_id, &location.repo_id, &thread_b)); 130 try notify.deliver(io, allocator, users_dir, &recipient_id, &.{notif_b}); 131 try std.testing.expectEqual(1, (try readRecent(io, allocator, &arena, users_dir, &recipient_id)).len); 132 { 133 const subscribers = try readSubscribers(io, allocator, &arena, users_dir, &owner_id, &id_b); 134 try std.testing.expectEqual(1, subscribers.len); 135 try std.testing.expectEqualSlices(u8, &recipient_id, &subscribers[0]); 136 } 137 138 // muting drops the subscriber from the index 139 try notify.mute(io, allocator, users_dir, &recipient_id, location, &thread_b, author); 140 try std.testing.expectEqual(0, (try readSubscribers(io, allocator, &arena, users_dir, &owner_id, &id_b)).len); 141 142 // past the cap, the oldest go. times tie within a second, so which one goes isn't checked. 143 { 144 const many = try allocator.alloc(notify.Notif, notify.max_notifs + 1); 145 defer allocator.free(many); 146 for (many, 0..) |*notif, i| { 147 notif.* = notif_a; 148 notif.thread_id = @splat(0); 149 std.mem.writeInt(u64, notif.thread_id[0..@sizeOf(u64)], i, .big); 150 } 151 try notify.deliver(io, allocator, users_dir, &recipient_id, many); 152 } 153 try std.testing.expectEqual(notify.max_notifs, (try readRecent(io, allocator, &arena, users_dir, &recipient_id)).len); 154 } 155