2020-05-19 19:50:49 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-19 19:50:49 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.PleromaAPI.EmojiReactionView do
|
|
|
|
use Pleroma.Web, :view
|
|
|
|
|
|
|
|
alias Pleroma.Web.MastodonAPI.AccountView
|
2022-06-08 16:19:42 +00:00
|
|
|
alias Pleroma.Web.MediaProxy
|
2020-05-19 19:50:49 +00:00
|
|
|
|
2022-09-04 23:31:41 +00:00
|
|
|
def emoji_name(emoji, nil), do: emoji
|
|
|
|
|
|
|
|
def emoji_name(emoji, url) do
|
|
|
|
url = URI.parse(url)
|
|
|
|
|
|
|
|
if url.host == Pleroma.Web.Endpoint.host() do
|
|
|
|
emoji
|
|
|
|
else
|
|
|
|
"#{emoji}@#{url.host}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-19 19:50:49 +00:00
|
|
|
def render("index.json", %{emoji_reactions: emoji_reactions} = opts) do
|
|
|
|
render_many(emoji_reactions, __MODULE__, "show.json", opts)
|
|
|
|
end
|
|
|
|
|
2022-06-08 01:42:44 +00:00
|
|
|
def render("show.json", %{emoji_reaction: {emoji, user_ap_ids, url}, user: user}) do
|
2020-05-19 19:50:49 +00:00
|
|
|
users = fetch_users(user_ap_ids)
|
2022-06-10 12:41:08 +00:00
|
|
|
|
2020-05-19 19:50:49 +00:00
|
|
|
%{
|
2022-09-04 23:31:41 +00:00
|
|
|
name: emoji_name(emoji, url),
|
2020-05-19 19:50:49 +00:00
|
|
|
count: length(users),
|
2020-07-22 16:06:00 +00:00
|
|
|
accounts: render(AccountView, "index.json", users: users, for: user),
|
2022-06-08 16:19:42 +00:00
|
|
|
url: MediaProxy.url(url),
|
2020-05-19 19:50:49 +00: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 22:42:27 +00:00
|
|
|
%{is_active: true} -> true
|
2020-05-19 19:50:49 +00:00
|
|
|
_ -> false
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|