summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/mastodon_api/views/custom_emoji_view.ex
blob: 7d2d605e9c5132bc74a034e9db36b74c48984288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.MastodonAPI.CustomEmojiView do
  use Pleroma.Web, :view

  alias Pleroma.Emoji
  alias Pleroma.Web.Endpoint

  def render("index.json", %{custom_emojis: custom_emojis}) do
    render_many(custom_emojis, __MODULE__, "show.json")
  end

  def render("show.json", %{custom_emoji: {shortcode, %Emoji{file: relative_url, tags: tags}}}) do
    url = Endpoint.url() |> URI.merge(relative_url) |> to_string()

    %{
      "shortcode" => shortcode,
      "static_url" => url,
      "visible_in_picker" => true,
      "url" => url,
      "tags" => tags,
      # Assuming that a comma is authorized in the category name
      "category" => tags |> List.delete("Custom") |> Enum.join(",")
    }
  end
end