A multi-channel notification being assembled - build with to, add
channels with .database()/.mail(), run them with .send(). Each
channel method builds and immediately boxes its own delivery future
while its own bound (N: Notification, or N: MailNotification, U: MailNotifiable) is known, erasing it to a plain BoxedDelivery<'a>
before storing it - which is what lets .send() itself need no bound
on U/N at all, regardless of how many or which channels were
actually selected.
One stored row, as read back by notifications_for. data stays a
raw serde_json::Value rather than a concrete type - a single query
reads rows for many different Notification types at once; the app
is expected to match on notification_type to interpret data if it
needs more than generic display.
A notifiable that knows its own mail address - Laravel’s
routeNotificationForMail(), narrowed to the common case (one,
always-available address) rather than Laravel’s full per-notification
override mechanism.
A notification that also knows how to render itself as mail -
Laravel’s Notification::toMail(), as a real trait method rather
than a runtime-dispatched one (see this crate’s own module doc
comment for why). Mail: Send + 'static isn’t this trait being
stricter than Mailable itself needs - it’s what lets
PendingNotification::mail box the delivery future as dyn Future <...> + Send regardless of what a specific Mailable impl happens
to capture.
A durable fact worth recording against a notifiable - Laravel’s
Notification class, narrowed to just its database-channel shape.
Serializing Selfis the stored data payload; there’s no separate
render step the way [Notification::to_database] would imply if it
existed. NOTIFICATION_TYPE is the same explicit, stable, app-chosen
tag convention larust_queue::Job::JOB_TYPE already establishes -
deliberately not std::any::type_name::<Self>(), since that string
isn’t stable across a rename and an already-stored row would silently
stop being attributable to its type.
Permanently removes one notification, after verifying it belongs to the
acting notifiable. This mirrors mark_as_read’s ownership behavior:
missing rows are NotFound, while another user’s row is FORBIDDEN.
Marks every one of notifiable’s own notifications read. No ownership
check needed the way mark_as_read needs one - WHERE notifiable_id = ? already makes touching another notifiable’s rows structurally
impossible.
Marks one notification read, verifying it actually belongs to
notifiable first - the same “does this row belong to the acting
user?” question larust_auth::Policy<U>::update/delete already
answer, so this reuses larust_auth::authorize rather than
reinventing the check: a mismatched owner is a loud
AppError::Http{FORBIDDEN, ..}, matching how e.g. updating someone
else’s post already responds today, not a silent no-op (silently
collapsing “not yours” into Ok(()) is the right call for an
authentication-state ambiguity like “am I logged in at all” -
larust_auth::guard’s own precedent - but this is an authorization
question about a specific id someone is deliberately trying to act on,
a different question with a different, louder, established answer in
this codebase). A nonexistent id is AppError::NotFound, kept
distinct from the mismatched-owner case.
Reads notifiable’s own notifications, newest first, capped at
limit rows. limit is caller-supplied rather than a framework-picked
constant - the same real precedent larust_orm::QueryBuilder:: paginate(per_page) already sets in this crate family - making an
unbounded query structurally impossible rather than merely
policy-discouraged. No cursor/before_id pagination in v1, the same
documented gap paginate itself carries.
Records notification against notifiable - Laravel’s
$user->notify(new InvoiceSent($invoice)), narrowed to the database
channel (see this crate’s own doc comment for why mail/broadcast
aren’t wrapped here).
Runs notify and mail().to(email).send(mailable) concurrently -
sugar for the common “record it and email it” case, not a new
dispatch mechanism (see this crate’s own module doc comment). Both
calls still exist, still fully typed, still independently callable on
their own; this only removes the sequencing cost of awaiting them one
after the other, via tokio::try_join!. Fails with whichever error
occurs first if either side fails - the other side is not rolled
back, matching this crate’s own notify’s “one plain INSERT, no
transaction” posture (a partially-delivered notification, e.g.
recorded but not emailed, is treated the same accepted-tradeoff way
larust-mail’s own .queue() already treats a similar gap).