checkpoint: updated follow and block

This commit is contained in:
Dan Anglin 2024-05-21 20:20:14 +01:00
parent 0002aa347e
commit 6ef2aec560
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 20 additions and 18 deletions

View file

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

View file

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