From 5da2355e715722f2f80a7587264a08d4281cb519 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 23 Mar 2018 16:07:02 +0100 Subject: [PATCH] For outgoing objects, fake mastodon style ap id for ostatus. --- lib/pleroma/web/activity_pub/transmogrifier.ex | 12 ++++++++++++ test/web/activity_pub/transmogrifier_test.exs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index d759ca2b2..61631e1ea 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -183,6 +183,17 @@ def get_obj_helper(id) do if object = Object.get_by_ap_id(id), do: {:ok, object}, else: nil end + def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do + with false <- String.starts_with?(inReplyTo, "http"), + {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do + Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo) + else + _e -> object + end + end + def set_reply_to_uri(obj), do: obj + + # Prepares the object of an outgoing create activity. def prepare_object(object) do object |> set_sensitive @@ -192,6 +203,7 @@ def prepare_object(object) do |> add_attributed_to |> prepare_attachments |> set_conversation + |> set_reply_to_uri end @doc diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 51b09b166..caad9737a 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -233,6 +233,18 @@ test "it translates ostatus IDs to external URLs" do assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29" end + + test "it translates ostatus reply_to IDs to external URLs" do + incoming = File.read!("test/fixtures/incoming_note_activity.xml") + {:ok, [referred_activity]} = OStatus.handle_incoming(incoming) + + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id}) + {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) + + assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29" + end end describe "user upgrade" do