2020-04-15 16:23:16 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-06 09:51:10 +00:00
|
|
|
defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceView do
|
2020-04-15 16:23:16 +00:00
|
|
|
use Pleroma.Web, :view
|
|
|
|
|
2020-04-27 15:55:29 +00:00
|
|
|
alias Pleroma.User
|
2020-04-20 12:38:53 +00:00
|
|
|
alias Pleroma.Web.CommonAPI.Utils
|
|
|
|
alias Pleroma.Web.MastodonAPI.StatusView
|
2020-04-15 16:23:16 +00:00
|
|
|
|
|
|
|
def render(
|
|
|
|
"show.json",
|
|
|
|
%{
|
2020-06-03 10:30:12 +00:00
|
|
|
chat_message_reference: %{
|
|
|
|
id: id,
|
|
|
|
object: %{data: chat_message},
|
|
|
|
chat_id: chat_id,
|
2020-06-04 15:14:42 +00:00
|
|
|
unread: unread
|
2020-06-03 10:30:12 +00:00
|
|
|
}
|
2020-04-15 16:23:16 +00:00
|
|
|
}
|
|
|
|
) do
|
|
|
|
%{
|
2020-04-16 16:43:31 +00:00
|
|
|
id: id |> to_string(),
|
2020-04-15 16:23:16 +00:00
|
|
|
content: chat_message["content"],
|
2020-04-16 16:43:31 +00:00
|
|
|
chat_id: chat_id |> to_string(),
|
2020-04-27 15:48:34 +00:00
|
|
|
account_id: User.get_cached_by_ap_id(chat_message["actor"]).id,
|
2020-04-20 12:38:53 +00:00
|
|
|
created_at: Utils.to_masto_date(chat_message["published"]),
|
2020-05-06 14:12:36 +00:00
|
|
|
emojis: StatusView.build_emojis(chat_message["emoji"]),
|
|
|
|
attachment:
|
|
|
|
chat_message["attachment"] &&
|
2020-06-03 10:30:12 +00:00
|
|
|
StatusView.render("attachment.json", attachment: chat_message["attachment"]),
|
2020-06-04 15:14:42 +00:00
|
|
|
unread: unread
|
2020-04-15 16:23:16 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("index.json", opts) do
|
2020-06-03 10:30:12 +00:00
|
|
|
render_many(
|
|
|
|
opts[:chat_message_references],
|
|
|
|
__MODULE__,
|
|
|
|
"show.json",
|
|
|
|
Map.put(opts, :as, :chat_message_reference)
|
|
|
|
)
|
2020-04-15 16:23:16 +00:00
|
|
|
end
|
|
|
|
end
|