OStatusController: Add Mastodon activity compat route.

This commit is contained in:
lain 2020-05-22 17:11:59 +02:00
parent 355aa3bdc7
commit 91c8467582
2 changed files with 14 additions and 5 deletions

View File

@ -59,8 +59,8 @@ def activity(%{assigns: %{format: format}} = conn, _params)
ActivityPubController.call(conn, :activity) ActivityPubController.call(conn, :activity)
end end
def activity(%{assigns: %{format: format}} = conn, %{"uuid" => uuid}) do def activity(%{assigns: %{format: format}} = conn, _params) do
with id <- o_status_url(conn, :activity, uuid), with id <- Endpoint.url() <> conn.request_path,
{_, %Activity{} = activity} <- {:activity, Activity.normalize(id)}, {_, %Activity{} = activity} <- {:activity, Activity.normalize(id)},
{_, true} <- {:public?, Visibility.is_public?(activity)} do {_, true} <- {:public?, Visibility.is_public?(activity)} do
case format do case format do

View File

@ -26,10 +26,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
describe "Mastodon compatibility routes" do describe "Mastodon compatibility routes" do
setup %{conn: conn} do setup %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html") conn = put_req_header(conn, "accept", "text/html")
%{conn: conn}
end
test "redirects to /notice/:id for html format", %{conn: conn} do
{:ok, object} = {:ok, object} =
%{ %{
"type" => "Note", "type" => "Note",
@ -50,9 +47,21 @@ test "redirects to /notice/:id for html format", %{conn: conn} do
} }
|> ActivityPub.persist(local: true) |> ActivityPub.persist(local: true)
%{conn: conn, activity: activity}
end
test "redirects to /notice/:id for html format", %{conn: conn, activity: activity} do
conn = get(conn, "/users/raymoo/statuses/999999999") conn = get(conn, "/users/raymoo/statuses/999999999")
assert redirected_to(conn) == "/notice/#{activity.id}" assert redirected_to(conn) == "/notice/#{activity.id}"
end end
test "redirects to /notice/:id for html format for activity", %{
conn: conn,
activity: activity
} do
conn = get(conn, "/users/raymoo/statuses/999999999/activity")
assert redirected_to(conn) == "/notice/#{activity.id}"
end
end end
# Note: see ActivityPubControllerTest for JSON format tests # Note: see ActivityPubControllerTest for JSON format tests