add anti hellthread policy

This commit is contained in:
Your New SJW Waifu 2020-01-11 18:20:01 -06:00 committed by a1batross
parent 4d213d0fbc
commit 7ec510b966
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.AntiHellthreadPolicy do
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@moduledoc "Notify local users upon remote block."
@behaviour Pleroma.Web.ActivityPub.MRF
defp is_block_or_unblock(%{"type" => "Block", "object" => object}),
do: {true, "blocked", object}
defp is_block_or_unblock(%{
"type" => "Undo",
"object" => %{"type" => "Block", "object" => object}
}),
do: {true, "unblocked", object}
defp is_block_or_unblock(_), do: {false, nil, nil}
defp is_remote_or_displaying_local?(%User{local: false}), do: true
defp is_remote_or_displaying_local?(_),
do: Pleroma.Config.get([:mrf_blockpolicy, :display_local])
@impl true
def filter(message) do
with {true, action, object} <- is_block_or_unblock(message),
%User{} = actor <- User.get_cached_by_ap_id(message["actor"]),
%User{} = recipient <- User.get_cached_by_ap_id(object),
true <- recipient.local,
true <- is_remote_or_displaying_local?(actor),
false <- User.blocks_user?(recipient, actor) do
bot_user = Pleroma.Config.get([:mrf_blockpolicy, :user])
_reply =
CommonAPI.post(User.get_by_nickname(bot_user), %{
"status" =>
"@" <> recipient.nickname <> " you have been " <> action <> " by @" <> actor.nickname,
"visibility" => "direct"
})
end
{:ok, message}
end
@impl true
def describe, do: {:ok, %{}}
end