From aa5d0c611a4a5cdfefe3229def42834a6af05a51 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Sat, 9 May 2026 09:00:59 +0100 Subject: [PATCH] appview/state: fix pagination in vouches tab Signed-off-by: oppiliappan --- appview/db/vouch.go | 17 +++++++++++++++++ appview/pages/pages.go | 1 + appview/pages/templates/user/vouches.html | 4 ++-- appview/state/profile.go | 8 ++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/appview/db/vouch.go b/appview/db/vouch.go index 3acf054a..b2d00050 100644 --- a/appview/db/vouch.go +++ b/appview/db/vouch.go @@ -169,6 +169,23 @@ func DeleteVouchByRkey(e Execer, did, rkey string) error { return err } +func CountNetworkVouchTimeline(e Execer, viewerDid, profileDid string) (int, error) { + var count int + err := e.QueryRow( + `select count(*) from ( + select v.id from vouches v + where ( + v.subject_did = ? and v.did in (select subject_did from vouches where did = ? and kind = 'vouch') + ) or ( + v.did = ? and v.subject_did in (select subject_did from vouches where did = ? and kind = 'vouch') + ) + group by v.did, v.subject_did + )`, + profileDid, viewerDid, profileDid, viewerDid, + ).Scan(&count) + return count, err +} + func GetNetworkVouchTimeline(e Execer, viewerDid, profileDid string, page pagination.Page) ([]models.Vouch, error) { pageClause := "" if page.Limit > 0 { diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 92fa26e6..88a9b373 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -717,6 +717,7 @@ type ProfileVouchesParams struct { Suggestions []models.VouchSuggestion Card *ProfileCard Page pagination.Page + VouchCount int Active string EvidencePulls map[syntax.ATURI]*models.Pull EvidenceIssues map[syntax.ATURI]*models.Issue diff --git a/appview/pages/templates/user/vouches.html b/appview/pages/templates/user/vouches.html index 9cf51414..0c081b97 100644 --- a/appview/pages/templates/user/vouches.html +++ b/appview/pages/templates/user/vouches.html @@ -5,11 +5,11 @@
{{ if $isSelf }}{{ template "vouchSuggestions" . }}{{ end }} {{ block "vouchTimeline" . }}{{ end }} - {{ if ge (len .Vouches) .Page.Limit }} + {{ if gt .VouchCount .Page.Limit }} {{ $handle := resolve .Card.UserDid }} {{ template "fragments/pagination" (dict "Page" .Page - "TotalCount" (add (len .Vouches) .Page.Offset) + "TotalCount" .VouchCount "BasePath" (printf "/%s" $handle) "QueryParams" (queryParams "tab" "vouches") ) }} diff --git a/appview/state/profile.go b/appview/state/profile.go index 6fae8398..71f095ba 100644 --- a/appview/state/profile.go +++ b/appview/state/profile.go @@ -406,6 +406,7 @@ func (s *State) vouchesPage(w http.ResponseWriter, r *http.Request) { page := pagination.FromContext(r.Context()) var vouches []models.Vouch + var vouchCount int if loggedInUser != nil { vouches, err = db.GetNetworkVouchTimeline(s.db, loggedInUser.Did, profile.UserDid, page) if err != nil { @@ -413,6 +414,12 @@ func (s *State) vouchesPage(w http.ResponseWriter, r *http.Request) { s.pages.Error500(w) return } + vouchCount, err = db.CountNetworkVouchTimeline(s.db, loggedInUser.Did, profile.UserDid) + if err != nil { + l.Error("failed to count vouch timeline", "err", err) + s.pages.Error500(w) + return + } } var suggestions []models.VouchSuggestion @@ -480,6 +487,7 @@ func (s *State) vouchesPage(w http.ResponseWriter, r *http.Request) { Suggestions: suggestions, Card: profile, Page: page, + VouchCount: vouchCount, EvidencePulls: evidencePulls, EvidenceIssues: evidenceIssues, }) -- 2.51.2