Transmogrifier: Switch to pipeline for Blocks.
This commit is contained in:
parent
89e5b2046b
commit
e38293c8f1
|
@ -20,6 +20,22 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||||
|
|
||||||
def handle(object, meta \\ [])
|
def handle(object, meta \\ [])
|
||||||
|
|
||||||
|
# Tasks this handles:
|
||||||
|
# - Unfollow and block
|
||||||
|
def handle(
|
||||||
|
%{data: %{"type" => "Block", "object" => blocked_user, "actor" => blocking_user}} =
|
||||||
|
object,
|
||||||
|
meta
|
||||||
|
) do
|
||||||
|
with %User{} = blocker <- User.get_cached_by_ap_id(blocking_user),
|
||||||
|
%User{} = blocked <- User.get_cached_by_ap_id(blocked_user) do
|
||||||
|
User.unfollow(blocker, blocked)
|
||||||
|
User.block(blocker, blocked)
|
||||||
|
end
|
||||||
|
|
||||||
|
{:ok, object, meta}
|
||||||
|
end
|
||||||
|
|
||||||
# Tasks this handles:
|
# Tasks this handles:
|
||||||
# - Update the user
|
# - Update the user
|
||||||
#
|
#
|
||||||
|
|
|
@ -673,7 +673,7 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(%{"type" => type} = data, _options)
|
def handle_incoming(%{"type" => type} = data, _options)
|
||||||
when type in ["Like", "EmojiReact", "Announce"] do
|
when type in ~w{Like EmojiReact Announce} do
|
||||||
with :ok <- ObjectValidator.fetch_actor_and_object(data),
|
with :ok <- ObjectValidator.fetch_actor_and_object(data),
|
||||||
{:ok, activity, _meta} <-
|
{:ok, activity, _meta} <-
|
||||||
Pipeline.common_pipeline(data, local: false) do
|
Pipeline.common_pipeline(data, local: false) do
|
||||||
|
@ -684,9 +684,10 @@ def handle_incoming(%{"type" => type} = data, _options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Update"} = data,
|
%{"type" => type} = data,
|
||||||
_options
|
_options
|
||||||
) do
|
)
|
||||||
|
when type in ~w{Update Block} do
|
||||||
with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
|
with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
|
||||||
{:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
|
{:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -765,21 +766,6 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
|
||||||
%{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = _data,
|
|
||||||
_options
|
|
||||||
) do
|
|
||||||
with %User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
|
|
||||||
{:ok, %User{} = blocker} = User.get_or_fetch_by_ap_id(blocker),
|
|
||||||
{:ok, activity} <- ActivityPub.block(blocker, blocked, id, false) do
|
|
||||||
User.unfollow(blocker, blocked)
|
|
||||||
User.block(blocker, blocked)
|
|
||||||
{:ok, activity}
|
|
||||||
else
|
|
||||||
_e -> :error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{
|
%{
|
||||||
"type" => "Move",
|
"type" => "Move",
|
||||||
|
|
|
@ -64,6 +64,31 @@ test "it streams out notifications and streams" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "blocking users" do
|
||||||
|
setup do
|
||||||
|
user = insert(:user)
|
||||||
|
blocked = insert(:user)
|
||||||
|
User.follow(blocked, user)
|
||||||
|
User.follow(user, blocked)
|
||||||
|
|
||||||
|
{:ok, block_data, []} = Builder.block(user, blocked)
|
||||||
|
{:ok, block, _meta} = ActivityPub.persist(block_data, local: true)
|
||||||
|
|
||||||
|
%{user: user, blocked: blocked, block: block}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it unfollows and blocks", %{user: user, blocked: blocked, block: block} do
|
||||||
|
assert User.following?(user, blocked)
|
||||||
|
assert User.following?(blocked, user)
|
||||||
|
|
||||||
|
{:ok, _, _} = SideEffects.handle(block)
|
||||||
|
|
||||||
|
refute User.following?(user, blocked)
|
||||||
|
refute User.following?(blocked, user)
|
||||||
|
assert User.blocks?(user, blocked)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "update users" do
|
describe "update users" do
|
||||||
setup do
|
setup do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
Loading…
Reference in New Issue