ChatView: Add a mastodon api representation of the recipient.

This commit is contained in:
lain 2020-04-17 14:23:59 +02:00
commit 372614cfd3
4 changed files with 55 additions and 1 deletions

View file

@ -22,6 +22,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageHandling do
# For now, just strip HTML
stripped_content = Pleroma.HTML.strip_tags(object_cast_data["content"]),
object_cast_data = object_cast_data |> Map.put("content", stripped_content),
{_, true} <- {:to_fields_match, cast_data["to"] == object_cast_data["to"]},
{_, {:ok, validated_object, _meta}} <-
{:validate_object, ObjectValidator.validate(object_cast_data, %{})},
{_, {:ok, _created_object}} <- {:persist_object, Object.create(validated_object)},

View file

@ -6,11 +6,16 @@ defmodule Pleroma.Web.PleromaAPI.ChatView do
use Pleroma.Web, :view
alias Pleroma.Chat
alias Pleroma.User
alias Pleroma.Web.MastodonAPI.AccountView
def render("show.json", %{chat: %Chat{} = chat} = opts) do
recipient = User.get_cached_by_ap_id(chat.recipient)
def render("show.json", %{chat: %Chat{} = chat}) do
%{
id: chat.id |> to_string(),
recipient: chat.recipient,
recipient_account: AccountView.render("show.json", Map.put(opts, :user, recipient)),
unread: chat.unread
}
end