Fix timeline pagination

This commit is contained in:
r 2019-12-25 04:39:34 +00:00
parent 1939d120cd
commit c18a1be21a
1 changed files with 5 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
@ -243,7 +244,7 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
if len(maxID) > 0 && len(statuses) > 0 { if len(maxID) > 0 && len(statuses) > 0 {
hasPrev = true hasPrev = true
prevLink = "/timeline?min_id=" + statuses[0].ID prevLink = fmt.Sprintf("/timeline/$s?min_id=%s", timelineType, statuses[0].ID)
} }
if len(minID) > 0 && len(pg.MinID) > 0 { if len(minID) > 0 && len(pg.MinID) > 0 {
newStatuses, err := c.GetTimelineHome(ctx, &mastodon.Pagination{MinID: pg.MinID, Limit: 20}) newStatuses, err := c.GetTimelineHome(ctx, &mastodon.Pagination{MinID: pg.MinID, Limit: 20})
@ -253,18 +254,18 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
newStatusesLen := len(newStatuses) newStatusesLen := len(newStatuses)
if newStatusesLen == 20 { if newStatusesLen == 20 {
hasPrev = true hasPrev = true
prevLink = "/timeline?min_id=" + pg.MinID prevLink = fmt.Sprintf("/timeline/%s?min_id=%s", timelineType, pg.MinID)
} else { } else {
i := 20 - newStatusesLen - 1 i := 20 - newStatusesLen - 1
if len(statuses) > i { if len(statuses) > i {
hasPrev = true hasPrev = true
prevLink = "/timeline?min_id=" + statuses[i].ID prevLink = fmt.Sprintf("/timeline/%s?min_id=%s", timelineType, statuses[i].ID)
} }
} }
} }
if len(pg.MaxID) > 0 { if len(pg.MaxID) > 0 {
hasNext = true hasNext = true
nextLink = "/timeline?max_id=" + pg.MaxID nextLink = fmt.Sprintf("/timeline/%s?max_id=%s", timelineType, pg.MaxID)
} }
postContext := model.PostContext{ postContext := model.PostContext{