fix(protocol): avoid duplicate private voice elements
Prefer a successfully decoded modern voice record over the empty legacy voice placeholder that can accompany private message pushes. Preserve legacy-only voice messages and add a protobuf round-trip regression covering the duplicate segment reported in #291. Fixes #291
This commit is contained in:
2 files changed
+56
-2
No files matched your search
@@ -870,8 +870,14 @@ function extractRichtextExtras(
|
|||||||
elements: MessageElement[],
|
elements: MessageElement[],
|
||||||
isGroup = false
|
isGroup = false
|
||||||
): void {
|
): void {
|
||||||
// Ptt (voice)
|
// QQ's PTT codec selects either the NTV2 CommonElem representation or the
|
||||||
if (rt.ptt) {
|
// 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 p = rt.ptt;
|
||||||
const md5Hex = p.fileMd5 && p.fileMd5.length > 0 ? toHexUpper(p.fileMd5) : undefined;
|
const md5Hex = p.fileMd5 && p.fileMd5.length > 0 ? toHexUpper(p.fileMd5) : undefined;
|
||||||
const me: MessageElementOf<'record'> = {
|
const me: MessageElementOf<'record'> = {
|
||||||
|
|||||||
@@ -252,6 +252,54 @@ describe('decodeRichBody / market face', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('decodeRichBody / decoded element contract', () => {
|
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<MessageBody>({
|
||||||
|
richText: {
|
||||||
|
elems: [{
|
||||||
|
commonElem: {
|
||||||
|
serviceType: 48,
|
||||||
|
businessType: 22,
|
||||||
|
pbElem: protobuf_encode<MsgInfo>({
|
||||||
|
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<MessageBody>(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', () => {
|
it('omits an absent PTT fingerprint instead of emitting an invalid empty hash', () => {
|
||||||
const body: MessageBody = {
|
const body: MessageBody = {
|
||||||
richText: {
|
richText: {
|
||||||
|
|||||||
Reference in new issue
Block a user