fix(protocol): preserve friend category metadata
This commit is contained in:
7 files changed
+347
-51
No files matched your search
@@ -1,8 +1,8 @@
|
||||
// 0xFD4_1 — single-page friend-roster fetch.
|
||||
//
|
||||
// QQ paginates the friend list with a wire-level cursor (`nextUin`).
|
||||
// QQ paginates the friend list with an opaque wire-level cookie.
|
||||
// This namespace handles ONE round-trip — the facade drives the
|
||||
// while-loop until the server stops emitting a next cursor and
|
||||
// while-loop until the server stops emitting a cookie and
|
||||
// concatenates results into the public FriendInfo[] shape.
|
||||
|
||||
import type { OidbBase, OidbSvcTrpcTcp0xFD4_1Response } from '@snowluma/proto-defs/oidb';
|
||||
@@ -15,9 +15,8 @@ export namespace FetchFriendListPage {
|
||||
export const subCommand = 1;
|
||||
|
||||
export interface Params {
|
||||
/** Cursor: `null` for the first page, otherwise the previous
|
||||
* page's `nextUin`. */
|
||||
nextUin: number | null;
|
||||
/** Opaque cookie returned by the previous page. Omit on page one. */
|
||||
cookie?: Uint8Array;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender;
|
||||
@@ -35,8 +34,8 @@ export namespace FetchFriendListPage {
|
||||
field10002: [13578, 13579, 13573, 13572, 13568],
|
||||
field10003: 4051,
|
||||
};
|
||||
if (p.nextUin !== null) {
|
||||
body.nextUin = { uin: p.nextUin };
|
||||
if (p.cookie?.length) {
|
||||
body.cookie = p.cookie;
|
||||
}
|
||||
return body;
|
||||
};
|
||||
|
||||
@@ -21,6 +21,14 @@ export interface FriendInfo {
|
||||
remark: string;
|
||||
}
|
||||
|
||||
export interface FriendCategoryInfo {
|
||||
categoryId: number;
|
||||
categoryName: string;
|
||||
memberCount: number;
|
||||
sortId: number;
|
||||
friends: FriendInfo[];
|
||||
}
|
||||
|
||||
export interface GroupMemberInfo {
|
||||
uin: number;
|
||||
uid: string;
|
||||
|
||||
@@ -1,11 +1,32 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import {
|
||||
protobuf_decode,
|
||||
protobuf_encode,
|
||||
type bool,
|
||||
type bytes,
|
||||
type pb,
|
||||
type pb_repeated,
|
||||
type uint_32,
|
||||
} from '@snowluma/proton';
|
||||
import type { OidbBase, OidbSvcTrpcTcp0xFD4_1Response } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbFriendListRequest } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchFriendListPage } from '../../../src/oidb-services/contacts/fetch-friend-list-page';
|
||||
|
||||
interface TestFriendCategory {
|
||||
categoryId?: pb<1, uint_32>;
|
||||
categoryName?: pb<2, string>;
|
||||
memberCount?: pb<3, uint_32>;
|
||||
sortId?: pb<4, uint_32>;
|
||||
}
|
||||
|
||||
interface TestFriendListResponse {
|
||||
cookie?: pb<2, bytes>;
|
||||
isEnd?: pb<3, bool>;
|
||||
categories?: pb_repeated<102, TestFriendCategory>;
|
||||
}
|
||||
|
||||
function makeSender(body?: OidbSvcTrpcTcp0xFD4_1Response) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbSvcTrpcTcp0xFD4_1Response>>({ body }))
|
||||
@@ -21,20 +42,22 @@ describe('FetchFriendListPage namespace', () => {
|
||||
});
|
||||
|
||||
describe('serialize', () => {
|
||||
it('omits nextUin on the first page', () => {
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: null }) as any;
|
||||
expect(out.nextUin).toBeUndefined();
|
||||
it('omits the cookie on the first page', () => {
|
||||
const out = FetchFriendListPage.serialize({} as any, {} as any) as any;
|
||||
expect(out.cookie).toBeUndefined();
|
||||
expect(out.friendCount).toBe(300);
|
||||
expect(out.field4).toBe(0);
|
||||
});
|
||||
|
||||
it('includes nextUin sub-message on follow-up pages', () => {
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: 10001 }) as any;
|
||||
expect(out.nextUin).toEqual({ uin: 10001 });
|
||||
it('replays the opaque response cookie in request tag 5', () => {
|
||||
const cookie = Uint8Array.from([0x08, 0x96, 0x01, 0xFF]);
|
||||
const out = FetchFriendListPage.serialize({} as any, { cookie } as any) as any;
|
||||
expect(out.cookie).toEqual(cookie);
|
||||
expect(out.nextUin).toBeUndefined();
|
||||
});
|
||||
|
||||
it('emits the verbatim property request list (codes 100/101/102/103/20002/27394)', () => {
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: null }) as any;
|
||||
const out = FetchFriendListPage.serialize({} as any, {}) as any;
|
||||
expect(out.body).toEqual([
|
||||
{ type: 1, number: { numbers: [103, 102, 20002, 27394] } },
|
||||
{ type: 4, number: { numbers: [100, 101, 102] } },
|
||||
@@ -45,24 +68,47 @@ describe('FetchFriendListPage namespace', () => {
|
||||
describe('invoke (e2e)', () => {
|
||||
it('routes to OidbSvcTrpcTcp.0xfd4_1', async () => {
|
||||
const sender = makeSender({ friends: [] });
|
||||
await FetchFriendListPage.invoke(sender, { nextUin: null });
|
||||
await FetchFriendListPage.invoke(sender, {});
|
||||
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0xfd4_1');
|
||||
});
|
||||
|
||||
it('returns the wire body verbatim (facade does the FriendInfo mapping)', async () => {
|
||||
const body = { friends: [{ uin: 10001, uid: 'u', additional: [] }], next: { uin: 0 } };
|
||||
it('returns the wire body verbatim (facade does the roster mapping)', async () => {
|
||||
const body = { friends: [{ uin: 10001, uid: 'u', additional: [] }] };
|
||||
const sender = makeSender(body as any);
|
||||
const out = await FetchFriendListPage.invoke(sender, { nextUin: null });
|
||||
const out = await FetchFriendListPage.invoke(sender, {} as any);
|
||||
expect(out.friends).toBeDefined();
|
||||
expect(out.next?.uin ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('encodes envelope body correctly', async () => {
|
||||
it('encodes a follow-up cookie in the envelope body', async () => {
|
||||
const sender = makeSender({ friends: [] });
|
||||
await FetchFriendListPage.invoke(sender, { nextUin: 10001 });
|
||||
const cookie = Uint8Array.from([0xAA, 0xBB]);
|
||||
await FetchFriendListPage.invoke(sender, { cookie } as any);
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbFriendListRequest>>(bytes);
|
||||
expect(env.body?.nextUin).toEqual({ uin: 10001 });
|
||||
expect((env.body as any)?.cookie).toEqual(cookie);
|
||||
});
|
||||
|
||||
it('decodes category metadata and the opaque response cookie', () => {
|
||||
const bytes = protobuf_encode<OidbBase<TestFriendListResponse>>({
|
||||
body: {
|
||||
cookie: Uint8Array.from([0xAA, 0xBB]),
|
||||
isEnd: false,
|
||||
categories: [{
|
||||
categoryId: 7,
|
||||
categoryName: 'Work',
|
||||
memberCount: 2,
|
||||
sortId: 3,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const body = FetchFriendListPage.decode(bytes).body as any;
|
||||
expect(body.cookie).toEqual(Uint8Array.from([0xAA, 0xBB]));
|
||||
expect(body.categories).toEqual([{
|
||||
categoryId: 7,
|
||||
categoryName: 'Work',
|
||||
memberCount: 2,
|
||||
sortId: 3,
|
||||
}]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user