From f452430acc042bb49df702b3b1ebf487c34138ff Mon Sep 17 00:00:00 2001 From: Oneric Date: Mon, 9 Jun 2025 20:24:33 +0200 Subject: [PATCH] Remove non-local recipients from local post addressing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They won’t receive local-only posts anyway so it makes no sense to list them as recipients. --- lib/pleroma/web/common_api/utils.ex | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index b884dbaaf..207e51105 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -73,13 +73,8 @@ def get_to_and_cc(%{visibility: visibility} = draft) do ) end - def get_to_and_cc_for_visibility(visibility, follower_collection, parent_actor, mentions) - when visibility in ["public", "local"] do - scope_addr = - case visibility do - "public" -> Pleroma.Constants.as_public() - "local" -> Utils.as_local_public() - end + def get_to_and_cc_for_visibility("public", follower_collection, parent_actor, mentions) do + scope_addr = Pleroma.Constants.as_public() to = if parent_actor, @@ -89,6 +84,22 @@ def get_to_and_cc_for_visibility(visibility, follower_collection, parent_actor, {to, [follower_collection]} end + def get_to_and_cc_for_visibility("local", follower_collection, parent_actor, mentions) do + recipients = + if parent_actor, + do: Enum.uniq([parent_actor | mentions]), + else: mentions + + to = [ + Utils.as_local_public() + | Enum.filter(recipients, fn addr -> + String.starts_with?(addr, Pleroma.Web.Endpoint.url() <> "/") + end) + ] + + {to, [follower_collection]} + end + def get_to_and_cc_for_visibility("unlisted", follower_collection, parent_actor, mentions) do to = if parent_actor,