Repository navigation
bridge: 聊天记录里的消息可以复制转发 - #29
Open
std-external wants to merge 1 commit into
Open
std-external wants to merge 1 commit into
std-external wants to merge 1 commit into
Conversation
客户端在合并转发的聊天记录里点「转发」后,消息一直发送失败:聊天记录是合成 peer,它的消息只按需投影、从未落库,`forwardMessages` 走到 `_resolvePeer` 时 只认 user/channel,直接抛 `PEER_ID_INVALID`,Telegram 只能把本地占位画成红色 感叹号(群里那条截图就是三次都这样)。普通消息有 QQ 原生转发,所以只有聊天记 录里的消息会挂。 现在 bridge 在解析转发来源之前先问一眼合成 peer 的注册表:投影这类 peer 的插 件(目前是 merged-forward)给出存档内容,bridge 就按复制语义重发——把归档的 文本、媒体、卡片标题当作账号自己的消息发到目标会话,并沿用原有的落库、pts、 randomId 确认和多端回显流程。 - `VirtualForwardSources`:bridge 与插件共用的注册表,`ctx.mtprotoBridge.registerForwardSource` 注册,插件卸载即失效。 - `DialogRpc.forwardMessages`:合成 peer 跳过落库查询,强制走适配器的复制转发(`dropAuthor`),并支持把内容投递到 system peer。 - `merged-forward`:按聊天记录的消息 ID 反查归档内容,同一条消息的多个相册分片只复制一次;不是这份聊天记录里的 ID 仍然报 `MSG_ID_INVALID`。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
在 Telegram 里打开一条 QQ 合并转发的「聊天记录」,选中里面的消息再转发出去,Telegram 只会把本地占位画成红色感叹号(发送失败),每次重试都一样。
原因
聊天记录是 relay 自己投影出来的合成 peer(
peerChat),它的消息按需生成、从不落库。而DialogRpc.forwardMessages解析来源时只认 user/channel:所以从聊天记录转发必然 400,客户端没有任何消息能对应上
randomId,就显示成发送失败。普通消息转发走 QQ 原生 forward,因此只有聊天记录里的消息会挂。修复
给「合成 peer」开一个注册表,让投影这类 peer 的插件能把自己 peer 里的消息交出来按复制语义转发:
packages/bridge/src/virtual-forward.ts(新):VirtualForwardSources注册表 +VirtualForwardSource接口,ctx.mtprotoBridge.registerForwardSource()注册,插件 dispose 时自动移除。DialogRpc.forwardMessages:解析来源前先问注册表;命中时跳过落库查询,把存档内容当作账号自己的消息、强制走适配器的复制转发(dropAuthor),落库 / pts /randomId确认 / 多端回显仍走原流程。投递到 system peer 的场景另有一个文本 + 媒体的输入构造。packages/merged-forward:注册来源,按聊天记录的消息 ID(rank * stride + ordinal)反查归档内容;同一条消息的多个相册分片一起选中时只复制一次;不属于这份聊天记录的 ID 仍然报MSG_ID_INVALID。已知取舍:复制转发在 QQ 侧是账号自己发的一条普通消息,Telegram 上没有「Forwarded from …」头——QQ 无法原生转发归档记录,复制是唯一可行的语义。
验证
packages/merged-forward/src/forward-source.e2e.test.ts:两条归档消息一起转发 → 适配器收到dropAuthor: true和对应sourceMessages,客户端拿到两条updateNewMessage;单条转发;不存在的消息 ID 报MSG_ID_INVALID。packages/bridge/src/virtual-forward.test.ts:注册表按顺序询问、命中即停、dispose 后不再应答。tsc --project tsconfig.test.json通过;packages/bridge单测 930 passed(仅voice/voice-worker-client.test.ts因本机没有 cargo 失败,与本次改动无关);packages/merged-forward全部单测与 e2e(含原有 8 个 e2e 文件)通过。