fix: CLI client types mismatched server response format
- SessionResponse: use 'id' (int64) not 'session_id'/'client_id' - StateResponse: match actual server response shape - GetMembers: strip '#' from channel name for URL path - These bugs prevented the CLI from working correctly with the server
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -167,7 +168,9 @@ func (c *Client) ListChannels() ([]Channel, error) {
|
|||||||
|
|
||||||
// GetMembers returns members of a channel.
|
// GetMembers returns members of a channel.
|
||||||
func (c *Client) GetMembers(channel string) ([]string, error) {
|
func (c *Client) GetMembers(channel string) ([]string, error) {
|
||||||
data, err := c.do("GET", "/api/v1/channels/"+url.PathEscape(channel)+"/members", nil)
|
// Server route is /channels/{channel}/members where channel is without '#'
|
||||||
|
name := strings.TrimPrefix(channel, "#")
|
||||||
|
data, err := c.do("GET", "/api/v1/channels/"+url.PathEscape(name)+"/members", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,18 +9,16 @@ type SessionRequest struct {
|
|||||||
|
|
||||||
// SessionResponse is the response from POST /api/v1/session.
|
// SessionResponse is the response from POST /api/v1/session.
|
||||||
type SessionResponse struct {
|
type SessionResponse struct {
|
||||||
SessionID string `json:"session_id"`
|
ID int64 `json:"id"`
|
||||||
ClientID string `json:"client_id"`
|
Nick string `json:"nick"`
|
||||||
Nick string `json:"nick"`
|
Token string `json:"token"`
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateResponse is the response from GET /api/v1/state.
|
// StateResponse is the response from GET /api/v1/state.
|
||||||
type StateResponse struct {
|
type StateResponse struct {
|
||||||
SessionID string `json:"session_id"`
|
ID int64 `json:"id"`
|
||||||
ClientID string `json:"client_id"`
|
Nick string `json:"nick"`
|
||||||
Nick string `json:"nick"`
|
Channels []string `json:"channels"`
|
||||||
Channels []string `json:"channels"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message represents a chat message envelope.
|
// Message represents a chat message envelope.
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ func (a *App) cmdConnect(serverURL string) {
|
|||||||
a.lastQID = 0
|
a.lastQID = 0
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
|
|
||||||
a.ui.AddStatus(fmt.Sprintf("[green]Connected! Nick: %s, Session: %s", resp.Nick, resp.SessionID))
|
a.ui.AddStatus(fmt.Sprintf("[green]Connected! Nick: %s, Session: %d", resp.Nick, resp.ID))
|
||||||
a.ui.SetStatus(resp.Nick, "", "connected")
|
a.ui.SetStatus(resp.Nick, "", "connected")
|
||||||
|
|
||||||
// Start polling.
|
// Start polling.
|
||||||
|
|||||||
Reference in New Issue
Block a user