mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 11:19:19 +00:00
MastoAPI: More link headers.
This commit is contained in:
parent
0df4a0f26d
commit
f1d9f2f6cd
1 changed files with 10 additions and 6 deletions
|
@ -38,14 +38,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
json(conn, response)
|
json(conn, response)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp add_link_headers(conn, activities) do
|
defp add_link_headers(conn, method, activities) do
|
||||||
last = List.last(activities)
|
last = List.last(activities)
|
||||||
first = List.first(activities)
|
first = List.first(activities)
|
||||||
if last do
|
if last do
|
||||||
min = last.id
|
min = last.id
|
||||||
max = first.id
|
max = first.id
|
||||||
next_url = mastodon_api_url(Pleroma.Web.Endpoint, :home_timeline, max_id: min)
|
next_url = mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min)
|
||||||
prev_url = mastodon_api_url(Pleroma.Web.Endpoint, :home_timeline, since_id: max)
|
prev_url = mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max)
|
||||||
conn
|
conn
|
||||||
|> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"")
|
|> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"")
|
||||||
else
|
else
|
||||||
|
@ -58,7 +58,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
|> Enum.reverse
|
|> Enum.reverse
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(activities)
|
|> add_link_headers(:home_timeline, activities)
|
||||||
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
|
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,7 +70,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
activities = ActivityPub.fetch_public_activities(params)
|
activities = ActivityPub.fetch_public_activities(params)
|
||||||
|> Enum.reverse
|
|> Enum.reverse
|
||||||
|
|
||||||
render conn, StatusView, "index.json", %{activities: activities, for: user, as: :activity}
|
conn
|
||||||
|
|> add_link_headers(:public_timeline, activities)
|
||||||
|
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_statuses(%{assigns: %{user: user}} = conn, params) do
|
def user_statuses(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
@ -170,7 +172,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
end)
|
end)
|
||||||
|> Enum.filter(&(&1))
|
|> Enum.filter(&(&1))
|
||||||
|
|
||||||
json(conn, result)
|
conn
|
||||||
|
|> add_link_headers(:notifications, notifications)
|
||||||
|
|> json(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty_array(conn, _) do
|
def empty_array(conn, _) do
|
||||||
|
|
Loading…
Reference in a new issue