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 \\ [])
|
||||
|
||||
# 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:
|
||||
# - Update the user
|
||||
#
|
||||
|
@ -673,7 +673,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||
end
|
||||
|
||||
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),
|
||||
{:ok, activity, _meta} <-
|
||||
Pipeline.common_pipeline(data, local: false) do
|
||||
@ -684,9 +684,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||
end
|
||||
|
||||
def handle_incoming(
|
||||
%{"type" => "Update"} = data,
|
||||
%{"type" => type} = data,
|
||||
_options
|
||||
) do
|
||||
)
|
||||
when type in ~w{Update Block} do
|
||||
with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
|
||||
{:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
|
||||
{:ok, activity}
|
||||
@ -765,21 +766,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||
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(
|
||||
%{
|
||||
"type" => "Move",
|
||||
|
@ -64,6 +64,31 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
||||
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
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
Loading…
Reference in New Issue
Block a user