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
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(
+++ /dev/null
-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