ChatView: Add actor_account_id
[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 alias Pleroma.User
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 actor: chat_message["actor"],
25 actor_account_id: User.get_cached_by_ap_id(chat_message["actor"]).id,
26 created_at: Utils.to_masto_date(chat_message["published"]),
27 emojis: StatusView.build_emojis(chat_message["emoji"])
28 }
29 end
30
31 def render("index.json", opts) do
32 render_many(opts[:objects], __MODULE__, "show.json", Map.put(opts, :as, :object))
33 end
34 end