2020-05-19 13:50:49 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-19 13:50:49 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.PleromaAPI.EmojiReactionView do
|
|
|
|
use Pleroma.Web, :view
|
|
|
|
|
|
|
|
alias Pleroma.Web.MastodonAPI.AccountView
|
|
|
|
|
|
|
|
def render("index.json", %{emoji_reactions: emoji_reactions} = opts) do
|
|
|
|
render_many(emoji_reactions, __MODULE__, "show.json", opts)
|
|
|
|
end
|
|
|
|
|
2020-11-16 11:23:25 -07:00
|
|
|
def render("show.json", %{emoji_reaction: {emoji, user_ap_ids}, user: user}) do
|
2020-05-19 13:50:49 -06:00
|
|
|
users = fetch_users(user_ap_ids)
|
|
|
|
|
|
|
|
%{
|
|
|
|
name: emoji,
|
|
|
|
count: length(users),
|
2020-07-22 10:06:00 -06:00
|
|
|
accounts: render(AccountView, "index.json", users: users, for: user),
|
2020-05-19 13:50:49 -06:00
|
|
|
me: !!(user && user.ap_id in user_ap_ids)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp fetch_users(user_ap_ids) do
|
|
|
|
user_ap_ids
|
|
|
|
|> Enum.map(&Pleroma.User.get_cached_by_ap_id/1)
|
|
|
|
|> Enum.filter(fn
|
2020-10-12 16:42:27 -06:00
|
|
|
%{is_active: true} -> true
|
2020-05-19 13:50:49 -06:00
|
|
|
_ -> false
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|