add `mix pleroma.user delete_activities NICKNAME` task
authorEgor Kislitsyn <egor@kislitsyn.com>
Tue, 12 Mar 2019 15:04:08 +0000 (22:04 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Tue, 12 Mar 2019 15:04:08 +0000 (22:04 +0700)
lib/mix/tasks/pleroma/user.ex
lib/pleroma/user.ex

index 037e4471679d5f6ce780b80437964f49fa38c661..e232df14f0fc1fa34f0f283c14a421900795882c 100644 (file)
@@ -304,6 +304,18 @@ defmodule Mix.Tasks.Pleroma.User do
     end
   end
 
+  def run(["delete_activities", nickname]) do
+    Common.start_pleroma()
+
+    with %User{local: true} = user <- User.get_by_nickname(nickname) do
+      User.delete_user_activities(user)
+      Mix.shell().info("User #{nickname} deleted.")
+    else
+      _ ->
+        Mix.shell().error("No local user #{nickname}")
+    end
+  end
+
   defp set_moderator(user, value) do
     info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value})
 
index 50e7e7ccd64f8a53877dcaf2cc25ae3be1463d4e..2d0a8cde4c055edfe568994e1c92f513e8f085f7 100644 (file)
@@ -1083,6 +1083,12 @@ defmodule Pleroma.User do
     friends
     |> Enum.each(fn followed -> User.unfollow(user, followed) end)
 
+    delete_user_activities(user)
+
+    {:ok, user}
+  end
+
+  def delete_user_activities(user) do
     query = from(a in Activity, where: a.actor == ^user.ap_id)
 
     Repo.all(query)
@@ -1096,8 +1102,6 @@ defmodule Pleroma.User do
           "Doing nothing"
       end
     end)
-
-    {:ok, user}
   end
 
   def html_filter_policy(%User{info: %{no_rich_text: true}}) do