checkpoint: check if user can mute or unmute a status
This commit is contained in:
parent
57973f63d1
commit
0a7620a16e
2 changed files with 56 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue