logo

pleroma

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

chat_view.ex (955B)


  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.AdminAPI.ChatView do
  5. use Pleroma.Web, :view
  6. alias Pleroma.Chat
  7. alias Pleroma.User
  8. alias Pleroma.Web.MastodonAPI
  9. alias Pleroma.Web.PleromaAPI
  10. def render("index.json", %{chats: chats} = opts) do
  11. render_many(chats, __MODULE__, "show.json", Map.delete(opts, :chats))
  12. end
  13. def render("show.json", %{chat: %Chat{user_id: user_id}} = opts) do
  14. user = User.get_by_id(user_id)
  15. sender = MastodonAPI.AccountView.render("show.json", user: user, skip_visibility_check: true)
  16. serialized_chat = PleromaAPI.ChatView.render("show.json", opts)
  17. serialized_chat
  18. |> Map.put(:sender, sender)
  19. |> Map.put(:receiver, serialized_chat[:account])
  20. |> Map.delete(:account)
  21. end
  22. def render(view, opts), do: PleromaAPI.ChatView.render(view, opts)
  23. end