feat: added rich notification
basically just adding field "seen" to activities
This commit is contained in:
parent
79c03669b9
commit
c1ab0d474e
3 changed files with 29 additions and 4 deletions
|
@ -5,7 +5,7 @@ mod query;
|
|||
pub use query::Query;
|
||||
|
||||
mod rich;
|
||||
pub use rich::RichActivity;
|
||||
pub use rich::{RichActivity, RichNotification};
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -132,3 +132,28 @@ impl RichActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RichNotification {
|
||||
pub activity: crate::model::activity::Model,
|
||||
pub seen: bool,
|
||||
}
|
||||
|
||||
impl FromQueryResult for RichNotification {
|
||||
fn from_query_result(res: &QueryResult, _pre: &str) -> Result<Self, DbErr> {
|
||||
Ok(RichNotification {
|
||||
activity: crate::model::activity::Model::from_query_result(res, crate::model::activity::Entity.table_name())?,
|
||||
seen: res.try_get(
|
||||
crate::model::notification::Entity.table_name(),
|
||||
&crate::model::notification::Column::Seen.to_string()
|
||||
).unwrap_or(false),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl RichNotification {
|
||||
pub fn ap(self) -> serde_json::Value {
|
||||
let seen = self.seen;
|
||||
self.activity.ap()
|
||||
.set_seen(Some(seen))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use axum::extract::{Path, Query, State};
|
||||
use sea_orm::{PaginatorTrait, QuerySelect};
|
||||
|
||||
use upub::Context;
|
||||
use upub::{selector::RichNotification, Context};
|
||||
|
||||
use crate::{activitypub::Pagination, builders::JsonLD, AuthIdentity, Identity};
|
||||
|
||||
|
@ -42,10 +42,10 @@ pub async fn page(
|
|||
let limit = page.batch.unwrap_or(20).min(50);
|
||||
let offset = page.offset.unwrap_or(0);
|
||||
|
||||
let activities = upub::Query::notifications(*internal, false)
|
||||
let activities = upub::Query::notifications(*internal, true)
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.into_model::<upub::model::activity::Model>()
|
||||
.into_model::<RichNotification>()
|
||||
.all(ctx.db())
|
||||
.await?
|
||||
.into_iter()
|
||||
|
|
Loading…
Reference in a new issue