Move unsubscribe user task to pleroma/user.ex. Delete unsubscribe_user.ex. Fix pleroma.user toggle_activated to work not only on local users.

This commit is contained in:
Rin Toshaka 2018-12-02 18:05:59 +01:00
parent 31b3ac05ac
commit 7983b0bdfe
2 changed files with 31 additions and 40 deletions

View File

@ -132,12 +132,12 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["toggle_activated", nickname]) do def run(["toggle_activated", nickname]) do
Mix.Task.run("app.start") 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"]) User.deactivate(user, !user.info["deactivated"])
Mix.shell().info("Activation status of #{nickname}: #{user.info["deactivated"]}") Mix.shell().info("Activation status of #{nickname}: #{user.info["deactivated"]}")
else else
_ -> _ ->
Mix.shell().error("No local user #{nickname}") Mix.shell().error("No user #{nickname}")
end end
end end
@ -163,6 +163,35 @@ defmodule Mix.Tasks.Pleroma.User do
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 def run(["set", nickname | rest]) do
{options, [], []} = {options, [], []} =
OptionParser.parse( OptionParser.parse(

View File

@ -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