fix(protocol): classify private file subcommand receipts
Drop download acknowledgements carried by the offline-file subcommand in both push and history paths, while retaining incoming file transfers. Fixes #477
This commit is contained in:
@@ -16,7 +16,7 @@ import type {
|
||||
TextElem,
|
||||
} from '@snowluma/proto-defs/element';
|
||||
import type { MarkdownData } from '@snowluma/proto-defs/action';
|
||||
import type { FileExtra, MessageBody, PushMsgBody as PushMsgBodyFull, RichText } from '@snowluma/proto-defs/message';
|
||||
import type { FileExtra, MessageBody, NotOnlineFile, PushMsgBody as PushMsgBodyFull, RichText } from '@snowluma/proto-defs/message';
|
||||
import {
|
||||
decompressData,
|
||||
imageUrlFromMd5,
|
||||
@@ -1200,7 +1200,7 @@ function extractRichtextExtras(
|
||||
}
|
||||
|
||||
// NotOnlineFile (C2C file)
|
||||
if (rt.notOnlineFile && !isOfflineFileReceiptFlag(rt.notOnlineFile.downloadFlag)) {
|
||||
if (rt.notOnlineFile && !isOfflineFileReceiptMetadata(rt.notOnlineFile)) {
|
||||
const f = rt.notOnlineFile;
|
||||
elements.push({
|
||||
type: 'file', fileId: f.fileUuid ?? '',
|
||||
@@ -1228,7 +1228,7 @@ function extractMsgContent(msgContent: Uint8Array, elements: MessageElement[]):
|
||||
);
|
||||
if (!extra?.file) return;
|
||||
const f = extra.file;
|
||||
if (isOfflineFileReceiptFlag(f.downloadFlag)) return;
|
||||
if (isOfflineFileReceiptMetadata(f)) return;
|
||||
if (!f.fileUuid) return;
|
||||
elements.push({
|
||||
type: 'file',
|
||||
@@ -1239,19 +1239,19 @@ function extractMsgContent(msgContent: Uint8Array, elements: MessageElement[]):
|
||||
});
|
||||
}
|
||||
|
||||
/** QQ treats downloadFlag=2 as an offline-file receipt gray tip, not a chat bubble. */
|
||||
function isOfflineFileReceiptFlag(flag: number | undefined): boolean {
|
||||
return flag === 2;
|
||||
/** Download acknowledgements can use either the receipt flag or the file subcommand. */
|
||||
function isOfflineFileReceiptMetadata(file: NotOnlineFile | null | undefined): boolean {
|
||||
return file?.downloadFlag === 2 || (file?.fileType === 1 && file.subcmd === 2);
|
||||
}
|
||||
|
||||
/** True when this body is an offline-file download receipt, not a new file message. */
|
||||
export function isOfflineFileReceipt(body: PushMsgBody | undefined): boolean {
|
||||
if (isOfflineFileReceiptFlag(body?.richText?.notOnlineFile?.downloadFlag)) return true;
|
||||
if (isOfflineFileReceiptMetadata(body?.richText?.notOnlineFile)) return true;
|
||||
if (!body?.msgContent || body.msgContent.length === 0) return false;
|
||||
const extra = decodeProtobufPayload(
|
||||
'messageBody.msgContent',
|
||||
body.msgContent,
|
||||
() => protobuf_decode<FileExtra>(body.msgContent!),
|
||||
);
|
||||
return isOfflineFileReceiptFlag(extra?.file?.downloadFlag);
|
||||
return isOfflineFileReceiptMetadata(extra?.file);
|
||||
}
|
||||
|
||||
@@ -51,4 +51,17 @@ describe('classifyMessageSurvival', () => {
|
||||
};
|
||||
expect(classifyMessageSurvival(privateHead, [{ type: 'file' }], body)).toBe('drop-receipt');
|
||||
});
|
||||
|
||||
it('classifies subcommand receipts consistently for history and push consumers (#477)', () => {
|
||||
const file = { fileType: 1, subcmd: 2, fileUuid: 'already-sent', fileName: 'test.json', fileSize: 42n };
|
||||
for (const body of [
|
||||
{ msgContent: protobuf_encode<FileExtra>({ file }) },
|
||||
{ richText: { notOnlineFile: file } },
|
||||
]) {
|
||||
expect(classifyMessageSurvival(privateHead, [{ type: 'file' }], body)).toBe('drop-receipt');
|
||||
}
|
||||
expect(classifyMessageSurvival(privateHead, [{ type: 'file' }], {
|
||||
richText: { notOnlineFile: { ...file, fileType: 3 } },
|
||||
})).toBe('keep');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -123,6 +123,7 @@ describe('parseMsgPush — empty message drop (#102)', () => {
|
||||
it('keeps a real incoming c2c file (#442)', () => {
|
||||
const extra = protobuf_encode<FileExtra>({
|
||||
file: {
|
||||
fileType: 1,
|
||||
fileUuid: 'fid-from-user',
|
||||
fileName: 'doc.bin',
|
||||
fileSize: 10n,
|
||||
@@ -141,6 +142,26 @@ describe('parseMsgPush — empty message drop (#102)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each(['msgContent', 'richText'] as const)('drops a subcommand receipt in %s without a download flag (#477)', (location) => {
|
||||
const entries: LogEntry[] = [];
|
||||
setLogLevel('trace');
|
||||
const unsubscribe = subscribeLogs((entry) => entries.push(entry));
|
||||
const file = { fileType: 1, subcmd: 2, fileUuid: 'already-sent', fileName: 'test.json', fileSize: 42n };
|
||||
try {
|
||||
const out = parseMsgPush(pushPacket({
|
||||
responseHead: { fromUin: 10001, fromUid: 'u_x' },
|
||||
contentHead: { msgType: 529, subType: 4, c2cCmd: 4, sequence: 10, timestamp: 1, msgId: 1 },
|
||||
body: location === 'msgContent'
|
||||
? { msgContent: protobuf_encode<FileExtra>({ file }) }
|
||||
: { richText: { notOnlineFile: file } },
|
||||
}), identity);
|
||||
expect(out).toEqual([]);
|
||||
expect(traceMessages(entries).some((message) => message.includes('branch=offline_file_receipt'))).toBe(true);
|
||||
} finally {
|
||||
unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user