Forward image sub_type and summary fields

Include optional element.subType and element.summary in the image segment payload (mapped to sub_type and summary) so custom emoji/sticker metadata is preserved. Adds a unit test to verify these fields are forwarded.
This commit is contained in:
手瓜一十雪 committed 2026-05-20 10:52:43 +08:00
1 parent 312df29b5f
commit 6de2e071be
2 files changed
+23

No files matched your search

@@ -54,6 +54,8 @@ async function elementToSegment(
const data: JsonObject = {
url,
file: element.fileId ?? '',
sub_type: element.subType ?? 0,
summary: element.summary ?? '',
};
if (mediaSegmentSink) mediaSegmentSink('image', element, data, isGroup, sessionId);
return { type: 'image', data };
@@ -343,6 +343,8 @@ describe('convertEvent — message elements (13 segment types)', () => {
expect(seg.type).toBe('image');
expect((seg.data as Record<string, unknown>).url).toBe('http://resolved');
expect((seg.data as Record<string, unknown>).file).toBe('fid');
expect((seg.data as Record<string, unknown>).sub_type).toBe(0);
expect((seg.data as Record<string, unknown>).summary).toBe('');
});
it('image without resolver uses element.imageUrl', async () => {
@@ -350,6 +352,25 @@ describe('convertEvent — message elements (13 segment types)', () => {
expect((seg.data as Record<string, unknown>).url).toBe('http://x');
});
it('image: forwards optional sub_type and summary for custom emoji/stickers', async () => {
const seg = await segment({
type: 'image',
fileId: 'fid',
imageUrl: 'http://x',
subType: 1,
summary: '[动画表情]',
});
expect(seg).toEqual({
type: 'image',
data: {
url: 'http://x',
file: 'fid',
sub_type: 1,
summary: '[动画表情]',
},
});
});
it('at: targetUin -> qq string', async () => {
const seg = await segment({ type: 'at', targetUin: PEER_UIN });
expect(seg).toEqual({ type: 'at', data: { qq: String(PEER_UIN) } });