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
@@ -47,6 +47,12 @@ export interface OidbCallSpec<TReq, TResp, TParams, TResult> {
|
||||
resolveSubCommand?(params: TParams): number;
|
||||
/** Set OIDB envelope `reserved = 1` (UIN-form variant, see makeOidbEnvelope's isUid). */
|
||||
uinForm?: boolean;
|
||||
/** Override the default `OidbSvcTrpcTcp.0xNNNN_N` wire name. A few
|
||||
* cmds route through different SSO names (e.g. 0xE17_0 lives at
|
||||
* `MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0`); supply a function
|
||||
* that takes the resolved `(cmd, subCmd)` and returns the actual
|
||||
* wire name. Omit for the default scheme. */
|
||||
wireName?(command: number, subCommand: number): string;
|
||||
/** Business params → wire-shaped request body. */
|
||||
serialize(params: TParams): TReq;
|
||||
/** Wire-shaped response body → business result. */
|
||||
@@ -88,7 +94,9 @@ export async function invokeOidb<TReq, TResp, TParams, TResult>(
|
||||
const reqBody = spec.serialize(params);
|
||||
const env = makeOidbEnvelope(spec.command, subCommand, reqBody, spec.uinForm ?? false);
|
||||
const reqBytes = spec.encode(env);
|
||||
const wireName = `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
|
||||
const wireName = spec.wireName
|
||||
? spec.wireName(spec.command, subCommand)
|
||||
: `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
|
||||
|
||||
const result = await sender.sendRawPacket(wireName, reqBytes, timeoutMs);
|
||||
if (!result.success) throw new Error(result.errorMessage || 'packet send failed');
|
||||
@@ -127,7 +135,9 @@ export function buildOidbRequest<TReq, TResp, TParams, TResult>(
|
||||
const reqBody = spec.serialize(params);
|
||||
const env = makeOidbEnvelope(spec.command, subCommand, reqBody, spec.uinForm ?? false);
|
||||
const bytes = spec.encode(env);
|
||||
const wireName = `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
|
||||
const wireName = spec.wireName
|
||||
? spec.wireName(spec.command, subCommand)
|
||||
: `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
|
||||
return { wireName, bytes };
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// 0x7ED_12 — fetch QQ "thumbs up" (赞) summary for self or another user.
|
||||
//
|
||||
// Self lookup needs the bot's own UID, hence the `identity` dependency.
|
||||
// For other users we use `resolveUserUid` to translate the uin first.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x7edReq, Oidb0x7edResp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
|
||||
export interface LikeInfo {
|
||||
uid: string;
|
||||
time: number;
|
||||
favoriteInfo: {
|
||||
total_count: number;
|
||||
last_time: number;
|
||||
today_count: number;
|
||||
userInfos: never[];
|
||||
};
|
||||
voteInfo: {
|
||||
total_count: number;
|
||||
new_count: number;
|
||||
new_nearby_count: number;
|
||||
last_visit_time: number;
|
||||
userInfos: never[];
|
||||
};
|
||||
}
|
||||
|
||||
export namespace GetLike {
|
||||
export const command = 0x7ED;
|
||||
export const subCommand = 12;
|
||||
|
||||
export interface Params {
|
||||
/** Omit / 0 → query self. */
|
||||
userId?: number;
|
||||
start?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity' | 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): Oidb0x7edReq => ({
|
||||
targetUid,
|
||||
basic: 1,
|
||||
vote: 1,
|
||||
favorite: 1,
|
||||
start: p.start ?? 0,
|
||||
limit: p.limit ?? 10,
|
||||
});
|
||||
|
||||
export const deserialize = (body: Oidb0x7edResp): LikeInfo => {
|
||||
const data = body.userLikeInfos?.[0];
|
||||
if (!data) throw new Error('get profile like info empty');
|
||||
return {
|
||||
uid: data.uid ?? '',
|
||||
time: Number(data.time ?? 0),
|
||||
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: [],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0x7edReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0x7edReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x7edResp> =>
|
||||
protobuf_decode<OidbBase<Oidb0x7edResp>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<LikeInfo> => {
|
||||
const isSelf = !params.userId;
|
||||
const targetUid = isSelf
|
||||
? await resolveSelf(deps)
|
||||
: await deps.resolveUserUid(params.userId!);
|
||||
if (!targetUid) throw new Error('target uid not found');
|
||||
return invokeOidb(deps, {
|
||||
...GetLike,
|
||||
serialize: p => serialize(p, targetUid),
|
||||
}, params);
|
||||
};
|
||||
}
|
||||
|
||||
async function resolveSelf(deps: Pick<BridgeContext, 'identity' | 'resolveUserUid'>): Promise<string> {
|
||||
// Mirrors `apis/shared.ts::resolveSelfUid` — kept inline here so the
|
||||
// namespace is self-contained against just the BridgeContext slice.
|
||||
const cached = deps.identity.selfUid;
|
||||
if (cached) return cached;
|
||||
const selfUin = Number(deps.identity.uin);
|
||||
if (!Number.isFinite(selfUin) || selfUin <= 0) {
|
||||
throw new Error('self uid is unavailable');
|
||||
}
|
||||
return deps.resolveUserUid(selfUin);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 0xE17_0 — fetch the unidirectional friend block list. Wire name is
|
||||
// non-standard (`MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0`) — uses
|
||||
// the `wireName` override to bypass the default
|
||||
// `OidbSvcTrpcTcp.0xNNNN_N` scheme.
|
||||
//
|
||||
// Request and response carry a JSON-encoded string in a single
|
||||
// protobuf field, so the namespace's `serialize` / `deserialize` do
|
||||
// the JSON marshalling.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0xe17Req, Oidb0xe17Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
|
||||
export namespace GetUnidirectionalFriendList {
|
||||
export const command = 0xE17;
|
||||
export const subCommand = 0;
|
||||
|
||||
/** Wire name override — this cmd lives outside the standard
|
||||
* `OidbSvcTrpcTcp.0xNNNN_N` namespace. */
|
||||
export const wireName = (): string => 'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||
export interface Params {}
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
|
||||
|
||||
export const serialize = (_: Params, uin: string): Oidb0xe17Req => {
|
||||
const reqObj = {
|
||||
uint64_uin: uin,
|
||||
uint64_top: 0,
|
||||
uint32_req_num: 99,
|
||||
bytes_cookies: '',
|
||||
};
|
||||
return { jsonBody: JSON.stringify(reqObj) };
|
||||
};
|
||||
|
||||
export const deserialize = (body: Oidb0xe17Resp): unknown[] => {
|
||||
if (!body || !body.jsonBody) throw new Error('get unidirectional friend list empty');
|
||||
const parsed = JSON.parse(body.jsonBody);
|
||||
return parsed.rpt_block_list || [];
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0xe17Req>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0xe17Req>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xe17Resp> =>
|
||||
protobuf_decode<OidbBase<Oidb0xe17Resp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps): Promise<unknown[]> => {
|
||||
const uin = String(deps.identity.uin);
|
||||
return invokeOidb(deps, {
|
||||
...GetUnidirectionalFriendList,
|
||||
serialize: p => serialize(p, uin),
|
||||
}, {});
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// 0xCD4_1 — set typing / recording / etc. "input status" indicator
|
||||
// shown to a peer in a 1:1 chat.
|
||||
//
|
||||
// Resolves the target uin → uid via the identity service before
|
||||
// building the body. `chatType: 0` is the wire constant for friend
|
||||
// chats (the only flavor SnowLuma currently supports here).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0xcd4Req, Oidb0xcd4Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
|
||||
export namespace SetInputStatus {
|
||||
export const command = 0xCD4;
|
||||
export const subCommand = 1;
|
||||
|
||||
export interface Params {
|
||||
userId: number;
|
||||
eventType: number;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): Oidb0xcd4Req => ({
|
||||
reqBody: {
|
||||
uid: targetUid,
|
||||
chatType: 0,
|
||||
eventType: p.eventType,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: Oidb0xcd4Resp): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0xcd4Req>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0xcd4Req>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xcd4Resp> =>
|
||||
protobuf_decode<OidbBase<Oidb0xcd4Resp>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const targetUid = await deps.resolveUserUid(params.userId);
|
||||
if (!targetUid) throw new Error('target uid not found');
|
||||
await invokeOidb(deps, {
|
||||
...SetInputStatus,
|
||||
serialize: p => serialize(p, targetUid),
|
||||
}, params);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// 0x112A_2 — write profile string/int field-value pairs.
|
||||
//
|
||||
// SnowLuma's facade currently exposes only nickname (field 20002) and
|
||||
// personalNote (field 102) but the underlying wire supports arbitrary
|
||||
// (fieldId, value) tuples. The serialize step skips the call entirely
|
||||
// when both inputs are undefined so the facade keeps its no-op-on-
|
||||
// noop-input behavior — `invokeOidb` is bypassed at the call-site.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x112aResp, OidbSetProfile } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
|
||||
export namespace SetProfile {
|
||||
export const command = 0x112A;
|
||||
export const subCommand = 2;
|
||||
|
||||
export interface Params {
|
||||
nickname?: string;
|
||||
personalNote?: string;
|
||||
}
|
||||
|
||||
/** Needs identity to read `uin` for the request body. */
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
|
||||
|
||||
export const serialize = (p: Params, uin: bigint): OidbSetProfile => {
|
||||
const stringProfiles: { fieldId: number; value: string }[] = [];
|
||||
if (p.nickname !== undefined) stringProfiles.push({ fieldId: 20002, value: p.nickname });
|
||||
if (p.personalNote !== undefined) stringProfiles.push({ fieldId: 102, value: p.personalNote });
|
||||
return { uin, stringProfiles };
|
||||
};
|
||||
|
||||
export const deserialize = (_: Oidb0x112aResp): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbSetProfile>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbSetProfile>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x112aResp> =>
|
||||
protobuf_decode<OidbBase<Oidb0x112aResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> => {
|
||||
// No-op when there's nothing to write — preserves the facade's
|
||||
// historic short-circuit (avoid a wasted SSO round-trip).
|
||||
if (params.nickname === undefined && params.personalNote === undefined) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const uin = BigInt(deps.identity.uin);
|
||||
return invokeOidb(deps, {
|
||||
...SetProfile,
|
||||
// Bind uin into serialize so the OidbCallSpec contract (single-arg
|
||||
// serialize) still holds — we can't pass uin through `params`
|
||||
// without leaking identity to the facade signature.
|
||||
serialize: p => serialize(p, uin),
|
||||
}, params);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// 0x112A_2 — set the self "long nick" / personal signature. Same cmd
|
||||
// as SetProfile but a different request shape (uses the single
|
||||
// `profile: { tag, value }` field instead of the repeated string
|
||||
// profiles list). Kept separate because the wire body is structurally
|
||||
// different — proton needs distinct types so the codec is correctly
|
||||
// monomorphized per call site.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x112aReq, Oidb0x112aResp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
|
||||
export namespace SetSelfLongNick {
|
||||
export const command = 0x112A;
|
||||
export const subCommand = 2;
|
||||
|
||||
export interface Params {
|
||||
longNick: string;
|
||||
}
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
|
||||
|
||||
export const serialize = (p: Params, uin: bigint): Oidb0x112aReq => ({
|
||||
uin,
|
||||
profile: { tag: 102, value: String(p.longNick) },
|
||||
});
|
||||
|
||||
export const deserialize = (_: Oidb0x112aResp): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0x112aReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0x112aReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x112aResp> =>
|
||||
protobuf_decode<OidbBase<Oidb0x112aResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> => {
|
||||
const uin = BigInt(deps.identity.uin);
|
||||
return invokeOidb(deps, {
|
||||
...SetSelfLongNick,
|
||||
serialize: p => serialize(p, uin),
|
||||
}, params);
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user