fix(image): use Chinese summary defaults to match QQ ecosystem
Mobile QQ, Lagrange.Core, and NapCat all use the literal Chinese
bubble-preview strings `[图片]` / `[动画表情]`. SnowLuma was emitting
English `[image]` / `[sticker]` as fallback, so QQ clients showed
"[image]" in chat-list previews instead of the expected Chinese.
Cross-checked against:
dev/NapCatQQ/.../packet/message/element.ts:367-371
dev/Lagrange.Core/.../Message/Entity/ImageEntity.cs:186-192
Both branch the same way: subType=1 → `[动画表情]`, else → `[图片]`.
Changes:
- `bridge/highway/image-upload.ts`: both code paths (fingerprint +
load-from-source) now emit the Chinese defaults. Subtype branch
flipped to `subType === 1 ? '[动画表情]' : '[图片]'` to match the
upstream convention (our old check was `subType === 0` →
`[image]`, which would label any non-zero subType — not just
stickers — as `[sticker]`).
- `bridge/msg-push/rich-body-decoder.ts`: all three decode paths
(NotOnlineImage / CustomFace / commonElem image) now substitute
the Chinese default when the server omits `textSummary`. Empty-
string is also treated as missing (matches NapCat's `=== ''`).
- Tests updated to assert the Chinese defaults; new test pins
that a caller-supplied summary still overrides verdef.
The OneBot caller's `summary` field on the MessageElement still
wins when set, so downstream clients passing custom bubble text
(e.g. for accessibility) keep working.
This commit is contained in:
3 files changed
+34
-10
No files matched your search
@@ -46,7 +46,14 @@ function imageDataFromFingerprint(element: MessageElement): ImageData {
|
||||
sha1Hex: element.sha1Hex ?? '',
|
||||
fileName: element.fileName || `${element.md5Hex ?? 'image'}.jpg`,
|
||||
fileSize: element.fileSize ?? 0,
|
||||
summary: element.summary || (element.subType === 0 ? '[image]' : '[sticker]'),
|
||||
// QQ ecosystem convention — mobile QQ + Lagrange.Core + NapCat all
|
||||
// surface these exact Chinese strings as the chat-list bubble
|
||||
// preview text. English fallbacks would render `[image]` /
|
||||
// `[sticker]` in QQ users' chat lists instead of the expected
|
||||
// `[图片]` / `[动画表情]`. Cross-checked against:
|
||||
// dev/NapCatQQ/.../packet/message/element.ts:367-371
|
||||
// dev/Lagrange.Core/.../Message/Entity/ImageEntity.cs:186-192
|
||||
summary: element.summary || (element.subType === 1 ? '[动画表情]' : '[图片]'),
|
||||
subType: element.subType ?? 0,
|
||||
width: element.width ?? 0,
|
||||
height: element.height ?? 0,
|
||||
@@ -89,7 +96,7 @@ async function loadImageFromSource(source: string, fileName: string, subType: nu
|
||||
sha1Hex: hashes.sha1Hex,
|
||||
fileName: finalName,
|
||||
fileSize: loaded.bytes.length,
|
||||
summary: summary || (subType === 0 ? '[image]' : '[sticker]'),
|
||||
summary: summary || (subType === 1 ? '[动画表情]' : '[图片]'),
|
||||
subType,
|
||||
width: fmt.width,
|
||||
height: fmt.height,
|
||||
|
||||
@@ -97,7 +97,11 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] {
|
||||
width: img.picWidth ?? 0,
|
||||
height: img.picHeight ?? 0,
|
||||
subType: img.pbRes?.subType ?? 0,
|
||||
summary: img.pbRes?.summary ?? '[image]',
|
||||
// `[图片]` / `[动画表情]` are the QQ-ecosystem default
|
||||
// bubble texts; mobile QQ + Lagrange.Core + NapCat all
|
||||
// expect these literal Chinese strings when the wire
|
||||
// doesn't carry a per-image override.
|
||||
summary: img.pbRes?.summary || (img.pbRes?.subType === 1 ? '[动画表情]' : '[图片]'),
|
||||
md5Hex: toHexUpper(img.picMd5),
|
||||
});
|
||||
}
|
||||
@@ -115,7 +119,7 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] {
|
||||
width: img.width ?? 0,
|
||||
height: img.height ?? 0,
|
||||
subType: img.pbRes?.subType ?? 0,
|
||||
summary: img.pbRes?.summary ?? '[image]',
|
||||
summary: img.pbRes?.summary || (img.pbRes?.subType === 1 ? '[动画表情]' : '[图片]'),
|
||||
md5Hex: toHexUpper(img.md5),
|
||||
});
|
||||
}
|
||||
@@ -311,7 +315,8 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] {
|
||||
if (fi.type?.picFormat) me.picFormat = fi.type.picFormat;
|
||||
if (info.extBizInfo?.pic) {
|
||||
me.subType = info.extBizInfo.pic.bizType ?? 0;
|
||||
me.summary = info.extBizInfo.pic.textSummary || '[image]';
|
||||
me.summary = info.extBizInfo.pic.textSummary
|
||||
|| (me.subType === 1 ? '[动画表情]' : '[图片]');
|
||||
}
|
||||
result.push(me);
|
||||
} else if (bizType === 12 || bizType === 22) {
|
||||
|
||||
@@ -67,16 +67,18 @@ describe('image-upload', () => {
|
||||
expect(fileInfo.original).toBe(1);
|
||||
});
|
||||
|
||||
it('forwards subType into bizType and ${subType}-aware textSummary', async () => {
|
||||
it('forwards subType=1 (sticker) into bizType + Chinese textSummary `[动画表情]`', async () => {
|
||||
// QQ chat-list bubble preview text — must match the literal
|
||||
// strings mobile QQ / Lagrange.Core / NapCat all emit.
|
||||
await uploadImageMsgInfo({} as any, true, 12345, { url: 'http://x', subType: 1 } as any);
|
||||
const args = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0];
|
||||
expect((args.extBizInfo as any).pic.bizType).toBe(1);
|
||||
expect((args.extBizInfo as any).pic.textSummary).toBe('[sticker]');
|
||||
expect((args.extBizInfo as any).pic.textSummary).toBe('[动画表情]');
|
||||
});
|
||||
|
||||
it('fingerprint path (noByteFallback): zero bytes, fastOnly error message ready', async () => {
|
||||
await uploadImageMsgInfo({} as any, true, 12345, {
|
||||
noByteFallback: true, md5Hex: 'aa', sha1Hex: 'bb', summary: '[image]',
|
||||
noByteFallback: true, md5Hex: 'aa', sha1Hex: 'bb', summary: '[图片]',
|
||||
} as any);
|
||||
const sub = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploads[0]!;
|
||||
expect(sub.bytes.length).toBe(0);
|
||||
@@ -89,10 +91,20 @@ describe('image-upload', () => {
|
||||
} as any)).rejects.toThrow(/requires md5Hex/);
|
||||
});
|
||||
|
||||
it('finalize is invoked with pic defaults for image', async () => {
|
||||
it('finalize is invoked with pic defaults for image (Chinese `[图片]`)', async () => {
|
||||
await uploadImageMsgInfo({} as any, true, 12345, { url: 'http://x', subType: 0 } as any);
|
||||
expect(pipeline.finalizeMediaMsgInfo).toHaveBeenCalledOnce();
|
||||
const [, defaultPic] = vi.mocked(pipeline.finalizeMediaMsgInfo).mock.calls[0]!;
|
||||
expect(defaultPic).toEqual({ bizType: 0, textSummary: '[image]' });
|
||||
expect(defaultPic).toEqual({ bizType: 0, textSummary: '[图片]' });
|
||||
});
|
||||
|
||||
it('caller-supplied summary wins over the Chinese default', async () => {
|
||||
// OneBot clients can pass `summary: '[心形图片]'` (or any custom
|
||||
// text) — that overrides our default and goes through verbatim.
|
||||
await uploadImageMsgInfo({} as any, true, 12345, {
|
||||
url: 'http://x', subType: 0, summary: '[custom-bubble]',
|
||||
} as any);
|
||||
const [, defaultPic] = vi.mocked(pipeline.finalizeMediaMsgInfo).mock.calls[0]!;
|
||||
expect(defaultPic).toEqual({ bizType: 0, textSummary: '[custom-bubble]' });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user