110e8a041ffcfdd370c7d6d997e4868bcd9b5c6c
[akkoma] / lib / pleroma / web / pleroma_api / views / emoji_reaction_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
10 def render("index.json", %{emoji_reactions: emoji_reactions} = opts) do
11 render_many(emoji_reactions, __MODULE__, "show.json", opts)
12 end
13
14 def render("show.json", %{emoji_reaction: {emoji, user_ap_ids}, user: user}) do
15 users = fetch_users(user_ap_ids)
16
17 %{
18 name: emoji,
19 count: length(users),
20 accounts: render(AccountView, "index.json", users: users, for: user),
21 me: !!(user && user.ap_id in user_ap_ids)
22 }
23 end
24
25 defp fetch_users(user_ap_ids) do
26 user_ap_ids
27 |> Enum.map(&Pleroma.User.get_cached_by_ap_id/1)
28 |> Enum.filter(fn
29 %{deactivated: false} -> true
30 _ -> false
31 end)
32 end
33 end