refactor: extract shared cloud IPC message handler, fix Discord TS error - #143
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughThese changes consist of formatting refinements and architectural refactoring across the Discord channel implementation and IPC message handling system. The Discord module receives style updates with a minor type-safety guard addition, while the IPC module introduces centralized cloud message handlers to replace existing inline handler implementations. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
… error Two improvements in this PR: 1. **Extract `makeCloudMessageHandler` in `ipc.ts`** — the `processMessage` callback passed to both `startSpritesIpcPoller` and `startDaytonaIpcPoller` was copy-pasted verbatim (16 lines each), differing only in the log label. Extracted into a shared factory `makeCloudMessageHandler(deps)` that accepts a `backendLabel` string for the logger. Also extracts the `processTask` handler into a shared `cloudTaskHandler` constant. Net change: removes ~12 lines of duplication, single place to update routing logic when adding future cloud backends. 2. **Fix `mentionsOtherUsersOnly` type error in `discord.ts`** — `botId` is `string | undefined`, but `Map.has()` requires `string`. Added `botId != null` guard at the start of the expression so TypeScript can narrow the type. No behavior change (outer `if (!isDM && botId && ...)` already guarded it), but eliminates the pre-existing TS2345 error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3a36b10 to
2e6df7f
Compare
Summary
Two code quality improvements found during routine simplification analysis (2026-02-19):
1. Extract
makeCloudMessageHandler(ipc.ts)The
processMessagecallback passed to bothstartSpritesIpcPollerandstartDaytonaIpcPollerwas copy-pasted verbatim — 16 lines each, differing only in the log label string.Before: Two identical 16-line blocks in
startIpcWatcher(), one for each backend poller.After: Single
makeCloudMessageHandler(deps)factory function that returns the shared handler closure. Each poller passes its own label:processMessage: (s, d) => cloudMessageHandler(s, d, 'Sprites')Benefit: Any future routing logic change only needs a single update. Also shared
cloudTaskHandlerconstant removes the identical 1-lineprocessTaskblocks.2. Fix
mentionsOtherUsersOnlytype error (discord.ts)botIdis typed asstring | undefined, butMap.has()requiresstring. AddedbotId \!= nullguard at the start of the expression so TypeScript can narrow the type correctly.No behavior change — the outer
if (\!isDM && botId && ...)already prevented execution whenbotIdwas falsy. This eliminates the pre-existing TS2345 compiler error.Test plan
bun run typecheckpasses (no new errors in modified files)🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Style