pub struct DatabaseChannel { /* private fields */ }Expand description
Stores notifications in a table, for an in-app notification list.
Uses to_data, falling back to
wrapping to_text — so a
notification that only wrote a line still gets a row rather than being
silently dropped.
Addresses the recipient by their id, not by a route: every notifiable has one, so this channel is never skipped for want of an address.
Implementations§
Source§impl DatabaseChannel
impl DatabaseChannel
Sourcepub fn migrations() -> Migrator
pub fn migrations() -> Migrator
The migration this channel needs.
Merge it into the application’s migrator:
Migrator::new()
.create_table::<User>("0001_create_users")
.merge(DatabaseChannel::migrations())Sourcepub async fn for_recipient(
&self,
notifiable_type: &str,
notifiable_id: &str,
limit: u64,
) -> Result<Vec<NotificationRow>>
pub async fn for_recipient( &self, notifiable_type: &str, notifiable_id: &str, limit: u64, ) -> Result<Vec<NotificationRow>>
Everything sent to a recipient, newest first.
Sourcepub async fn unread(
&self,
notifiable_type: &str,
notifiable_id: &str,
limit: u64,
) -> Result<Vec<NotificationRow>>
pub async fn unread( &self, notifiable_type: &str, notifiable_id: &str, limit: u64, ) -> Result<Vec<NotificationRow>>
The unread ones, newest first.
Sourcepub async fn unread_count(
&self,
notifiable_type: &str,
notifiable_id: &str,
) -> Result<u64>
pub async fn unread_count( &self, notifiable_type: &str, notifiable_id: &str, ) -> Result<u64>
How many are unread — what the badge on the bell shows.
Sourcepub async fn find_for(
&self,
notifiable_type: &str,
notifiable_id: &str,
id: &str,
) -> Result<Option<NotificationRow>>
pub async fn find_for( &self, notifiable_type: &str, notifiable_id: &str, id: &str, ) -> Result<Option<NotificationRow>>
One notification, but only if it belongs to this recipient.
What an endpoint should look it up with. Reading the row and then comparing the owner in the handler is the same query with one more place to forget the comparison.
Sourcepub async fn mark_read(&self, id: &str) -> Result<bool>
pub async fn mark_read(&self, id: &str) -> Result<bool>
Mark one as read. true if it was there and unread.
Sourcepub async fn mark_all_read(
&self,
notifiable_type: &str,
notifiable_id: &str,
) -> Result<u64>
pub async fn mark_all_read( &self, notifiable_type: &str, notifiable_id: &str, ) -> Result<u64>
Mark everything for a recipient as read. Returns how many changed.
Sourcepub async fn prune_read(&self, before: DateTime<Utc>) -> Result<u64>
pub async fn prune_read(&self, before: DateTime<Utc>) -> Result<u64>
Delete everything read before before. Returns how many.
A notifications table grows forever otherwise. Worth scheduling.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DatabaseChannel
impl !UnwindSafe for DatabaseChannel
impl Freeze for DatabaseChannel
impl Send for DatabaseChannel
impl Sync for DatabaseChannel
impl Unpin for DatabaseChannel
impl UnsafeUnpin for DatabaseChannel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more