From 3045525e373a43e1a7f35e1761682016ba919fcd Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Fri, 21 Aug 2026 18:25:45 +0800 Subject: [PATCH] fix(onebot): restore emoji reaction users from the native list get_msg_emoji_likes was asking the recent-used emoji catalog, so a reacted message came back empty. Use the native reactor list and the local reaction cache instead. Fixes #409 --- packages/core/src/bridge/apis/interaction.ts | 11 +-- .../core/tests/actions/interaction.test.ts | 11 +-- packages/onebot/src/instance-context.ts | 74 +++++++++++++------ .../onebot/tests/instance-context.test.ts | 73 ++++++++++-------- packages/proto-defs/src/oidb-actions/base.ts | 47 +++++------- .../reaction/fetch-reaction-summary.ts | 15 +--- .../oidb-services/reaction/get-emoji-likes.ts | 31 +++----- .../reaction/get-emoji-likes.test.ts | 61 ++++++++------- 8 files changed, 169 insertions(+), 154 deletions(-) diff --git a/packages/core/src/bridge/apis/interaction.ts b/packages/core/src/bridge/apis/interaction.ts index 4ace0f61..27c63fe4 100644 --- a/packages/core/src/bridge/apis/interaction.ts +++ b/packages/core/src/bridge/apis/interaction.ts @@ -33,11 +33,7 @@ export class InteractionApi { return SetEssence.invoke(this.ctx, { groupId, sequence, random, enable }); } - /** - * Legacy stub: see `GetEmojiLikes` namespace comment for why this - * SSO path can never surface the user list. Real data lives in - * ReactionStore on the OneBot side. - */ + /** Fetch the reactor list for one emoji on a group message. */ async getEmojiLikes( groupId: number, sequence: number, @@ -54,10 +50,7 @@ export class InteractionApi { } /** - * Fetch the per-emoji reaction summary on a group message via - * 0x9084_1 — emoji_id + reactor count + last-reaction timestamp. - * Cross-checked against the local ReactionStore cache for callers - * that need to detect cache gaps. + * Recent-used emoji catalog (0x9084_1). Not a per-message reaction list. */ fetchReactionSummary( groupId: number, diff --git a/packages/core/tests/actions/interaction.test.ts b/packages/core/tests/actions/interaction.test.ts index a2d6dc65..156196c8 100644 --- a/packages/core/tests/actions/interaction.test.ts +++ b/packages/core/tests/actions/interaction.test.ts @@ -51,20 +51,21 @@ describe('apis/interaction', () => { expect(cmds).toEqual(['OidbSvcTrpcTcp.0xeac_1', 'OidbSvcTrpcTcp.0xeac_2']); }); - it('getEmojiLikes decodes user list, base64-encodes cookie, and reports isLast', async () => { + it('getEmojiLikes decodes user list, returns the cookie, and reports isLast', async () => { const bridge = mockBridge(); bridge.sendRawPacket.mockResolvedValueOnce({ success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.from(protobuf_encode>({ body: { - inner: { userInfo: [{ uin: 10001n }, { uin: 20002n }] }, - cookie: new Uint8Array([0xCA, 0xFE]), - } as any, + users: [{ uin: 10001n }, { uin: 20002n }], + cookie: 'next-page', + isLast: false, + }, })), }); const out = await new InteractionApi(bridge as any).getEmojiLikes(12345, 99, '128516'); expect(out.users).toEqual([{ uin: 10001 }, { uin: 20002 }]); - expect(out.cookie).toBe(Buffer.from([0xCA, 0xFE]).toString('base64')); + expect(out.cookie).toBe('next-page'); expect(out.isLast).toBe(false); }); diff --git a/packages/onebot/src/instance-context.ts b/packages/onebot/src/instance-context.ts index 903a5f4b..f735d95b 100644 --- a/packages/onebot/src/instance-context.ts +++ b/packages/onebot/src/instance-context.ts @@ -128,31 +128,51 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext { if (!meta.isGroup) throw new Error('emoji reactions are not supported on private messages'); if (!hasAuthoritativeSequence(meta)) throw new Error('message has no authoritative QQ sequence'); await bridge.apis.interaction.setReaction(meta.targetId, meta.sequence, emojiId, set); + const emojiType = emojiId.length > 3 ? 2 : 1; + if (set) { + reactionStore.recordAdd( + meta.targetId, meta.sequence, emojiId, emojiType, + ref.selfId, '', Math.floor(Date.now() / 1000), + ); + } else { + reactionStore.recordRemove(meta.targetId, meta.sequence, emojiId, ref.selfId); + } }, fetchEmojiLikeSummary: async (messageId) => { const meta = messageStore.findMeta(messageId); if (!meta) throw new Error('message not found'); if (!meta.isGroup) throw new Error('emoji reactions are not supported on private messages'); if (!hasAuthoritativeSequence(meta)) throw new Error('message has no authoritative QQ sequence'); - let summary: Array<{ emojiId: string; emojiType: number; count: number; lastReactionTime: number }>; - try { - summary = await bridge.apis.interaction.fetchReactionSummary(meta.targetId, meta.sequence); - } catch { - summary = reactionStore.summarizeMessage(meta.targetId, meta.sequence).map((entry) => ({ - emojiId: entry.emojiId, - emojiType: entry.emojiType, - count: entry.count, - lastReactionTime: entry.lastSetAt, - })); + const summary = reactionStore.summarizeMessage(meta.targetId, meta.sequence); + const out: Array<{ + emoji_id: string; + emoji_type: number; + count: number; + last_reaction_time: number; + users: Array<{ user_id: number }>; + }> = []; + for (const entry of summary) { + let users = reactionStore.listUsers(meta.targetId, meta.sequence, entry.emojiId, 1000, 0) + .map((user) => ({ user_id: user.operatorUin })); + try { + const remote = await bridge.apis.interaction.getEmojiLikes( + meta.targetId, meta.sequence, entry.emojiId, entry.emojiType, 1000, + ); + if (remote.users.length > 0) { + users = remote.users.map((user) => ({ user_id: user.uin })); + } + } catch { + /* keep cached users */ + } + out.push({ + emoji_id: entry.emojiId, + emoji_type: entry.emojiType, + count: Math.max(entry.count, users.length), + last_reaction_time: entry.lastSetAt, + users, + }); } - return summary.map((entry) => ({ - emoji_id: entry.emojiId, - emoji_type: entry.emojiType, - count: entry.count, - last_reaction_time: entry.lastReactionTime, - users: reactionStore.listUsers(meta.targetId, meta.sequence, entry.emojiId, 1000, 0) - .map((user) => ({ user_id: user.operatorUin })), - })); + return out; }, fetchEmojiLikeUsers: async (messageId, emojiId, count, offset = 0) => { const meta = messageStore.findMeta(messageId); @@ -160,15 +180,23 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext { if (!meta.isGroup) throw new Error('emoji reactions are not supported on private messages'); if (!hasAuthoritativeSequence(meta)) throw new Error('message has no authoritative QQ sequence'); const raw = reactionStore.listUsers(meta.targetId, meta.sequence, emojiId, count, offset); - const users = raw.map(r => ({ uin: r.operatorUin, uid: r.operatorUid, setAt: r.setAt })); + let users = raw.map(r => ({ uin: r.operatorUin, uid: r.operatorUid, setAt: r.setAt })); const cachedCount = reactionStore.countUsers(meta.targetId, meta.sequence, emojiId); let serverCount = cachedCount; try { - const summary = await bridge.apis.interaction.fetchReactionSummary(meta.targetId, meta.sequence); - const match = summary.find(s => s.emojiId === emojiId); - if (match) serverCount = match.count; + const remote = await bridge.apis.interaction.getEmojiLikes( + meta.targetId, meta.sequence, emojiId, emojiId.length > 3 ? 2 : 1, count, + ); + if (remote.users.length > 0) { + serverCount = remote.users.length; + if (offset === 0) { + users = remote.users.slice(0, count).map((user) => ({ + uin: user.uin, uid: '', setAt: 0, + })); + } + } } catch { - /* keep serverCount = cachedCount */ + /* keep cached users / count */ } return { users, diff --git a/packages/onebot/tests/instance-context.test.ts b/packages/onebot/tests/instance-context.test.ts index 075e6d0c..f6f92120 100644 --- a/packages/onebot/tests/instance-context.test.ts +++ b/packages/onebot/tests/instance-context.test.ts @@ -200,6 +200,7 @@ function makeRef(overrides: { }, interaction: { setReaction: vi.fn(async () => undefined), + getEmojiLikes: vi.fn(async () => ({ users: [], cookie: '', isLast: true })), fetchReactionSummary: vi.fn(async () => []), setEssence: vi.fn(async () => undefined), ...overrides.apis?.interaction, @@ -232,6 +233,9 @@ function makeRef(overrides: { reactionStore: { listUsers: vi.fn(() => []), countUsers: vi.fn(() => 0), + summarizeMessage: vi.fn(() => []), + recordAdd: vi.fn(), + recordRemove: vi.fn(), ...overrides.reactionStore, }, tempSessions: new TempSessionStore(), @@ -387,8 +391,10 @@ describe('buildApiContext setMsgEmojiLike', () => { it('sets the reaction on the group message', async () => { const setReaction = vi.fn(async () => undefined); + const recordAdd = vi.fn(); const { api, metas, ref } = makeRef({ - apis: { interaction: { setReaction, fetchReactionSummary: vi.fn(async () => []) } }, + reactionStore: { recordAdd }, + apis: { interaction: { setReaction } }, }); metas.set(-5, groupMeta({ targetId: 710201, sequence: 4242 })); @@ -396,32 +402,37 @@ describe('buildApiContext setMsgEmojiLike', () => { expect(setReaction).toHaveBeenCalledWith(710201, 4242, '76', true); expect(ref.bridge.apis.interaction.setReaction).toHaveBeenCalledOnce(); + expect(recordAdd).toHaveBeenCalledWith(710201, 4242, '76', 1, SELF_ID, '', expect.any(Number)); }); it('clears the reaction when set is false', async () => { const setReaction = vi.fn(async () => undefined); + const recordRemove = vi.fn(); const { api, metas } = makeRef({ - apis: { interaction: { setReaction, fetchReactionSummary: vi.fn(async () => []) } }, + reactionStore: { recordRemove }, + apis: { interaction: { setReaction } }, }); metas.set(-6, groupMeta({ targetId: 710202, sequence: 88 })); await api.setMsgEmojiLike(-6, '144', false); expect(setReaction).toHaveBeenCalledWith(710202, 88, '144', false); + expect(recordRemove).toHaveBeenCalledWith(710202, 88, '144', SELF_ID); }); }); describe('buildApiContext fetchEmojiLikeSummary', () => { - it('returns every emoji on the message with cached users', async () => { + it('returns every cached emoji on the message with cached users', async () => { const listUsers = vi.fn(() => [ { operatorUin: 20002, operatorUid: 'u_20002', setAt: 1_700_000_001 }, ]); - const fetchReactionSummary = vi.fn(async () => [ - { emojiId: '76', emojiType: 1, count: 1, lastReactionTime: 1_700_000_001 }, + const summarizeMessage = vi.fn(() => [ + { emojiId: '76', emojiType: 1, count: 1, lastSetAt: 1_700_000_001 }, ]); + const getEmojiLikes = vi.fn(async () => ({ users: [], cookie: '', isLast: true })); const { api, metas } = makeRef({ - reactionStore: { listUsers, summarizeMessage: vi.fn(() => []) }, - apis: { interaction: { setReaction: vi.fn(), fetchReactionSummary } }, + reactionStore: { listUsers, summarizeMessage }, + apis: { interaction: { getEmojiLikes } }, }); metas.set(-20, groupMeta({ targetId: 710301, sequence: 55 })); @@ -434,7 +445,8 @@ describe('buildApiContext fetchEmojiLikeSummary', () => { users: [{ user_id: 20002 }], }, ]); - expect(fetchReactionSummary).toHaveBeenCalledWith(710301, 55); + expect(summarizeMessage).toHaveBeenCalledWith(710301, 55); + expect(getEmojiLikes).toHaveBeenCalledWith(710301, 55, '76', 1, 1000); expect(listUsers).toHaveBeenCalledWith(710301, 55, '76', 1000, 0); }); }); @@ -464,10 +476,8 @@ describe('buildApiContext fetchEmojiLikeUsers', () => { { operatorUin: 20002, operatorUid: 'u_20002', setAt: 1_700_000_001 }, ]); const countUsers = vi.fn(() => 1); - const fetchReactionSummary = vi.fn(async () => [{ emojiId: '76', count: 1 }]); const { api, metas } = makeRef({ reactionStore: { listUsers, countUsers }, - apis: { interaction: { setReaction: vi.fn(), fetchReactionSummary } }, }); metas.set(-7, groupMeta({ targetId: 710301, sequence: 55 })); @@ -494,7 +504,7 @@ describe('buildApiContext fetchEmojiLikeUsers', () => { expect(listUsers).toHaveBeenCalledWith(710302, 9, '144', 5, 3); }); - it('uses the matching server summary count and reports incomplete when cache is short', async () => { + it('uses the native reactor list when the first page has users', async () => { const { api, metas } = makeRef({ reactionStore: { listUsers: () => [{ operatorUin: 1, operatorUid: 'u_1', setAt: 10 }], @@ -502,36 +512,30 @@ describe('buildApiContext fetchEmojiLikeUsers', () => { }, apis: { interaction: { - setReaction: vi.fn(), - fetchReactionSummary: vi.fn(async () => [ - { emojiId: '99', count: 4 }, - { emojiId: '76', count: 8 }, - ]), + getEmojiLikes: vi.fn(async () => ({ + users: Array.from({ length: 8 }, (_, i) => ({ uin: 1000 + i })), + cookie: '', + isLast: true, + })), }, }, }); metas.set(-9, groupMeta({ targetId: 710303, sequence: 12 })); await expect(api.fetchEmojiLikeUsers(-9, '76', 10)).resolves.toEqual({ - users: [{ uin: 1, uid: 'u_1', setAt: 10 }], + users: Array.from({ length: 8 }, (_, i) => ({ uin: 1000 + i, uid: '', setAt: 0 })), cachedCount: 2, serverCount: 8, complete: false, }); }); - it('keeps the cached count when the summary has no matching emoji', async () => { + it('keeps the cached count when the native list is empty', async () => { const { api, metas } = makeRef({ reactionStore: { listUsers: () => [], countUsers: () => 3, }, - apis: { - interaction: { - setReaction: vi.fn(), - fetchReactionSummary: vi.fn(async () => [{ emojiId: '99', count: 9 }]), - }, - }, }); metas.set(-10, groupMeta({ targetId: 710304, sequence: 13 })); @@ -551,21 +555,31 @@ describe('buildApiContext fetchEmojiLikeUsers', () => { }, apis: { interaction: { - fetchReactionSummary: vi.fn(async () => [{ emojiId: '76', count: 5 }]), + getEmojiLikes: vi.fn(async () => ({ + users: [{ uin: 1 }, { uin: 2 }, { uin: 3 }, { uin: 4 }, { uin: 5 }], + cookie: '', + isLast: true, + })), }, }, }); metas.set(-12, groupMeta({ targetId: 710306, sequence: 15 })); await expect(api.fetchEmojiLikeUsers(-12, '76', 10)).resolves.toEqual({ - users: [], + users: [ + { uin: 1, uid: '', setAt: 0 }, + { uin: 2, uid: '', setAt: 0 }, + { uin: 3, uid: '', setAt: 0 }, + { uin: 4, uid: '', setAt: 0 }, + { uin: 5, uid: '', setAt: 0 }, + ], cachedCount: 6, serverCount: 5, complete: true, }); }); - it('keeps the cached count when the summary fetch fails', async () => { + it('keeps the cached count when the native list fetch fails', async () => { const { api, metas } = makeRef({ reactionStore: { listUsers: () => [], @@ -573,9 +587,8 @@ describe('buildApiContext fetchEmojiLikeUsers', () => { }, apis: { interaction: { - setReaction: vi.fn(), - fetchReactionSummary: vi.fn(async () => { - throw new Error('summary down'); + getEmojiLikes: vi.fn(async () => { + throw new Error('list down'); }), }, }, diff --git a/packages/proto-defs/src/oidb-actions/base.ts b/packages/proto-defs/src/oidb-actions/base.ts index 33940b1c..6d78afea 100644 --- a/packages/proto-defs/src/oidb-actions/base.ts +++ b/packages/proto-defs/src/oidb-actions/base.ts @@ -905,46 +905,33 @@ export interface FaceroamOpResp { field3?: pb<3, uint_32>; item?: pb<4, FaceroamOpRespItem>; } -// 0x9083_1: fetch emoji-like user list. Field numbers must mirror the -// sibling 0x9082 reaction Req (OidbGroupReaction): field 4 = emoji_id -// (string), field 5 = emoji_type (uint). The pre-fix definition had -// these two swapped, which silently dropped both fields on the server -// side (wire type mismatch → protobuf decoder discards) and made every -// call return an empty list with no error. Cross-checked against -// Lagrange.Core V2 `Internal/Packets/Service/SetGroupReaction.cs`. +// 0x9083_1: fetch emoji-like user list for one emoji on a group message. +// Request/response tags follow Windows QQ EncodeGetMsgEmojiLikesListReq / +// DecodeGetMsgEmojiLikesListRsp. This is not the 0x9082 set-reaction body. export interface Oidb0x9083Req { groupId?: pb<2, uint_64>; - // ulong on LagrangeV2's `SetGroupReactionRequest`. wire-compatible - // with uint_32 for small seq values (which is what message sequences - // actually are today), but match the spec to be safe — costs nothing. sequence?: pb<3, uint_64>; - emojiId?: pb<4, string>; - emojiType?: pb<5, uint_32>; - cookie?: pb<6, bytes>; + emojiType?: pb<4, uint_32>; + emojiId?: pb<5, string>; + cookie?: pb<6, string>; field7?: pb<7, uint_32>; count?: pb<8, uint_32>; - field12?: pb<12, uint_32>; } -export interface Oidb0x9083RespUserInfo { - uin?: pb<1, uint_64>; - field3?: pb<3, uint_32>; -} -export interface Oidb0x9083RespInner { - // The server returns one entry per liker — must be repeated. A single - // field collapses N wire entries into "last writer wins", so groups - // with multiple likers used to come back as a single user (or empty - // if the wire layout shifted). - userInfo?: pb_repeated<1, Oidb0x9083RespUserInfo>; - field4?: pb<4, uint_32>; +export interface Oidb0x9083RespUser { + uin?: pb<1, uint_64>; + nick?: pb<2, string>; + headUrl?: pb<3, string>; } export interface Oidb0x9083Resp { - inner?: pb<4, Oidb0x9083RespInner>; - cookie?: pb<5, bytes>; + users?: pb_repeated<1, Oidb0x9083RespUser>; + cookie?: pb<2, string>; + isLast?: pb<3, bool>; + isFirst?: pb<4, bool>; } -// 0x9084_1: fetch reaction summary on a message. Returns one entry per -// emoji used + an "available reactions" catalog tail. Schema decoded -// from production wire dump: +// 0x9084_1: recent-used emoji catalog (GetRecentUseEmojiListForC2CAndGroup). +// Not the per-message reaction list (that is 0x9083_1). Schema from a +// production dump of the catalog body: // { 08 0A ← top-level field 1 (uint, meaning unclear: maybe // "total reactions on msg" or a flag — empirically // constant across messages) diff --git a/packages/protocol/src/oidb-services/reaction/fetch-reaction-summary.ts b/packages/protocol/src/oidb-services/reaction/fetch-reaction-summary.ts index 7d445dcb..094b5948 100644 --- a/packages/protocol/src/oidb-services/reaction/fetch-reaction-summary.ts +++ b/packages/protocol/src/oidb-services/reaction/fetch-reaction-summary.ts @@ -1,14 +1,7 @@ -// 0x9084_1 — fetch per-emoji reaction summary on a group message. -// -// Server returns the full summary unconditionally; the emoji_id / -// emoji_type / count fields in the request body are ignored by the -// summary handler but kept to mirror the working 0x9083_1 request shape -// (same `Pick` of fields the wire format prefers). -// -// "Used" entries carry (lastReactionTime, count, emojiType, emojiId). -// Catalog-tail entries (available reactions the server suggests but -// nobody has reacted with) carry only emojiType + emojiId — filtered -// out here so callers see only the meaningful subset. +// 0x9084_1 — recent-used emoji catalog for C2C/group (GetRecentUseEmojiList). +// Not the per-message reaction summary. get_msg_emoji_likes uses 0x9083_1 +// plus the local reaction cache. This namespace is kept for the catalog +// command itself. import { protobuf_decode, protobuf_encode } from '@snowluma/proton'; import type { OidbBase } from '@snowluma/proto-defs/oidb'; diff --git a/packages/protocol/src/oidb-services/reaction/get-emoji-likes.ts b/packages/protocol/src/oidb-services/reaction/get-emoji-likes.ts index 25ae06a0..5022c3fd 100644 --- a/packages/protocol/src/oidb-services/reaction/get-emoji-likes.ts +++ b/packages/protocol/src/oidb-services/reaction/get-emoji-likes.ts @@ -1,15 +1,6 @@ -// 0x9083_1 — historic "fetch reactor user list" cmd. CONFIRMED to be -// a real server endpoint (errorCode=0, trace string echoes the cmd -// name), but its reply is always a 4-byte minimal ack `18 01 20 01` -// regardless of the message / emoji / whether the bot just set a -// reaction. The actual "who reacted" data is NOT served via SSO at -// all — NTQQ's own client uses a wrapper-internal cache. SnowLuma -// mirrors that with `ReactionStore` (fed from GroupMsgEmojiLikeEvent -// push) on the OneBot side. -// -// This namespace exists as a legacy stub so older callers don't crash -// — `invoke` always returns an empty user list. Newer code should -// query `ReactionStore` instead. +// 0x9083_1 — fetch the reactor user list for one emoji on a group message. +// Encode/decode follow Windows QQ GetMsgEmojiLikesList. 0x9084_1 is a +// different command (recent-used emoji catalog) and must not be used here. import { protobuf_decode, protobuf_encode } from '@snowluma/proton'; import type { OidbBase } from '@snowluma/proto-defs/oidb'; @@ -28,13 +19,13 @@ export namespace GetEmojiLikes { emojiId: string; emojiType?: number; count?: number; - /** Base64-encoded continuation cookie from a previous page. */ + /** Continuation cookie from a previous page. */ cookie?: string; } export interface Result { users: Array<{ uin: number }>; - /** Base64 cookie for next page (empty when on last page). */ + /** Cookie for next page (empty when on last page). */ cookie: string; isLast: boolean; } @@ -44,20 +35,18 @@ export namespace GetEmojiLikes { export const serialize = (_ctx: Deps, p: Params): Oidb0x9083Req => ({ groupId: BigInt(p.groupId), sequence: BigInt(p.sequence), - emojiId: p.emojiId, emojiType: p.emojiType ?? 1, - cookie: p.cookie ? Buffer.from(p.cookie, 'base64') : new Uint8Array(0), - field7: 0, + emojiId: p.emojiId, + cookie: p.cookie ?? '', count: p.count ?? 10, - field12: 1, }); export const deserialize = (_ctx: Deps, body: Oidb0x9083Resp): Result => { - const users: Array<{ uin: number }> = (body.inner?.userInfo ?? []) + const users: Array<{ uin: number }> = (body.users ?? []) .map(u => ({ uin: Number(u?.uin ?? 0) })) .filter(u => u.uin > 0); - const cookie = body.cookie ? Buffer.from(body.cookie).toString('base64') : ''; - return { users, cookie, isLast: !cookie }; + const cookie = body.cookie ?? ''; + return { users, cookie, isLast: body.isLast ?? !cookie }; }; export const encode = (env: OidbBase): Uint8Array => diff --git a/packages/protocol/tests/oidb-services/reaction/get-emoji-likes.test.ts b/packages/protocol/tests/oidb-services/reaction/get-emoji-likes.test.ts index 5e1224e5..63eb5d36 100644 --- a/packages/protocol/tests/oidb-services/reaction/get-emoji-likes.test.ts +++ b/packages/protocol/tests/oidb-services/reaction/get-emoji-likes.test.ts @@ -5,6 +5,7 @@ import type { Oidb0x9083Req, Oidb0x9083Resp } from '@snowluma/proto-defs/oidb-ac import type { SendPacketResult } from '@snowluma/common/packet-sender'; import { GetEmojiLikes } from '../../../src/oidb-services/reaction/get-emoji-likes'; +import { env, s, v } from '../_pb-oracle'; function makeSender(resp?: Buffer) { const defaultResp: SendPacketResult = { @@ -54,39 +55,32 @@ describe('GetEmojiLikes namespace', () => { expect(out.count).toBe(50); }); - it('decodes base64 cookie into the bytes field for continuation', () => { - const cookie = Buffer.from([0xCA, 0xFE]).toString('base64'); - const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x', cookie }); - expect(out.cookie).toBeInstanceOf(Uint8Array); - expect(Buffer.from(out.cookie!).equals(Buffer.from([0xCA, 0xFE]))).toBe(true); + it('passes the continuation cookie through as a string', () => { + const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x', cookie: 'next' }); + expect(out.cookie).toBe('next'); }); - it('emits a 0-length cookie buffer for the first page (no cookie supplied)', () => { + it('emits an empty cookie for the first page', () => { const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x' }); - expect(out.cookie!.length).toBe(0); - }); - - it('sets field7=0 and field12=1 (magic values matching the historic wire shape)', () => { - const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x' }); - expect(out.field7).toBe(0); - expect(out.field12).toBe(1); + expect(out.cookie).toBe(''); }); }); describe('deserialize', () => { - it('extracts users from inner.userInfo and base64-encodes the cookie', () => { + it('extracts users from the repeated list and returns the cookie', () => { const result = GetEmojiLikes.deserialize({} as any, { - inner: { userInfo: [{ uin: 10001n }, { uin: 20002n }] }, - cookie: new Uint8Array([0xCA, 0xFE]), + users: [{ uin: 10001n }, { uin: 20002n }], + cookie: 'next', + isLast: false, }); expect(result.users).toEqual([{ uin: 10001 }, { uin: 20002 }]); - expect(result.cookie).toBe(Buffer.from([0xCA, 0xFE]).toString('base64')); + expect(result.cookie).toBe('next'); expect(result.isLast).toBe(false); }); it('filters out users with uin=0 (placeholder / zero-value)', () => { const result = GetEmojiLikes.deserialize({} as any, { - inner: { userInfo: [{ uin: 10001n }, { uin: 0n }, { uin: 20002n }] }, + users: [{ uin: 10001n }, { uin: 0n }, { uin: 20002n }], }); expect(result.users).toEqual([{ uin: 10001 }, { uin: 20002 }]); }); @@ -100,13 +94,13 @@ describe('GetEmojiLikes namespace', () => { it('returns isLast=true when cookie is absent (final page)', () => { const result = GetEmojiLikes.deserialize({} as any, { - inner: { userInfo: [{ uin: 10001n }] }, + users: [{ uin: 10001n }], }); expect(result.isLast).toBe(true); }); - it('handles missing userInfo entries field', () => { - const result = GetEmojiLikes.deserialize({} as any, { inner: {} }); + it('handles a missing users field', () => { + const result = GetEmojiLikes.deserialize({} as any, {}); expect(result.users).toEqual([]); }); }); @@ -122,14 +116,15 @@ describe('GetEmojiLikes namespace', () => { const respEnvelope = Buffer.from(protobuf_encode>({ command: 0x9083, subCommand: 1, body: { - inner: { userInfo: [{ uin: 10001n }] }, - cookie: new Uint8Array([0xDE, 0xAD]), - } as any, + users: [{ uin: 10001n }], + cookie: 'next', + isLast: false, + }, })); const sender = makeSender(respEnvelope); const result = await GetEmojiLikes.invoke(sender, { groupId: 1, sequence: 1, emojiId: '76' }); expect(result.users).toEqual([{ uin: 10001 }]); - expect(result.cookie).toBe(Buffer.from([0xDE, 0xAD]).toString('base64')); + expect(result.cookie).toBe('next'); expect(result.isLast).toBe(false); }); @@ -154,5 +149,21 @@ describe('GetEmojiLikes namespace', () => { expect(env.body?.emojiType).toBe(2); expect(env.body?.count).toBe(20); }); + + it('byte-oracle: request body uses type then emoji id, not the set-reaction order', async () => { + const sender = makeSender(); + await GetEmojiLikes.invoke(sender, { + groupId: 12345, sequence: 99, emojiId: '76', emojiType: 1, count: 20, + }); + const [, reqBytes] = sender.sendRawPacket.mock.calls[0]!; + const body = [ + ...v(2, 12345), + ...v(3, 99), + ...v(4, 1), + ...s(5, '76'), + ...v(8, 20), + ]; + expect(Buffer.from(reqBytes).toString('hex')).toBe(env(0x9083, 1, body, false)); + }); }); });