From 6ef2aec560cb93bfa5a2fc70c3507e3211228fcb Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Tue, 21 May 2024 20:20:14 +0100 Subject: [PATCH] checkpoint: updated follow and block --- cmd/enbas/block.go | 19 ++++++++++--------- cmd/enbas/follow.go | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/cmd/enbas/block.go b/cmd/enbas/block.go index 6eb6413..03a7069 100644 --- a/cmd/enbas/block.go +++ b/cmd/enbas/block.go @@ -11,7 +11,7 @@ type blockCommand struct { *flag.FlagSet resourceType string - accountID string + accountName string unblock bool } @@ -23,7 +23,7 @@ func newBlockCommand(name, summary string, unblock bool) *blockCommand { } command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to block or unblock") - command.StringVar(&command.accountID, accountIDFlag, "", "specify the ID of the account you want to block or unblock") + command.StringVar(&command.accountName, accountNameFlag, "", "specify the account name in full (username@domain)") command.Usage = commandUsageFunc(name, summary, command.FlagSet) @@ -48,16 +48,17 @@ func (c *blockCommand) Execute() error { return doFunc(gtsClient) } -func (c *blockCommand) blockAccount(gts *client.Client) error { - if c.accountID == "" { - return flagNotSetError{flagText: accountIDFlag} +func (c *blockCommand) blockAccount(gtsClient *client.Client) error { + accountID, err := getAccountID(gtsClient, false, c.accountName) + if err != nil { + return fmt.Errorf("received an error while getting the account ID; %w", err) } if c.unblock { - return c.unblockAccount(gts) + return c.unblockAccount(gtsClient, accountID) } - if err := gts.BlockAccount(c.accountID); err != nil { + if err := gtsClient.BlockAccount(accountID); err != nil { return fmt.Errorf("unable to block the account; %w", err) } @@ -66,8 +67,8 @@ func (c *blockCommand) blockAccount(gts *client.Client) error { return nil } -func (c *blockCommand) unblockAccount(gts *client.Client) error { - if err := gts.UnblockAccount(c.accountID); err != nil { +func (c *blockCommand) unblockAccount(gtsClient *client.Client, accountID string) error { + if err := gtsClient.UnblockAccount(accountID); err != nil { return fmt.Errorf("unable to unblock the account; %w", err) } diff --git a/cmd/enbas/follow.go b/cmd/enbas/follow.go index 20ff36d..ff0148e 100644 --- a/cmd/enbas/follow.go +++ b/cmd/enbas/follow.go @@ -11,7 +11,7 @@ type followCommand struct { *flag.FlagSet resourceType string - accountID string + accountName string showReposts bool notify bool unfollow bool @@ -25,7 +25,7 @@ func newFollowCommand(name, summary string, unfollow bool) *followCommand { } command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to follow") - command.StringVar(&command.accountID, accountIDFlag, "", "specify the ID of the account you want to follow") + command.StringVar(&command.accountName, accountNameFlag, "", "specify the account name in full (username@domain)") command.BoolVar(&command.showReposts, showRepostsFlag, true, "show reposts from the account you want to follow") command.BoolVar(&command.notify, notifyFlag, false, "get notifications when the account you want to follow posts a status") @@ -52,16 +52,17 @@ func (c *followCommand) Execute() error { return doFunc(gtsClient) } -func (c *followCommand) followAccount(gts *client.Client) error { - if c.accountID == "" { - return flagNotSetError{flagText: accountIDFlag} +func (c *followCommand) followAccount(gtsClient *client.Client) error { + accountID, err := getAccountID(gtsClient, false, c.accountName) + if err != nil { + return fmt.Errorf("received an error while getting the account ID; %w", err) } if c.unfollow { - return c.unfollowAccount(gts) + return c.unfollowAccount(gtsClient, accountID) } - if err := gts.FollowAccount(c.accountID, c.showReposts, c.notify); err != nil { + if err := gtsClient.FollowAccount(accountID, c.showReposts, c.notify); err != nil { return fmt.Errorf("unable to follow the account; %w", err) } @@ -70,8 +71,8 @@ func (c *followCommand) followAccount(gts *client.Client) error { return nil } -func (c *followCommand) unfollowAccount(gts *client.Client) error { - if err := gts.UnfollowAccount(c.accountID); err != nil { +func (c *followCommand) unfollowAccount(gtsClient *client.Client, accountID string) error { + if err := gtsClient.UnfollowAccount(accountID); err != nil { return fmt.Errorf("unable to unfollow the account; %w", err) }