forked from AkkomaGang/akkoma
ActivityPub: Remove delete
function.
This is handled by the common pipeline now.
This commit is contained in:
parent
3b443cbc1d
commit
999d639873
2 changed files with 0 additions and 198 deletions
|
@ -519,67 +519,6 @@ defp do_unfollow(follower, followed, activity_id, local) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec delete(User.t() | Object.t(), keyword()) :: {:ok, User.t() | Object.t()} | {:error, any()}
|
|
||||||
def delete(entity, options \\ []) do
|
|
||||||
with {:ok, result} <- Repo.transaction(fn -> do_delete(entity, options) end) do
|
|
||||||
result
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp do_delete(%User{ap_id: ap_id, follower_address: follower_address} = user, _) do
|
|
||||||
with data <- %{
|
|
||||||
"to" => [follower_address],
|
|
||||||
"type" => "Delete",
|
|
||||||
"actor" => ap_id,
|
|
||||||
"object" => %{"type" => "Person", "id" => ap_id}
|
|
||||||
},
|
|
||||||
{:ok, activity} <- insert(data, true, true, true),
|
|
||||||
:ok <- maybe_federate(activity) do
|
|
||||||
{:ok, user}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp do_delete(%Object{data: %{"id" => id, "actor" => actor}} = object, options) do
|
|
||||||
local = Keyword.get(options, :local, true)
|
|
||||||
activity_id = Keyword.get(options, :activity_id, nil)
|
|
||||||
actor = Keyword.get(options, :actor, actor)
|
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(actor)
|
|
||||||
to = (object.data["to"] || []) ++ (object.data["cc"] || [])
|
|
||||||
|
|
||||||
with create_activity <- Activity.get_create_by_object_ap_id(id),
|
|
||||||
data <-
|
|
||||||
%{
|
|
||||||
"type" => "Delete",
|
|
||||||
"actor" => actor,
|
|
||||||
"object" => id,
|
|
||||||
"to" => to,
|
|
||||||
"deleted_activity_id" => create_activity && create_activity.id
|
|
||||||
}
|
|
||||||
|> maybe_put("id", activity_id),
|
|
||||||
{:ok, activity} <- insert(data, local, false),
|
|
||||||
{:ok, object, _create_activity} <- Object.delete(object),
|
|
||||||
stream_out_participations(object, user),
|
|
||||||
_ <- decrease_replies_count_if_reply(object),
|
|
||||||
{:ok, _actor} <- decrease_note_count_if_public(user, object),
|
|
||||||
:ok <- maybe_federate(activity) do
|
|
||||||
{:ok, activity}
|
|
||||||
else
|
|
||||||
{:error, error} ->
|
|
||||||
Repo.rollback(error)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp do_delete(%Object{data: %{"type" => "Tombstone", "id" => ap_id}}, _) do
|
|
||||||
activity =
|
|
||||||
ap_id
|
|
||||||
|> Activity.Queries.by_object_id()
|
|
||||||
|> Activity.Queries.by_type("Delete")
|
|
||||||
|> Repo.one()
|
|
||||||
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec block(User.t(), User.t(), String.t() | nil, boolean()) ::
|
@spec block(User.t(), User.t(), String.t() | nil, boolean()) ::
|
||||||
{:ok, Activity.t()} | {:error, any()}
|
{:ok, Activity.t()} | {:error, any()}
|
||||||
def block(blocker, blocked, activity_id \\ nil, local \\ true) do
|
def block(blocker, blocked, activity_id \\ nil, local \\ true) do
|
||||||
|
|
|
@ -1331,143 +1331,6 @@ test "creates an undo activity for the last block" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "deletion" do
|
|
||||||
setup do: clear_config([:instance, :rewrite_policy])
|
|
||||||
|
|
||||||
test "it reverts deletion on error" do
|
|
||||||
note = insert(:note_activity)
|
|
||||||
object = Object.normalize(note)
|
|
||||||
|
|
||||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
|
||||||
assert {:error, :reverted} = ActivityPub.delete(object)
|
|
||||||
end
|
|
||||||
|
|
||||||
assert Repo.aggregate(Activity, :count, :id) == 1
|
|
||||||
assert Repo.get(Object, object.id) == object
|
|
||||||
assert Activity.get_by_id(note.id) == note
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it creates a delete activity and deletes the original object" do
|
|
||||||
note = insert(:note_activity)
|
|
||||||
object = Object.normalize(note)
|
|
||||||
{:ok, delete} = ActivityPub.delete(object)
|
|
||||||
|
|
||||||
assert delete.data["type"] == "Delete"
|
|
||||||
assert delete.data["actor"] == note.data["actor"]
|
|
||||||
assert delete.data["object"] == object.data["id"]
|
|
||||||
|
|
||||||
assert Activity.get_by_id(delete.id) != nil
|
|
||||||
|
|
||||||
assert Repo.get(Object, object.id).data["type"] == "Tombstone"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it doesn't fail when an activity was already deleted" do
|
|
||||||
{:ok, delete} = insert(:note_activity) |> Object.normalize() |> ActivityPub.delete()
|
|
||||||
|
|
||||||
assert {:ok, ^delete} = delete |> Object.normalize() |> ActivityPub.delete()
|
|
||||||
end
|
|
||||||
|
|
||||||
test "decrements user note count only for public activities" do
|
|
||||||
user = insert(:user, note_count: 10)
|
|
||||||
|
|
||||||
{:ok, a1} =
|
|
||||||
CommonAPI.post(User.get_cached_by_id(user.id), %{
|
|
||||||
"status" => "yeah",
|
|
||||||
"visibility" => "public"
|
|
||||||
})
|
|
||||||
|
|
||||||
{:ok, a2} =
|
|
||||||
CommonAPI.post(User.get_cached_by_id(user.id), %{
|
|
||||||
"status" => "yeah",
|
|
||||||
"visibility" => "unlisted"
|
|
||||||
})
|
|
||||||
|
|
||||||
{:ok, a3} =
|
|
||||||
CommonAPI.post(User.get_cached_by_id(user.id), %{
|
|
||||||
"status" => "yeah",
|
|
||||||
"visibility" => "private"
|
|
||||||
})
|
|
||||||
|
|
||||||
{:ok, a4} =
|
|
||||||
CommonAPI.post(User.get_cached_by_id(user.id), %{
|
|
||||||
"status" => "yeah",
|
|
||||||
"visibility" => "direct"
|
|
||||||
})
|
|
||||||
|
|
||||||
{:ok, _} = Object.normalize(a1) |> ActivityPub.delete()
|
|
||||||
{:ok, _} = Object.normalize(a2) |> ActivityPub.delete()
|
|
||||||
{:ok, _} = Object.normalize(a3) |> ActivityPub.delete()
|
|
||||||
{:ok, _} = Object.normalize(a4) |> ActivityPub.delete()
|
|
||||||
|
|
||||||
user = User.get_cached_by_id(user.id)
|
|
||||||
assert user.note_count == 10
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do
|
|
||||||
user = insert(:user)
|
|
||||||
note = insert(:note_activity)
|
|
||||||
object = Object.normalize(note)
|
|
||||||
|
|
||||||
{:ok, object} =
|
|
||||||
object
|
|
||||||
|> Object.change(%{
|
|
||||||
data: %{
|
|
||||||
"actor" => object.data["actor"],
|
|
||||||
"id" => object.data["id"],
|
|
||||||
"to" => [user.ap_id],
|
|
||||||
"type" => "Note"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|> Object.update_and_set_cache()
|
|
||||||
|
|
||||||
{:ok, delete} = ActivityPub.delete(object)
|
|
||||||
|
|
||||||
assert user.ap_id in delete.data["to"]
|
|
||||||
end
|
|
||||||
|
|
||||||
test "decreases reply count" do
|
|
||||||
user = insert(:user)
|
|
||||||
user2 = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "1", "visibility" => "public"})
|
|
||||||
reply_data = %{"status" => "1", "in_reply_to_status_id" => activity.id}
|
|
||||||
ap_id = activity.data["id"]
|
|
||||||
|
|
||||||
{:ok, public_reply} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "public"))
|
|
||||||
{:ok, unlisted_reply} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "unlisted"))
|
|
||||||
{:ok, private_reply} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "private"))
|
|
||||||
{:ok, direct_reply} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "direct"))
|
|
||||||
|
|
||||||
_ = CommonAPI.delete(direct_reply.id, user2)
|
|
||||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
|
||||||
assert object.data["repliesCount"] == 2
|
|
||||||
|
|
||||||
_ = CommonAPI.delete(private_reply.id, user2)
|
|
||||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
|
||||||
assert object.data["repliesCount"] == 2
|
|
||||||
|
|
||||||
_ = CommonAPI.delete(public_reply.id, user2)
|
|
||||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
|
||||||
assert object.data["repliesCount"] == 1
|
|
||||||
|
|
||||||
_ = CommonAPI.delete(unlisted_reply.id, user2)
|
|
||||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
|
||||||
assert object.data["repliesCount"] == 0
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it passes delete activity through MRF before deleting the object" do
|
|
||||||
Pleroma.Config.put([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.DropPolicy)
|
|
||||||
|
|
||||||
note = insert(:note_activity)
|
|
||||||
object = Object.normalize(note)
|
|
||||||
|
|
||||||
{:error, {:reject, _}} = ActivityPub.delete(object)
|
|
||||||
|
|
||||||
assert Activity.get_by_id(note.id)
|
|
||||||
assert Repo.get(Object, object.id).data["type"] == object.data["type"]
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue