1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceView do
10 alias Pleroma.Web.CommonAPI.Utils
11 alias Pleroma.Web.MastodonAPI.StatusView
13 @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
18 chat_message_reference: %{
20 object: %{data: chat_message} = object,
27 id: id |> to_string(),
28 content: chat_message["content"],
29 chat_id: chat_id |> to_string(),
30 account_id: User.get_cached_by_ap_id(chat_message["actor"]).id,
31 created_at: Utils.to_masto_date(chat_message["published"]),
32 emojis: StatusView.build_emojis(chat_message["emoji"]),
34 chat_message["attachment"] &&
35 StatusView.render("attachment.json", attachment: chat_message["attachment"]),
40 Pleroma.Web.RichMedia.Helpers.fetch_data_for_object(object)
43 |> put_idempotency_key()
46 def render("index.json", opts) do
48 opts[:chat_message_references],
51 Map.put(opts, :as, :chat_message_reference)
55 defp put_idempotency_key(data) do
56 with {:ok, idempotency_key} <- @cachex.get(:chat_message_id_idempotency_key_cache, data.id) do
58 |> Maps.put_if_present(:idempotency_key, idempotency_key)