For outgoing objects, fake mastodon style ap id for ostatus.
authorlain <lain@soykaf.club>
Fri, 23 Mar 2018 15:07:02 +0000 (16:07 +0100)
committerlain <lain@soykaf.club>
Fri, 23 Mar 2018 15:07:02 +0000 (16:07 +0100)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier_test.exs

index d759ca2b2faf21a65074a0a09d7fac1cc21dc6b4..61631e1eaafb7ea8b3924cbc7868350d3f34959d 100644 (file)
@@ -183,6 +183,17 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier 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 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     |> add_attributed_to
     |> prepare_attachments
     |> set_conversation
+    |> set_reply_to_uri
   end
 
   @doc
index 51b09b166eb7f1f3cc309434478fb7fc59a8a1ae..caad9737a556ad8f4ffecf8032624d94f77c1d27 100644 (file)
@@ -233,6 +233,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest 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