Add notice compatibility routes for other frontends
Fixes: https://git.pleroma.social/pleroma/pleroma/-/issues/1785
This commit is contained in:
		
							parent
							
								
									b221d77a6d
								
							
						
					
					
						commit
						50e3750758
					
				
					 4 changed files with 66 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -168,6 +168,15 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) 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)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -343,4 +343,54 @@ test "does not require authentication on non-federating instances", %{
 | 
			
		|||
      |> 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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -86,6 +86,8 @@ test "api routes are detected correctly" do
 | 
			
		|||
      "objects",
 | 
			
		||||
      "activities",
 | 
			
		||||
      "notice",
 | 
			
		||||
      "@:nickname",
 | 
			
		||||
      ":nickname",
 | 
			
		||||
      "users",
 | 
			
		||||
      "tags",
 | 
			
		||||
      "mailer",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue