From 2bbc1270a11fb5cc89bf28350108687d08989e31 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 11 Aug 2024 12:50:50 +0200 Subject: [PATCH] fix: add compat options to add target to likes this is a nastier compat option: lemmy sends likes anonymously by design (you can't see who upvoted/downvoted you). however mastodon likes are intended to be seen (as mastodon shows every like as public on their frontend). issue is: they both come with completely empty addressing! thanks mastodon... so this compat option makes likes addressed to local objects always address the object author. this restores mastodon likes behavior but "leaks" lemmy votes. i don't know how to fix it: maybe do some weird magic checking what is in `@context`??? disgusting but at least i can stop leaking lemmy's likes... --- upub/core/src/config.rs | 2 ++ upub/core/src/traits/process.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/upub/core/src/config.rs b/upub/core/src/config.rs index 6788909..a26cd2a 100644 --- a/upub/core/src/config.rs +++ b/upub/core/src/config.rs @@ -105,6 +105,8 @@ pub struct CompatibilityConfig { #[serde(default)] pub fix_attachment_images_media_type: bool, + #[serde(default)] + pub add_explicit_target_to_likes_if_local: bool, } impl Config { diff --git a/upub/core/src/traits/process.rs b/upub/core/src/traits/process.rs index 598ee24..4f455db 100644 --- a/upub/core/src/traits/process.rs +++ b/upub/core/src/traits/process.rs @@ -98,6 +98,7 @@ pub async fn create(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat pub async fn like(ctx: &crate::Context, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> { let actor = ctx.fetch_user(activity.actor().id()?, tx).await?; let obj = ctx.fetch_object(activity.object().id()?, tx).await?; + let likes_local_object = obj.attributed_to.as_ref().map(|x| ctx.is_local(x)).unwrap_or_default(); if crate::model::like::Entity::find_by_uid_oid(actor.internal, obj.internal) .any(tx) .await? @@ -120,8 +121,11 @@ pub async fn like(ctx: &crate::Context, activity: impl apb::Activity, tx: &Datab .await?; // likes without addressing are "silent likes", process them but dont store activity or notify - if !activity.addressed().is_empty() { - let activity_model = ctx.insert_activity(activity, tx).await?; + if likes_local_object || !activity.addressed().is_empty() { + let mut activity_model = ctx.insert_activity(activity, tx).await?; + if likes_local_object { + activity_model.to.0.push(obj.attributed_to.clone().unwrap_or_default()); + } ctx.address((Some(&activity_model), None), tx).await?; // TODO check that object author is in this like addressing!!! otherwise skip notification