Skip to content
Corex

NotificationRepository

Corex\Notifications\NotificationRepository · interface · Core layer

Persistence for notifications and per-user state. Every actor-scoped read takes the actor id and a capability check, and returns only what the actor may see (spec 072 FR-002/FR-003) — visibility is never optional. The WP adapter clamps page size, prepares every query, and prunes in bounded batches, mirroring {@see \Corex\Config\Activity\WpActivityRepository}.

upsertByDedupKey(Notification $notification): Notification

Section titled “upsertByDedupKey(Notification $notification): Notification”

Insert, or if an unresolved notification with the same dedup key exists, record another occurrence and return the merged record (spec 072 FR-011).

findForActor(int $id, int $actorId, callable $userCan): ?array

Section titled “findForActor(int $id, int $actorId, callable $userCan): ?array”

One notification presented for the actor, or null if absent or the actor may not see it.

queryForActor(NotificationQuery $query, int $actorId, callable $userCan): array

Section titled “queryForActor(NotificationQuery $query, int $actorId, callable $userCan): array”

A bounded, visibility-filtered page for the actor.

unreadCountForActor(int $actorId, callable $userCan): int

Section titled “unreadCountForActor(int $actorId, callable $userCan): int”

markRead(int $notificationId, int $actorId): bool

Section titled “markRead(int $notificationId, int $actorId): bool”

Per-user state mutations. Each asserts the actor may see the notification first.

markUnread(int $notificationId, int $actorId): bool

Section titled “markUnread(int $notificationId, int $actorId): bool”

markAllVisibleRead(int $actorId, callable $userCan): int

Section titled “markAllVisibleRead(int $actorId, callable $userCan): int”

dismiss(int $notificationId, int $actorId): bool

Section titled “dismiss(int $notificationId, int $actorId): bool”

snooze(int $notificationId, int $actorId, DateTimeImmutable $until): bool

Section titled “snooze(int $notificationId, int $actorId, DateTimeImmutable $until): bool”

resolveByDedupKey(string $dedupKey, string $reason, DateTimeImmutable $at): int

Section titled “resolveByDedupKey(string $dedupKey, string $reason, DateTimeImmutable $at): int”

Condition lifecycle — resolve/reopen by dedup key, independent of any user’s dismissal.

rewordByDedupKey(Notification $notification): int

Section titled “rewordByDedupKey(Notification $notification): int”

Rewrite what an open notification says, its title, body and action label, without recording another occurrence (spec 118). Returns how many rows changed: none when the words are already these.

pruneOlderThan(DateTimeImmutable $cutoff, int $limit): int

Section titled “pruneOlderThan(DateTimeImmutable $cutoff, int $limit): int”

Bounded prune of expired/resolved notifications older than the cutoff; returns the count removed.