From 2bb801b6d04c3b760840b0baa7a9592df6d05f85 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Tue, 9 Jul 2024 00:13:46 +0100 Subject: [PATCH] feat: add ability to reply to statuses --- docs/manual.md | 5 +++++ internal/client/statuses.go | 17 +++++++++++------ internal/executor/create.go | 3 +++ internal/executor/flags.go | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/manual.md b/docs/manual.md index 5dbd1ac..37b2d6c 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -401,6 +401,10 @@ enbas show --type status --status-id 01J1Z9PT0243JT9QNQ5W96Z8CA ``` enbas create --type status --content-type markdown --visibility private --from-file status.md ``` +- Reply to another status. + ``` + enbas create --type status --in-reply-to 01J2A86E3M7WWH37H1QENT7CSH --content "@bernie thanks for this! Looking forward to trying this out." + ``` - Create a status with a poll ``` enbas create \ @@ -428,6 +432,7 @@ enbas show --type status --status-id 01J1Z9PT0243JT9QNQ5W96Z8CA | `enable-likes` | boolean | false | The status can be liked (favourtied). | true | | `enable-replies` | boolean | false | The status can be replied to. | true | | `from-file` | string | false | The path to the file where to read the contents of the status from. | | +| `in-reply-to` | string | false | The ID of the status that you want to reply to. | | | `language` | string | false | The ISO 639 language code that the status is written in.
If this is not specified then the default language from your posting preferences will be used. | | | `sensitive` | string | false | The status should be marked as sensitive.
If this is not specified then the default sensitivity from your posting preferences will be used. | | | `spoiler-text` | string | false | The text to display as the status' warning or subject. | | diff --git a/internal/client/statuses.go b/internal/client/statuses.go index fee3af4..253ff17 100644 --- a/internal/client/statuses.go +++ b/internal/client/statuses.go @@ -13,8 +13,12 @@ import ( "codeflow.dananglin.me.uk/apollo/enbas/internal/model" ) +const ( + baseStatusesPath string = "/api/v1/statuses" +) + func (g *Client) GetStatus(statusID string) (model.Status, error) { - path := "/api/v1/statuses/" + statusID + path := baseStatusesPath + "/" + statusID url := g.Authentication.Instance + path var status model.Status @@ -31,6 +35,7 @@ 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"` @@ -57,7 +62,7 @@ func (g *Client) CreateStatus(form CreateStatusForm) (model.Status, error) { } requestBody := bytes.NewBuffer(data) - url := g.Authentication.Instance + "/api/v1/statuses" + url := g.Authentication.Instance + baseStatusesPath var status model.Status @@ -119,7 +124,7 @@ func (g *Client) RemoveStatusFromBookmarks(statusID string) error { } func (g *Client) LikeStatus(statusID string) error { - url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/favourite" + url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/favourite" if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { return fmt.Errorf( @@ -132,7 +137,7 @@ func (g *Client) LikeStatus(statusID string) error { } func (g *Client) UnlikeStatus(statusID string) error { - url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/unfavourite" + url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/unfavourite" if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { return fmt.Errorf( @@ -163,7 +168,7 @@ func (g *Client) GetLikedStatuses(limit int, resourceName string) (model.StatusL } func (g *Client) ReblogStatus(statusID string) error { - url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/reblog" + url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/reblog" if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { return fmt.Errorf( @@ -176,7 +181,7 @@ func (g *Client) ReblogStatus(statusID string) error { } func (g *Client) UnreblogStatus(statusID string) error { - url := g.Authentication.Instance + "/api/v1/statuses/" + statusID + "/unreblog" + url := g.Authentication.Instance + baseStatusesPath + "/" + statusID + "/unreblog" if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { return fmt.Errorf( diff --git a/internal/executor/create.go b/internal/executor/create.go index 8c98558..a7d14a7 100644 --- a/internal/executor/create.go +++ b/internal/executor/create.go @@ -32,6 +32,7 @@ type CreateExecutor struct { content string contentType string fromFile string + inReplyTo string language string resourceType string listTitle string @@ -58,6 +59,7 @@ func NewCreateExecutor(printer *printer.Printer, config *config.Config, name, su createExe.StringVar(&createExe.contentType, flagContentType, "plain", "The type that the contents should be parsed from (valid values are plain and markdown)") createExe.BoolVar(&createExe.federated, flagEnableFederation, true, "Specify if the status can be federated beyond the local timelines") createExe.StringVar(&createExe.fromFile, flagFromFile, "", "The file path where to read the contents from") + createExe.StringVar(&createExe.inReplyTo, flagInReplyTo, "", "The ID of the status that you want to reply to") createExe.StringVar(&createExe.language, flagLanguage, "", "The ISO 639 language code for this status") createExe.BoolVar(&createExe.likeable, flagEnableLikes, true, "Specify if the status can be liked/favourited") createExe.BoolVar(&createExe.replyable, flagEnableReplies, true, "Specify if the status can be replied to") @@ -204,6 +206,7 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error { SpoilerText: c.spoilerText, Boostable: c.boostable, Federated: c.federated, + InReplyTo: c.inReplyTo, Likeable: c.likeable, Replyable: c.replyable, Sensitive: sensitive, diff --git a/internal/executor/flags.go b/internal/executor/flags.go index 1f85e7c..1d73ff6 100644 --- a/internal/executor/flags.go +++ b/internal/executor/flags.go @@ -25,6 +25,7 @@ const ( flagFrom = "from" flagFromFile = "from-file" flagFull = "full" + flagInReplyTo = "in-reply-to" flagInstance = "instance" flagLanguage = "language" flagLimit = "limit"