1
0
Fork 0
forked from mirrors/akkoma

MastoAPI: Add link headers to home timeline

This commit is contained in:
Roger Braun 2017-09-12 08:51:56 +02:00
parent cd6cba2f67
commit 02f824f9d5

View file

@ -38,10 +38,28 @@ def masto_instance(conn, _params) do
json(conn, response)
end
defp add_link_headers(conn, 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)
conn
|> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"")
else
conn
end
end
def home_timeline(%{assigns: %{user: user}} = conn, params) do
activities = ActivityPub.fetch_activities([user.ap_id | user.following], Map.put(params, "type", "Create"))
|> Enum.reverse
render conn, StatusView, "index.json", %{activities: activities, for: user, as: :activity}
conn
|> add_link_headers(activities)
|> render StatusView, "index.json", %{activities: activities, for: user, as: :activity}
end
def public_timeline(%{assigns: %{user: user}} = conn, params) do