fix(line): log loading refresh errors, skip typing without recorder

Address review feedback from @alexhoshina and Codex:
- Log sendLoading errors in ticker goroutine instead of discarding
- Only start typing indicator when PlaceholderRecorder is available
  to avoid wasted API calls and unnecessary goroutine creation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ex-takashima 2026-02-26 20:29:09 +09:00
parent 3dc65ff7d7
commit 84667206b6

View file

@ -380,7 +380,9 @@ func (c *LINEChannel) processEvent(event lineEvent) {
// Thinking indicator (LINE loading animation is 1:1 only).
// For group/room chats, LINE provides no equivalent API.
// Only start if PlaceholderRecorder is available to avoid wasted API calls.
if !isGroup {
if rec := c.GetPlaceholderRecorder(); rec != nil {
typingCtx, typingCancel := context.WithTimeout(c.ctx, 5*time.Minute)
stop, err := c.StartTyping(typingCtx, chatID)
if err == nil {
@ -391,16 +393,12 @@ func (c *LINEChannel) processEvent(event lineEvent) {
typingCancel()
})
}
if rec := c.GetPlaceholderRecorder(); rec != nil {
rec.RecordTypingStop("line", chatID, stopFn)
} else {
// No recorder — stop immediately to avoid goroutine leaks.
stopFn()
}
} else {
typingCancel()
}
}
}
c.HandleMessage(c.ctx, peer, msg.ID, senderID, chatID, content, mediaPaths, metadata, sender)
}
@ -627,7 +625,11 @@ func (c *LINEChannel) StartTyping(ctx context.Context, chatID string) (func(), e
case <-typingCtx.Done():
return
case <-ticker.C:
_ = c.sendLoading(typingCtx, chatID)
if err := c.sendLoading(typingCtx, chatID); err != nil {
logger.DebugCF("line", "Failed to refresh loading indicator", map[string]any{
"error": err.Error(),
})
}
}
}
}()