diff --git a/internal/executor/mute.go b/internal/executor/mute.go index 1696e45..f8cd30d 100644 --- a/internal/executor/mute.go +++ b/internal/executor/mute.go @@ -1,6 +1,7 @@ package executor import ( + "errors" "fmt" "codeflow.dananglin.me.uk/apollo/enbas/internal/client" @@ -50,6 +51,33 @@ func (m *MuteExecutor) muteStatus(gtsClient *client.Client) error { return FlagNotSetError{flagText: flagStatusID} } + status, err := gtsClient.GetStatus(m.statusID) + if err != nil { + return fmt.Errorf("unable to retrieve the status: %w", err) + } + + myAccountID, err := getAccountID(gtsClient, true, nil) + if err != nil { + return fmt.Errorf("unable to get your account ID: %w", err) + } + + canMute := false + + if status.Account.ID == myAccountID { + canMute = true + } else { + for _, mention := range status.Mentions { + if mention.ID == myAccountID { + canMute = true + break + } + } + } + + if !canMute { + return errors.New("unable to mute the status because you are not the owner and you are not mentioned in it") + } + if err := gtsClient.MuteStatus(m.statusID); err != nil { return fmt.Errorf("unable to mute the status: %w", err) } diff --git a/internal/executor/unmute.go b/internal/executor/unmute.go index 487451d..d643e46 100644 --- a/internal/executor/unmute.go +++ b/internal/executor/unmute.go @@ -1,6 +1,7 @@ package executor import ( + "errors" "fmt" "codeflow.dananglin.me.uk/apollo/enbas/internal/client" @@ -45,6 +46,33 @@ func (m *UnmuteExecutor) unmuteStatus(gtsClient *client.Client) error { return FlagNotSetError{flagText: flagStatusID} } + status, err := gtsClient.GetStatus(m.statusID) + if err != nil { + return fmt.Errorf("unable to retrieve the status: %w", err) + } + + myAccountID, err := getAccountID(gtsClient, true, nil) + if err != nil { + return fmt.Errorf("unable to get your account ID: %w", err) + } + + canUnmute := false + + if status.Account.ID == myAccountID { + canUnmute = true + } else { + for _, mention := range status.Mentions { + if mention.ID == myAccountID { + canUnmute = true + break + } + } + } + + if !canUnmute { + return errors.New("unable to unmute the status because you are not the owner and you are not mentioned in it") + } + if err := gtsClient.UnmuteStatus(m.statusID); err != nil { return fmt.Errorf("unable to unmute the status: %w", err) }