Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[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 alias Pleroma.Web.CommonAPI.Utils
10 alias Pleroma.Web.MastodonAPI.StatusView
11
12 def render(
13 "show.json",
14 %{
15 object: %{id: id, data: %{"type" => "ChatMessage"} = chat_message},
16 chat: %Chat{id: chat_id}
17 }
18 ) do
19 %{
20 id: id |> to_string(),
21 content: chat_message["content"],
22 chat_id: chat_id |> to_string(),
23 actor: chat_message["actor"],
24 created_at: Utils.to_masto_date(chat_message["published"]),
25 emojis: StatusView.build_emojis(chat_message["emoji"])
26 }
27 end
28
29 def render("index.json", opts) do
30 render_many(opts[:objects], __MODULE__, "show.json", Map.put(opts, :as, :object))
31 end
32 end