From 2e455fc9f8eedef7c2f3f785e2696fb97c0d60d2 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Fri, 9 Aug 2024 09:12:08 +0100 Subject: [PATCH] checkpoint --- internal/client/statuses.go | 25 ++++++++++---------- internal/executor/create.go | 46 ++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/internal/client/statuses.go b/internal/client/statuses.go index 6e1a59e..0b8d60a 100644 --- a/internal/client/statuses.go +++ b/internal/client/statuses.go @@ -38,18 +38,19 @@ func (g *Client) GetStatus(statusID string) (model.Status, error) { } type CreateStatusForm struct { - Content string `json:"status"` - InReplyTo string `json:"in_reply_to_id"` - Language string `json:"language"` - SpoilerText string `json:"spoiler_text"` - Boostable bool `json:"boostable"` - Federated bool `json:"federated"` - Likeable bool `json:"likeable"` - Replyable bool `json:"replyable"` - Sensitive bool `json:"sensitive"` - Poll *CreateStatusPollForm `json:"poll,omitempty"` - ContentType model.StatusContentType `json:"content_type"` - Visibility model.StatusVisibility `json:"visibility"` + Content string `json:"status"` + InReplyTo string `json:"in_reply_to_id"` + Language string `json:"language"` + SpoilerText string `json:"spoiler_text"` + Boostable bool `json:"boostable"` + Federated bool `json:"federated"` + Likeable bool `json:"likeable"` + Replyable bool `json:"replyable"` + Sensitive bool `json:"sensitive"` + Poll *CreateStatusPollForm `json:"poll,omitempty"` + ContentType model.StatusContentType `json:"content_type"` + Visibility model.StatusVisibility `json:"visibility"` + AttachmentIDs []string `json:"media_ids,omitempty"` } type CreateStatusPollForm struct { diff --git a/internal/executor/create.go b/internal/executor/create.go index 08acb81..6a8792c 100644 --- a/internal/executor/create.go +++ b/internal/executor/create.go @@ -39,6 +39,7 @@ type CreateExecutor struct { visibility string pollExpiresIn TimeDurationFlagValue pollOptions MultiStringFlagValue + attachmentIDs MultiStringFlagValue } func NewCreateExecutor(printer *printer.Printer, config *config.Config, name, summary string) *CreateExecutor { @@ -74,6 +75,7 @@ func NewCreateExecutor(printer *printer.Printer, config *config.Config, name, su return nil }) + createExe.Var(&createExe.attachmentIDs, flagAttachmentID, "Specify the ID of the media attachment to add to the status") // Flags specifically for polls createExe.BoolVar(&createExe.addPoll, flagAddPoll, false, "Add a poll to the status") @@ -161,12 +163,19 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error { return fmt.Errorf("unable to get the status contents from %q: %w", c.fromFile, err) } default: - return EmptyContentError{ - ResourceType: resourceStatus, - Hint: "please use --" + flagContent + " or --" + flagFromFile, + if len(c.attachmentIDs) == 0 { + // TODO: revisit this error type + return EmptyContentError{ + ResourceType: resourceStatus, + Hint: "please use --" + flagContent + " or --" + flagFromFile, + } } } + if len(c.attachmentIDs) > 0 && c.addPoll { + return fmt.Errorf("attaching media to a poll is not allowed") + } + preferences, err := gtsClient.GetUserPreferences() if err != nil { fmt.Println("WARNING: Unable to get your posting preferences: %w", err) @@ -201,18 +210,23 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error { } form := client.CreateStatusForm{ - Content: content, - ContentType: parsedContentType, - Language: language, - SpoilerText: c.spoilerText, - Boostable: c.boostable, - Federated: c.federated, - InReplyTo: c.inReplyTo, - Likeable: c.likeable, - Replyable: c.replyable, - Sensitive: sensitive, - Visibility: parsedVisibility, - Poll: nil, + Content: content, + ContentType: parsedContentType, + Language: language, + SpoilerText: c.spoilerText, + Boostable: c.boostable, + Federated: c.federated, + InReplyTo: c.inReplyTo, + Likeable: c.likeable, + Replyable: c.replyable, + Sensitive: sensitive, + Visibility: parsedVisibility, + Poll: nil, + AttachmentIDs: nil, + } + + if len(c.attachmentIDs) > 0 { + form.AttachmentIDs = c.attachmentIDs } if c.addPoll { @@ -246,7 +260,7 @@ func (c *CreateExecutor) createMediaAttachment(gtsClient *client.Client) error { return FlagNotSetError{flagText: flagFromFile} } - attachment, err := gtsClient.CreateMediaAttachment(c.fromFile, c.description, c.focus); + attachment, err := gtsClient.CreateMediaAttachment(c.fromFile, c.description, c.focus) if err != nil { return fmt.Errorf("unable to create the media attachment: %w", err) }