2020-09-10 08:44:32 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 07:49:20 +01:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-09-10 08:44:32 +02: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
|