checkpoint: display followed accounts

This commit is contained in:
Dan Anglin 2024-05-20 15:41:45 +01:00
parent c080568c2d
commit 031dd9a0b0
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 53 additions and 2 deletions

View file

@ -31,6 +31,7 @@ const (
statusResource = "status"
timelineResource = "timeline"
followersResource = "followers"
followingResource = "following"
)
type Executor interface {

View file

@ -57,6 +57,7 @@ func (c *showCommand) Execute() error {
timelineResource: c.showTimeline,
listResource: c.showList,
followersResource: c.showFollowers,
followingResource: c.showFollowing,
}
doFunc, ok := funcMap[c.resourceType]
@ -197,6 +198,7 @@ func (c *showCommand) showList(gts *client.Client) error {
for i := range accounts {
accountMap[accounts[i].ID] = accounts[i].Username
}
list.Accounts = accountMap
}
@ -241,3 +243,22 @@ func (c *showCommand) showFollowers(gts *client.Client) error {
return nil
}
func (c *showCommand) showFollowing(gts *client.Client) error {
if c.accountID == "" {
return flagNotSetError{flagText: accountIDFlag}
}
following, err := gts.GetFollowing(c.accountID, c.limit)
if err != nil {
return fmt.Errorf("unable to retrieve the list of followed accounts; %w", err)
}
if len(following) > 0 {
fmt.Println(following)
} else {
fmt.Println("This account is not following anyone or the list is hidden.")
}
return nil
}

View file

@ -51,8 +51,20 @@ func (g *Client) GetFollowers(accountID string, limit int) (model.Followers, err
var followers model.Followers
if err := g.sendRequest(http.MethodGet, url, nil, &followers); err != nil {
return nil, fmt.Errorf("received an error after sending the request to get followers; %w", err)
return nil, fmt.Errorf("received an error after sending the request to get the list of followers; %w", err)
}
return followers, nil
}
func (g *Client) GetFollowing(accountID string, limit int) (model.Following, error) {
url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/following?limit=%d", accountID, limit)
var following model.Following
if err := g.sendRequest(http.MethodGet, url, nil, &following); err != nil {
return nil, fmt.Errorf("received an error after sending the request to get the list of followed accounts; %w", err)
}
return following, nil
}

View file

@ -10,7 +10,24 @@ type Followers []Account
func (f Followers) String() string {
output := "\n"
output += utilities.HeaderFormat("FOLLOWERS:")
output += utilities.HeaderFormat("FOLLOWED BY:")
for i := range f {
output += fmt.Sprintf(
"\n • %s (%s)",
utilities.DisplayNameFormat(f[i].DisplayName),
f[i].Acct,
)
}
return output
}
type Following []Account
func (f Following) String() string {
output := "\n"
output += utilities.HeaderFormat("FOLLOWING:")
for i := range f {
output += fmt.Sprintf(