2021-02-05 15:31:06 +01:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-03-19 18:56:39 +01:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2021-02-05 15:31:06 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.AntiHellthreadPolicy do
|
|
|
|
@moduledoc "Notify local users upon remote block."
|
|
|
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
|
|
|
|
|
|
|
alias Pleroma.Config
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
defp is_block_or_unblock(%{"type" => "Block", "object" => object}),
|
|
|
|
do: {true, "blocked", object}
|
|
|
|
|
2021-03-19 18:56:39 +01:00
|
|
|
defp is_block_or_unblock(%{"type" => "Block", "object" => object}),
|
|
|
|
do: {true, "blocked", object}
|
|
|
|
|
2021-02-05 15:31:06 +01:00
|
|
|
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?(_),
|
2021-03-19 18:56:39 +01:00
|
|
|
do: Pleroma.Config.get([:mrf_anti_hellthread_policy, :display_local])
|
2021-02-05 15:31:06 +01:00
|
|
|
|
|
|
|
@impl true
|
|
|
|
def filter(message) do
|
2021-03-19 18:56:39 +01:00
|
|
|
|
2021-02-05 15:31:06 +01:00
|
|
|
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
|
2021-03-19 18:56:39 +01:00
|
|
|
bot_user = Pleroma.Config.get([:mrf_anti_hellthread_policy, :user])
|
2021-02-05 15:31:06 +01:00
|
|
|
|
|
|
|
_reply =
|
|
|
|
CommonAPI.post(User.get_by_nickname(bot_user), %{
|
2021-03-19 18:56:39 +01:00
|
|
|
status: "@" <> recipient.nickname <> " you have been " <> action <> " by @" <> actor.nickname,
|
2021-02-05 15:31:06 +01:00
|
|
|
"visibility" => "direct"
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
{:ok, message}
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def describe, do: {:ok, %{}}
|
|
|
|
end
|