Move unsubscribe user task to pleroma/user.ex. Delete unsubscribe_user.ex. Fix plerom...
authorRin Toshaka <rinpatch@sdf.org>
Sun, 2 Dec 2018 17:05:59 +0000 (18:05 +0100)
committerRin Toshaka <rinpatch@sdf.org>
Sun, 2 Dec 2018 17:05:59 +0000 (18:05 +0100)
lib/mix/tasks/pleroma/user.ex
lib/mix/tasks/unsubscribe_user.ex [deleted file]

index d7a6be84495b4658a83cb9e452781871f41eb018..d7e17299464a7032a1690fd79e1f1682582ef891 100644 (file)
@@ -132,12 +132,12 @@ defmodule Mix.Tasks.Pleroma.User do
   def run(["toggle_activated", nickname]) do
     Mix.Task.run("app.start")
 
-    with %User{local: true} = user <- User.get_by_nickname(nickname) do
+    with %User{} = user <- User.get_by_nickname(nickname) do
       User.deactivate(user, !user.info["deactivated"])
       Mix.shell().info("Activation status of #{nickname}: #{user.info["deactivated"]}")
     else
       _ ->
-        Mix.shell().error("No local user #{nickname}")
+        Mix.shell().error("No user #{nickname}")
     end
   end
 
@@ -163,6 +163,35 @@ defmodule Mix.Tasks.Pleroma.User do
     end
   end
 
+  def run(["unsubscribe", nickname]) do
+    Mix.Task.run("app.start")
+
+    with %User{} = user <- User.get_by_nickname(nickname) do
+      Mix.shell().info("Deactivating #{user.nickname}")
+      User.deactivate(user)
+
+      {:ok, friends} = User.get_friends(user)
+
+      Enum.each(friends, fn friend ->
+        user = Repo.get(User, user.id)
+
+        Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
+        User.unfollow(user, friend)
+      end)
+
+      :timer.sleep(500)
+
+      user = Repo.get(User, user.id)
+
+      if length(user.following) == 0 do
+        Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
+      end
+    else
+      _ ->
+        Mix.shell().error("No user #{nickname}")
+    end
+  end
+
   def run(["set", nickname | rest]) do
     {options, [], []} =
       OptionParser.parse(
diff --git a/lib/mix/tasks/unsubscribe_user.ex b/lib/mix/tasks/unsubscribe_user.ex
deleted file mode 100644 (file)
index 62ea61a..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-defmodule Mix.Tasks.UnsubscribeUser do
-  use Mix.Task
-  alias Pleroma.{User, Repo}
-  require Logger
-
-  @moduledoc """
-  Deactivate and Unsubscribe local users from a user
-
-  Usage: ``mix unsubscribe_user <nickname>``
-
-  Example: ``mix unsubscribe_user lain``
-  """
-  def run([nickname]) do
-    Mix.Task.run("app.start")
-
-    with %User{} = user <- User.get_by_nickname(nickname) do
-      Logger.info("Deactivating #{user.nickname}")
-      User.deactivate(user)
-
-      {:ok, friends} = User.get_friends(user)
-
-      Enum.each(friends, fn friend ->
-        user = Repo.get(User, user.id)
-
-        Logger.info("Unsubscribing #{friend.nickname} from #{user.nickname}")
-        User.unfollow(user, friend)
-      end)
-
-      :timer.sleep(500)
-
-      user = Repo.get(User, user.id)
-
-      if length(user.following) == 0 do
-        Logger.info("Successfully unsubscribed all followers from #{user.nickname}")
-      end
-    end
-  end
-end