activitypub: use Object.delete() instead of mutating the database and cache directly

This commit is contained in:
William Pitcock 2018-11-01 07:29:12 +00:00
parent c4e43da63e
commit 2bf358d7b4
2 changed files with 2 additions and 4 deletions

View File

@ -273,8 +273,7 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru
"to" => [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"]
}
with Repo.delete(object),
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
with Object.delete(object),
{:ok, activity} <- insert(data, local),
:ok <- maybe_federate(activity),
{:ok, _actor} <- User.decrease_note_count(user) do

View File

@ -9,8 +9,7 @@ def delete(activity_id, user) do
with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
%Object{} = object <- Object.normalize(object_id),
true <- user.info["is_moderator"] || user.ap_id == object.data["actor"],
{:ok, delete} <- ActivityPub.delete(object),
{:ok, true} <- Cachex.del(:user_cache, "object:#{object_id}") do
{:ok, delete} <- ActivityPub.delete(object) do
{:ok, delete}
end
end