ActivityPubController: Add Mastodon activity compat route.
authorlain <lain@soykaf.club>
Fri, 22 May 2020 15:06:12 +0000 (17:06 +0200)
committerlain <lain@soykaf.club>
Fri, 22 May 2020 15:06:12 +0000 (17:06 +0200)
lib/pleroma/web/activity_pub/activity_pub_controller.ex
lib/pleroma/web/common_api/utils.ex
lib/pleroma/web/ostatus/ostatus_controller.ex
lib/pleroma/web/router.ex
test/web/activity_pub/activity_pub_controller_test.exs
test/web/ostatus/ostatus_controller_test.exs

index 5a41dac5c70f885704057d815f94c4b1789c6a32..28727d619ea3d9180ecb811cf4ca6f0db2186103 100644 (file)
@@ -102,8 +102,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
     conn
   end
 
-  def activity(conn, %{"uuid" => uuid}) do
-    with ap_id <- o_status_url(conn, :activity, uuid),
+  def activity(conn, _params) do
+    with ap_id <- Endpoint.url() <> conn.request_path,
          %Activity{} = activity <- Activity.normalize(ap_id),
          {_, true} <- {:public?, Visibility.is_public?(activity)} do
       conn
index b9fa21648327a6ebc80389190cbbd22139eaace8..bf9ca7740f2420160b528de5ac2bfcf2ed169061 100644 (file)
@@ -468,6 +468,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
         |> Enum.map(& &1.ap_id)
 
       recipients ++ subscriber_ids
+    else
+      _e -> recipients
     end
   end
 
@@ -479,6 +481,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
       |> User.get_followers()
       |> Enum.map(& &1.ap_id)
       |> Enum.concat(recipients)
+    else
+      _e -> recipients
     end
   end
 
index b163bfb142b0ead016784d9b2aacff561b61daf3..04a4bdeb45b71339006ded81f8b6ce7da0fe39c8 100644 (file)
@@ -54,7 +54,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
     end
   end
 
-  def activity(%{assigns: %{format: format}} = conn, %{"uuid" => _uuid})
+  def activity(%{assigns: %{format: format}} = conn, _params)
       when format in ["json", "activity+json"] do
     ActivityPubController.call(conn, :activity)
   end
index b437e56fb0108022b8b69338a3392fbf2eaaafb4..08ab3c8bbdfa1f61a6e8b3c2a663b425312e2035 100644 (file)
@@ -556,8 +556,9 @@ defmodule Pleroma.Web.Router do
     get("/notice/:id", OStatus.OStatusController, :notice)
     get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
 
-    # Mastodon compat routes
+    # Mastodon compatibility routes
     get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object)
+    get("/users/:nickname/statuses/:id/activity", OStatus.OStatusController, :activity)
 
     get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
     get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
index b247163ec3b2654c1022f2bfc7c515ddac65eada..dd2a48a613b4ed4d72ef61731add3ba64083e178 100644 (file)
@@ -13,6 +13,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
   alias Pleroma.Object
   alias Pleroma.Tests.ObanHelpers
   alias Pleroma.User
+  alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.ObjectView
   alias Pleroma.Web.ActivityPub.Relay
   alias Pleroma.Web.ActivityPub.UserView
@@ -193,6 +194,37 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
       assert json_response(conn, 200) == ObjectView.render("object.json", %{object: object})
     end
+
+    test "it returns a json representation of the activity with accept application/json", %{
+      conn: conn
+    } do
+      {:ok, object} =
+        %{
+          "type" => "Note",
+          "content" => "hey",
+          "id" => Endpoint.url() <> "/users/raymoo/statuses/999999999",
+          "actor" => Endpoint.url() <> "/users/raymoo",
+          "to" => [Pleroma.Constants.as_public()]
+        }
+        |> Object.create()
+
+      {:ok, activity, _} =
+        %{
+          "id" => object.data["id"] <> "/activity",
+          "type" => "Create",
+          "object" => object.data["id"],
+          "actor" => object.data["actor"],
+          "to" => object.data["to"]
+        }
+        |> ActivityPub.persist(local: true)
+
+      conn =
+        conn
+        |> put_req_header("accept", "application/json")
+        |> get("/users/raymoo/statuses/999999999/activity")
+
+      assert json_response(conn, 200) == ObjectView.render("object.json", %{object: activity})
+    end
   end
 
   describe "/objects/:uuid" do
index 266fe2f4544c51c5de8c1eabdc60d53db999857c..0f973d5b6c2cf02269068583f769cdba7dff0016 100644 (file)
@@ -42,6 +42,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
       {:ok, activity, _} =
         %{
+          "id" => object.data["id"] <> "/activity",
           "type" => "Create",
           "object" => object.data["id"],
           "actor" => object.data["actor"],