╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ notify.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
126 127 // subscribing replaces the mute record and indexes the subscriber in the owner's repo 128 const id_b = notify.idOf(&location.repo_id, &thread_b); 129 try std.testing.expectEqual(.muted, try readMode(io, allocator, &arena, users_dir, &recipient_id, &location.repo_id, &thread_b)); 130 try notify.subscribe(io, allocator, users_dir, &recipient_id, location, &thread_b, author); 131 try std.testing.expectEqual(.subscribed, try readMode(io, allocator, &arena, users_dir, &recipient_id, &location.repo_id, &thread_b)); 132 try notify.deliver(io, allocator, users_dir, &recipient_id, &.{notif_b}); 133 try std.testing.expectEqual(1, (try readRecent(io, allocator, &arena, users_dir, &recipient_id)).len); 134 { 135 const notified = try readNotified(io, allocator, &arena, users_dir, &owner_id, &id_b); 136 try std.testing.expectEqual(1, notified.len); 137 try std.testing.expectEqualSlices(u8, &recipient_id, &notified[0]); 138 } 139 140 // muting drops the subscriber from the index 141 try notify.mute(io, allocator, users_dir, &recipient_id, location, &thread_b, author); 142 try std.testing.expectEqual(0, (try readNotified(io, allocator, &arena, users_dir, &owner_id, &id_b)).len); 143 144 // a full subscribed tier refuses one more 145 for (0..notify.max_subscribed) |_| { 146 const user_id = evt.EventWithId.randomId(prng.random()); 147 try initUserRepo(io, allocator, users_dir, &user_id); 148 try notify.subscribe(io, allocator, users_dir, &user_id, location, &thread_a, author); 149 } 150 try notify.subscribe(io, allocator, users_dir, &recipient_id, location, &thread_a, author); 151 try std.testing.expectEqual(null, try readMode(io, allocator, &arena, users_dir, &recipient_id, &location.repo_id, &thread_a)); 152 153 // past the cap, the oldest go. times tie within a second, so which one goes isn't checked. 154 { 155 const many = try allocator.alloc(notify.Notif, notify.max_notifs + 1); 156 defer allocator.free(many); 157 for (many, 0..) |*notif, i| { 158 notif.* = notif_a; 159 notif.thread_id = @splat(0); 160 std.mem.writeInt(u64, notif.thread_id[0..@sizeOf(u64)], i, .big); 161 } 162 try notify.deliver(io, allocator, users_dir, &recipient_id, many); 163 } 164 try std.testing.expectEqual(notify.max_notifs, (try readRecent(io, allocator, &arena, users_dir, &recipient_id)).len); 165 } 166