checkpoint: view the list of starred statuses

This commit is contained in:
Dan Anglin 2024-06-04 15:57:04 +01:00
parent 708816476a
commit c7de5477ed
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
5 changed files with 43 additions and 26 deletions

View file

@ -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
}

View file

@ -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,
}

View file

@ -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"
)

View file

@ -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
}

View file

@ -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")