pub struct Notifications { /* private fields */ }Expand description
Sends StoredNotifications to one panel’s users, and wakes their open bells. Cloning it is
cheap.
In a request, Notifications::of sends on the request’s panel, for the request’s tenant. A
job takes the handle from PanelHandle::notifications.
Notifications::of(cx)?
.send(
&owner.user_id(),
Notification::success("Your export is ready").action("Download", "/exports/42.csv"),
)
.await?;Implementations§
Source§impl Notifications
impl Notifications
Sourcepub fn of(cx: &Cx) -> Result<Notifications, Error>
pub fn of(cx: &Cx) -> Result<Notifications, Error>
Sourcepub fn tenant(self, tenant: impl Into<Option<TenantId>>) -> Notifications
pub fn tenant(self, tenant: impl Into<Option<TenantId>>) -> Notifications
Sends for tenant instead: the bell lists what this handle sends only while the
recipient acts for it, or whichever tenant they act for with None.
Sourcepub async fn send(
&self,
user_id: &str,
notification: Notification,
) -> Result<StoredNotification, Error>
pub async fn send( &self, user_id: &str, notification: Notification, ) -> Result<StoredNotification, Error>
Stores notification for the panel user user_id, their
PanelUser::user_id, unread, and wakes the bells they have
open on the panel. It commits on its own connection: inside a write’s transaction, such as
in Resource::before_commit, use Self::send_in.
§Errors
An opaque infrastructure failure when the row cannot be written, e.g. the database does
not register StoredNotification; the driver’s text goes to the log. A declaration
failure on a handle from Self::of while the request’s panel write has its transaction
open, as db refuses.
Sourcepub async fn send_in(
&self,
ex: &mut dyn Executor,
user_id: &str,
notification: Notification,
) -> Result<StoredNotification, Error>
pub async fn send_in( &self, ex: &mut dyn Executor, user_id: &str, notification: Notification, ) -> Result<StoredNotification, Error>
Stores notification as Self::send does, through ex, so it exists only if the
transaction ex runs commits. Within a panel write, such as in
Resource::before_commit on a handle from
Self::of, the recipient’s open bells wake once the write commits, and not at all if it
rolls back; anywhere else they wake at once, and pick the row up after the commit when
they next refresh.
async fn before_commit(
cx: &Cx,
change: &Change<Post>,
ex: &mut dyn toasty::Executor,
) -> Result<()> {
if let Change::Update { after, .. } = change {
Notifications::of(cx)?
.send_in(
&mut *ex,
&after.author,
Notification::info("Your post was edited"),
)
.await?;
}
Ok(())
}§Errors
As Self::send. A failure inside a transaction leaves it to roll back.
Sourcepub async fn prune(&self, age: Duration) -> Result<(), Error>
pub async fn prune(&self, age: Duration) -> Result<(), Error>
Deletes the panel’s stored notifications, read or not, sent more than age ago. Nothing
prunes them otherwise; a job calls it on the schedule the app keeps them for.
§Errors
An opaque infrastructure failure when the rows cannot be deleted.
Trait Implementations§
Source§impl Clone for Notifications
impl Clone for Notifications
Source§fn clone(&self) -> Notifications
fn clone(&self) -> Notifications
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more