refactor(protocol): keep hasDecodableContent next to decodeRichBody
Move the body-shape predicate into RichBody so admission no longer mirrors decode slots. C2C control stays a header check.
This commit is contained in:
4 files changed
+40
-20
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import type { MsgPushHead, PushMsgBody } from './context';
|
||||
import { hasDecodableContent } from './rich-body-decoder';
|
||||
|
||||
// C2C-family message types (private 166, temp 141, and 167) whose pushes QQ NT
|
||||
// classifies by `c2c_cmd`. RE: `long_cnn_msg_mgr.cc::OnRecvSysMsg` gates on
|
||||
@@ -24,22 +25,6 @@ export function isC2cControlPush(head: Pick<MsgPushHead, 'msgType' | 'c2cCmd'>):
|
||||
return C2C_CONTROL_TYPES.has(head.msgType) && C2C_CONTROL_CMDS.has(head.c2cCmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a push body carries anything {@link decodeRichBody} could turn into an
|
||||
* element: source `richText.elems`, a voice (`ptt`), a c2c file
|
||||
* (`notOnlineFile`), or serialised `msgContent` file metadata. Mirrors exactly
|
||||
* what the rich-body decoder reads. A body with none of these is a genuinely
|
||||
* content-less control push, not an element type we merely fail to decode.
|
||||
*/
|
||||
export function bodyHasDecodableContent(body: PushMsgBody | undefined): boolean {
|
||||
const rt = body?.richText;
|
||||
if (rt) {
|
||||
if (rt.elems && rt.elems.length > 0) return true;
|
||||
if (rt.ptt || rt.notOnlineFile) return true;
|
||||
}
|
||||
return !!(body?.msgContent && body.msgContent.length > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* A message-kind event is "blank" — the "[空消息]" phantom from #102 — when it
|
||||
* decoded to zero elements AND its body carried nothing decodable. These are
|
||||
@@ -62,5 +47,5 @@ export function isBlankMessage(
|
||||
elements: readonly unknown[],
|
||||
body: PushMsgBody | undefined,
|
||||
): boolean {
|
||||
return elements.length === 0 && !bodyHasDecodableContent(body);
|
||||
return elements.length === 0 && !hasDecodableContent(body);
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import type { Elem } from '@snowluma/proto-defs/element';
|
||||
import type { QQEventVariant } from '../events';
|
||||
import type { IdentityService } from '../identity-service';
|
||||
import { bodyHasDecodableContent, isC2cControlPush } from './blank-filter';
|
||||
import { isC2cControlPush } from './blank-filter';
|
||||
import { hasDecodableContent } from './rich-body-decoder';
|
||||
import { buildContext, type PushMsgBody } from './context';
|
||||
import { decodeEvent0x210 } from './decoders/event-0x210';
|
||||
import { decodeEvent0x2DC } from './decoders/event-0x2dc';
|
||||
@@ -217,7 +218,7 @@ function parseMsgPushInternal(
|
||||
// If instead the body *had* content we just couldn't decode, keep the
|
||||
// (still-empty) event but warn so the missing decoder gets noticed rather
|
||||
// than silently swallowed.
|
||||
if (bodyHasDecodableContent(ctx.body)) {
|
||||
if (hasDecodableContent(ctx.body)) {
|
||||
log.warn('message had content but decoded to 0 elements — missing decoder? (kind=%s seq=%d from=%d msgType=%d/%d): %s',
|
||||
ev.kind, ctx.head.sequence, ctx.fromUin, ctx.head.msgType, ctx.head.subType,
|
||||
describeUndecodedBody(ctx.body));
|
||||
|
||||
@@ -457,6 +457,19 @@ function buildMediaNode(idx: IndexNode, fi: FileInfo): MessageElement['mediaNode
|
||||
};
|
||||
}
|
||||
|
||||
/** Whether this body carries any slot {@link decodeRichBody} would try:
|
||||
* `richText.elems`, a voice (`ptt`), a c2c file (`notOnlineFile`), or
|
||||
* serialized `msgContent`. Presence, not successful decode — a body that
|
||||
* has elems we do not yet understand is still decodable content. */
|
||||
export function hasDecodableContent(body: PushMsgBody | undefined): boolean {
|
||||
const rt = body?.richText;
|
||||
if (rt) {
|
||||
if (rt.elems && rt.elems.length > 0) return true;
|
||||
if (rt.ptt || rt.notOnlineFile) return true;
|
||||
}
|
||||
return !!(body?.msgContent && body.msgContent.length > 0);
|
||||
}
|
||||
|
||||
export function decodeRichBody(body: PushMsgBody | undefined, isGroup: boolean): MessageElement[] {
|
||||
const elements: MessageElement[] = [];
|
||||
logUnknownWireFields(body, 'body');
|
||||
|
||||
Reference in new issue
Block a user