OStatusController: Add Mastodon compatibility route for objects.
authorlain <lain@soykaf.club>
Fri, 22 May 2020 14:47:22 +0000 (16:47 +0200)
committerlain <lain@soykaf.club>
Fri, 22 May 2020 14:47:22 +0000 (16:47 +0200)
lib/pleroma/web/ostatus/ostatus_controller.ex
test/web/ostatus/ostatus_controller_test.exs

index 513e69c6e569d059cdcc1bdca5283c867d50ce0e..b163bfb142b0ead016784d9b2aacff561b61daf3 100644 (file)
@@ -37,8 +37,8 @@ defmodule Pleroma.Web.OStatus.OStatusController do
     ActivityPubController.call(conn, :object)
   end
 
-  def object(%{assigns: %{format: format}} = conn, %{"uuid" => uuid}) do
-    with id <- o_status_url(conn, :object, uuid),
+  def object(%{assigns: %{format: format}} = conn, _params) do
+    with id <- Endpoint.url() <> conn.request_path,
          {_, %Activity{} = activity} <-
            {:activity, Activity.get_create_by_object_ap_id_with_object(id)},
          {_, true} <- {:public?, Visibility.is_public?(activity)} do
index bb349cb1968216ed136d6f512cf21fd785f67abc..266fe2f4544c51c5de8c1eabdc60d53db999857c 100644 (file)
@@ -10,7 +10,11 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
   alias Pleroma.Config
   alias Pleroma.Object
   alias Pleroma.User
+  alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.CommonAPI
+  alias Pleroma.Web.Endpoint
+
+  require Pleroma.Constants
 
   setup_all do
     Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -19,6 +23,37 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
 
   setup do: clear_config([:instance, :federating], true)
 
+  describe "Mastodon compatibility routes" do
+    setup %{conn: conn} do
+      conn = put_req_header(conn, "accept", "text/html")
+      %{conn: conn}
+    end
+
+    test "redirects to /notice/:id for html format", %{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, _} =
+        %{
+          "type" => "Create",
+          "object" => object.data["id"],
+          "actor" => object.data["actor"],
+          "to" => object.data["to"]
+        }
+        |> ActivityPub.persist(local: true)
+
+      conn = get(conn, "/users/raymoo/statuses/999999999")
+      assert redirected_to(conn) == "/notice/#{activity.id}"
+    end
+  end
+
   # Note: see ActivityPubControllerTest for JSON format tests
   describe "GET /objects/:uuid (text/html)" do
     setup %{conn: conn} do