Page MenuHomePhorge

No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/pleroma/web/activity_pub/mrf/block_policy.ex b/lib/pleroma/web/activity_pub/mrf/block_policy.ex
index da4f246ba..040bee822 100644
--- a/lib/pleroma/web/activity_pub/mrf/block_policy.ex
+++ b/lib/pleroma/web/activity_pub/mrf/block_policy.ex
@@ -1,41 +1,49 @@
# 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.BlockPolicy do
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@moduledoc "Notify local users upon remote block."
@behaviour Pleroma.Web.ActivityPub.MRF
- @impl true
- def filter(message) do
- type = message["type"]
-
- if type == "Block" or (type == "Undo" and message["object"]["type"] == "Block") do
- recipient = User.get_cached_by_ap_id(hd(message["to"]))
-
- if recipient.local do
- actor = User.get_cached_by_ap_id(message["actor"])
- # default: do not show blocks from local users
- display_local = Pleroma.Config.get([:mrf_blockpolicy, :display_local])
- # ignore notifications from blocked users to stop spam
- if !User.blocks_ap_id?(recipient, actor) and (!actor.local or display_local) do
- bot_user = Pleroma.Config.get([:mrf_blockpolicy, :user])
- term = if type == "Block", do: "blocked", else: "unblocked"
+ defp is_block_or_unblock(message) do
+ case message do
+ %{"type" => "Block", "object" => object} ->
+ {true, "blocked", object}
+ %{"type" => "Undo", "object" => %{"type" => "Block", "object" => object}} ->
+ {true, "unblocked", object}
+ _ ->
+ {false, :nil, :nil}
+ end
+ end
- _reply =
- CommonAPI.post(User.get_by_nickname(bot_user), %{
- "status" =>
- "@" <> recipient.nickname <> " you are now " <> term <> " by " <> actor.nickname,
- "visibility" => "direct"
- })
- end
- end
+ defp is_remote_or_displaying_local?(actor) do
+ case actor do
+ %User{local: false} -> true
+ _ -> Pleroma.Config.get([:mrf_blockpolicy, :display_local])
end
+ end
+ @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_ap_id?(recipient, actor) do
+ bot_user = Pleroma.Config.get([:mrf_blockpolicy, :user])
+ _reply =
+ CommonAPI.post(User.get_by_nickname(bot_user), %{
+ "status" =>
+ "@" <> recipient.nickname <> " you are now " <> action <> " by " <> actor.nickname,
+ "visibility" => "direct"
+ })
+ end
{:ok, message}
end
end

File Metadata

Mime Type
text/x-diff
Expires
Tue, Oct 13, 8:36 PM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1786897
Default Alt Text
(2 KB)

Event Timeline