feat: added rich notification

basically just adding field "seen" to activities
This commit is contained in:
əlemi 2024-08-15 05:27:55 +02:00
parent 79c03669b9
commit c1ab0d474e
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 29 additions and 4 deletions

View file

@ -5,7 +5,7 @@ mod query;
pub use query::Query; pub use query::Query;
mod rich; mod rich;
pub use rich::RichActivity; pub use rich::{RichActivity, RichNotification};

View file

@ -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))
}
}

View file

@ -1,7 +1,7 @@
use axum::extract::{Path, Query, State}; use axum::extract::{Path, Query, State};
use sea_orm::{PaginatorTrait, QuerySelect}; use sea_orm::{PaginatorTrait, QuerySelect};
use upub::Context; use upub::{selector::RichNotification, Context};
use crate::{activitypub::Pagination, builders::JsonLD, AuthIdentity, Identity}; 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 limit = page.batch.unwrap_or(20).min(50);
let offset = page.offset.unwrap_or(0); let offset = page.offset.unwrap_or(0);
let activities = upub::Query::notifications(*internal, false) let activities = upub::Query::notifications(*internal, true)
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)
.into_model::<upub::model::activity::Model>() .into_model::<RichNotification>()
.all(ctx.db()) .all(ctx.db())
.await? .await?
.into_iter() .into_iter()