Create tombstone instead of object deletion
This commit is contained in:
parent
61a88a6757
commit
0f412cf6e6
8 changed files with 74 additions and 8 deletions
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Pleroma.Activity do
|
||||
use Ecto.Schema
|
||||
alias Pleroma.{Repo, Activity, Notification}
|
||||
import Ecto.Query
|
||||
import Ecto.{Query, Changeset}
|
||||
|
||||
# https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
|
||||
@mastodon_notification_types %{
|
||||
|
|
@ -103,4 +103,22 @@ defmodule Pleroma.Activity do
|
|||
end
|
||||
|
||||
def mastodon_notification_type(%Activity{}), do: nil
|
||||
|
||||
def get_tombstone(%Activity{data: data}, deleted \\ DateTime.utc_now()) do
|
||||
%{
|
||||
id: data["id"],
|
||||
context: data["context"],
|
||||
type: "tombstone",
|
||||
published: data["published"],
|
||||
deleted: deleted
|
||||
}
|
||||
end
|
||||
|
||||
def swap_data_with_tombstone(activity) do
|
||||
tombstone = get_tombstone(activity)
|
||||
|
||||
activity
|
||||
|> change(%{data: tombstone})
|
||||
|> Repo.update()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -62,9 +62,27 @@ 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",
|
||||
deleted: deleted
|
||||
}
|
||||
end
|
||||
|
||||
def swap_data_with_tombstone(object) do
|
||||
tombstone = get_tombstone(object)
|
||||
|
||||
object
|
||||
|> Object.change(%{data: tombstone})
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def delete(%Object{data: %{"id" => id}} = object) do
|
||||
with Repo.delete(object),
|
||||
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
||||
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),
|
||||
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
|
||||
{:ok, object}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -69,7 +69,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
mentioned_users = Enum.map(mentions, fn {_, %{ap_id: ap_id}} -> ap_id end)
|
||||
|
||||
if inReplyTo do
|
||||
{Enum.uniq([inReplyTo.data["actor"] | mentioned_users]), []}
|
||||
to =
|
||||
[inReplyTo.data["actor"] | mentioned_users]
|
||||
|> Enum.uniq()
|
||||
|> Enum.reject(&is_nil/1)
|
||||
|
||||
{to, []}
|
||||
else
|
||||
{mentioned_users, []}
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue