2df5913584b83688e807ebf9419b1bec5e7abd1d
[akkoma] / lib / pleroma / web / pleroma_api / views / chat_message_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.PleromaAPI.ChatMessageView do
6 use Pleroma.Web, :view
7
8 alias Pleroma.Chat
9
10 def render(
11 "show.json",
12 %{
13 object: %{id: id, data: %{"type" => "ChatMessage"} = chat_message},
14 chat: %Chat{id: chat_id}
15 }
16 ) do
17 %{
18 id: id,
19 content: chat_message["content"],
20 chat_id: chat_id,
21 actor: chat_message["actor"]
22 }
23 end
24
25 def render("index.json", opts) do
26 render_many(opts[:objects], __MODULE__, "show.json", Map.put(opts, :as, :object))
27 end
28 end