Support activity+json request for activity
This commit is contained in:
parent
5c5c8508c2
commit
20c0dd1e24
|
@ -54,6 +54,19 @@ def object(conn, %{"uuid" => uuid}) do
|
|||
end
|
||||
end
|
||||
|
||||
def activity(conn, %{"uuid" => uuid}) do
|
||||
with ap_id <- o_status_url(conn, :activity, uuid),
|
||||
%Activity{} = activity <- Activity.normalize(ap_id),
|
||||
{_, true} <- {:public?, ActivityPub.is_public?(activity)} do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(ObjectView.render("object.json", %{object: activity}))
|
||||
else
|
||||
{:public?, false} ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def following(conn, %{"nickname" => nickname, "page" => page}) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
{:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
|
||||
|
|
|
@ -112,6 +112,9 @@ def object(conn, %{"uuid" => uuid}) do
|
|||
end
|
||||
|
||||
def activity(conn, %{"uuid" => uuid}) do
|
||||
if get_format(conn) == "activity+json" do
|
||||
ActivityPubController.call(conn, :activity)
|
||||
else
|
||||
with id <- o_status_url(conn, :activity, uuid),
|
||||
{_, %Activity{} = activity} <- {:activity, Activity.normalize(id)},
|
||||
{_, true} <- {:public?, ActivityPub.is_public?(activity)},
|
||||
|
@ -131,6 +134,7 @@ def activity(conn, %{"uuid" => uuid}) do
|
|||
e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def notice(conn, %{"id" => id}) do
|
||||
with {_, %Activity{} = activity} <- {:activity, Repo.get(Activity, id)},
|
||||
|
|
|
@ -89,6 +89,32 @@ test "it returns 404 for tombstone objects", %{conn: conn} do
|
|||
end
|
||||
end
|
||||
|
||||
describe "/activities/:uuid" do
|
||||
test "it returns a json representation of the activity", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: activity})
|
||||
end
|
||||
|
||||
test "it returns 404 for non-public activities", %{conn: conn} do
|
||||
activity = insert(:direct_note_activity)
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert json_response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/inbox" do
|
||||
test "it inserts an incoming activity into the database", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
|
Loading…
Reference in New Issue