checkpoint: add default user posting preferences for consideration
This commit is contained in:
parent
b2dc570385
commit
4038814d6a
2 changed files with 43 additions and 20 deletions
|
@ -2,24 +2,33 @@ package executor
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagAccountName = "account-name"
|
flagAccountName = "account-name"
|
||||||
|
flagBoostable = "boostable"
|
||||||
flagBrowser = "browser"
|
flagBrowser = "browser"
|
||||||
|
flagContentType = "content-type"
|
||||||
flagContent = "content"
|
flagContent = "content"
|
||||||
|
flagFederated = "federated"
|
||||||
|
flagFrom = "from"
|
||||||
flagInstance = "instance"
|
flagInstance = "instance"
|
||||||
|
flagLanguage = "language"
|
||||||
|
flagLikeable = "likeable"
|
||||||
flagLimit = "limit"
|
flagLimit = "limit"
|
||||||
flagListID = "list-id"
|
flagListID = "list-id"
|
||||||
flagListTitle = "list-title"
|
flagListTitle = "list-title"
|
||||||
flagListRepliesPolicy = "list-replies-policy"
|
flagListRepliesPolicy = "list-replies-policy"
|
||||||
flagMyAccount = "my-account"
|
flagMyAccount = "my-account"
|
||||||
flagNotify = "notify"
|
flagNotify = "notify"
|
||||||
flagFrom = "from"
|
flagReplyable = "replyable"
|
||||||
flagType = "type"
|
flagSensitive = "sensitive"
|
||||||
flagSkipRelationship = "skip-relationship"
|
flagSkipRelationship = "skip-relationship"
|
||||||
flagShowPreferences = "show-preferences"
|
flagShowPreferences = "show-preferences"
|
||||||
flagShowReposts = "show-reposts"
|
flagShowReposts = "show-reposts"
|
||||||
|
flagSpoilerText = "spoiler-text"
|
||||||
flagStatusID = "status-id"
|
flagStatusID = "status-id"
|
||||||
flagTag = "tag"
|
flagTag = "tag"
|
||||||
flagTimelineCategory = "timeline-category"
|
flagTimelineCategory = "timeline-category"
|
||||||
flagTo = "to"
|
flagTo = "to"
|
||||||
|
flagType = "type"
|
||||||
|
flagVisibility = "visibility"
|
||||||
|
|
||||||
resourceAccount = "account"
|
resourceAccount = "account"
|
||||||
resourceBlocked = "blocked"
|
resourceBlocked = "blocked"
|
||||||
|
|
|
@ -34,16 +34,16 @@ func NewCreateExecutor(tlf TopLevelFlags, name, summary string) *CreateExecutor
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
createExe.BoolVar(&createExe.boostable, "boostable", true, "specify if the status can be reposted/boosted by others")
|
createExe.BoolVar(&createExe.boostable, flagBoostable, 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.federated, flagFederated, 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.likeable, flagLikeable, 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.replyable, flagReplyable, 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.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.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.contentType, flagContentType, "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.language, flagLanguage, "", "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.spoilerText, flagSpoilerText, "", "the text to display as the status' warning or subject")
|
||||||
createExe.StringVar(&createExe.visibility, "visibility", "", "the visibility of the posted status")
|
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.resourceType, flagType, "", "specify the type of resource to create")
|
||||||
createExe.StringVar(&createExe.listTitle, flagListTitle, "", "specify the title of the list")
|
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)")
|
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}
|
return FlagNotSetError{flagText: flagContent}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.language == "" {
|
var (
|
||||||
return FlagNotSetError{flagText: "language"}
|
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 == "" {
|
if c.language != "" {
|
||||||
return FlagNotSetError{flagText: "visibility"}
|
language = c.language
|
||||||
|
} else {
|
||||||
|
language = preferences.PostingDefaultLanguage
|
||||||
}
|
}
|
||||||
|
|
||||||
visibility := model.ParseStatusVisibility(c.visibility)
|
if c.visibility != "" {
|
||||||
if visibility == model.StatusVisibilityUnknown {
|
visibility = c.visibility
|
||||||
return fmt.Errorf("invalid status visibility %q", 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(
|
status, err := gtsClient.CreateStatus(
|
||||||
c.content,
|
c.content,
|
||||||
c.contentType,
|
c.contentType,
|
||||||
c.language,
|
language,
|
||||||
c.spoilerText,
|
c.spoilerText,
|
||||||
c.boostable,
|
c.boostable,
|
||||||
c.federated,
|
c.federated,
|
||||||
c.likeable,
|
c.likeable,
|
||||||
c.replyable,
|
c.replyable,
|
||||||
c.sensitive,
|
c.sensitive,
|
||||||
visibility,
|
parsedVisibility,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create the status; %w", err)
|
return fmt.Errorf("unable to create the status; %w", err)
|
||||||
|
|
Loading…
Reference in a new issue