Add task to delete all user posts before their new expiry
This commit is contained in:
parent
d1af78aba1
commit
acbe507a2d
4 changed files with 37 additions and 4 deletions
|
@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
## Added
|
## Added
|
||||||
- Full compatibility with Erlang OTP26
|
- Full compatibility with Erlang OTP26
|
||||||
- handling of GET /api/v1/preferences
|
- handling of GET /api/v1/preferences
|
||||||
|
- Utility mix task to backfill user post expiry onto other posts
|
||||||
|
|
||||||
## Changed
|
## Changed
|
||||||
- OTP builds are now built on erlang OTP26
|
- OTP builds are now built on erlang OTP26
|
||||||
|
|
|
@ -342,6 +342,34 @@ defmodule Mix.Tasks.Pleroma.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run(["backfill_expiry", nickname]) do
|
||||||
|
start_pleroma()
|
||||||
|
|
||||||
|
with %User{ap_id: ap_id, local: true, status_ttl_days: days} = user <-
|
||||||
|
User.get_cached_by_nickname(nickname),
|
||||||
|
false <- is_nil(days) do
|
||||||
|
last_time =
|
||||||
|
Timex.now()
|
||||||
|
|> Timex.shift(days: -days)
|
||||||
|
|
||||||
|
ap_id
|
||||||
|
|> Pleroma.Activity.Queries.by_actor()
|
||||||
|
|> Pleroma.Activity.Queries.by_type("Create")
|
||||||
|
|> Pleroma.Activity.Queries.before_time(last_time)
|
||||||
|
|> Pleroma.Repo.chunk_stream(50, :batches)
|
||||||
|
|> Stream.each(fn activities ->
|
||||||
|
Enum.each(activities, fn activity ->
|
||||||
|
IO.inspect(activity.id)
|
||||||
|
User.delete_activity(activity, user)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|> Stream.run()
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
shell_error("No local user #{nickname}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def run(["delete_activities", nickname]) do
|
def run(["delete_activities", nickname]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,10 @@ defmodule Pleroma.Activity.Queries do
|
||||||
from(a in query, where: a.actor == ^ap_id)
|
from(a in query, where: a.actor == ^ap_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def before_time(query \\ Activity, time) do
|
||||||
|
from(a in query, where: a.inserted_at < ^time)
|
||||||
|
end
|
||||||
|
|
||||||
def find_by_object_ap_id(activities, object_ap_id) do
|
def find_by_object_ap_id(activities, object_ap_id) do
|
||||||
Enum.find(
|
Enum.find(
|
||||||
activities,
|
activities,
|
||||||
|
|
|
@ -1920,7 +1920,7 @@ defmodule Pleroma.User do
|
||||||
|> Stream.run()
|
|> Stream.run()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp delete_activity(%{data: %{"type" => "Create", "object" => object}} = activity, user) do
|
def delete_activity(%{data: %{"type" => "Create", "object" => object}} = activity, user) do
|
||||||
with {_, %Object{}} <- {:find_object, Object.get_by_ap_id(object)},
|
with {_, %Object{}} <- {:find_object, Object.get_by_ap_id(object)},
|
||||||
{:ok, delete_data, _} <- Builder.delete(user, object) do
|
{:ok, delete_data, _} <- Builder.delete(user, object) do
|
||||||
Pipeline.common_pipeline(delete_data, local: user.local)
|
Pipeline.common_pipeline(delete_data, local: user.local)
|
||||||
|
@ -1939,13 +1939,13 @@ defmodule Pleroma.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp delete_activity(%{data: %{"type" => type}} = activity, user)
|
def delete_activity(%{data: %{"type" => type}} = activity, user)
|
||||||
when type in ["Like", "Announce"] do
|
when type in ["Like", "Announce"] do
|
||||||
{:ok, undo, _} = Builder.undo(user, activity)
|
{:ok, undo, _} = Builder.undo(user, activity)
|
||||||
Pipeline.common_pipeline(undo, local: user.local)
|
Pipeline.common_pipeline(undo, local: user.local)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp delete_activity(_activity, _user), do: "Doing nothing"
|
def delete_activity(_activity, _user), do: "Doing nothing"
|
||||||
|
|
||||||
defp delete_outgoing_pending_follow_requests(user) do
|
defp delete_outgoing_pending_follow_requests(user) do
|
||||||
user
|
user
|
||||||
|
|
Loading…
Reference in a new issue