From 7bcb6a183a13cabd32bafd0e3ca20f8ca543565b Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov <ivantashkinov@gmail.com>
Date: Thu, 6 Dec 2018 20:23:16 +0300
Subject: [PATCH] [#394] Refactoring.

---
 lib/pleroma/user.ex                                | 11 +++++------
 lib/pleroma/web/mastodon_api/views/account_view.ex |  2 +-
 lib/pleroma/web/twitter_api/views/user_view.ex     |  2 +-
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 24bc80894..3984e610e 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -846,12 +846,7 @@ defmodule Pleroma.User do
 
     Repo.transaction(fn ->
       for user <- users do
-        new_tags =
-          if action == :tag do
-            Enum.uniq(user.tags ++ tags)
-          else
-            user.tags -- tags
-          end
+        new_tags = mutate_tags(user, tags, action)
 
         {:ok, updated_user} =
           user
@@ -862,4 +857,8 @@ defmodule Pleroma.User do
       end
     end)
   end
+
+  defp mutate_tags(user, tags, :tag), do: Enum.uniq(user.tags ++ tags)
+
+  defp mutate_tags(user, tags, :untag), do: user.tags -- tags
 end
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 0add1b686..2762813ae 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -59,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
         privacy: user_info.default_scope,
         sensitive: false
       },
-      # Note: Mastodon does not return this field:
+      # Pleroma extension
       tags: user.tags
     }
   end
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index dae656372..f460ddd80 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -78,7 +78,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
       "default_scope" => user.info.default_scope,
       "no_rich_text" => user.info.no_rich_text,
       "fields" => fields,
-      # Note: twitter.com does not return this field:
+      # Pleroma extension
       "tags" => user.tags
     }