Skip to content

[Milky] Implement get_forwarded_messages and forward segment title, preview and summary - #924

Open
ilyfairy wants to merge 1 commit into
LagrangeDev:masterfrom
ilyfairy:feat/forwarded-messages
Open

ilyfairy wants to merge 1 commit into
LagrangeDev:masterfrom
ilyfairy:feat/forwarded-messages

Conversation

@ilyfairy

Copy link
Copy Markdown
Contributor

问题

  • Milky 的 get_forwarded_messages 没有实现,拿不到合并转发里的内容。
  • 接收到的 forward 段里,title、preview 和 summary 都是空的。

原因

LongMsgRecvService 下载转发内容后,用和普通消息相同的流程解析每条消息:

  • MessagePacker 会去好友列表或群成员列表里查找发送者。转发里的发送者通常不是 bot 的联系人,查找失败会导致整条转发解析失败。
  • 转发里的引用回复会在 ReplyEntity.Postprocess 里查找原消息。原消息一般不在 bot 能访问的会话里,同样会失败。

修改

Core

  • MessagePacker.Parse 增加 isForwarded 参数:
    • 转发里的消息不再查找联系人,直接用转发里带的名字 (GroupCard / CommonC2C.Name) 构造发送者;
    • BotMessage 增加 IsForwarded。
  • 单个 entity 的 Postprocess 抛出异常时只记录 warning,不再导致整条消息丢失。例如转发里的图片拿不到 url时,只影响这张图片。
  • ReplyEntity:
    • 增加 SourceEntities 和 SourceTime,保存引用里自带的内容;
    • 消息在转发里时跳过 Postprocess。
  • MultiMsgEntity:
    • 从卡片的 XML 解析 Title、Preview 和 Summary;
    • 嵌套的转发不再在 Postprocess 里递归下载,改为需要时再获取。
  • 新增 BotContext.GetForwardedMessages(resId)。res id 本身不带场景信息,所以先按群聊请求,失败后再按私聊请求。

Milky

  • 实现 get_forwarded_messages,返回 IncomingForwardedMessage 列表,并取消注释 IncomingForwardedMessage。
  • forward 接收段填充 title、preview 和 summary。
  • 引用的原消息找不到时,reply 段改用引用里自带的内容 (seq、发送者、时间和消息段)。
  • README 中对应项标记为已实现。

测试

在 linux-x64 AOT 构建上,用群聊和私聊里收到的合并转发测试:

  • forward 段的 title、preview 和 summary 与 QQ 客户端显示一致;
  • get_forwarded_messages 能返回完整内容,包括文字、图片和引用回复;
  • 嵌套转发 (最深 3 层) 的内层 forward_id 可以再次通过 get_forwarded_messages 获取。

…review and summary

[Core] Parse forwarded messages without resolving contacts and keep the content carried by replies
@NoirHare
NoirHare requested a review from Linwenxuan04 October 30, 2026 06:52
@NoirHare

Copy link
Copy Markdown
Collaborator

@Linwenxuan04

This branch has not been deployed

No deployments
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