Skip to content

fix: 修复 thread 消息 channel_type 字符串比较失败导致串频道#179

Closed
caster-Q wants to merge 1 commit intodevelopfrom
fix/thread-channel-type-coercion
Closed

fix: 修复 thread 消息 channel_type 字符串比较失败导致串频道#179
caster-Q wants to merge 1 commit intodevelopfrom
fix/thread-channel-type-coercion

Conversation

@caster-Q
Copy link
Copy Markdown
Contributor

Summary

WuKongIM 在 CommunityTopic(子区) 场景下可能推送 channel_type 为字符串 "5" 而非数字 5,JavaScript 的 === 不做类型转换,导致:

  1. isGroup 判定为 false,thread 消息被当成 DM 处理
  2. readReceipt + typing 发到私聊而非 thread
  3. session 路由到 direct 而非 thread session

Fix

在消息入口统一 Number() 转换 channel_type

  • channel.ts onMessage 回调入口
  • inbound.ts handleInboundMessage 入口(defense-in-depth)

Test plan

  • npm run build 通过
  • npm test 476 通过
  • thread 里 @bot 发消息,回复在 thread 里而非私聊

🤖 Generated with Claude Code

WuKongIM 在 CommunityTopic 场景下可能推送 channel_type 为字符串 "5"
而非数字 5,导致 === ChannelType.CommunityTopic 比较失败,thread 消息
被误判为 DM,readReceipt/typing 发到私聊、session 路由到 direct。

修复:在消息入口(channel.ts onMessage + inbound.ts handleInboundMessage)
统一 Number() 转换 channel_type,确保后续所有 === 比较正常工作。

Fixes #172 相关

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@lml2468 lml2468 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: LGTM,可以合入

修复逻辑正确:WuKongIM 有时将 channel_type 以字符串 "5" 发出,导致与 ChannelType enum 严格比较失败。两处 Number(msg.channel_type) as ChannelType 正确处理了类型强制转换。

两点值得注意:

  1. 双重防御设计合理channel.ts 在入口处规范化,inbound.ts 再做一次兜底,注释也明确写了defense-in-depth。可以接受,但如果后续 SDK 修复了类型,记得清理两处。

  2. #169 冲突风险:两个文件(channel.ts / inbound.ts)都在 #169 的改动范围内。如果 #169 先合,#179 需要 rebase 确认无冲突。

建议合并顺序:先确认 #169 的合并计划再处理 #179,或先合 #179(改动小、独立),再让 #169 在 rebase 时吸收。

@caster-Q caster-Q closed this Apr 14, 2026
@caster-Q caster-Q deleted the fix/thread-channel-type-coercion branch April 14, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants