From f73f1f5872d6dd9191408e538fb126d1caa8eeff Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sun, 16 Jun 2024 20:29:16 +0100 Subject: [PATCH] fix: check following before adding to list Check if the user is following a specified account before adding it to a list. --- internal/executor/add.go | 11 ++++++++++- internal/executor/errors.go | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/executor/add.go b/internal/executor/add.go index 25350dc..d48926b 100644 --- a/internal/executor/add.go +++ b/internal/executor/add.go @@ -105,7 +105,16 @@ func (a *AddExecutor) addAccountsToList(gtsClient *client.Client) error { for ind := range a.accountNames { accountID, err := getTheirAccountID(gtsClient, a.accountNames[ind]) if err != nil { - return fmt.Errorf("unable to get the account ID for %s, %w", a.accountNames[ind], err) + return fmt.Errorf("unable to get the account ID for %s: %w", a.accountNames[ind], err) + } + + relationship, err := gtsClient.GetAccountRelationship(accountID) + if err != nil { + return fmt.Errorf("unable to get your relationship to %s: %w", a.accountNames[ind], err) + } + + if !relationship.Following { + return NotFollowingError{Account: a.accountNames[ind]} } accountIDs[ind] = accountID diff --git a/internal/executor/errors.go b/internal/executor/errors.go index b001de7..3e5f571 100644 --- a/internal/executor/errors.go +++ b/internal/executor/errors.go @@ -94,3 +94,11 @@ func (e NoPollOptionError) Error() string { flagPollOption + " flag to add options to the poll" } + +type NotFollowingError struct { + Account string +} + +func (e NotFollowingError) Error() string { + return "you are not following " + e.Account +}