From c1ab0d474eaf365d56e7b2e2c0d50ec3837fef22 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 15 Aug 2024 05:27:55 +0200 Subject: [PATCH] feat: added rich notification basically just adding field "seen" to activities --- upub/core/src/selector/mod.rs | 2 +- upub/core/src/selector/rich.rs | 25 +++++++++++++++++++ .../src/activitypub/actor/notifications.rs | 6 ++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/upub/core/src/selector/mod.rs b/upub/core/src/selector/mod.rs index 5b2e3a8..75c8b9a 100644 --- a/upub/core/src/selector/mod.rs +++ b/upub/core/src/selector/mod.rs @@ -5,7 +5,7 @@ mod query; pub use query::Query; mod rich; -pub use rich::RichActivity; +pub use rich::{RichActivity, RichNotification}; diff --git a/upub/core/src/selector/rich.rs b/upub/core/src/selector/rich.rs index aa6e4ca..625fb04 100644 --- a/upub/core/src/selector/rich.rs +++ b/upub/core/src/selector/rich.rs @@ -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 { + 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)) + } +} diff --git a/upub/routes/src/activitypub/actor/notifications.rs b/upub/routes/src/activitypub/actor/notifications.rs index 567f0c1..8d0d215 100644 --- a/upub/routes/src/activitypub/actor/notifications.rs +++ b/upub/routes/src/activitypub/actor/notifications.rs @@ -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::() + .into_model::() .all(ctx.db()) .await? .into_iter()