logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

chat_message_reference_view.ex (1268B)


      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.ChatMessageReferenceView do
      6   use Pleroma.Web, :view
      7 
      8   alias Pleroma.User
      9   alias Pleroma.Web.CommonAPI.Utils
     10   alias Pleroma.Web.MastodonAPI.StatusView
     11 
     12   def render(
     13         "show.json",
     14         %{
     15           chat_message_reference: %{
     16             id: id,
     17             object: %{data: chat_message},
     18             chat_id: chat_id,
     19             unread: unread
     20           }
     21         }
     22       ) do
     23     %{
     24       id: id |> to_string(),
     25       content: chat_message["content"],
     26       chat_id: chat_id |> to_string(),
     27       account_id: User.get_cached_by_ap_id(chat_message["actor"]).id,
     28       created_at: Utils.to_masto_date(chat_message["published"]),
     29       emojis: StatusView.build_emojis(chat_message["emoji"]),
     30       attachment:
     31         chat_message["attachment"] &&
     32           StatusView.render("attachment.json", attachment: chat_message["attachment"]),
     33       unread: unread
     34     }
     35   end
     36 
     37   def render("index.json", opts) do
     38     render_many(
     39       opts[:chat_message_references],
     40       __MODULE__,
     41       "show.json",
     42       Map.put(opts, :as, :chat_message_reference)
     43     )
     44   end
     45 end