X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fpleroma_api%2Fviews%2Fchat_view.ex;h=1c996da119474501a145a75e766f8cf7044a0ecf;hb=0883a706dc376fdfb7de9df1366803e87c8e7c98;hp=7b8c6450a5c25febb4a1a855bb3e8b849f98b2b7;hpb=f8c3ae7a627817789776f11497041445bb273c19;p=akkoma diff --git a/lib/pleroma/web/pleroma_api/views/chat_view.ex b/lib/pleroma/web/pleroma_api/views/chat_view.ex index 7b8c6450a..1c996da11 100644 --- a/lib/pleroma/web/pleroma_api/views/chat_view.ex +++ b/lib/pleroma/web/pleroma_api/views/chat_view.ex @@ -6,12 +6,24 @@ defmodule Pleroma.Web.PleromaAPI.ChatView do use Pleroma.Web, :view alias Pleroma.Chat + alias Pleroma.Chat.MessageReference + alias Pleroma.User + alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView + + def render("show.json", %{chat: %Chat{} = chat} = opts) do + recipient = User.get_cached_by_ap_id(chat.recipient) + last_message = opts[:last_message] || MessageReference.last_message_for_chat(chat) - def render("show.json", %{chat: %Chat{} = chat}) do %{ id: chat.id |> to_string(), - recipient: chat.recipient, - unread: chat.unread + account: AccountView.render("show.json", Map.put(opts, :user, recipient)), + unread: MessageReference.unread_count_for_chat(chat), + last_message: + last_message && + MessageReferenceView.render("show.json", chat_message_reference: last_message), + updated_at: Utils.to_masto_date(chat.updated_at) } end