forked from AkkomaGang/akkoma
SideEffects: Handle strange deletion case.
This commit is contained in:
parent
e08ea01d09
commit
7e4932362b
2 changed files with 28 additions and 3 deletions
|
@ -22,6 +22,8 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||||
alias Pleroma.Web.Streamer
|
alias Pleroma.Web.Streamer
|
||||||
alias Pleroma.Workers.BackgroundWorker
|
alias Pleroma.Workers.BackgroundWorker
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
def handle(object, meta \\ [])
|
def handle(object, meta \\ [])
|
||||||
|
|
||||||
# Tasks this handle
|
# Tasks this handle
|
||||||
|
@ -217,13 +219,15 @@ def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do
|
||||||
# - Stream out the activity
|
# - Stream out the activity
|
||||||
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)
|
||||||
|
|
||||||
result =
|
result =
|
||||||
case deleted_object do
|
case deleted_object do
|
||||||
%Object{} ->
|
%Object{} ->
|
||||||
with {:ok, deleted_object, activity} <- Object.delete(deleted_object),
|
with {:ok, deleted_object, activity} <- Object.delete(deleted_object),
|
||||||
%User{} = user <- User.get_cached_by_ap_id(deleted_object.data["actor"]) do
|
{_, actor} when is_binary(actor) <- {:actor, deleted_object.data["actor"]},
|
||||||
|
%User{} = user <- User.get_cached_by_ap_id(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)
|
{:ok, user} = ActivityPub.decrease_note_count_if_public(user, deleted_object)
|
||||||
|
@ -237,6 +241,10 @@ def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = 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
|
||||||
|
else
|
||||||
|
{:actor, _} ->
|
||||||
|
Logger.error("The object doesn't have an actor: #{inspect(deleted_object)}")
|
||||||
|
:no_object_actor
|
||||||
end
|
end
|
||||||
|
|
||||||
%User{} ->
|
%User{} ->
|
||||||
|
|
|
@ -19,8 +19,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
||||||
alias Pleroma.Web.ActivityPub.SideEffects
|
alias Pleroma.Web.ActivityPub.SideEffects
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
import Pleroma.Factory
|
import ExUnit.CaptureLog
|
||||||
import Mock
|
import Mock
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "handle_after_transaction" do
|
describe "handle_after_transaction" do
|
||||||
test "it streams out notifications and streams" do
|
test "it streams out notifications and streams" do
|
||||||
|
@ -221,6 +222,22 @@ test "it handles user deletions", %{delete_user: delete, user: user} do
|
||||||
|
|
||||||
assert User.get_cached_by_ap_id(user.ap_id).deactivated
|
assert User.get_cached_by_ap_id(user.ap_id).deactivated
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it logs issues with objects deletion", %{
|
||||||
|
delete: delete,
|
||||||
|
object: object
|
||||||
|
} do
|
||||||
|
{:ok, object} =
|
||||||
|
object
|
||||||
|
|> Object.change(%{data: Map.delete(object.data, "actor")})
|
||||||
|
|> Repo.update()
|
||||||
|
|
||||||
|
Object.invalid_object_cache(object)
|
||||||
|
|
||||||
|
assert capture_log(fn ->
|
||||||
|
{:error, :no_object_actor} = SideEffects.handle(delete)
|
||||||
|
end) =~ "object doesn't have an actor"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "EmojiReact objects" do
|
describe "EmojiReact objects" do
|
||||||
|
|
Loading…
Reference in a new issue