fix: check following before adding to list

Check if the user is following a specified account before adding it to a
list.
This commit is contained in:
Dan Anglin 2024-06-16 20:29:16 +01:00
parent eb2d9f44f6
commit f73f1f5872
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 18 additions and 1 deletions

View file

@ -105,7 +105,16 @@ func (a *AddExecutor) addAccountsToList(gtsClient *client.Client) error {
for ind := range a.accountNames { for ind := range a.accountNames {
accountID, err := getTheirAccountID(gtsClient, a.accountNames[ind]) accountID, err := getTheirAccountID(gtsClient, a.accountNames[ind])
if err != nil { 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 accountIDs[ind] = accountID

View file

@ -94,3 +94,11 @@ func (e NoPollOptionError) Error() string {
flagPollOption + flagPollOption +
" flag to add options to the poll" " flag to add options to the poll"
} }
type NotFollowingError struct {
Account string
}
func (e NotFollowingError) Error() string {
return "you are not following " + e.Account
}