Merge branch 'issue/1880' into 'develop'
[#1880] fixed delete `Like` activity in remove user See merge request pleroma/pleroma!2725
This commit is contained in:
commit
8be0c04b40
|
@ -209,14 +209,20 @@ def handle_object_creation(object) do
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_undoing(%{data: %{"type" => "Like"}} = object) do
|
defp undo_like(nil, object), do: delete_object(object)
|
||||||
with %Object{} = liked_object <- Object.get_by_ap_id(object.data["object"]),
|
|
||||||
{:ok, _} <- Utils.remove_like_from_object(object, liked_object),
|
defp undo_like(%Object{} = liked_object, object) do
|
||||||
{:ok, _} <- Repo.delete(object) do
|
with {:ok, _} <- Utils.remove_like_from_object(object, liked_object) do
|
||||||
:ok
|
delete_object(object)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_undoing(%{data: %{"type" => "Like"}} = object) do
|
||||||
|
object.data["object"]
|
||||||
|
|> Object.get_by_ap_id()
|
||||||
|
|> undo_like(object)
|
||||||
|
end
|
||||||
|
|
||||||
def handle_undoing(%{data: %{"type" => "EmojiReact"}} = object) do
|
def handle_undoing(%{data: %{"type" => "EmojiReact"}} = object) do
|
||||||
with %Object{} = reacted_object <- Object.get_by_ap_id(object.data["object"]),
|
with %Object{} = reacted_object <- Object.get_by_ap_id(object.data["object"]),
|
||||||
{:ok, _} <- Utils.remove_emoji_reaction_from_object(object, reacted_object),
|
{:ok, _} <- Utils.remove_emoji_reaction_from_object(object, reacted_object),
|
||||||
|
@ -246,6 +252,11 @@ def handle_undoing(
|
||||||
|
|
||||||
def handle_undoing(object), do: {:error, ["don't know how to handle", object]}
|
def handle_undoing(object), do: {:error, ["don't know how to handle", object]}
|
||||||
|
|
||||||
|
@spec delete_object(Object.t()) :: :ok | {:error, Ecto.Changeset.t()}
|
||||||
|
defp delete_object(object) do
|
||||||
|
with {:ok, _} <- Repo.delete(object), do: :ok
|
||||||
|
end
|
||||||
|
|
||||||
defp send_notifications(meta) do
|
defp send_notifications(meta) do
|
||||||
Keyword.get(meta, :notifications, [])
|
Keyword.get(meta, :notifications, [])
|
||||||
|> Enum.each(fn notification ->
|
|> Enum.each(fn notification ->
|
||||||
|
|
|
@ -110,7 +110,23 @@ test "user is deleted" do
|
||||||
|
|
||||||
test "a remote user's create activity is deleted when the object has been pruned" do
|
test "a remote user's create activity is deleted when the object has been pruned" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
user2 = insert(:user)
|
||||||
|
|
||||||
{:ok, post} = CommonAPI.post(user, %{status: "uguu"})
|
{:ok, post} = CommonAPI.post(user, %{status: "uguu"})
|
||||||
|
{:ok, post2} = CommonAPI.post(user2, %{status: "test"})
|
||||||
|
obj = Object.normalize(post2)
|
||||||
|
|
||||||
|
{:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj)
|
||||||
|
|
||||||
|
{:ok, like_activity, _meta} =
|
||||||
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
|
||||||
|
like_object,
|
||||||
|
Keyword.put(meta, :local, true)
|
||||||
|
)
|
||||||
|
|
||||||
|
like_activity.data["object"]
|
||||||
|
|> Pleroma.Object.get_by_ap_id()
|
||||||
|
|> Repo.delete()
|
||||||
|
|
||||||
clear_config([:instance, :federating], true)
|
clear_config([:instance, :federating], true)
|
||||||
|
|
||||||
|
@ -127,6 +143,7 @@ test "a remote user's create activity is deleted when the object has been pruned
|
||||||
assert %{deactivated: true} = User.get_by_nickname(user.nickname)
|
assert %{deactivated: true} = User.get_by_nickname(user.nickname)
|
||||||
|
|
||||||
assert called(Pleroma.Web.Federator.publish(:_))
|
assert called(Pleroma.Web.Federator.publish(:_))
|
||||||
|
refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
refute Activity.get_by_id(post.id)
|
refute Activity.get_by_id(post.id)
|
||||||
|
|
Loading…
Reference in a new issue