MastoAPI: More link headers.

This commit is contained in:
Roger Braun 2017-09-12 09:06:32 +02:00
parent 0df4a0f26d
commit f1d9f2f6cd

View file

@ -38,14 +38,14 @@ def masto_instance(conn, _params) do
json(conn, response)
end
defp add_link_headers(conn, activities) do
defp add_link_headers(conn, method, activities) do
last = List.last(activities)
first = List.first(activities)
if last do
min = last.id
max = first.id
next_url = mastodon_api_url(Pleroma.Web.Endpoint, :home_timeline, max_id: min)
prev_url = mastodon_api_url(Pleroma.Web.Endpoint, :home_timeline, since_id: max)
next_url = mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min)
prev_url = mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max)
conn
|> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"")
else
@ -58,7 +58,7 @@ def home_timeline(%{assigns: %{user: user}} = conn, params) do
|> Enum.reverse
conn
|> add_link_headers(activities)
|> add_link_headers(:home_timeline, activities)
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
end
@ -70,7 +70,9 @@ def public_timeline(%{assigns: %{user: user}} = conn, params) do
activities = ActivityPub.fetch_public_activities(params)
|> 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
def user_statuses(%{assigns: %{user: user}} = conn, params) do
@ -170,7 +172,9 @@ def notifications(%{assigns: %{user: user}} = conn, params) do
end)
|> Enum.filter(&(&1))
json(conn, result)
conn
|> add_link_headers(:notifications, notifications)
|> json(result)
end
def empty_array(conn, _) do