From 82e34cae95a204475f4419758c980ddd922be095 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 24 Feb 2018 20:16:41 +0100 Subject: [PATCH] Unify object representation. --- lib/pleroma/web/activity_pub/transmogrifier.ex | 17 +++++++++++------ .../web/activity_pub/views/object_view.ex | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 2e5ca70fd..698cfa0a9 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -122,18 +122,23 @@ def get_obj_helper(id) do if object = Object.get_by_ap_id(id), do: {:ok, object}, else: nil end - @doc - """ - internal -> Mastodon - """ - def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do - object = object + def prepare_object(object) do + object |> set_sensitive |> add_hashtags |> add_mention_tags |> add_attributed_to |> prepare_attachments |> set_conversation + end + + @doc + """ + internal -> Mastodon + """ + def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do + object = object + |> prepare_object data = data |> Map.put("object", object) diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex index c39f99454..cc0b0556b 100644 --- a/lib/pleroma/web/activity_pub/views/object_view.ex +++ b/lib/pleroma/web/activity_pub/views/object_view.ex @@ -1,5 +1,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectView do use Pleroma.Web, :view + alias Pleroma.Web.ActivityPub.Transmogrifier def render("object.json", %{object: object}) do base = %{ @@ -20,8 +21,7 @@ def render("object.json", %{object: object}) do ] } - additional = Map.take(object.data, ["id", "to", "cc", "actor", "content", "summary", "type"]) - |> Map.put("attributedTo", object.data["actor"]) + additional = Transmogrifier.prepare_object(object.data) Map.merge(base, additional) end end