pub struct NotificationStore { /* private fields */ }Expand description
In-memory notification store
Thread-safe store for notifications, keyed by recipient_id. Each recipient has their own ordered list stored in chronological order (oldest first, newest last). Retrieval returns newest first.
When a user exceeds MAX_PER_USER notifications, the oldest are evicted.
§Real-time streaming
A tokio::sync::broadcast channel broadcasts every inserted notification
to subscribers (e.g., gRPC server-streaming RPCs). The broadcast is
fire-and-forget: if no subscriber is listening, the notification is simply
not delivered to the channel (no error, no panic).
Implementations§
Source§impl NotificationStore
impl NotificationStore
Sourcepub fn subscribe(&self) -> Receiver<StoredNotification>
pub fn subscribe(&self) -> Receiver<StoredNotification>
Subscribe to real-time notifications.
Returns a receiver that will get every notification inserted after this call. Notifications inserted before are NOT replayed.
The subscriber should filter by recipient_id if it only wants
notifications for a specific user.
Sourcepub async fn insert(&self, notification: StoredNotification)
pub async fn insert(&self, notification: StoredNotification)
Store a notification and broadcast it to real-time subscribers.
Notifications are stored in chronological order (oldest first).
If the user exceeds MAX_PER_USER, the oldest notifications are evicted.
The broadcast is fire-and-forget: if no subscriber is listening,
send() returns Err which is silently ignored.
Sourcepub async fn list_by_user(
&self,
recipient_id: &str,
limit: usize,
offset: usize,
) -> Vec<StoredNotification>
pub async fn list_by_user( &self, recipient_id: &str, limit: usize, offset: usize, ) -> Vec<StoredNotification>
List notifications for a user with pagination
Returns notifications ordered by creation time (newest first). No sorting needed — stored in chronological order, iterated in reverse.
Sourcepub async fn mark_as_read(
&self,
notification_ids: &[Uuid],
recipient_id: Option<&str>,
) -> usize
pub async fn mark_as_read( &self, notification_ids: &[Uuid], recipient_id: Option<&str>, ) -> usize
Mark notifications as read by their IDs
If recipient_id is provided, only searches that user’s notifications
(avoiding a full scan). Otherwise scans all users.
Returns the number of notifications actually marked as read.
Sourcepub async fn mark_all_as_read(&self, recipient_id: &str) -> usize
pub async fn mark_all_as_read(&self, recipient_id: &str) -> usize
Mark all notifications for a user as read
Sourcepub async fn unread_count(&self, recipient_id: &str) -> usize
pub async fn unread_count(&self, recipient_id: &str) -> usize
Count unread notifications for a user
Sourcepub async fn total_count(&self, recipient_id: &str) -> usize
pub async fn total_count(&self, recipient_id: &str) -> usize
Total notification count for a user