From abe8b18ea85ea6dbe569b20e64d754d48db7df84 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 3 Jan 2024 16:31:51 +0100 Subject: [PATCH] Also send reports to user's home instance (fixes #4286) (#4305) --- .../apub/src/activities/community/report.rs | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/apub/src/activities/community/report.rs b/crates/apub/src/activities/community/report.rs index 7da5ac8ae..974810f61 100644 --- a/crates/apub/src/activities/community/report.rs +++ b/crates/apub/src/activities/community/report.rs @@ -1,7 +1,7 @@ use crate::{ activities::{generate_activity_id, send_lemmy_activity, verify_person_in_community}, insert_received_activity, - objects::{community::ApubCommunity, person::ApubPerson}, + objects::{community::ApubCommunity, instance::ApubSite, person::ApubPerson}, protocol::{activities::community::report::Report, InCommunity}, PostOrComment, }; @@ -19,8 +19,9 @@ use lemmy_db_schema::{ community::Community, person::Person, post_report::{PostReport, PostReportForm}, + site::Site, }, - traits::Reportable, + traits::{Crud, Reportable}, }; use lemmy_utils::error::LemmyError; use url::Url; @@ -44,18 +45,31 @@ impl Report { let report = Report { actor: actor.id().into(), to: [community.id().into()], - object: object_id, + object: object_id.clone(), summary: reason, kind, id: id.clone(), audience: Some(community.id().into()), }; - let inbox = if community.local { - ActivitySendTargets::empty() - } else { - ActivitySendTargets::to_inbox(community.shared_inbox_or_inbox()) + + // send report to the community where object was posted + let mut inboxes = ActivitySendTargets::to_inbox(community.shared_inbox_or_inbox()); + + // also send report to user's home instance if possible + let object_creator_id = match object_id.dereference_local(&context).await? { + PostOrComment::Post(p) => p.creator_id, + PostOrComment::Comment(c) => c.creator_id, }; - send_lemmy_activity(&context, report, &actor, inbox, false).await + let object_creator = Person::read(&mut context.pool(), object_creator_id).await?; + let object_creator_site: Option = + Site::read_from_instance_id(&mut context.pool(), object_creator.instance_id) + .await? + .map(Into::into); + if let Some(inbox) = object_creator_site.map(|s| s.shared_inbox_or_inbox()) { + inboxes.add_inbox(inbox); + } + + send_lemmy_activity(&context, report, &actor, inboxes, false).await } }