From 50e3750758510a2790ce6229d9194ace72d1e012 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 5 May 2021 13:58:50 -0500 Subject: [PATCH 1/3] Add notice compatibility routes for other frontends Fixes: https://git.pleroma.social/pleroma/pleroma/-/issues/1785 --- lib/pleroma/web/router.ex | 5 ++ .../web/static_fe/static_fe_controller.ex | 9 ++++ .../web/o_status/o_status_controller_test.exs | 50 +++++++++++++++++++ .../web/plugs/frontend_static_plug_test.exs | 2 + 4 files changed, 66 insertions(+) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 72ad14f05..5e732e4bb 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -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) diff --git a/lib/pleroma/web/static_fe/static_fe_controller.ex b/lib/pleroma/web/static_fe/static_fe_controller.ex index fe485d10d..421070636 100644 --- a/lib/pleroma/web/static_fe/static_fe_controller.ex +++ b/lib/pleroma/web/static_fe/static_fe_controller.ex @@ -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) diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs index 2038f4ddd..fab042439 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -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 = + "" + + 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 = + "" + + 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 = + "" + + assert resp =~ expected + end + end end diff --git a/test/pleroma/web/plugs/frontend_static_plug_test.exs b/test/pleroma/web/plugs/frontend_static_plug_test.exs index 100b83d6a..7596a9a54 100644 --- a/test/pleroma/web/plugs/frontend_static_plug_test.exs +++ b/test/pleroma/web/plugs/frontend_static_plug_test.exs @@ -86,6 +86,8 @@ test "api routes are detected correctly" do "objects", "activities", "notice", + "@:nickname", + ":nickname", "users", "tags", "mailer", From b15c4629ff3093353ac5e37d381db1cdc4da1c3a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 5 May 2021 14:36:27 -0500 Subject: [PATCH 2/3] CHANGELOG: notice routes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bb4b1e73..625cf3266 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Don't crash so hard when email settings are invalid. +- Display OpenGraph data on alternative notice routes. ## Unreleased (Patch) From 2c06eff519f63e67aada70d492094e6e56bbfccd Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 25 Dec 2021 20:11:14 -0600 Subject: [PATCH 3/3] Pleroma.Web.base_url() --> Endpoint.url() --- test/pleroma/web/o_status/o_status_controller_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs index b243e1692..41aef98b1 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -356,7 +356,7 @@ test "Soapbox FE", %{conn: conn} do |> response(200) expected = - "" + "" assert resp =~ expected end @@ -372,7 +372,7 @@ test "Mastodon", %{conn: conn} do |> response(200) expected = - "" + "" assert resp =~ expected end @@ -388,7 +388,7 @@ test "Twitter", %{conn: conn} do |> response(200) expected = - "" + "" assert resp =~ expected end