1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.ChatMessageView do
10 alias Pleroma.Web.CommonAPI.Utils
11 alias Pleroma.Web.MastodonAPI.StatusView
16 object: %{id: id, data: %{"type" => "ChatMessage"} = chat_message},
17 chat: %Chat{id: chat_id}
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"]),
28 chat_message["attachment"] &&
29 StatusView.render("attachment.json", attachment: chat_message["attachment"])
33 def render("index.json", opts) do
34 render_many(opts[:objects], __MODULE__, "show.json", Map.put(opts, :as, :object))