Skip to main content

Notifications

Struct Notifications 

Source
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

Source

pub fn of(cx: &Cx) -> Result<Self>

Sends on the request’s panel, for the tenant the request acts for: the bell lists what it sends only while the recipient acts for the same tenant. tenant changes it.

§Errors

A declaration error outside every panel, such as on a public page that did not enter one.

Source

pub fn tenant(self, tenant: impl Into<Option<Uuid>>) -> 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.

Source

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.

Source

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.

Source

pub async fn prune(&self, age: Duration) -> Result<()>

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more