X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Femoji%2Floader.ex;h=67acd7069ac6f10fa75691ea55e6c89bf03d2e49;hb=3989ec508c00a66d9093ead06deb8b1272b0b985;hp=82fc3b8c34b9834ef155cb3313744ddc7b3dd176;hpb=5c90b7073332ac333a5db9dfc82744cee03843fa;p=akkoma
diff --git a/lib/pleroma/emoji/loader.ex b/lib/pleroma/emoji/loader.ex
index 82fc3b8c3..67acd7069 100644
--- a/lib/pleroma/emoji/loader.ex
+++ b/lib/pleroma/emoji/loader.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emoji.Loader do
@@ -11,13 +11,16 @@ defmodule Pleroma.Emoji.Loader do
* glob paths, nested folder is used as tag name for grouping e.g. priv/static/emoji/custom/nested_folder
"""
alias Pleroma.Config
+ alias Pleroma.Emoji
require Logger
+ @mix_env Mix.env()
+
@type pattern :: Regex.t() | module() | String.t()
@type patterns :: pattern() | [pattern()]
@type group_patterns :: keyword(patterns())
- @type emoji :: {String.t(), String.t(), list(String.t())}
+ @type emoji :: {String.t(), Emoji.t()}
@doc """
Loads emojis from files/packs.
@@ -63,54 +66,74 @@ defmodule Pleroma.Emoji.Loader do
)
end
- Enum.flat_map(packs, fn pack ->
- load_pack(Path.join(emoji_dir_path, pack), emoji_groups)
- end)
+ emojis =
+ Enum.flat_map(packs, fn pack ->
+ load_pack(Path.join(emoji_dir_path, pack), emoji_groups)
+ end)
+
+ Emoji.clear_all()
+ emojis
end
# Compat thing for old custom emoji handling & default emoji,
# it should run even if there are no emoji packs
shortcode_globs = Config.get([:emoji, :shortcode_globs], [])
+ # for testing emoji.txt entries we do not want exposed in normal operation
+ test_emoji =
+ if @mix_env == :test do
+ load_from_file("test/config/emoji.txt", emoji_groups)
+ else
+ []
+ end
+
emojis_txt =
(load_from_file("config/emoji.txt", emoji_groups) ++
load_from_file("config/custom_emoji.txt", emoji_groups) ++
- load_from_globs(shortcode_globs, emoji_groups))
+ load_from_globs(shortcode_globs, emoji_groups) ++
+ test_emoji)
|> Enum.reject(fn value -> value == nil end)
Enum.map(emojis ++ emojis_txt, &prepare_emoji/1)
end
- defp prepare_emoji({code, file, tags} = _emoji) do
- {
- code,
- file,
- tags,
- Pleroma.HTML.strip_tags(code),
- Pleroma.HTML.strip_tags(file)
- }
- end
+ defp prepare_emoji({code, _, _} = emoji), do: {code, Emoji.build(emoji)}
defp load_pack(pack_dir, emoji_groups) do
pack_name = Path.basename(pack_dir)
- emoji_txt = Path.join(pack_dir, "emoji.txt")
+ pack_file = Path.join(pack_dir, "pack.json")
+
+ if File.exists?(pack_file) do
+ contents = Jason.decode!(File.read!(pack_file))
- if File.exists?(emoji_txt) do
- load_from_file(emoji_txt, emoji_groups)
+ contents["files"]
+ |> Enum.map(fn {name, rel_file} ->
+ filename = Path.join("/emoji/#{pack_name}", rel_file)
+ {name, filename, ["pack:#{pack_name}"]}
+ end)
else
- extensions = Config.get([:emoji, :pack_extensions])
+ # Load from emoji.txt / all files
+ emoji_txt = Path.join(pack_dir, "emoji.txt")
- Logger.info(
- "No emoji.txt found for pack \"#{pack_name}\", assuming all #{Enum.join(extensions, ", ")} files are emoji"
- )
+ if File.exists?(emoji_txt) do
+ load_from_file(emoji_txt, emoji_groups)
+ else
+ extensions = Config.get([:emoji, :pack_extensions])
- make_shortcode_to_file_map(pack_dir, extensions)
- |> Enum.map(fn {shortcode, rel_file} ->
- filename = Path.join("/emoji/#{pack_name}", rel_file)
+ Logger.info(
+ "No emoji.txt found for pack \"#{pack_name}\", assuming all #{
+ Enum.join(extensions, ", ")
+ } files are emoji"
+ )
- {shortcode, filename, [to_string(match_extra(emoji_groups, filename))]}
- end)
+ make_shortcode_to_file_map(pack_dir, extensions)
+ |> Enum.map(fn {shortcode, rel_file} ->
+ filename = Path.join("/emoji/#{pack_name}", rel_file)
+
+ {shortcode, filename, [to_string(match_extra(emoji_groups, filename))]}
+ end)
+ end
end
end