From 6a7b5e9c3de62949f40ea7391d61d0f6324daabe Mon Sep 17 00:00:00 2001 From: Mark Mennell Date: Sun, 17 May 2026 13:07:18 +0800 Subject: [PATCH] remove wait command (route removed from web API) Co-Authored-By: Claude Opus 4.7 --- README.md | 5 ---- cmd/wait.go | 58 ------------------------------------------ internal/api/client.go | 45 -------------------------------- 3 files changed, 108 deletions(-) delete mode 100644 cmd/wait.go diff --git a/README.md b/README.md index 7e60aa3..b7bc09e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,6 @@ If a `.env` file exists in the working directory it is loaded automatically on s | `fmsg login [address]` | Authenticate and store a local token (optional address argument) | | `fmsg list` \| `fmsg ls [--limit N] [--offset N]` | List messages for the authenticated user | | `fmsg sent [--limit N] [--offset N]` | List messages authored by the authenticated user | -| `fmsg wait [--since-id N] [--timeout N]` | Long-poll for new messages | | `fmsg get ` | Retrieve a message by ID, including the short text body for `text/*` messages | | `fmsg send ` | Send a message (file path, text, or `-` for stdin) | | `fmsg draft create ` | Create a draft message without sending | @@ -90,10 +89,6 @@ fmsg list --limit 10 --offset 20 fmsg sent fmsg sent --limit 10 --offset 20 -# Wait for a new message -fmsg wait -fmsg wait --since-id 120 --timeout 10 - # Get a specific message fmsg get 101 diff --git a/cmd/wait.go b/cmd/wait.go deleted file mode 100644 index 8409949..0000000 --- a/cmd/wait.go +++ /dev/null @@ -1,58 +0,0 @@ -package cmd - -import ( - "fmt" - "os" - - "github.com/markmnl/fmsg-cli/internal/api" - "github.com/markmnl/fmsg-cli/internal/auth" - "github.com/markmnl/fmsg-cli/internal/config" - "github.com/spf13/cobra" -) - -var ( - waitSinceID int64 - waitTimeout int -) - -var waitCmd = &cobra.Command{ - Use: "wait", - Short: "Long-poll for new messages", - Long: `Long-poll until a new message arrives for the authenticated user. - -Returns immediately when a new message is available, or exits after timeout when none arrive.`, - RunE: func(cmd *cobra.Command, args []string) error { - if waitSinceID < 0 { - return fmt.Errorf("--since-id must be >= 0") - } - if waitTimeout < 1 || waitTimeout > 60 { - return fmt.Errorf("--timeout must be between 1 and 60 seconds") - } - - creds, err := auth.LoadValid() - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - - client := api.New(config.GetAPIURL(), creds.Token) - result, err := client.WaitForMessage(waitSinceID, waitTimeout) - if err != nil { - return err - } - - if result.HasNew { - fmt.Printf("New message available. Latest ID: %d\n", result.LatestID) - return nil - } - - fmt.Println("No new messages.") - return nil - }, -} - -func init() { - waitCmd.Flags().Int64Var(&waitSinceID, "since-id", 0, "Only consider messages with ID greater than this value") - waitCmd.Flags().IntVar(&waitTimeout, "timeout", 25, "Maximum seconds to wait (1-60)") - rootCmd.AddCommand(waitCmd) -} diff --git a/internal/api/client.go b/internal/api/client.go index bd1faa7..34283ae 100644 --- a/internal/api/client.go +++ b/internal/api/client.go @@ -129,12 +129,6 @@ type AddRecipientsResponse struct { Added int `json:"added"` } -// WaitResponse is the response from GET /fmsg/wait. -type WaitResponse struct { - HasNew bool `json:"has_new"` - LatestID int64 `json:"latest_id"` -} - // ListMessages returns messages for the authenticated user. func (c *Client) ListMessages(limit, offset int) ([]MessageListItem, error) { u, err := url.Parse(c.BaseURL + "/fmsg") @@ -209,45 +203,6 @@ func (c *Client) ListSentMessages(limit, offset int) ([]MessageListItem, error) return messages, nil } -// WaitForMessage long-polls for a new message for the authenticated user. -func (c *Client) WaitForMessage(sinceID int64, timeout int) (*WaitResponse, error) { - u, err := url.Parse(c.BaseURL + "/fmsg/wait") - if err != nil { - return nil, err - } - - q := u.Query() - q.Set("since_id", strconv.FormatInt(sinceID, 10)) - q.Set("timeout", strconv.Itoa(timeout)) - u.RawQuery = q.Encode() - - req, err := http.NewRequest(http.MethodGet, u.String(), nil) - if err != nil { - return nil, err - } - - resp, err := c.do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - if err := checkStatus(resp); err != nil { - return nil, err - } - - if resp.StatusCode == http.StatusNoContent { - return &WaitResponse{HasNew: false}, nil - } - - var result WaitResponse - if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { - return nil, fmt.Errorf("decoding response: %w", err) - } - - return &result, nil -} - // GetMessage retrieves a single message by ID. func (c *Client) GetMessage(id string) (*Message, error) { req, err := http.NewRequest(http.MethodGet, c.BaseURL+"/fmsg/"+id, nil)