forked from AkkomaGang/akkoma
ActivityPubController: Add Mastodon activity compat route.
This commit is contained in:
parent
8a4bd9e5d1
commit
355aa3bdc7
6 changed files with 42 additions and 4 deletions
|
@ -102,8 +102,8 @@ def track_object_fetch(conn, object_id) do
|
||||||
conn
|
conn
|
||||||
end
|
end
|
||||||
|
|
||||||
def activity(conn, %{"uuid" => uuid}) do
|
def activity(conn, _params) do
|
||||||
with ap_id <- o_status_url(conn, :activity, uuid),
|
with ap_id <- Endpoint.url() <> conn.request_path,
|
||||||
%Activity{} = activity <- Activity.normalize(ap_id),
|
%Activity{} = activity <- Activity.normalize(ap_id),
|
||||||
{_, true} <- {:public?, Visibility.is_public?(activity)} do
|
{_, true} <- {:public?, Visibility.is_public?(activity)} do
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -468,6 +468,8 @@ def maybe_notify_subscribers(
|
||||||
|> Enum.map(& &1.ap_id)
|
|> Enum.map(& &1.ap_id)
|
||||||
|
|
||||||
recipients ++ subscriber_ids
|
recipients ++ subscriber_ids
|
||||||
|
else
|
||||||
|
_e -> recipients
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -479,6 +481,8 @@ def maybe_notify_followers(recipients, %Activity{data: %{"type" => "Move"}} = ac
|
||||||
|> User.get_followers()
|
|> User.get_followers()
|
||||||
|> Enum.map(& &1.ap_id)
|
|> Enum.map(& &1.ap_id)
|
||||||
|> Enum.concat(recipients)
|
|> Enum.concat(recipients)
|
||||||
|
else
|
||||||
|
_e -> recipients
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ def object(%{assigns: %{format: format}} = conn, _params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def activity(%{assigns: %{format: format}} = conn, %{"uuid" => _uuid})
|
def activity(%{assigns: %{format: format}} = conn, _params)
|
||||||
when format in ["json", "activity+json"] do
|
when format in ["json", "activity+json"] do
|
||||||
ActivityPubController.call(conn, :activity)
|
ActivityPubController.call(conn, :activity)
|
||||||
end
|
end
|
||||||
|
|
|
@ -556,8 +556,9 @@ defmodule Pleroma.Web.Router do
|
||||||
get("/notice/:id", OStatus.OStatusController, :notice)
|
get("/notice/:id", OStatus.OStatusController, :notice)
|
||||||
get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
|
get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
|
||||||
|
|
||||||
# Mastodon compat routes
|
# Mastodon compatibility routes
|
||||||
get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object)
|
get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object)
|
||||||
|
get("/users/:nickname/statuses/:id/activity", OStatus.OStatusController, :activity)
|
||||||
|
|
||||||
get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
|
get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
|
||||||
get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
|
get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
|
||||||
|
|
|
@ -13,6 +13,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.ObjectView
|
alias Pleroma.Web.ActivityPub.ObjectView
|
||||||
alias Pleroma.Web.ActivityPub.Relay
|
alias Pleroma.Web.ActivityPub.Relay
|
||||||
alias Pleroma.Web.ActivityPub.UserView
|
alias Pleroma.Web.ActivityPub.UserView
|
||||||
|
@ -193,6 +194,37 @@ test "it returns a json representation of the object with accept application/jso
|
||||||
|
|
||||||
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: object})
|
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: object})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it returns a json representation of the activity with accept application/json", %{
|
||||||
|
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, _} =
|
||||||
|
%{
|
||||||
|
"id" => object.data["id"] <> "/activity",
|
||||||
|
"type" => "Create",
|
||||||
|
"object" => object.data["id"],
|
||||||
|
"actor" => object.data["actor"],
|
||||||
|
"to" => object.data["to"]
|
||||||
|
}
|
||||||
|
|> ActivityPub.persist(local: true)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/json")
|
||||||
|
|> get("/users/raymoo/statuses/999999999/activity")
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: activity})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/objects/:uuid" do
|
describe "/objects/:uuid" do
|
||||||
|
|
|
@ -42,6 +42,7 @@ test "redirects to /notice/:id for html format", %{conn: conn} do
|
||||||
|
|
||||||
{:ok, activity, _} =
|
{:ok, activity, _} =
|
||||||
%{
|
%{
|
||||||
|
"id" => object.data["id"] <> "/activity",
|
||||||
"type" => "Create",
|
"type" => "Create",
|
||||||
"object" => object.data["id"],
|
"object" => object.data["id"],
|
||||||
"actor" => object.data["actor"],
|
"actor" => object.data["actor"],
|
||||||
|
|
Loading…
Reference in a new issue