logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: e34a975dd946cc609638d85c20a57e2bfed6ebc7
parent 5f5533b88a66bdd3547eb5e29f29191093457052
Author: tusooa <tusooa@kazv.moe>
Date:   Tue,  7 Nov 2023 21:16:24 -0500

Do not boost if group is blocking poster

Diffstat:

Mlib/pleroma/web/activity_pub/utils.ex8+++++++-
Mtest/pleroma/web/activity_pub/side_effects_test.exs19+++++++++++++++++++
Mtest/pleroma/web/common_api_test.exs8++++++++
3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex @@ -937,13 +937,19 @@ defmodule Pleroma.Web.ActivityPub.Utils do end def maybe_handle_group_posts(activity) do + poster = User.get_cached_by_ap_id(activity.actor) + mentions = activity.data["to"] |> Enum.filter(&(&1 != activity.actor)) mentioned_local_groups = User.get_all_by_ap_id(mentions) - |> Enum.filter(&(&1.actor_type == "Group" and &1.local)) + |> Enum.filter(fn user -> + user.actor_type == "Group" and + user.local and + not User.blocks?(user, poster) + end) mentioned_local_groups |> Enum.each(fn group -> diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs @@ -984,5 +984,24 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do assert [announce] = get_announces_of_object(object) assert announce.actor == group.ap_id end + + test "group should not boost it if group is blocking poster", %{ + make_create: make_create, + group: group, + poster: poster + } do + {:ok, _} = CommonAPI.block(group, poster) + create_activity_data = make_create.([group]) + {:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false) + + {:ok, _create_activity, _meta} = + SideEffects.handle(create_activity, + local: false, + object_data: create_activity_data["object"] + ) + + object = Object.normalize(create_activity, fetch: false) + assert [] = get_announces_of_object(object) + end end end diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs @@ -1883,5 +1883,13 @@ defmodule Pleroma.Web.CommonAPITest do announces = get_announces_of_object(post.object) assert [_, _] = announces end + + test "it does not boost if group is blocking poster", %{poster: poster, group: group} do + {:ok, _} = CommonAPI.block(group, poster) + {:ok, post} = CommonAPI.post(poster, %{status: "hey @#{group.nickname}"}) + + announces = get_announces_of_object(post.object) + assert [] = announces + end end end