diff --git a/packages/protocol/src/msg-push/rich-body-decoder.ts b/packages/protocol/src/msg-push/rich-body-decoder.ts index 7f1ddf6f..1a7746a8 100644 --- a/packages/protocol/src/msg-push/rich-body-decoder.ts +++ b/packages/protocol/src/msg-push/rich-body-decoder.ts @@ -870,8 +870,14 @@ function extractRichtextExtras( elements: MessageElement[], isGroup = false ): void { - // Ptt (voice) - if (rt.ptt) { + // QQ's PTT codec selects either the NTV2 CommonElem representation or the + // legacy RichText.ptt representation. Some C2C pushes still carry an empty + // legacy placeholder beside a complete NTV2 record; decoding both produces a + // second, unusable voice segment (#291). + const hasNtv2Record = elements.some((element) => element.type === 'record'); + + // Ptt (legacy voice) + if (rt.ptt && !hasNtv2Record) { const p = rt.ptt; const md5Hex = p.fileMd5 && p.fileMd5.length > 0 ? toHexUpper(p.fileMd5) : undefined; const me: MessageElementOf<'record'> = { 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 c8c5c584..6b222c33 100644 --- a/packages/protocol/tests/msg-push/rich-body-decoder.test.ts +++ b/packages/protocol/tests/msg-push/rich-body-decoder.test.ts @@ -252,6 +252,54 @@ describe('decodeRichBody / market face', () => { }); describe('decodeRichBody / decoded element contract', () => { + it('[#291] prefers a decoded C2C media record over the empty legacy PTT placeholder', () => { + const fileHash = '469e23ff66ae3ebbf4c78d616e0df18b'; + const fileSha1 = 'a00c7fbe3bfa92773ae17a2f6d381375810972e2'; + const encoded = protobuf_encode({ + richText: { + elems: [{ + commonElem: { + serviceType: 48, + businessType: 22, + pbElem: protobuf_encode({ + msgInfoBody: [{ + index: { + fileUuid: 'voice-uuid', + storeId: 1, + uploadTime: 1785116936, + ttl: 604800, + info: { + fileName: `${fileHash}.amr`, + fileSize: 2015, + fileHash, + fileSha1, + time: 1, + type: { type: 3, voiceFormat: 1 }, + }, + }, + }], + }), + }, + }], + ptt: {}, + }, + }); + + const out = decodeRichBody(protobuf_decode(encoded), false); + + expect(out).toHaveLength(1); + expect(out[0]).toMatchObject({ + type: 'record', + fileName: `${fileHash}.amr`, + fileId: 'voice-uuid', + fileSize: 2015, + duration: 1, + voiceFormat: 1, + md5Hex: fileHash, + sha1Hex: fileSha1, + }); + }); + it('omits an absent PTT fingerprint instead of emitting an invalid empty hash', () => { const body: MessageBody = { richText: {