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
@@ -5,11 +5,54 @@
|
||||
// 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';
|
||||
import type { OidbBase, OidbFriend, OidbSvcTrpcTcp0xFD4_1Response } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbFriendListRequest } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { FriendInfo } from '../../qq-info';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export interface FriendListPageEntry {
|
||||
friend: FriendInfo;
|
||||
categoryId: number;
|
||||
}
|
||||
|
||||
export interface FriendListPageCategory {
|
||||
categoryId: number;
|
||||
categoryName: string;
|
||||
memberCount: number;
|
||||
sortId: number;
|
||||
}
|
||||
|
||||
export interface FriendListPage {
|
||||
entries: FriendListPageEntry[];
|
||||
categories: FriendListPageCategory[];
|
||||
cookie?: Uint8Array;
|
||||
}
|
||||
|
||||
function friendProperties(raw: OidbFriend): Map<number, string> {
|
||||
const props = new Map<number, string>();
|
||||
for (const additional of raw.additional ?? []) {
|
||||
if ((additional.type ?? 0) !== 1 || !additional.layer1) continue;
|
||||
for (const property of additional.layer1.properties ?? []) {
|
||||
props.set(property.code ?? 0, property.value ?? '');
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
function mapFriend(raw: OidbFriend): FriendListPageEntry {
|
||||
const props = friendProperties(raw);
|
||||
return {
|
||||
categoryId: raw.customGroup ?? 0,
|
||||
friend: {
|
||||
uin: raw.uin ?? 0,
|
||||
uid: raw.uid ?? '',
|
||||
nickname: props.get(20002) ?? String(raw.uin ?? 0),
|
||||
remark: props.get(103) ?? '',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export namespace FetchFriendListPage {
|
||||
export const command = 0xFD4;
|
||||
export const subCommand = 1;
|
||||
@@ -40,7 +83,16 @@ export namespace FetchFriendListPage {
|
||||
return body;
|
||||
};
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbSvcTrpcTcp0xFD4_1Response): OidbSvcTrpcTcp0xFD4_1Response => body;
|
||||
export const deserialize = (_ctx: Deps, body: OidbSvcTrpcTcp0xFD4_1Response): FriendListPage => ({
|
||||
entries: (body.friends ?? []).map(mapFriend),
|
||||
categories: (body.categories ?? []).map((raw) => ({
|
||||
categoryId: raw.categoryId ?? 0,
|
||||
categoryName: raw.categoryName ?? '',
|
||||
memberCount: raw.memberCount ?? 0,
|
||||
sortId: raw.sortId ?? 0,
|
||||
})),
|
||||
cookie: body.cookie?.length ? Uint8Array.from(body.cookie) : undefined,
|
||||
});
|
||||
|
||||
export const encode = (env: OidbBase<OidbFriendListRequest>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbFriendListRequest>>(env);
|
||||
@@ -48,6 +100,6 @@ export namespace FetchFriendListPage {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbSvcTrpcTcp0xFD4_1Response> =>
|
||||
protobuf_decode<OidbBase<OidbSvcTrpcTcp0xFD4_1Response>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<OidbSvcTrpcTcp0xFD4_1Response> =>
|
||||
export const invoke = (deps: Deps, params: Params): Promise<FriendListPage> =>
|
||||
invokeOidb(deps, FetchFriendListPage, params);
|
||||
}
|
||||
Reference in new issue
Block a user