diff --git a/cmd/enbas/follow.go b/cmd/enbas/follow.go index 315fd32..db4bc0b 100644 --- a/cmd/enbas/follow.go +++ b/cmd/enbas/follow.go @@ -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 } diff --git a/cmd/enbas/main.go b/cmd/enbas/main.go index 3c34cc9..820890b 100644 --- a/cmd/enbas/main.go +++ b/cmd/enbas/main.go @@ -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() diff --git a/internal/client/follow.go b/internal/client/follow.go index 0b3b523..afc5449 100644 --- a/internal/client/follow.go +++ b/internal/client/follow.go @@ -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 +} diff --git a/internal/model/account_relationship.go b/internal/model/account_relationship.go index 1648d70..a7e0d9b 100644 --- a/internal/model/account_relationship.go +++ b/internal/model/account_relationship.go @@ -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,