Open a channel only when the server accepts the join (closes #197)
check / check (push) Waiting to run
check / check (push) Waiting to run
When the server refuses a JOIN, POST /api/v1/messages answers 200 with status "error" and sends the error numeric to the queue. Both clients opened the channel anyway. JoinChannel in internal/cli/api now returns an error unless the status is "joined". cmdJoin then keeps its buffer and target and prints its usual "Join failed" line. The web client opens no tab for a refused join, whether it came from /join or from the saved channels a fresh session joins again. Model: opus-5-5
This commit is contained in:
@@ -25,7 +25,10 @@ const (
|
||||
httpErrThreshold = 400
|
||||
)
|
||||
|
||||
var errHTTP = errors.New("HTTP error")
|
||||
var (
|
||||
errHTTP = errors.New("HTTP error")
|
||||
errJoinRefused = errors.New("the server refused the join")
|
||||
)
|
||||
|
||||
// Client wraps HTTP calls to the neoirc server API.
|
||||
type Client struct {
|
||||
@@ -206,13 +209,35 @@ func (client *Client) PollMessages(
|
||||
}, nil
|
||||
}
|
||||
|
||||
// JoinChannel joins a channel.
|
||||
// JoinChannel joins a channel. It returns an error unless the
|
||||
// server answers that the session joined. When the server
|
||||
// refuses the join, it sends the reason to the message queue as
|
||||
// an error numeric.
|
||||
func (client *Client) JoinChannel(channel string) error {
|
||||
return client.SendMessage(
|
||||
data, err := client.do(
|
||||
http.MethodPost, "/api/v1/messages",
|
||||
&Message{ //nolint:exhaustruct // only command+to needed
|
||||
Command: irc.CmdJoin, To: channel,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var resp struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, &resp)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decode join: %w", err)
|
||||
}
|
||||
|
||||
if resp.Status != "joined" {
|
||||
return errJoinRefused
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PartChannel leaves a channel.
|
||||
|
||||
Reference in New Issue
Block a user