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 tenant(self, tenant: impl Into<Option<TenantId>>) -> Self
pub fn tenant(self, tenant: impl Into<Option<TenantId>>) -> Self
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>
pub async fn send( &self, user_id: &str, notification: Notification, ) -> Result<StoredNotification>
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>
pub async fn send_in( &self, ex: &mut dyn Executor, user_id: &str, notification: Notification, ) -> Result<StoredNotification>
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.