From 6ad1c5436ae4b623143db9def4b160213456a69e Mon Sep 17 00:00:00 2001 From: r Date: Mon, 12 Feb 2024 05:51:06 +0000 Subject: Show follow request count on user page --- mastodon/accounts.go | 14 +++++++++----- service/service.go | 11 +++++++++-- templates/user.tmpl | 4 +++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/mastodon/accounts.go b/mastodon/accounts.go index 1a0ac2e..31021fd 100644 --- a/mastodon/accounts.go +++ b/mastodon/accounts.go @@ -40,6 +40,9 @@ type Account struct { Bot bool `json:"bot"` Source *AccountSource `json:"source"` Pleroma *AccountPleroma `json:"pleroma"` + + // Duplicate field for compatibilty with Pleroma + FollowRequestsCount int64 `json:"follow_requests_count"` } // Field is a Mastodon account profile field. @@ -51,11 +54,12 @@ type Field struct { // AccountSource is a Mastodon account profile field. type AccountSource struct { - Privacy *string `json:"privacy"` - Sensitive *bool `json:"sensitive"` - Language *string `json:"language"` - Note *string `json:"note"` - Fields *[]Field `json:"fields"` + Privacy *string `json:"privacy"` + Sensitive *bool `json:"sensitive"` + Language *string `json:"language"` + Note *string `json:"note"` + Fields *[]Field `json:"fields"` + FollowRequestsCount int64 `json:"follow_requests_count"` } // GetAccount return Account. diff --git a/service/service.go b/service/service.go index 953a1b9..0245042 100644 --- a/service/service.go +++ b/service/service.go @@ -511,12 +511,19 @@ func (s *service) UserPage(c *client, id string, pageType string, MinID: minID, Limit: 20, } + isCurrent := c.s.UserID == id - user, err := c.GetAccount(c.ctx, id) + // Some fields like AccountSource are only available in the + // CurrentUser API + var user *mastodon.Account + if isCurrent { + user, err = c.GetAccountCurrentUser(c.ctx) + } else { + user, err = c.GetAccount(c.ctx, id) + } if err != nil { return } - isCurrent := c.s.UserID == user.ID switch pageType { case "": diff --git a/templates/user.tmpl b/templates/user.tmpl index f34a9df..4323b2f 100644 --- a/templates/user.tmpl +++ b/templates/user.tmpl @@ -110,7 +110,9 @@ - likes - mutes - blocks - {{if .User.Locked}}- requests{{end}} + {{if .User.Locked}}- requests ( + {{- if .User.FollowRequestsCount}}{{.User.FollowRequestsCount}}{{else}}{{.User.Source.FollowRequestsCount}}{{end -}} + ){{end}} {{end}}
-- cgit v1.2.3