From ecc277a1f076532c4bc0cd88378f994086c8578a Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 7 Jun 2024 23:21:41 +0200 Subject: [PATCH] fix: always create activities if local --- upub/core/src/traits/process.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/upub/core/src/traits/process.rs b/upub/core/src/traits/process.rs index c6fa710c..94cb40be 100644 --- a/upub/core/src/traits/process.rs +++ b/upub/core/src/traits/process.rs @@ -74,7 +74,7 @@ pub async fn create(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat let object_model = ctx.insert_object(object_node, tx).await?; // only likes mentioning local users are stored to generate notifications, everything else // produces side effects but no activity, and thus no notification - if activity.mentioning().iter().any(|x| ctx.is_local(x)) { + if ctx.is_local(activity.actor().id()?) || activity.mentioning().iter().any(|x| ctx.is_local(x)) { ctx.insert_activity(activity, tx).await?; } tracing::debug!("{} posted {}", object_model.attributed_to.as_deref().unwrap_or(""), object_model.id); @@ -107,7 +107,7 @@ pub async fn like(ctx: &crate::Context, activity: impl apb::Activity, tx: &Datab // only likes mentioning local users are stored to generate notifications, everything else // produces side effects but no activity, and thus no notification - if activity.mentioning().iter().any(|x| ctx.is_local(x)) { + if ctx.is_local(&actor.id) || activity.mentioning().iter().any(|x| ctx.is_local(x)) { ctx.insert_activity(activity, tx).await?; } @@ -205,11 +205,13 @@ pub async fn delete(_ctx: &crate::Context, activity: impl apb::Activity, tx: &Da Ok(()) } -pub async fn update(_ctx: &crate::Context, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> { +pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> { let Some(object_node) = activity.object().extract() else { tracing::error!("refusing to process activity without embedded object"); return Err(ProcessorError::Unprocessable(activity.id()?.to_string())); }; + + let actor_id = activity.actor().id()?.to_string(); let oid = object_node.id()?.to_string(); match object_node.object_type()? { @@ -238,7 +240,11 @@ pub async fn update(_ctx: &crate::Context, activity: impl apb::Activity, tx: &Da _ => return Err(ProcessorError::Unprocessable(activity.id()?.to_string())), } - tracing::debug!("{} updated {}", activity.actor().id()?, oid); + if ctx.is_local(&actor_id) { + ctx.insert_activity(activity, tx).await?; + } + + tracing::debug!("{} updated {}", actor_id, oid); Ok(()) } @@ -360,12 +366,16 @@ pub async fn announce(ctx: &crate::Context, activity: impl apb::Activity, tx: &D .exec(tx) .await?; } + } - // TODO we should probably insert an activity, otherwise this won't appear on timelines!! - // or maybe go update all addressing records for this object, pushing them up - // or maybe create new addressing rows with more recent dates - // or maybe create fake objects that reference the original one - // idk!!!! + // TODO we should probably insert an activity, otherwise this won't appear on timelines!! + // or maybe go update all addressing records for this object, pushing them up + // or maybe create new addressing rows with more recent dates + // or maybe create fake objects that reference the original one + // idk!!!! + + if ctx.is_local(&actor.id) { + ctx.insert_activity(activity, tx).await?; } tracing::debug!("{} shared {}", actor.id, announced_id);