From 953b18b5cbc56346337923bcf81f2268c3f76056 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 26 Sep 2026 15:59:07 +0800 Subject: [PATCH] fix(protocol): avoid duplicate text for animated faces Recognize animated face compatibility labels consistently while preserving user-authored text. Fixes #484 --- .../src/msg-push/rich-body-decoder.ts | 2 +- .../tests/msg-push/rich-body-decoder.test.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/protocol/src/msg-push/rich-body-decoder.ts b/packages/protocol/src/msg-push/rich-body-decoder.ts index 759f5f8a..5d3e91cc 100644 --- a/packages/protocol/src/msg-push/rich-body-decoder.ts +++ b/packages/protocol/src/msg-push/rich-body-decoder.ts @@ -395,7 +395,7 @@ function bytesEqual(left: Uint8Array, right: Uint8Array): boolean { function isBigFaceCompatibilityText(extra: QFaceExtra, text: TextElem): boolean { const faceText = extra.text ?? ''; const reserveData = text.pbReserve; - if (!faceText.startsWith('/') || faceText.length === 1 || text.str !== faceText || !reserveData?.length) { + if (!faceText || text.str !== faceText || !reserveData?.length) { return false; } diff --git a/packages/protocol/tests/msg-push/rich-body-decoder.test.ts b/packages/protocol/tests/msg-push/rich-body-decoder.test.ts index c68a61ef..fc69ae75 100644 --- a/packages/protocol/tests/msg-push/rich-body-decoder.test.ts +++ b/packages/protocol/tests/msg-push/rich-body-decoder.test.ts @@ -594,6 +594,26 @@ describe('decodeRichBody / unknown wire element observability', () => { ]); }); + it.each(['/打call', '[蛇年快乐]', 'name'])('recognizes native compatibility text independently of the face label prefix (%s)', (faceText) => { + const reserve = protobuf_encode({ + str: `[${faceText.slice(1)}]请使用最新版手机QQ体验新功能`, + }); + const body: MessageBody = { + richText: { + elems: [ + { commonElem: { serviceType: 37, businessType: 3, + pbElem: protobuf_encode({ qsid: 429, text: faceText }) } } as never, + { text: { str: faceText, pbReserve: reserve } } as never, + { text: { str: faceText } } as never, + ], + }, + }; + expect(decodeRichBody(body, false)).toEqual([ + { type: 'face', faceId: 429 }, + { type: 'text', text: faceText }, + ]); + }); + it('[#289] preserves compatibility text when the big face has no valid face id', () => { const body: MessageBody = { richText: {