diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-10-02 12:14:08 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-10-02 12:15:06 +0200 |
commit | 86880b9821671ee07a65ca7e65b68b900759b483 (patch) | |
tree | c9b8f0bf34f8cf92c01443aa70ac984bd5269434 | |
parent | 89ab673d00b4dd96fd29f35d7c355b777b9ec0c7 (diff) | |
download | pleroma-86880b9821671ee07a65ca7e65b68b900759b483.tar.gz |
Inline object when Announcing a self-owned private object
-rw-r--r-- | lib/pleroma/web/activity_pub/transmogrifier.ex | 21 | ||||
-rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 14 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 3ca2e8773..64c470fc8 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -830,6 +830,27 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do {:ok, data} end + def prepare_outgoing(%{"type" => "Announce", "actor" => ap_id, "object" => object_id} = data) do + object = + object_id + |> Object.normalize() + + data = + if Visibility.is_private?(object) && object.data["actor"] == ap_id do + data |> Map.put("object", object |> Map.get(:data) |> prepare_object) + else + data |> maybe_fix_object_url + end + + data = + data + |> strip_internal_fields + |> Map.merge(Utils.make_json_ld_header()) + |> Map.delete("bcc") + + {:ok, data} + end + # Mastodon Accept/Reject requires a non-normalized object containing the actor URIs, # because of course it does. def prepare_outgoing(%{"type" => "Accept"} = data) do diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 6c64be10b..b995f0224 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -1076,6 +1076,20 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do end describe "prepare outgoing" do + test "it inlines private announced objects" do + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "hey", "visibility" => "private"}) + + {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user) + + {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data) + object = modified["object"] + + assert modified["object"]["content"] == "hey" + assert modified["object"]["actor"] == modified["object"]["attributedTo"] + end + test "it turns mentions into tags" do user = insert(:user) other_user = insert(:user) |