summaryrefslogtreecommitdiff
path: root/internal/util
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-09-29 15:31:10 +0200
committerLibravatar GitHub <noreply@github.com>2023-09-29 15:31:10 +0200
commit2b6b9cdf832078980ca668126bce3b4fcfff02a9 (patch)
tree77928699c5e40a20233ad2b795213cdb98a7d92e /internal/util
parent[frontend] Add `discoverable` flag to settings panel (#2235) (diff)
downloadgotosocial-2b6b9cdf832078980ca668126bce3b4fcfff02a9.tar.xz
[bugfix] Fix paging for empty items (#2236)
* use minID properly for public timeline * return paged response properly even when 0 items * use gtserror * page more consistently (for now) * test * aaa
Diffstat (limited to 'internal/util')
-rw-r--r--internal/util/paging.go5
-rw-r--r--internal/util/paging_test.go7
2 files changed, 4 insertions, 8 deletions
diff --git a/internal/util/paging.go b/internal/util/paging.go
index 0ab4b9567..190f40afd 100644
--- a/internal/util/paging.go
+++ b/internal/util/paging.go
@@ -48,11 +48,6 @@ type PageableResponseParams struct {
// a bunch of pageable items (notifications, statuses, etc), as well
// as a Link header to inform callers of where to find next/prev items.
func PackagePageableResponse(params PageableResponseParams) (*apimodel.PageableResponse, gtserror.WithCode) {
- if len(params.Items) == 0 {
- // No items to page through.
- return EmptyPageableResponse(), nil
- }
-
// Set default paging values, if
// they weren't set by the caller.
if params.NextMaxIDKey == "" {
diff --git a/internal/util/paging_test.go b/internal/util/paging_test.go
index 685db14ba..66c5b2c56 100644
--- a/internal/util/paging_test.go
+++ b/internal/util/paging_test.go
@@ -118,6 +118,7 @@ func (suite *PagingSuite) TestPagingNoItems() {
config.SetHost("example.org")
params := util.PageableResponseParams{
+ Path: "/api/v1/accounts/01H11KA68PM4NNYJEG0FJQ90R3/statuses",
NextMaxIDValue: "01H11KA1DM2VH3747YDE7FV5HN",
PrevMinIDValue: "01H11KBBVRRDYYC5KEPME1NP5R",
Limit: 10,
@@ -129,9 +130,9 @@ func (suite *PagingSuite) TestPagingNoItems() {
}
suite.Empty(resp.Items)
- suite.Empty(resp.LinkHeader)
- suite.Empty(resp.NextLink)
- suite.Empty(resp.PrevLink)
+ suite.Equal(`<https://example.org/api/v1/accounts/01H11KA68PM4NNYJEG0FJQ90R3/statuses?limit=10&max_id=01H11KA1DM2VH3747YDE7FV5HN>; rel="next", <https://example.org/api/v1/accounts/01H11KA68PM4NNYJEG0FJQ90R3/statuses?limit=10&min_id=01H11KBBVRRDYYC5KEPME1NP5R>; rel="prev"`, resp.LinkHeader)
+ suite.Equal(`https://example.org/api/v1/accounts/01H11KA68PM4NNYJEG0FJQ90R3/statuses?limit=10&max_id=01H11KA1DM2VH3747YDE7FV5HN`, resp.NextLink)
+ suite.Equal(`https://example.org/api/v1/accounts/01H11KA68PM4NNYJEG0FJQ90R3/statuses?limit=10&min_id=01H11KBBVRRDYYC5KEPME1NP5R`, resp.PrevLink)
}
func TestPagingSuite(t *testing.T) {