Add notice compatibility routes for other frontends
authorAlex Gleason <alex@alexgleason.me>
Wed, 5 May 2021 18:58:50 +0000 (13:58 -0500)
committerAlex Gleason <alex@alexgleason.me>
Wed, 5 May 2021 19:50:10 +0000 (14:50 -0500)
Fixes: https://git.pleroma.social/pleroma/pleroma/-/issues/1785
lib/pleroma/web/router.ex
lib/pleroma/web/static_fe/static_fe_controller.ex
test/pleroma/web/o_status/o_status_controller_test.exs
test/pleroma/web/plugs/frontend_static_plug_test.exs

index 72ad14f052a39e56f10e8262e07406f52620f97b..5e732e4bb7de34fc1b187bbb7bd362793db94909 100644 (file)
@@ -637,6 +637,11 @@ defmodule Pleroma.Web.Router do
     get("/activities/:uuid", OStatus.OStatusController, :activity)
     get("/notice/:id", OStatus.OStatusController, :notice)
 
+    # Notice compatibility routes for other frontends
+    get("/@:nickname/:id", OStatus.OStatusController, :notice)
+    get("/@:nickname/posts/:id", OStatus.OStatusController, :notice)
+    get("/:nickname/status/:id", OStatus.OStatusController, :notice)
+
     # Mastodon compatibility routes
     get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object)
     get("/users/:nickname/statuses/:id/activity", OStatus.OStatusController, :activity)
index fe485d10db892e64ca254ad781e8707258314012..42107063618045f837158abd5735cd3c664ae86b 100644 (file)
@@ -168,6 +168,15 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
   defp assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),
     do: assign(conn, :notice_id, notice_id)
 
+  defp assign_id(%{path_info: ["@" <> _nickname, notice_id]} = conn, _opts),
+    do: assign(conn, :notice_id, notice_id)
+
+  defp assign_id(%{path_info: ["@" <> _nickname, "posts", notice_id]} = conn, _opts),
+    do: assign(conn, :notice_id, notice_id)
+
+  defp assign_id(%{path_info: [_nickname, "status", notice_id]} = conn, _opts),
+    do: assign(conn, :notice_id, notice_id)
+
   defp assign_id(%{path_info: ["users", user_id]} = conn, _opts),
     do: assign(conn, :username_or_id, user_id)
 
index 2038f4ddd12bd654062a9484695892f59ba381b9..fab042439ac9ce81f10e38c14501874d974f431d 100644 (file)
@@ -343,4 +343,54 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
       |> response(200)
     end
   end
+
+  describe "notice compatibility routes" do
+    test "Soapbox FE", %{conn: conn} do
+      user = insert(:user)
+      note_activity = insert(:note_activity, user: user)
+
+      resp =
+        conn
+        |> put_req_header("accept", "text/html")
+        |> get("/@#{user.nickname}/posts/#{note_activity.id}")
+        |> response(200)
+
+      expected =
+        "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+
+      assert resp =~ expected
+    end
+
+    test "Mastodon", %{conn: conn} do
+      user = insert(:user)
+      note_activity = insert(:note_activity, user: user)
+
+      resp =
+        conn
+        |> put_req_header("accept", "text/html")
+        |> get("/@#{user.nickname}/#{note_activity.id}")
+        |> response(200)
+
+      expected =
+        "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+
+      assert resp =~ expected
+    end
+
+    test "Twitter", %{conn: conn} do
+      user = insert(:user)
+      note_activity = insert(:note_activity, user: user)
+
+      resp =
+        conn
+        |> put_req_header("accept", "text/html")
+        |> get("/#{user.nickname}/status/#{note_activity.id}")
+        |> response(200)
+
+      expected =
+        "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+
+      assert resp =~ expected
+    end
+  end
 end
index 100b83d6a30a69e759772330a59e6fe4af1ac2bd..7596a9a5467efacd1d11efce204afe4c369f30b8 100644 (file)
@@ -86,6 +86,8 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
       "objects",
       "activities",
       "notice",
+      "@:nickname",
+      ":nickname",
       "users",
       "tags",
       "mailer",