fix: CLI poll loop used UUID instead of queue cursor (last_id)
The poll loop was storing msg.ID (UUID string) as afterID, but the server expects the integer queue cursor from last_id. This caused the CLI to re-fetch ALL messages on every poll cycle. - Change PollMessages to accept int64 afterID and return PollResult with LastID - Track lastQID (queue cursor) instead of lastMsgID (UUID) - Parse the wrapped MessagesResponse properly
This commit is contained in:
@@ -19,7 +19,7 @@ type App struct {
|
||||
nick string
|
||||
target string // current target (#channel or nick for DM)
|
||||
connected bool
|
||||
lastMsgID string
|
||||
lastQID int64 // queue cursor for polling
|
||||
stopPoll chan struct{}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func (a *App) cmdConnect(serverURL string) {
|
||||
a.client = client
|
||||
a.nick = resp.Nick
|
||||
a.connected = true
|
||||
a.lastMsgID = ""
|
||||
a.lastQID = 0
|
||||
a.mu.Unlock()
|
||||
|
||||
a.ui.AddStatus(fmt.Sprintf("[green]Connected! Nick: %s, Session: %s", resp.Nick, resp.SessionID))
|
||||
@@ -462,27 +462,28 @@ func (a *App) pollLoop() {
|
||||
|
||||
a.mu.Lock()
|
||||
client := a.client
|
||||
lastID := a.lastMsgID
|
||||
lastQID := a.lastQID
|
||||
a.mu.Unlock()
|
||||
|
||||
if client == nil {
|
||||
return
|
||||
}
|
||||
|
||||
msgs, err := client.PollMessages(lastID, 15)
|
||||
result, err := client.PollMessages(lastQID, 15)
|
||||
if err != nil {
|
||||
// Transient error — retry after delay.
|
||||
time.Sleep(2 * time.Second)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, msg := range msgs {
|
||||
if result.LastID > 0 {
|
||||
a.mu.Lock()
|
||||
a.lastQID = result.LastID
|
||||
a.mu.Unlock()
|
||||
}
|
||||
|
||||
for _, msg := range result.Messages {
|
||||
a.handleServerMessage(&msg)
|
||||
if msg.ID != "" {
|
||||
a.mu.Lock()
|
||||
a.lastMsgID = msg.ID
|
||||
a.mu.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user