SideEffects: On deletion, reduce the User note count.
This commit is contained in:
parent
3d0dc58e2e
commit
ab60ee1776
|
@ -34,6 +34,7 @@ def handle(%{data: %{"type" => "Like"}} = object, meta) do
|
||||||
# - Delete and unpins the create activity
|
# - Delete and unpins the create activity
|
||||||
# - Replace object with Tombstone
|
# - Replace object with Tombstone
|
||||||
# - Set up notification
|
# - Set up notification
|
||||||
|
# - Reduce the user note count
|
||||||
def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
|
def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
|
||||||
deleted_object =
|
deleted_object =
|
||||||
Object.normalize(deleted_object, false) || User.get_cached_by_ap_id(deleted_object)
|
Object.normalize(deleted_object, false) || User.get_cached_by_ap_id(deleted_object)
|
||||||
|
@ -45,6 +46,7 @@ def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object,
|
||||||
%User{} = user <- User.get_cached_by_ap_id(deleted_object.data["actor"]) do
|
%User{} = user <- User.get_cached_by_ap_id(deleted_object.data["actor"]) do
|
||||||
User.remove_pinnned_activity(user, activity)
|
User.remove_pinnned_activity(user, activity)
|
||||||
|
|
||||||
|
{:ok, user} = ActivityPub.decrease_note_count_if_public(user, deleted_object)
|
||||||
ActivityPub.stream_out(object)
|
ActivityPub.stream_out(object)
|
||||||
ActivityPub.stream_out_participations(deleted_object, user)
|
ActivityPub.stream_out_participations(deleted_object, user)
|
||||||
:ok
|
:ok
|
||||||
|
|
|
@ -32,15 +32,16 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
||||||
%{user: user, delete: delete, post: post, object: object, delete_user: delete_user}
|
%{user: user, delete: delete, post: post, object: object, delete_user: delete_user}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it handles object deletions", %{delete: delete, post: post, object: object} do
|
test "it handles object deletions", %{delete: delete, post: post, object: object, user: user} do
|
||||||
# In object deletions, the object is replaced by a tombstone and the
|
# In object deletions, the object is replaced by a tombstone and the
|
||||||
# create activity is deleted.
|
# create activity is deleted.
|
||||||
|
|
||||||
with_mock Pleroma.Web.ActivityPub.ActivityPub,
|
with_mock Pleroma.Web.ActivityPub.ActivityPub, [:passthrough],
|
||||||
stream_out: fn _ -> nil end,
|
stream_out: fn _ -> nil end,
|
||||||
stream_out_participations: fn _, _ -> nil end do
|
stream_out_participations: fn _, _ -> nil end do
|
||||||
{:ok, delete, _} = SideEffects.handle(delete)
|
{:ok, delete, _} = SideEffects.handle(delete)
|
||||||
user = User.get_cached_by_ap_id(object.data["actor"])
|
user = User.get_cached_by_ap_id(object.data["actor"])
|
||||||
|
|
||||||
assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out(delete))
|
assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out(delete))
|
||||||
assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out_participations(object, user))
|
assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out_participations(object, user))
|
||||||
end
|
end
|
||||||
|
@ -48,6 +49,9 @@ test "it handles object deletions", %{delete: delete, post: post, object: object
|
||||||
object = Object.get_by_id(object.id)
|
object = Object.get_by_id(object.id)
|
||||||
assert object.data["type"] == "Tombstone"
|
assert object.data["type"] == "Tombstone"
|
||||||
refute Activity.get_by_id(post.id)
|
refute Activity.get_by_id(post.id)
|
||||||
|
|
||||||
|
user = User.get_by_id(user.id)
|
||||||
|
assert user.note_count == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it handles user deletions", %{delete_user: delete, user: user} do
|
test "it handles user deletions", %{delete_user: delete, user: user} do
|
||||||
|
|
Loading…
Reference in a new issue