9993480dbe224262d92e08f6a28779ca7d73d9a1
[akkoma] / lib / pleroma / web / pleroma_api / views / emoji_reaction_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.PleromaAPI.EmojiReactionView do
6 use Pleroma.Web, :view
7
8 alias Pleroma.Web.MastodonAPI.AccountView
9 alias Pleroma.Web.MediaProxy
10
11 def render("index.json", %{emoji_reactions: emoji_reactions} = opts) do
12 render_many(emoji_reactions, __MODULE__, "show.json", opts)
13 end
14
15 def render("show.json", %{emoji_reaction: {emoji, user_ap_ids, url}, user: user}) do
16 users = fetch_users(user_ap_ids)
17
18 %{
19 name: emoji,
20 count: length(users),
21 accounts: render(AccountView, "index.json", users: users, for: user),
22 url: MediaProxy.url(url),
23 me: !!(user && user.ap_id in user_ap_ids)
24 }
25 end
26
27 defp fetch_users(user_ap_ids) do
28 user_ap_ids
29 |> Enum.map(&Pleroma.User.get_cached_by_ap_id/1)
30 |> Enum.filter(fn
31 %{is_active: true} -> true
32 _ -> false
33 end)
34 end
35 end