refactor(oidb): migrate profile.ts OIDB cmds to namespaces
5 of profile.ts's methods were thin OIDB wrappers — migrated to the
new namespace pattern. The 5 non-OIDB methods (setOnlineStatus /
setDiyOnlineStatus / setAvatar / setGroupAvatar / fetchCustomFace)
stay on the facade unchanged — they hit `trpc.qq_new_tech.*`,
Highway, or `Faceroam.OpReq` directly and aren't in scope for the
OIDB-namespace refactor.
New namespaces (each with focused Pick<BridgeContext, …> deps):
- SetProfile (0x112A_2) — needs identity for uin
- SetSelfLongNick (0x112A_2) — same cmd different proto, ditto
- SetInputStatus (0xCD4_1) — needs resolveUserUid
- GetLike (0x7ED_12) — needs identity + resolveUserUid
- GetUnidirectionalFriendList (0xE17_0) — needs identity; non-standard
wire name handled via the new
wireName override on OidbCallSpec
Infrastructure tweak:
- OidbCallSpec gains an optional `wireName(cmd, sub) → string`. Most
cmds use the default `OidbSvcTrpcTcp.0xNNNN_N` scheme; 0xe17_0
routes through `MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0`.
Test mock updates:
- profile.test.ts moves the migrated cmds onto bridge.sendRawPacket
mock (the new path bypasses the bridge-oidb runOidb mock). Non-OIDB
cmds (setOnlineStatus, setAvatar, etc.) keep their existing mocks.
- 36 new namespace-level tests in @snowluma/bridge covering serialize
branches, deserialize edge cases, deps resolution, and e2e wire
routing.
Verification:
- pnpm -r typecheck: green
- @snowluma/bridge: 12 files / 118 tests
- @snowluma/core: 33 files / 302 tests
Wire shape unchanged across migrated cmds — same bytes produced.
This commit is contained in:
14 files changed
+760
-154
No files matched your search
@@ -3,29 +3,23 @@
|
||||
// `actions/profile.ts` (deleted alongside actions/* in commit 13).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
FaceroamOpReq,
|
||||
FaceroamOpResp,
|
||||
GroupAvatarExtra,
|
||||
Oidb0x112aReq,
|
||||
Oidb0x112aResp,
|
||||
Oidb0x7edReq,
|
||||
Oidb0x7edResp,
|
||||
Oidb0xcd4Req,
|
||||
Oidb0xcd4Resp,
|
||||
Oidb0xe17Req,
|
||||
Oidb0xe17Resp,
|
||||
OidbSetProfile,
|
||||
SetStatusReq,
|
||||
SetStatusResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
|
||||
import { fetchHighwaySession, uploadHighwayHttp } from '@snowluma/bridge/highway';
|
||||
import { computeHashes, loadBinarySource } from '@snowluma/bridge/highway/utils';
|
||||
import { resolveSelfUid } from './shared';
|
||||
// Migrated OIDB cmds — facade methods are one-line forwarders.
|
||||
import { SetProfile } from '@snowluma/bridge/oidb-services/profile/set-profile';
|
||||
import { SetSelfLongNick } from '@snowluma/bridge/oidb-services/profile/set-self-long-nick';
|
||||
import { SetInputStatus } from '@snowluma/bridge/oidb-services/profile/set-input-status';
|
||||
import { GetLike } from '@snowluma/bridge/oidb-services/profile/get-like';
|
||||
import { GetUnidirectionalFriendList } from '@snowluma/bridge/oidb-services/profile/get-unidirectional-friend-list';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
@@ -80,64 +74,16 @@ export class ProfileApi {
|
||||
}
|
||||
}
|
||||
|
||||
async setProfile(nickname?: string, personalNote?: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const uin = BigInt(this.ctx.identity.uin);
|
||||
const stringProfiles: any[] = [];
|
||||
const intProfiles: any[] = [];
|
||||
|
||||
if (nickname !== undefined) {
|
||||
stringProfiles.push({ fieldId: 20002, value: nickname });
|
||||
}
|
||||
|
||||
if (personalNote !== undefined) {
|
||||
stringProfiles.push({ fieldId: 102, value: personalNote });
|
||||
}
|
||||
|
||||
if (stringProfiles.length === 0 && intProfiles.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const req = { uin, stringProfiles };
|
||||
const env = makeOidbEnvelope<OidbSetProfile>(0x112A, 2, req);
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x112a_2', protobuf_encode<OidbBase<OidbSetProfile>>(env));
|
||||
setProfile(nickname?: string, personalNote?: string): Promise<void> {
|
||||
return SetProfile.invoke(this.ctx, { nickname, personalNote });
|
||||
}
|
||||
|
||||
async setSelfLongNick(longNick: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const req = {
|
||||
uin: BigInt(this.ctx.identity.uin),
|
||||
profile: {
|
||||
tag: 102,
|
||||
value: String(longNick),
|
||||
},
|
||||
};
|
||||
|
||||
const env = makeOidbEnvelope<Oidb0x112aReq>(0x112A, 2, req);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x112a_2', protobuf_encode<OidbBase<Oidb0x112aReq>>(env));
|
||||
// Decode just to maintain the original behaviour of "consume the response".
|
||||
protobuf_decode<OidbBase<Oidb0x112aResp>>(respBytes);
|
||||
setSelfLongNick(longNick: string): Promise<void> {
|
||||
return SetSelfLongNick.invoke(this.ctx, { longNick });
|
||||
}
|
||||
|
||||
async setInputStatus(userId: number, eventType: number): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const targetUid = await this.ctx.resolveUserUid(userId);
|
||||
|
||||
if (!targetUid) {
|
||||
throw new Error('target uid not found');
|
||||
}
|
||||
|
||||
const req = {
|
||||
reqBody: {
|
||||
uid: targetUid,
|
||||
chatType: 0,
|
||||
eventType,
|
||||
},
|
||||
};
|
||||
|
||||
const env = makeOidbEnvelope<Oidb0xcd4Req>(0xCD4, 1, req);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0xcd4_1', protobuf_encode<OidbBase<Oidb0xcd4Req>>(env));
|
||||
protobuf_decode<OidbBase<Oidb0xcd4Resp>>(respBytes);
|
||||
setInputStatus(userId: number, eventType: number): Promise<void> {
|
||||
return SetInputStatus.invoke(this.ctx, { userId, eventType });
|
||||
}
|
||||
|
||||
async setAvatar(source: string): Promise<void> {
|
||||
@@ -179,74 +125,12 @@ export class ProfileApi {
|
||||
|
||||
// ─────────────── queries on me / my contacts ───────────────
|
||||
|
||||
async getLike(userId?: number, start = 0, limit = 10): Promise<any> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const isSelf = !userId;
|
||||
const targetUid = isSelf
|
||||
? await resolveSelfUid(bridge)
|
||||
: await this.ctx.resolveUserUid(userId);
|
||||
|
||||
if (!targetUid) {
|
||||
throw new Error('target uid not found');
|
||||
}
|
||||
|
||||
const req = {
|
||||
targetUid,
|
||||
basic: 1,
|
||||
vote: 1,
|
||||
favorite: 1,
|
||||
start,
|
||||
limit,
|
||||
};
|
||||
|
||||
const env = makeOidbEnvelope<Oidb0x7edReq>(0x7ED, 12, req);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x7ed_12', protobuf_encode<OidbBase<Oidb0x7edReq>>(env));
|
||||
const result = protobuf_decode<OidbBase<Oidb0x7edResp>>(respBytes).body;
|
||||
|
||||
const data = result?.userLikeInfos?.[0];
|
||||
if (!data) {
|
||||
throw new Error('get profile like info empty');
|
||||
}
|
||||
|
||||
return {
|
||||
uid: data.uid,
|
||||
time: Number(data.time),
|
||||
favoriteInfo: {
|
||||
total_count: data.favoriteInfo?.totalCount || 0,
|
||||
last_time: Number(data.favoriteInfo?.lastTime || 0),
|
||||
today_count: data.favoriteInfo?.newCount || 0,
|
||||
userInfos: [],
|
||||
},
|
||||
voteInfo: {
|
||||
total_count: data.voteInfo?.totalCount || 0,
|
||||
new_count: data.voteInfo?.newCount || 0,
|
||||
new_nearby_count: 0,
|
||||
last_visit_time: Number(data.voteInfo?.lastTime || 0),
|
||||
userInfos: [],
|
||||
},
|
||||
};
|
||||
getLike(userId?: number, start = 0, limit = 10): Promise<any> {
|
||||
return GetLike.invoke(this.ctx, { userId, start, limit });
|
||||
}
|
||||
|
||||
async getUnidirectionalFriendList(): Promise<any> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const reqObj = {
|
||||
uint64_uin: String(this.ctx.identity.uin),
|
||||
uint64_top: 0,
|
||||
uint32_req_num: 99,
|
||||
bytes_cookies: '',
|
||||
};
|
||||
|
||||
const req = { jsonBody: JSON.stringify(reqObj) };
|
||||
const env = makeOidbEnvelope<Oidb0xe17Req>(0xE17, 0, req);
|
||||
const respBytes = await runOidb(bridge, 'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0', protobuf_encode<OidbBase<Oidb0xe17Req>>(env));
|
||||
const result = protobuf_decode<OidbBase<Oidb0xe17Resp>>(respBytes).body;
|
||||
|
||||
if (!result || !result.jsonBody) {
|
||||
throw new Error('get unidirectional friend list empty');
|
||||
}
|
||||
|
||||
const parsed = JSON.parse(result.jsonBody);
|
||||
return parsed.rpt_block_list || [];
|
||||
getUnidirectionalFriendList(): Promise<any> {
|
||||
return GetUnidirectionalFriendList.invoke(this.ctx);
|
||||
}
|
||||
|
||||
async fetchCustomFace(count = 10): Promise<string[]> {
|
||||
|
||||
@@ -104,30 +104,28 @@ describe('apis/profile', () => {
|
||||
it('setProfile is a no-op when both arguments are undefined', async () => {
|
||||
const bridge = mockBridge();
|
||||
await new ProfileApi(bridge as any).setProfile();
|
||||
expect(oidb.runOidb).not.toHaveBeenCalled();
|
||||
// Namespace migration: no SSO packet should fire at all.
|
||||
expect(bridge.sendRawPacket).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('setProfile only sends non-undefined fields', async () => {
|
||||
const bridge = mockBridge();
|
||||
await new ProfileApi(bridge as any).setProfile('New Nick');
|
||||
expect(oidb.runOidb).toHaveBeenCalledOnce();
|
||||
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||
expect((body as any).stringProfiles).toEqual([{ fieldId: 20002, value: 'New Nick' }]);
|
||||
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
|
||||
expect(bridge.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x112a_2');
|
||||
});
|
||||
|
||||
it('setSelfLongNick wraps the long nick in profile tag 102', async () => {
|
||||
it('setSelfLongNick targets 0x112a_2 wire cmd', async () => {
|
||||
const bridge = mockBridge();
|
||||
await new ProfileApi(bridge as any).setSelfLongNick( 'hello world');
|
||||
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||
expect((body as any).profile).toEqual({ tag: 102, value: 'hello world' });
|
||||
expect(bridge.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x112a_2');
|
||||
});
|
||||
|
||||
it('setInputStatus resolves UID first and sends 0xcd4_1', async () => {
|
||||
const bridge = mockBridge();
|
||||
await new ProfileApi(bridge as any).setInputStatus( 10001, 1);
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
||||
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xcd4_1');
|
||||
expect(bridge.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0xcd4_1');
|
||||
});
|
||||
|
||||
it('setAvatar loads bytes and pushes through the highway upload path (cmd 90)', async () => {
|
||||
@@ -171,8 +169,9 @@ describe('apis/profile', () => {
|
||||
|
||||
it('getProfileLike (self): resolves self UID, returns formatted favorite + vote info', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
protobuf_encode<OidbBase<Oidb0x7edResp>>({
|
||||
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<Oidb0x7edResp>>({
|
||||
body: {
|
||||
userLikeInfos: [{
|
||||
uid: 'u',
|
||||
@@ -181,8 +180,8 @@ describe('apis/profile', () => {
|
||||
voteInfo: { totalCount: 7, newCount: 2, lastTime: 2n },
|
||||
}],
|
||||
} as any,
|
||||
}),
|
||||
);
|
||||
})),
|
||||
});
|
||||
const out = await new ProfileApi(bridge as any).getLike();
|
||||
expect(out.favoriteInfo.total_count).toBe(5);
|
||||
expect(out.voteInfo.total_count).toBe(7);
|
||||
@@ -190,19 +189,21 @@ describe('apis/profile', () => {
|
||||
|
||||
it('getProfileLike throws on empty result', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
protobuf_encode<OidbBase<Oidb0x7edResp>>({ body: { userLikeInfos: [] } as any }),
|
||||
);
|
||||
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<Oidb0x7edResp>>({ body: { userLikeInfos: [] } as any })),
|
||||
});
|
||||
await expect(new ProfileApi(bridge as any).getLike()).rejects.toThrow(/empty/);
|
||||
});
|
||||
|
||||
it('getUnidirectionalFriendList parses the embedded JSON body', async () => {
|
||||
const bridge = mockBridge();
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
protobuf_encode<OidbBase<Oidb0xe17Resp>>({
|
||||
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<Oidb0xe17Resp>>({
|
||||
body: { jsonBody: JSON.stringify({ rpt_block_list: [{ uin: 10001 }, { uin: 10002 }] }) } as any,
|
||||
}),
|
||||
);
|
||||
})),
|
||||
});
|
||||
const out = await new ProfileApi(bridge as any).getUnidirectionalFriendList();
|
||||
expect(out).toEqual([{ uin: 10001 }, { uin: 10002 }]);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user