mastodon_api_controller.ex: Use min_id in link header instead of since_id
This commit is contained in:
parent
e83ad12c57
commit
6b407872b4
2 changed files with 16 additions and 11 deletions
|
@ -199,15 +199,20 @@ def custom_emojis(conn, _params) do
|
||||||
defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
|
defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
|
||||||
params =
|
params =
|
||||||
conn.params
|
conn.params
|
||||||
|> Map.drop(["since_id", "max_id"])
|
|> Map.drop(["since_id", "max_id", "min_id"])
|
||||||
|> Map.merge(params)
|
|> Map.merge(params)
|
||||||
|
|
||||||
last = List.last(activities)
|
last = List.last(activities)
|
||||||
first = List.first(activities)
|
|
||||||
|
|
||||||
if last do
|
if last do
|
||||||
min = last.id
|
max_id = last.id
|
||||||
max = first.id
|
|
||||||
|
limit =
|
||||||
|
params
|
||||||
|
|> Map.get("limit", "20")
|
||||||
|
|> String.to_integer()
|
||||||
|
|
||||||
|
min_id = Enum.at(activities, limit * -1)
|
||||||
|
|
||||||
{next_url, prev_url} =
|
{next_url, prev_url} =
|
||||||
if param do
|
if param do
|
||||||
|
@ -216,13 +221,13 @@ defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
|
||||||
Pleroma.Web.Endpoint,
|
Pleroma.Web.Endpoint,
|
||||||
method,
|
method,
|
||||||
param,
|
param,
|
||||||
Map.merge(params, %{max_id: min})
|
Map.merge(params, %{max_id: max_id})
|
||||||
),
|
),
|
||||||
mastodon_api_url(
|
mastodon_api_url(
|
||||||
Pleroma.Web.Endpoint,
|
Pleroma.Web.Endpoint,
|
||||||
method,
|
method,
|
||||||
param,
|
param,
|
||||||
Map.merge(params, %{since_id: max})
|
Map.merge(params, %{min_id: min_id})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -230,12 +235,12 @@ defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
|
||||||
mastodon_api_url(
|
mastodon_api_url(
|
||||||
Pleroma.Web.Endpoint,
|
Pleroma.Web.Endpoint,
|
||||||
method,
|
method,
|
||||||
Map.merge(params, %{max_id: min})
|
Map.merge(params, %{max_id: max_id})
|
||||||
),
|
),
|
||||||
mastodon_api_url(
|
mastodon_api_url(
|
||||||
Pleroma.Web.Endpoint,
|
Pleroma.Web.Endpoint,
|
||||||
method,
|
method,
|
||||||
Map.merge(params, %{since_id: max})
|
Map.merge(params, %{min_id: min_id})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1371,7 +1371,7 @@ test "getting followers, pagination", %{conn: conn} do
|
||||||
assert id2 == follower2.id
|
assert id2 == follower2.id
|
||||||
|
|
||||||
assert [link_header] = get_resp_header(res_conn, "link")
|
assert [link_header] = get_resp_header(res_conn, "link")
|
||||||
assert link_header =~ ~r/since_id=#{follower2.id}/
|
assert link_header =~ ~r/min_id=#{follower2.id}/
|
||||||
assert link_header =~ ~r/max_id=#{follower2.id}/
|
assert link_header =~ ~r/max_id=#{follower2.id}/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1450,7 +1450,7 @@ test "getting following, pagination", %{conn: conn} do
|
||||||
assert id2 == following2.id
|
assert id2 == following2.id
|
||||||
|
|
||||||
assert [link_header] = get_resp_header(res_conn, "link")
|
assert [link_header] = get_resp_header(res_conn, "link")
|
||||||
assert link_header =~ ~r/since_id=#{following2.id}/
|
assert link_header =~ ~r/min_id=#{following2.id}/
|
||||||
assert link_header =~ ~r/max_id=#{following2.id}/
|
assert link_header =~ ~r/max_id=#{following2.id}/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2261,7 +2261,7 @@ test "preserves parameters in link headers", %{conn: conn} do
|
||||||
|
|
||||||
assert [link_header] = get_resp_header(conn, "link")
|
assert [link_header] = get_resp_header(conn, "link")
|
||||||
assert link_header =~ ~r/media_only=true/
|
assert link_header =~ ~r/media_only=true/
|
||||||
assert link_header =~ ~r/since_id=#{notification2.id}/
|
assert link_header =~ ~r/min_id=#{notification2.id}/
|
||||||
assert link_header =~ ~r/max_id=#{notification1.id}/
|
assert link_header =~ ~r/max_id=#{notification1.id}/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue