logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

emoji_reaction_view.ex (1215B)


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