From 45aae92af5d1541ed19885a36e72571d3aad3baa Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Mon, 22 Jun 2026 20:37:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(protocol):=20group=20reply+at=20=E2=80=94?= =?UTF-8?q?=20emit=20replied-sender=20mention=20after=20srcMsg=20(#129)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a group message combined a reply with a user @ , the @ showed but never notified (no blue link, no ping). On-target capture showed SnowLuma sent [srcMsg, @target(mention), text] — the @ lands directly in the reply's mention slot right after srcMsg, which the QQ NT group server does not honor. Mirror Lagrange's ForwardEntity.PackElement: when a reply and an @ coexist in a group message, emit the replied sender as a trailing mention element right after srcMsg, so the user's @ is no longer the first post-srcMsg element and is honored. Gated to the reply+@ case so plain replies are unchanged. Validated on-target (Docker, group send): baseline reply+at -> @ not delivered; fixed -> @ delivered (blue link + notification). --- packages/protocol/src/element-builder.ts | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/protocol/src/element-builder.ts b/packages/protocol/src/element-builder.ts index d251084a..43be2636 100644 --- a/packages/protocol/src/element-builder.ts +++ b/packages/protocol/src/element-builder.ts @@ -105,6 +105,20 @@ function makeReplyElem(element: MessageElement): ProtoElem { return { srcMsg }; } +// The replied sender, encoded as a mention element placed right after srcMsg. +// QQ NT's group reply wire shape expects this; without it a following +// user-supplied @ is silently not honored by the server (issue #129). +async function makeReplyMentionElem(ctx: SendContext, uin: number): Promise { + if (ctx.groupId === undefined || uin <= 0) return null; + const member = ctx.bridge.identity.findGroupMember(ctx.groupId, uin); + let uid = member?.uid ?? ''; + if (!uid) uid = await ctx.bridge.identity.resolveUid(uin, ctx.groupId).catch(() => ''); + if (!uid) return null; + const name = member?.card?.trim() || member?.nickname?.trim() || String(uin); + const extra = protobuf_encode({ type: 2, uin, field5: 0, uid }); + return { text: { str: `@${name} `, pbReserve: extra } }; +} + function makeDeflatedPayload(content: string): Uint8Array { const deflated = deflateSync(Buffer.from(content, 'utf8')); const payload = new Uint8Array(deflated.length + 1); @@ -378,6 +392,12 @@ async function makeVideoElem(ctx: SendContext, element: MessageElement): Promise */ export async function buildSendElems(elements: MessageElement[], ctx?: SendContext): Promise { const result: ProtoElem[] = []; + // A user-supplied @ that lands immediately after a reply's srcMsg isn't + // honored by the QQ NT group server (the @ shows but never notifies, #129). + // When a reply and an @ coexist, emit the replied sender as a trailing + // mention right after srcMsg (mirrors Lagrange ForwardEntity.PackElement), + // which restores the wire shape the server expects. + const hasUserAt = elements.some((e) => e.type === 'at'); for (const elem of elements) { switch (elem.type) { @@ -398,7 +418,13 @@ export async function buildSendElems(elements: MessageElement[], ctx?: SendConte break; case 'reply': - if (elem.replySeq) result.push(makeReplyElem(elem)); + if (elem.replySeq) { + result.push(makeReplyElem(elem)); + if (hasUserAt && ctx?.groupId !== undefined && elem.replySenderUin) { + const replyMention = await makeReplyMentionElem(ctx, elem.replySenderUin); + if (replyMention) result.push(replyMention); + } + } break; case 'json':