checkpoint: add default user posting preferences for consideration

This commit is contained in:
Dan Anglin 2024-05-30 05:46:28 +01:00
parent b2dc570385
commit 4038814d6a
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 43 additions and 20 deletions

View file

@ -2,24 +2,33 @@ package executor
const (
flagAccountName = "account-name"
flagBoostable = "boostable"
flagBrowser = "browser"
flagContentType = "content-type"
flagContent = "content"
flagFederated = "federated"
flagFrom = "from"
flagInstance = "instance"
flagLanguage = "language"
flagLikeable = "likeable"
flagLimit = "limit"
flagListID = "list-id"
flagListTitle = "list-title"
flagListRepliesPolicy = "list-replies-policy"
flagMyAccount = "my-account"
flagNotify = "notify"
flagFrom = "from"
flagType = "type"
flagReplyable = "replyable"
flagSensitive = "sensitive"
flagSkipRelationship = "skip-relationship"
flagShowPreferences = "show-preferences"
flagShowReposts = "show-reposts"
flagSpoilerText = "spoiler-text"
flagStatusID = "status-id"
flagTag = "tag"
flagTimelineCategory = "timeline-category"
flagTo = "to"
flagType = "type"
flagVisibility = "visibility"
resourceAccount = "account"
resourceBlocked = "blocked"

View file

@ -34,16 +34,16 @@ func NewCreateExecutor(tlf TopLevelFlags, name, summary string) *CreateExecutor
topLevelFlags: tlf,
}
createExe.BoolVar(&createExe.boostable, "boostable", true, "specify if the status can be reposted/boosted by others")
createExe.BoolVar(&createExe.federated, "federated", true, "specify if the status can be federated beyond the local timelines")
createExe.BoolVar(&createExe.likeable, "likeable", true, "specify if the status can be liked/favourited")
createExe.BoolVar(&createExe.replyable, "replyable", true, "specify if the status can be replied to")
createExe.BoolVar(&createExe.sensitive, "sensitive", false, "specify if the status should be marked as sensitive")
createExe.BoolVar(&createExe.boostable, flagBoostable, true, "specify if the status can be reposted/boosted by others")
createExe.BoolVar(&createExe.federated, flagFederated, true, "specify if the status can be federated beyond the local timelines")
createExe.BoolVar(&createExe.likeable, flagLikeable, true, "specify if the status can be liked/favourited")
createExe.BoolVar(&createExe.replyable, flagReplyable, true, "specify if the status can be replied to")
createExe.BoolVar(&createExe.sensitive, flagSensitive, false, "specify if the status should be marked as sensitive")
createExe.StringVar(&createExe.content, flagContent, "", "the content of the status to create")
createExe.StringVar(&createExe.contentType, "content-type", "text/plain", "the type that the contents should be parsed from (valid values are plain and markdown)")
createExe.StringVar(&createExe.language, "language", "", "the ISO 639 language code for this status")
createExe.StringVar(&createExe.spoilerText, "spoiler-text", "", "the text to display as the status' warning or subject")
createExe.StringVar(&createExe.visibility, "visibility", "", "the visibility of the posted status")
createExe.StringVar(&createExe.contentType, flagContentType, "text/plain", "the type that the contents should be parsed from (valid values are plain and markdown)")
createExe.StringVar(&createExe.language, flagLanguage, "", "the ISO 639 language code for this status")
createExe.StringVar(&createExe.spoilerText, flagSpoilerText, "", "the text to display as the status' warning or subject")
createExe.StringVar(&createExe.visibility, flagVisibility, "", "the visibility of the posted status")
createExe.StringVar(&createExe.resourceType, flagType, "", "specify the type of resource to create")
createExe.StringVar(&createExe.listTitle, flagListTitle, "", "specify the title of the list")
createExe.StringVar(&createExe.listRepliesPolicy, flagListRepliesPolicy, "list", "specify the policy of the replies for this list (valid values are followed, list and none)")
@ -102,30 +102,44 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
return FlagNotSetError{flagText: flagContent}
}
if c.language == "" {
return FlagNotSetError{flagText: "language"}
var (
language string
visibility string
)
preferences, err := gtsClient.GetUserPreferences()
if err != nil {
fmt.Println("WARNING: Unable to get your posting preferences; %w", err)
}
if c.visibility == "" {
return FlagNotSetError{flagText: "visibility"}
if c.language != "" {
language = c.language
} else {
language = preferences.PostingDefaultLanguage
}
visibility := model.ParseStatusVisibility(c.visibility)
if visibility == model.StatusVisibilityUnknown {
return fmt.Errorf("invalid status visibility %q", c.visibility)
if c.visibility != "" {
visibility = c.visibility
} else {
visibility = preferences.PostingDefaultVisibility
}
parsedVisibility := model.ParseStatusVisibility(visibility)
if parsedVisibility == model.StatusVisibilityUnknown {
return fmt.Errorf("invalid status visibility %q", visibility)
}
status, err := gtsClient.CreateStatus(
c.content,
c.contentType,
c.language,
language,
c.spoilerText,
c.boostable,
c.federated,
c.likeable,
c.replyable,
c.sensitive,
visibility,
parsedVisibility,
)
if err != nil {
return fmt.Errorf("unable to create the status; %w", err)