╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ notify.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
95 try std.testing.expectEqual(2, recent.len); 96 for (recent) |item| { 97 if (std.mem.eql(u8, &item.notif.thread_id, &thread_a)) try std.testing.expectEqualSlices(u8, &child_ids[3], &item.notif.last_child_id); 98 } 99 } 100 101 // a read of a child the thread has moved past leaves it unread 102 try notify.markRead(io, allocator, users_dir, &recipient_id, &id_a, &child_ids[2]); 103 try std.testing.expectEqual(2, try unreadCount(io, allocator, users_dir, &recipient_id)); 104 try notify.markRead(io, allocator, users_dir, &recipient_id, &id_a, &child_ids[3]); 105 try std.testing.expectEqual(1, try unreadCount(io, allocator, users_dir, &recipient_id)); 106 for (try readRecent(io, allocator, &arena, users_dir, &recipient_id)) |item| { 107 try std.testing.expectEqual(!std.mem.eql(u8, &item.notif.thread_id, &thread_a), item.unread); 108 } 109 110 try notify.dismiss(io, allocator, users_dir, &recipient_id, &id_a); 111 { 112 const recent = try readRecent(io, allocator, &arena, users_dir, &recipient_id); 113 try std.testing.expectEqual(1, recent.len); 114 try std.testing.expectEqualSlices(u8, &thread_b, &recent[0].notif.thread_id); 115 } 116 117 // 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