From ca99d0a789f6ee1739103c158a2ccceaaf591bbb Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 26 Oct 2022 00:44:22 +0300 Subject: [PATCH] Added view pinned statuses in accounts --- mastodon/accounts.go | 3 ++- service/service.go | 13 +++++++++++-- templates/user.tmpl | 11 ++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/mastodon/accounts.go b/mastodon/accounts.go index 4f69e79..19b1714 100644 --- a/mastodon/accounts.go +++ b/mastodon/accounts.go @@ -152,10 +152,11 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account, } // GetAccountStatuses return statuses by specified accuont. -func (c *Client) GetAccountStatuses(ctx context.Context, id string, onlyMedia bool, pg *Pagination) ([]*Status, error) { +func (c *Client) GetAccountStatuses(ctx context.Context, id string, onlyMedia bool, onlyPinned bool, pg *Pagination) ([]*Status, error) { var statuses []*Status params := url.Values{} params.Set("only_media", strconv.FormatBool(onlyMedia)) + params.Set("pinned", strconv.FormatBool(onlyPinned)) err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/statuses", url.PathEscape(string(id))), params, &statuses, pg) if err != nil { return nil, err diff --git a/service/service.go b/service/service.go index eef434a..e30d5fc 100644 --- a/service/service.go +++ b/service/service.go @@ -610,7 +610,7 @@ func (s *service) UserPage(c *client, id string, pageType string, switch pageType { case "": - statuses, err = c.GetAccountStatuses(c.ctx, id, false, &pg) + statuses, err = c.GetAccountStatuses(c.ctx, id, false, false, &pg) if err != nil { return } @@ -637,7 +637,7 @@ func (s *service) UserPage(c *client, id string, pageType string, id, pg.MaxID) } case "media": - statuses, err = c.GetAccountStatuses(c.ctx, id, true, &pg) + statuses, err = c.GetAccountStatuses(c.ctx, id, true, false, &pg) if err != nil { return } @@ -645,6 +645,15 @@ func (s *service) UserPage(c *client, id string, pageType string, nextLink = fmt.Sprintf("/user/%s/media?max_id=%s", id, pg.MaxID) } + case "pinned": + statuses, err = c.GetAccountStatuses(c.ctx, id, false, true, &pg) + if err != nil { + return + } + if len(statuses) == 20 && len(pg.MaxID) > 0 { + nextLink = fmt.Sprintf("/user/%s/pinned?max_id=%s", + id, pg.MaxID) + } case "bookmarks": if !isCurrent { return errInvalidArgument diff --git a/templates/user.tmpl b/templates/user.tmpl index b5a65ca..53bf7a0 100644 --- a/templates/user.tmpl +++ b/templates/user.tmpl @@ -115,7 +115,8 @@ statuses ({{.User.StatusesCount}}) - following ({{.User.FollowingCount}}) - followers ({{.User.FollowersCount}}) - - media + media - + pinned statuses {{if .IsCurrent}}
@@ -173,6 +174,14 @@
No data found
{{end}} +{{else if eq .Type "pinned"}} +
Pinned statuses
+{{range .Statuses}} +{{template "status.tmpl" (WithContext . $.Ctx)}} +{{else}} +
No data found
+{{end}} + {{else if eq .Type "bookmarks"}}
Bookmarks
{{range .Statuses}}