checkpoint: add ability to unfollow accounts

This commit is contained in:
Dan Anglin 2024-05-20 11:11:34 +01:00
parent 4d0522eb49
commit 0e8f83f4e0
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 21 additions and 1 deletions

View file

@ -71,5 +71,11 @@ func (c *followCommand) followAccount(gts *client.Client) error {
}
func (c *followCommand) unfollowAccount(gts *client.Client) error {
if err := gts.UnfollowAccount(c.accountID); err != nil {
return fmt.Errorf("unable to unfollow the account; %w", err)
}
fmt.Println("Successfully unfollowed the account.")
return nil
}

View file

@ -58,6 +58,7 @@ func run() error {
add string = "add"
remove string = "remove"
follow string = "follow"
unfollow string = "unfollow"
)
summaries := map[string]string{
@ -72,6 +73,7 @@ func run() error {
add: "add a resource to another resource",
remove: "remove a resource from another resource",
follow: "follow a resource (e.g. an account)",
unfollow: "unfollow a resource (e.g. an account)",
}
flag.Usage = enbasUsageFunc(summaries)
@ -112,6 +114,8 @@ func run() error {
executor = newRemoveCommand(remove, summaries[remove])
case follow:
executor = newFollowCommand(follow, summaries[follow], false)
case unfollow:
executor = newFollowCommand(unfollow, summaries[unfollow], true)
default:
flag.Usage()

View file

@ -32,3 +32,13 @@ func (g *Client) FollowAccount(accountID string, reblogs, notify bool) error {
return nil
}
func (g *Client) UnfollowAccount(accountID string) error {
url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/unfollow", accountID)
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf("received an error after sending the request to unfollow the account; %w", err)
}
return nil
}

View file

@ -44,7 +44,7 @@ func (a AccountRelationship) String() string {
output := fmt.Sprintf(
format,
utilities.HeaderFormat("YOUR RELATIONSHIP TO THIS ACCOUNT:"),
utilities.HeaderFormat("YOUR RELATIONSHIP WITH THIS ACCOUNT:"),
utilities.FieldFormat("Following"), a.Following,
utilities.FieldFormat("Is following you"), a.FollowedBy,
utilities.FieldFormat("A follow request was sent and is pending"), a.FollowRequested,