aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/tag.ex37
-rw-r--r--lib/pleroma/user.ex9
-rw-r--r--lib/pleroma/web/admin_api/controllers/tag_controller.ex6
3 files changed, 38 insertions, 14 deletions
diff --git a/lib/pleroma/tag.ex b/lib/pleroma/tag.ex
new file mode 100644
index 000000000..16d0b0eda
--- /dev/null
+++ b/lib/pleroma/tag.ex
@@ -0,0 +1,37 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Tag do
+ use Ecto.Schema
+
+ import Ecto.Query
+
+ alias Pleroma.Repo
+ alias Pleroma.Web.ActivityPub.MRF
+
+ @type t :: %__MODULE__{}
+
+ schema "tags" do
+ field(:name, :string)
+
+ timestamps()
+ end
+
+ @spec upsert(String.t()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
+ def upsert(name) do
+ %__MODULE__{}
+ |> Ecto.Changeset.change(name: name)
+ |> Ecto.Changeset.unique_constraint(:name)
+ |> Repo.insert(on_conflict: :nothing, conflict_target: :name)
+ end
+
+ @spec list_tags() :: list(String.t())
+ def list_tags do
+ from(u in __MODULE__, select: u.name)
+ |> Repo.all()
+ |> Kernel.++(MRF.TagPolicy.policy_tags())
+ |> Enum.uniq()
+ |> Enum.sort()
+ end
+end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 5cbe5bb75..c1aa0f716 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -1259,15 +1259,6 @@ defmodule Pleroma.User do
|> Repo.all()
end
- @spec list_tags() :: list(String.t())
- def list_tags do
- from(
- u in __MODULE__,
- select: type(fragment("DISTINCT unnest(?)", u.tags), :string)
- )
- |> Repo.all()
- end
-
def increase_note_count(%User{} = user) do
User
|> where(id: ^user.id)
diff --git a/lib/pleroma/web/admin_api/controllers/tag_controller.ex b/lib/pleroma/web/admin_api/controllers/tag_controller.ex
index 9419bf31e..60b5d2ab9 100644
--- a/lib/pleroma/web/admin_api/controllers/tag_controller.ex
+++ b/lib/pleroma/web/admin_api/controllers/tag_controller.ex
@@ -25,11 +25,7 @@ defmodule Pleroma.Web.AdminAPI.TagController do
action_fallback(AdminAPI.FallbackController)
def list(%{assigns: %{user: _admin}} = conn, _) do
- tags =
- Pleroma.User.list_tags()
- |> Kernel.++(Pleroma.Web.ActivityPub.MRF.TagPolicy.policy_tags())
- |> Enum.uniq()
- |> Enum.sort()
+ tags = Pleroma.Tag.list_tags()
json(conn, tags)
end