Do not boost if group is blocking poster

This commit is contained in:
tusooa 2023-11-07 21:16:24 -05:00
parent 5f5533b88a
commit e34a975dd9
No known key found for this signature in database
GPG Key ID: 42AEC43D48433C51
3 changed files with 34 additions and 1 deletions

View File

@ -937,13 +937,19 @@ def get_existing_votes(actor, %{data: %{"id" => id}}) do
end end
def maybe_handle_group_posts(activity) do def maybe_handle_group_posts(activity) do
poster = User.get_cached_by_ap_id(activity.actor)
mentions = mentions =
activity.data["to"] activity.data["to"]
|> Enum.filter(&(&1 != activity.actor)) |> Enum.filter(&(&1 != activity.actor))
mentioned_local_groups = mentioned_local_groups =
User.get_all_by_ap_id(mentions) 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 mentioned_local_groups
|> Enum.each(fn group -> |> Enum.each(fn group ->

View File

@ -984,5 +984,24 @@ test "remote group should not boost it", %{make_create: make_create, group: grou
assert [announce] = get_announces_of_object(object) assert [announce] = get_announces_of_object(object)
assert announce.actor == group.ap_id assert announce.actor == group.ap_id
end 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
end end

View File

@ -1883,5 +1883,13 @@ test "multiple groups mentioned", %{poster: poster, group: group, other_group: o
announces = get_announces_of_object(post.object) announces = get_announces_of_object(post.object)
assert [_, _] = announces assert [_, _] = announces
end 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
end end