From 6418307c64da236a0268f4496f793d982e128ad0 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 13 Jul 2022 09:57:47 +0200 Subject: [feature] Add back/next buttons to profiles for paging through statuses (#708) * add GetAccountWebStatuses to db * add WebStatusesGet func to processor * don't add limit to next/prev links if 0 * take query params for next/prev statuses * add separate next + prev links for convenience * show 'nothing here' message if no statuses exist * add back / next links to profiles * allow paging down only * go fmt ./... * 'recent public toots' -> 'latest public toots' --- internal/web/profile.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'internal/web/profile.go') diff --git a/internal/web/profile.go b/internal/web/profile.go index ce3fe645b..542c015f1 100644 --- a/internal/web/profile.go +++ b/internal/web/profile.go @@ -36,6 +36,11 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) +const ( + // MaxStatusIDKey is for specifying the maximum ID of the status to retrieve. + MaxStatusIDKey = "max_id" +) + func (m *Module) profileGETHandler(c *gin.Context) { ctx := c.Request.Context() @@ -78,10 +83,18 @@ func (m *Module) profileGETHandler(c *gin.Context) { return } - // get latest 10 top-level public statuses; - // ie., exclude replies and boosts, public only, - // with or without media - statusResp, errWithCode := m.processor.AccountStatusesGet(ctx, authed, account.ID, 10, true, true, "", "", false, false, true) + // we should only show the 'back to top' button if the + // profile visitor is paging through statuses + showBackToTop := false + + maxStatusID := "" + maxStatusIDString := c.Query(MaxStatusIDKey) + if maxStatusIDString != "" { + maxStatusID = maxStatusIDString + showBackToTop = true + } + + statusResp, errWithCode := m.processor.AccountWebStatusesGet(ctx, account.ID, maxStatusID) if errWithCode != nil { api.ErrorHandler(c, errWithCode, instanceGet) return @@ -103,9 +116,11 @@ func (m *Module) profileGETHandler(c *gin.Context) { } c.HTML(http.StatusOK, "profile.tmpl", gin.H{ - "instance": instance, - "account": account, - "statuses": statusResp.Items, + "instance": instance, + "account": account, + "statuses": statusResp.Items, + "statuses_next": statusResp.NextLink, + "show_back_to_top": showBackToTop, "stylesheets": []string{ "/assets/Fork-Awesome/css/fork-awesome.min.css", "/assets/dist/status.css", -- cgit v1.2.3