Keep cursor cleanup scoped to grouped notifications
This commit is contained in:
parent
1db2b99e48
commit
a2a23b327b
2 changed files with 9 additions and 5 deletions
|
|
@ -56,7 +56,11 @@ defmodule Pleroma.Web.ControllerHelper do
|
|||
# TODO: Only fetch the params from open_api_spex when everything is converted
|
||||
@id_keys Pagination.page_keys() -- ["limit", "order"]
|
||||
@id_key_atoms Enum.map(@id_keys, &String.to_atom/1)
|
||||
@drop_id_params_key :drop_id_params
|
||||
defp build_pagination_fields(conn, min_id, max_id, extra_params, order) do
|
||||
drop_id_params? = Map.get(extra_params, @drop_id_params_key, false)
|
||||
extra_params = Map.delete(extra_params, @drop_id_params_key)
|
||||
|
||||
path_param_keys =
|
||||
conn.path_params
|
||||
|> Map.keys()
|
||||
|
|
@ -70,9 +74,9 @@ defmodule Pleroma.Web.ControllerHelper do
|
|||
end
|
||||
|> Map.drop(path_param_keys)
|
||||
|> Map.merge(extra_params)
|
||||
# OpenApiSpex casts params to atoms while uncast conn params are string-keyed. Drop both so
|
||||
# generated links replace pagination cursors instead of preserving stale request cursors.
|
||||
|> Map.drop(@id_keys ++ @id_key_atoms)
|
||||
# Some OpenApiSpex routes cast cursor params to atoms. Keep the historical default for
|
||||
# existing endpoints, but allow grouped notifications to opt out of stale request cursors.
|
||||
|> Map.drop(@id_keys ++ if(drop_id_params?, do: @id_key_atoms, else: []))
|
||||
|
||||
{{next_id, nid}, {prev_id, pid}} =
|
||||
if order == :desc,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.NotificationController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
|
||||
import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2, add_link_headers: 3]
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.User
|
||||
|
|
@ -184,7 +184,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do
|
|||
MastodonAPI.get_grouped_notification_page(user, params)
|
||||
|
||||
conn
|
||||
|> add_link_headers(page_notifications)
|
||||
|> add_link_headers(page_notifications, %{drop_id_params: true})
|
||||
|> render("grouped_index.json",
|
||||
notification_groups: notification_groups,
|
||||
notification_group_counts: notification_group_counts,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue