2020-09-10 00:44:32 -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-09-10 00:44:32 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.ChatView do
|
|
|
|
use Pleroma.Web, :view
|
|
|
|
|
|
|
|
alias Pleroma.Chat
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.MastodonAPI
|
|
|
|
alias Pleroma.Web.PleromaAPI
|
|
|
|
|
|
|
|
def render("index.json", %{chats: chats} = opts) do
|
|
|
|
render_many(chats, __MODULE__, "show.json", Map.delete(opts, :chats))
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("show.json", %{chat: %Chat{user_id: user_id}} = opts) do
|
|
|
|
user = User.get_by_id(user_id)
|
|
|
|
sender = MastodonAPI.AccountView.render("show.json", user: user, skip_visibility_check: true)
|
|
|
|
|
|
|
|
serialized_chat = PleromaAPI.ChatView.render("show.json", opts)
|
|
|
|
|
|
|
|
serialized_chat
|
|
|
|
|> Map.put(:sender, sender)
|
|
|
|
|> Map.put(:receiver, serialized_chat[:account])
|
|
|
|
|> Map.delete(:account)
|
|
|
|
end
|
|
|
|
|
|
|
|
def render(view, opts), do: PleromaAPI.ChatView.render(view, opts)
|
|
|
|
end
|