Revert Activity tombstones, add ObjectTombstone struct
This commit is contained in:
parent
2bbec33c71
commit
f75f707f6c
9 changed files with 43 additions and 62 deletions
|
|
@ -1,6 +1,6 @@
|
|||
defmodule Pleroma.Object do
|
||||
use Ecto.Schema
|
||||
alias Pleroma.{Repo, Object, User, Activity}
|
||||
alias Pleroma.{Repo, Object, User, Activity, ObjectTombstone}
|
||||
import Ecto.{Query, Changeset}
|
||||
|
||||
schema "objects" do
|
||||
|
|
@ -62,16 +62,17 @@ defmodule Pleroma.Object do
|
|||
Object.change(%Object{}, %{data: %{"id" => context}})
|
||||
end
|
||||
|
||||
def get_tombstone(%Object{data: data}, deleted \\ DateTime.utc_now()) do
|
||||
%{
|
||||
id: data["id"],
|
||||
type: "Tombstone",
|
||||
def make_tombstone(%Object{data: %{"id" => id, "type" => type}}, deleted \\ DateTime.utc_now()) do
|
||||
%ObjectTombstone{
|
||||
id: id,
|
||||
formerType: type,
|
||||
deleted: deleted
|
||||
}
|
||||
|> Map.from_struct()
|
||||
end
|
||||
|
||||
def swap_data_with_tombstone(object) do
|
||||
tombstone = get_tombstone(object)
|
||||
def swap_object_with_tombstone(object) do
|
||||
tombstone = make_tombstone(object)
|
||||
|
||||
object
|
||||
|> Object.change(%{data: tombstone})
|
||||
|
|
@ -79,10 +80,8 @@ defmodule Pleroma.Object do
|
|||
end
|
||||
|
||||
def delete(%Object{data: %{"id" => id}} = object) do
|
||||
with swap_data_with_tombstone(object),
|
||||
Activity.all_non_create_by_object_ap_id_q(id)
|
||||
|> Repo.all()
|
||||
|> Enum.each(&Activity.swap_data_with_tombstone/1),
|
||||
with {:ok, _obj} = swap_object_with_tombstone(object),
|
||||
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
||||
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
|
||||
{:ok, object}
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue