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.User
10 alias Pleroma.Web.CommonAPI.Utils
11 alias Pleroma.Web.MastodonAPI.StatusView
12
13 def render(
14 "show.json",
15 %{
16 object: %{id: id, data: %{"type" => "ChatMessage"} = chat_message},
17 chat: %Chat{id: chat_id}
18 }
19 ) do
20 %{
21 id: id |> to_string(),
22 content: chat_message["content"],
23 chat_id: chat_id |> to_string(),
24 account_id: User.get_cached_by_ap_id(chat_message["actor"]).id,
25 created_at: Utils.to_masto_date(chat_message["published"]),
26 emojis: StatusView.build_emojis(chat_message["emoji"]),
27 attachment:
28 chat_message["attachment"] &&
29 StatusView.render("attachment.json", attachment: chat_message["attachment"])
30 }
31 end
32
33 def render("index.json", opts) do
34 render_many(opts[:objects], __MODULE__, "show.json", Map.put(opts, :as, :object))
35 end
36 end