fix(protocol): restore forward image media and drop file receipts

Bot-built merged forwards left hollow NT images after long-msg fetch,
so get_forward_msg returned empty file/url. Decode now rebuilds identity
from md5, ignores stubs, and forward uploads keep a legacy image sibling.

C2C offline-file download receipts were reported as the peer sending a
file. Treat downloadFlag=2 as a receipt and drop it from the chat stream.
This commit is contained in:
DrSmoothl committed 2026-09-12 13:56:55 +08:00
1 parent 455763f109
commit 4379e4838d
10 files changed
+340 -24

No files matched your search

@@ -1,4 +1,6 @@
import { describe, expect, it } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { FileExtra } from '@snowluma/proto-defs/message';
import {
classifyMessageSurvival,
isBlankMessage,
@@ -34,4 +36,19 @@ describe('classifyMessageSurvival', () => {
richText: { elems: [{ text: { str: 'hi' } }] },
})).toBe('keep');
});
it('drops an offline-file download receipt even if a file element decoded (#442)', () => {
const body = {
msgContent: protobuf_encode<FileExtra>({
file: {
fileUuid: 'fid-sent-by-bot',
fileName: 'doc.bin',
fileSize: 6119608n,
subcmd: 1,
downloadFlag: 2,
},
}),
};
expect(classifyMessageSurvival(privateHead, [{ type: 'file' }], body)).toBe('drop-receipt');
});
});
@@ -13,7 +13,7 @@ import {
} from '@snowluma/common/logger';
import type { PacketInfo } from '@snowluma/common/protocol-types';
import { protobuf_encode } from '@snowluma/proton';
import type { PushMsg, PushMsgBody } from '@snowluma/proto-defs/message';
import type { FileExtra, PushMsg, PushMsgBody } from '@snowluma/proto-defs/message';
import { afterEach, describe, expect, it } from 'vitest';
import type { IdentityService } from '../../src/identity-service';
import { parseMsgPush } from '../../src/msg-push';
@@ -101,6 +101,46 @@ describe('parseMsgPush — empty message drop (#102)', () => {
});
});
it('drops an offline-file download receipt instead of a friend file message (#442)', () => {
const extra = protobuf_encode<FileExtra>({
file: {
fileUuid: 'fid-sent-by-bot',
fileName: 'doc.bin',
fileSize: 6119608n,
subcmd: 1,
downloadFlag: 2,
fileHash: 'abc',
},
});
const out = parseMsgPush(pushPacket({
responseHead: { fromUin: 10001, fromUid: 'u_x' },
contentHead: { msgType: 529, subType: 0, sequence: 1, timestamp: 1, msgId: 1 },
body: { msgContent: extra },
}), identity);
expect(out).toEqual([]);
});
it('keeps a real incoming c2c file (#442)', () => {
const extra = protobuf_encode<FileExtra>({
file: {
fileUuid: 'fid-from-user',
fileName: 'doc.bin',
fileSize: 10n,
subcmd: 1,
},
});
const out = parseMsgPush(pushPacket({
responseHead: { fromUin: 10001, fromUid: 'u_x' },
contentHead: { msgType: 529, subType: 0, sequence: 2, timestamp: 1, msgId: 2 },
body: { msgContent: extra },
}), identity);
expect(out).toHaveLength(1);
expect(out[0]).toMatchObject({
kind: 'friend_message',
elements: [{ type: 'file', fileId: 'fid-from-user', fileName: 'doc.bin' }],
});
});
it('records the precise branch for a C2C control push with content', () => {
// 166 + c2c_cmd ∈ {1,73,75,129,131,133,135,192} is a control/system signal
// QQ NT routes via OnRecvSysMsg, never a bubble — drop regardless of body.
@@ -1093,6 +1093,106 @@ describe('decodeRichBody / unknown wire element observability', () => {
})]);
});
it('does not emit a hollow NT image that has only picFormat (#441)', () => {
const msgInfo: MsgInfo = {
msgInfoBody: [{
index: {
info: {
type: { picFormat: 1001 },
width: 1080,
height: 1080,
},
},
}],
extBizInfo: { pic: { bizType: 0, textSummary: '[图片]' } },
};
const out = decodeRichBody({
richText: {
elems: [{
commonElem: {
serviceType: 48,
businessType: 20,
pbElem: protobuf_encode<MsgInfo>(msgInfo),
},
}],
},
}, true);
expect(out).toEqual([]);
});
it('keeps the customFace sibling when the NT image is hollow (#441)', () => {
const hollow: MsgInfo = {
msgInfoBody: [{
index: { info: { type: { picFormat: 1001 } } },
}],
extBizInfo: { pic: { bizType: 0, textSummary: '[图片]' } },
};
const out = decodeRichBody({
richText: {
elems: [
{
commonElem: {
serviceType: 48,
businessType: 20,
pbElem: protobuf_encode<MsgInfo>(hollow),
},
},
customFaceElem(fileName, '', otherMd5),
],
},
}, true);
expect(out).toEqual([{
type: 'image',
imageUrl: 'http://gchat.qpic.cn/gchatpic_new/0/0-0-0102030405060708090A0B0C0D0E0F10/0',
fileId: fileName,
fileSize: 10711,
width: 1080,
height: 1080,
subType: 0,
summary: '[图片]',
md5Hex: '0102030405060708090A0B0C0D0E0F10',
}]);
});
it('rebuilds file id and url from fileHash when name and uuid are missing (#441)', () => {
const hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
const msgInfo: MsgInfo = {
msgInfoBody: [{
index: {
info: {
fileHash: hash,
fileSha1: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
fileSize: 10711,
width: 1080,
height: 1080,
type: { picFormat: 1001 },
},
},
}],
extBizInfo: { pic: { bizType: 0, textSummary: '[图片]' } },
};
const out = decodeRichBody({
richText: {
elems: [{
commonElem: {
serviceType: 48,
businessType: 20,
pbElem: protobuf_encode<MsgInfo>(msgInfo),
},
}],
},
}, true);
expect(out).toEqual([expect.objectContaining({
type: 'image',
fileId: `${hash}.png`,
imageUrl: `http://gchat.qpic.cn/gchatpic_new/0/0-0-${hash.toUpperCase()}/0`,
md5Hex: hash,
picFormat: 1001,
})]);
});
it('keeps two distinct pictures', () => {
const second = 'other.png';
const out = decodeRichBody({