ActivityPub: Remove block
.
This commit is contained in:
parent
8cfb58a8c0
commit
44bb7cfccd
@ -1527,8 +1527,7 @@ defmodule Pleroma.User do
|
|||||||
blocked_identifiers,
|
blocked_identifiers,
|
||||||
fn blocked_identifier ->
|
fn blocked_identifier ->
|
||||||
with {:ok, %User{} = blocked} <- get_or_fetch(blocked_identifier),
|
with {:ok, %User{} = blocked} <- get_or_fetch(blocked_identifier),
|
||||||
{:ok, _user_block} <- block(blocker, blocked),
|
{:ok, _block} <- CommonAPI.block(blocker, blocked) do
|
||||||
{:ok, _} <- ActivityPub.block(blocker, blocked) do
|
|
||||||
blocked
|
blocked
|
||||||
else
|
else
|
||||||
err ->
|
err ->
|
||||||
|
@ -366,33 +366,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec block(User.t(), User.t(), String.t() | nil, boolean()) ::
|
|
||||||
{:ok, Activity.t()} | {:error, any()}
|
|
||||||
def block(blocker, blocked, activity_id \\ nil, local \\ true) do
|
|
||||||
with {:ok, result} <-
|
|
||||||
Repo.transaction(fn -> do_block(blocker, blocked, activity_id, local) end) do
|
|
||||||
result
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp do_block(blocker, blocked, activity_id, local) do
|
|
||||||
unfollow_blocked = Config.get([:activitypub, :unfollow_blocked])
|
|
||||||
|
|
||||||
if unfollow_blocked and fetch_latest_follow(blocker, blocked) do
|
|
||||||
unfollow(blocker, blocked, nil, local)
|
|
||||||
end
|
|
||||||
|
|
||||||
block_data = make_block_data(blocker, blocked, activity_id)
|
|
||||||
|
|
||||||
with {:ok, activity} <- insert(block_data, local),
|
|
||||||
_ <- notify_and_stream(activity),
|
|
||||||
:ok <- maybe_federate(activity) do
|
|
||||||
{:ok, activity}
|
|
||||||
else
|
|
||||||
{:error, error} -> Repo.rollback(error)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec flag(map()) :: {:ok, Activity.t()} | {:error, any()}
|
@spec flag(map()) :: {:ok, Activity.t()} | {:error, any()}
|
||||||
def flag(
|
def flag(
|
||||||
%{
|
%{
|
||||||
|
@ -992,54 +992,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "blocking" do
|
|
||||||
test "reverts block activity on error" do
|
|
||||||
[blocker, blocked] = insert_list(2, :user)
|
|
||||||
|
|
||||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
|
||||||
assert {:error, :reverted} = ActivityPub.block(blocker, blocked)
|
|
||||||
end
|
|
||||||
|
|
||||||
assert Repo.aggregate(Activity, :count, :id) == 0
|
|
||||||
assert Repo.aggregate(Object, :count, :id) == 0
|
|
||||||
end
|
|
||||||
|
|
||||||
test "creates a block activity" do
|
|
||||||
clear_config([:instance, :federating], true)
|
|
||||||
blocker = insert(:user)
|
|
||||||
blocked = insert(:user)
|
|
||||||
|
|
||||||
with_mock Pleroma.Web.Federator,
|
|
||||||
publish: fn _ -> nil end do
|
|
||||||
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
|
||||||
|
|
||||||
assert activity.data["type"] == "Block"
|
|
||||||
assert activity.data["actor"] == blocker.ap_id
|
|
||||||
assert activity.data["object"] == blocked.ap_id
|
|
||||||
|
|
||||||
assert called(Pleroma.Web.Federator.publish(activity))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "works with outgoing blocks disabled, but doesn't federate" do
|
|
||||||
clear_config([:instance, :federating], true)
|
|
||||||
clear_config([:activitypub, :outgoing_blocks], false)
|
|
||||||
blocker = insert(:user)
|
|
||||||
blocked = insert(:user)
|
|
||||||
|
|
||||||
with_mock Pleroma.Web.Federator,
|
|
||||||
publish: fn _ -> nil end do
|
|
||||||
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
|
||||||
|
|
||||||
assert activity.data["type"] == "Block"
|
|
||||||
assert activity.data["actor"] == blocker.ap_id
|
|
||||||
assert activity.data["object"] == blocked.ap_id
|
|
||||||
|
|
||||||
refute called(Pleroma.Web.Federator.publish(:_))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "timeline post-processing" do
|
describe "timeline post-processing" do
|
||||||
test "it filters broken threads" do
|
test "it filters broken threads" do
|
||||||
user1 = insert(:user)
|
user1 = insert(:user)
|
||||||
|
@ -267,8 +267,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||||||
{:ok, like} = CommonAPI.favorite(user, post.id)
|
{:ok, like} = CommonAPI.favorite(user, post.id)
|
||||||
{:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍")
|
{:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍")
|
||||||
{:ok, announce} = CommonAPI.repeat(post.id, user)
|
{:ok, announce} = CommonAPI.repeat(post.id, user)
|
||||||
{:ok, block} = ActivityPub.block(user, poster)
|
{:ok, block} = CommonAPI.block(user, poster)
|
||||||
User.block(user, poster)
|
|
||||||
|
|
||||||
{:ok, undo_data, _meta} = Builder.undo(user, like)
|
{:ok, undo_data, _meta} = Builder.undo(user, like)
|
||||||
{:ok, like_undo, _meta} = ActivityPub.persist(undo_data, local: true)
|
{:ok, like_undo, _meta} = ActivityPub.persist(undo_data, local: true)
|
||||||
|
@ -27,16 +27,6 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "fetch the latest Block" do
|
|
||||||
test "fetches the latest Block activity" do
|
|
||||||
blocker = insert(:user)
|
|
||||||
blocked = insert(:user)
|
|
||||||
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
|
||||||
|
|
||||||
assert activity == Utils.fetch_latest_block(blocker, blocked)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "determine_explicit_mentions()" do
|
describe "determine_explicit_mentions()" do
|
||||||
test "works with an object that has mentions" do
|
test "works with an object that has mentions" do
|
||||||
object = %{
|
object = %{
|
||||||
@ -344,9 +334,9 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||||||
user1 = insert(:user)
|
user1 = insert(:user)
|
||||||
user2 = insert(:user)
|
user2 = insert(:user)
|
||||||
|
|
||||||
assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
|
assert {:ok, %Activity{} = _} = CommonAPI.block(user1, user2)
|
||||||
assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
|
assert {:ok, %Activity{} = _} = CommonAPI.block(user1, user2)
|
||||||
assert {:ok, %Activity{} = activity} = ActivityPub.block(user1, user2)
|
assert {:ok, %Activity{} = activity} = CommonAPI.block(user1, user2)
|
||||||
|
|
||||||
assert Utils.fetch_latest_block(user1, user2) == activity
|
assert Utils.fetch_latest_block(user1, user2) == activity
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user