refactor(protocol): map friend and member pages to domain types
FetchFriendListPage and FetchGroupMemberListPage deserialized as identity functions and leaked Oidb property codes into ContactsApi. Each page now returns a domain page. Contacts keeps pagination, category assembly, member cache, and robot classification.
This commit is contained in:
5 files changed
+215
-102
No files matched your search
@@ -72,11 +72,57 @@ describe('FetchFriendListPage namespace', () => {
|
||||
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0xfd4_1');
|
||||
});
|
||||
|
||||
it('returns the wire body verbatim (facade does the roster mapping)', async () => {
|
||||
const body = { friends: [{ uin: 10001, uid: 'u', additional: [] }] };
|
||||
it('maps a page of friends and categories into domain types', async () => {
|
||||
const body = {
|
||||
cookie: Uint8Array.from([0xAA]),
|
||||
friends: [{
|
||||
uin: 10001,
|
||||
uid: 'u1',
|
||||
customGroup: 7,
|
||||
additional: [{
|
||||
type: 1,
|
||||
layer1: {
|
||||
properties: [
|
||||
{ code: 20002, value: 'Alice' },
|
||||
{ code: 103, value: 'A' },
|
||||
],
|
||||
},
|
||||
}],
|
||||
}],
|
||||
categories: [{
|
||||
categoryId: 7,
|
||||
categoryName: 'Work',
|
||||
memberCount: 1,
|
||||
sortId: 1,
|
||||
}],
|
||||
};
|
||||
const sender = makeSender(body as any);
|
||||
const out = await FetchFriendListPage.invoke(sender, {} as any);
|
||||
expect(out.friends).toBeDefined();
|
||||
await expect(FetchFriendListPage.invoke(sender, {} as any)).resolves.toEqual({
|
||||
entries: [{
|
||||
categoryId: 7,
|
||||
friend: { uin: 10001, uid: 'u1', nickname: 'Alice', remark: 'A' },
|
||||
}],
|
||||
categories: [{
|
||||
categoryId: 7,
|
||||
categoryName: 'Work',
|
||||
memberCount: 1,
|
||||
sortId: 1,
|
||||
}],
|
||||
cookie: Uint8Array.from([0xAA]),
|
||||
});
|
||||
});
|
||||
|
||||
it('fills missing friend fields with 0 / empty string', () => {
|
||||
expect(FetchFriendListPage.deserialize({} as any, {
|
||||
friends: [{ additional: [] }],
|
||||
})).toEqual({
|
||||
entries: [{
|
||||
categoryId: 0,
|
||||
friend: { uin: 0, uid: '', nickname: '0', remark: '' },
|
||||
}],
|
||||
categories: [],
|
||||
cookie: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('encodes a follow-up cookie in the envelope body', async () => {
|
||||
|
||||
+62
-4
@@ -1,13 +1,16 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbSvcTrpcTcp0xFE7_3Response } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupMemberListRequest } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchGroupMemberListPage } from '../../../src/oidb-services/contacts/fetch-group-member-list-page';
|
||||
|
||||
function makeSender() {
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
|
||||
function makeSender(body?: OidbSvcTrpcTcp0xFE7_3Response) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbSvcTrpcTcp0xFE7_3Response>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
@@ -53,5 +56,60 @@ describe('FetchGroupMemberListPage namespace', () => {
|
||||
const env = protobuf_decode<OidbBase<OidbGroupMemberListRequest>>(bytes);
|
||||
expect(env.body?.groupUin).toBe(12345);
|
||||
});
|
||||
|
||||
it('maps members into GroupMemberInfo and leaves isRobot unset-false', async () => {
|
||||
const sender = makeSender({
|
||||
token: 'next',
|
||||
members: [{
|
||||
uin: { uid: 'u_admin', uin: 22222 },
|
||||
memberName: 'Ada',
|
||||
specialTitle: 't',
|
||||
memberCard: { memberCard: 'card' },
|
||||
level: { level: 12 },
|
||||
joinTimestamp: 1,
|
||||
lastMsgTimestamp: 2,
|
||||
shutUpTimestamp: 3,
|
||||
permission: 2,
|
||||
}],
|
||||
});
|
||||
await expect(FetchGroupMemberListPage.invoke(sender, { groupId: 42, token: '' }))
|
||||
.resolves.toEqual({
|
||||
token: 'next',
|
||||
members: [{
|
||||
uin: 22222,
|
||||
uid: 'u_admin',
|
||||
nickname: 'Ada',
|
||||
card: 'card',
|
||||
isRobot: false,
|
||||
role: 'admin',
|
||||
level: 12,
|
||||
title: 't',
|
||||
joinTime: 1,
|
||||
lastSentTime: 2,
|
||||
shutUpTime: 3,
|
||||
}],
|
||||
});
|
||||
});
|
||||
|
||||
it('maps permission 1 to owner and missing fields to 0 / empty', () => {
|
||||
expect(FetchGroupMemberListPage.deserialize({} as any, {
|
||||
members: [
|
||||
{ permission: 1 },
|
||||
{},
|
||||
],
|
||||
})).toEqual({
|
||||
token: '',
|
||||
members: [
|
||||
{
|
||||
uin: 0, uid: '', nickname: '', card: '', isRobot: false,
|
||||
role: 'owner', level: 0, title: '', joinTime: 0, lastSentTime: 0, shutUpTime: 0,
|
||||
},
|
||||
{
|
||||
uin: 0, uid: '', nickname: '', card: '', isRobot: false,
|
||||
role: 'member', level: 0, title: '', joinTime: 0, lastSentTime: 0, shutUpTime: 0,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user