diff --git a/internal/client/statuses.go b/internal/client/statuses.go index fd0629c..ea75e12 100644 --- a/internal/client/statuses.go +++ b/internal/client/statuses.go @@ -68,8 +68,7 @@ func (g *Client) GetBookmarks(limit int) (model.StatusList, error) { url := g.Authentication.Instance + path bookmarks := model.StatusList{ - Type: model.StatusListBookMarks, - Name: "BOOKMARKS", + Name: "Your Bookmarks", Statuses: nil, } @@ -136,3 +135,21 @@ func (g *Client) UnlikeStatus(statusID string) error { return nil } + +func (g *Client) GetLikedStatuses(limit int, resourceName string) (model.StatusList, error) { + url := g.Authentication.Instance + fmt.Sprintf("/api/v1/favourites?limit=%d", limit) + + liked := model.StatusList{ + Name: "Your " + resourceName + " statuses", + Statuses: nil, + } + + if err := g.sendRequest(http.MethodGet, url, nil, &liked.Statuses); err != nil { + return model.StatusList{}, fmt.Errorf( + "received an error after sending the request to get the list of statuses: %w", + err, + ) + } + + return liked, nil +} diff --git a/internal/client/timelines.go b/internal/client/timelines.go index d27454f..8bfe753 100644 --- a/internal/client/timelines.go +++ b/internal/client/timelines.go @@ -15,8 +15,7 @@ func (g *Client) GetHomeTimeline(limit int) (model.StatusList, error) { path := fmt.Sprintf("/api/v1/timelines/home?limit=%d", limit) timeline := model.StatusList{ - Type: model.StatusListTimeline, - Name: "HOME", + Name: "Timeline: Home", Statuses: nil, } @@ -27,8 +26,7 @@ func (g *Client) GetPublicTimeline(limit int) (model.StatusList, error) { path := fmt.Sprintf("/api/v1/timelines/public?limit=%d", limit) timeline := model.StatusList{ - Type: model.StatusListTimeline, - Name: "PUBLIC", + Name: "Timeline: Public", Statuses: nil, } @@ -39,8 +37,7 @@ func (g *Client) GetListTimeline(listID, title string, limit int) (model.StatusL path := fmt.Sprintf("/api/v1/timelines/list/%s?limit=%d", listID, limit) timeline := model.StatusList{ - Type: model.StatusListTimeline, - Name: "LIST (" + title + ")", + Name: "Timeline: List (" + title + ")", Statuses: nil, } @@ -51,8 +48,7 @@ func (g *Client) GetTagTimeline(tag string, limit int) (model.StatusList, error) path := fmt.Sprintf("/api/v1/timelines/tag/%s?limit=%d", tag, limit) timeline := model.StatusList{ - Type: model.StatusListTimeline, - Name: "TAG (" + tag + ")", + Name: "Timeline: Tag (" + tag + ")", Statuses: nil, } diff --git a/internal/executor/const.go b/internal/executor/const.go index 386baf4..c020684 100644 --- a/internal/executor/const.go +++ b/internal/executor/const.go @@ -42,9 +42,11 @@ const ( resourceFollowing = "following" resourceInstance = "instance" resourceLike = "like" + resourceLiked = "liked" resourceList = "list" resourceNote = "note" resourceStatus = "status" resourceStar = "star" + resourceStarred = "starred" resourceTimeline = "timeline" ) diff --git a/internal/executor/show.go b/internal/executor/show.go index a51cb97..10a7069 100644 --- a/internal/executor/show.go +++ b/internal/executor/show.go @@ -67,6 +67,8 @@ func (s *ShowExecutor) Execute() error { resourceFollowing: s.showFollowing, resourceBlocked: s.showBlocked, resourceBookmarks: s.showBookmarks, + resourceLiked: s.showLiked, + resourceStarred: s.showLiked, } doFunc, ok := funcMap[s.resourceType] @@ -329,3 +331,18 @@ func (s *ShowExecutor) showBookmarks(gtsClient *client.Client) error { return nil } + +func (s *ShowExecutor) showLiked(gtsClient *client.Client) error { + liked, err := gtsClient.GetLikedStatuses(s.limit, s.resourceType) + if err != nil { + return fmt.Errorf("unable to retrieve the list of your %s statuses: %w", s.resourceType, err) + } + + if len(liked.Statuses) > 0 { + utilities.Display(liked, *s.topLevelFlags.NoColor) + } else { + fmt.Printf("You have no %s statuses.\n", s.resourceType) + } + + return nil +} diff --git a/internal/model/status.go b/internal/model/status.go index 85fb8be..486e0e5 100644 --- a/internal/model/status.go +++ b/internal/model/status.go @@ -201,32 +201,17 @@ func (s Status) Display(noColor bool) string { ) } -type StatusListType int - -const ( - StatusListTimeline StatusListType = iota - StatusListBookMarks -) - type StatusList struct { - Type StatusListType Name string Statuses []Status } func (s StatusList) Display(noColor bool) string { var builder strings.Builder - var name string separator := "────────────────────────────────────────────────────────────────────────────────" - if s.Type == StatusListTimeline { - name = "TIMELINE: " + s.Name - } else { - name = s.Name - } - - builder.WriteString(utilities.HeaderFormat(noColor, name) + "\n") + builder.WriteString(utilities.HeaderFormat(noColor, s.Name) + "\n") for _, status := range s.Statuses { builder.WriteString("\n" + utilities.DisplayNameFormat(noColor, status.Account.DisplayName) + " (@" + status.Account.Acct + ")\n")