checkpoint: can now create statuses with media attachments

This commit is contained in:
Dan Anglin 2024-08-14 14:02:09 +01:00
parent f3a5887cb9
commit 795e344198
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 40 additions and 27 deletions

View file

@ -50,6 +50,7 @@ type CreateStatusForm struct {
Poll *CreateStatusPollForm `json:"poll,omitempty"` Poll *CreateStatusPollForm `json:"poll,omitempty"`
ContentType model.StatusContentType `json:"content_type"` ContentType model.StatusContentType `json:"content_type"`
Visibility model.StatusVisibility `json:"visibility"` Visibility model.StatusVisibility `json:"visibility"`
AttachmentIDs []string `json:"media_ids,omitempty"`
} }
type CreateStatusPollForm struct { type CreateStatusPollForm struct {

View file

@ -76,11 +76,18 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
return fmt.Errorf("unable to get the status contents from %q: %w", c.fromFile, err) return fmt.Errorf("unable to get the status contents from %q: %w", c.fromFile, err)
} }
default: default:
if c.attachmentIDs.Empty() {
// TODO: revisit this error type
return EmptyContentError{ return EmptyContentError{
ResourceType: resourceStatus, ResourceType: resourceStatus,
Hint: "please use --" + flagContent + " or --" + flagFromFile, Hint: "please use --" + flagContent + " or --" + flagFromFile,
} }
} }
}
if c.addPoll && !c.attachmentIDs.Empty() {
return fmt.Errorf("attaching media to a poll is not allowed")
}
preferences, err := gtsClient.GetUserPreferences() preferences, err := gtsClient.GetUserPreferences()
if err != nil { if err != nil {
@ -128,6 +135,11 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
Sensitive: sensitive, Sensitive: sensitive,
Visibility: parsedVisibility, Visibility: parsedVisibility,
Poll: nil, Poll: nil,
AttachmentIDs: nil,
}
if !c.attachmentIDs.Empty() {
form.AttachmentIDs = c.attachmentIDs
} }
if c.addPoll { if c.addPoll {