1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Emoji do
7 This GenServer stores in an ETS table the list of the loaded emojis,
8 and also allows to reload the list at runtime.
12 alias Pleroma.Emoji.Loader
21 {:read_concurrency, true}
26 GenServer.start_link(__MODULE__, [], name: __MODULE__)
29 @doc "Reloads the emojis from disk."
32 GenServer.call(__MODULE__, :reload)
35 @doc "Returns the path of the emoji `name`."
36 @spec get(String.t()) :: String.t() | nil
38 case :ets.lookup(@ets, name) do
44 @doc "Returns all the emojos!!"
45 @spec get_all() :: list({String.t(), String.t(), String.t()})
52 @ets = :ets.new(@ets, @ets_options)
53 GenServer.cast(self(), :reload)
58 def handle_cast(:reload, state) do
59 update_emojis(Loader.load())
64 def handle_call(:reload, _from, state) do
65 update_emojis(Loader.load())
70 def terminate(_, _) do
75 def code_change(_old_vsn, state, _extra) do
76 update_emojis(Loader.load())
80 defp update_emojis(emojis) do
81 :ets.insert(@ets, emojis)