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
This commit is contained in:
8 files changed
+169
-154
No files matched your search
@@ -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';
|
||||
|
||||
@@ -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<Oidb0x9083Req>): Uint8Array =>
|
||||
|
||||
@@ -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<OidbBase<Oidb0x9083Resp>>({
|
||||
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));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user