Fix incorrect multiple emoji tag handling introduced in initial impl
[akkoma] / lib / pleroma / web / twitter_api / representers / base_representer.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do
6 defmacro __using__(_opts) do
7 quote do
8 def to_json(object) do
9 to_json(object, %{})
10 end
11
12 def to_json(object, options) do
13 object
14 |> to_map(options)
15 |> Jason.encode!()
16 end
17
18 def enum_to_list(enum, options) do
19 mapping = fn el -> to_map(el, options) end
20 Enum.map(enum, mapping)
21 end
22
23 def to_map(object) do
24 to_map(object, %{})
25 end
26
27 def enum_to_json(enum) do
28 enum_to_json(enum, %{})
29 end
30
31 def enum_to_json(enum, options) do
32 enum
33 |> enum_to_list(options)
34 |> Jason.encode!()
35 end
36 end
37 end
38 end