refactor(oidb): replace 3 positional helpers with one named runOidb
bridge-oidb.ts used to expose three thin functions —
makeOidbRequest / sendOidbAndCheck / sendOidbAndDecode — and every
action file repeated the same five-step envelope assembly with long
positional argument lists. Collapse them into one `runOidb(bridge,
call)` taking an OidbCall object: cmd / oidbCmd / subCmd / request
{ schema, value, isUid? } / response? { schema }.
Behavioural contract is preserved:
- No `response`: verify success + gotResponse, peek envelope retCode
iff response data is present (fire-and-check semantics).
- With `response`: require responseData, decode through the base
schema, validate retCode, return the inner body typed as TResp.
Migration touches 51 call sites across 9 source files (bridge-contacts,
actions/{group-file, group-admin, profile, group-message, friend,
interaction, misc}, web-actions/cookies) plus 9 test files that used
to assert on positional `.mock.calls[0]![4]` indices and now read
through `.mock.calls[0]![1].request.value` / `.cmd` / `.oidbCmd`.
Net effect: callers now name what each piece is for, and adding
cross-cutting OIDB behaviour (retry / timeout / per-cmd logging) is a
single-site change inside runOidb instead of a sweep across 9 files.
This commit is contained in:
19 files changed
+637
-549
No files matched your search
@@ -3,7 +3,7 @@
|
||||
// protocol uses opaque UIDs rather than QQ uin numbers.
|
||||
|
||||
import type { Bridge } from '../bridge';
|
||||
import { sendOidbAndCheck } from '../bridge-oidb';
|
||||
import { runOidb } from '../bridge-oidb';
|
||||
import {
|
||||
OidbDeleteFriendSchema,
|
||||
OidbFriendRequestActionSchema,
|
||||
@@ -15,30 +15,38 @@ export async function setFriendAddRequest(bridge: Bridge, uidOrFlag: string, app
|
||||
if (/^\d+$/.test(uidOrFlag)) {
|
||||
targetUid = await bridge.resolveUserUid(parseInt(uidOrFlag, 10));
|
||||
}
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0xb5d_44', 0xB5D, 44,
|
||||
{ accept: approve ? 3 : 5, targetUid }, OidbFriendRequestActionSchema);
|
||||
await runOidb(bridge, {
|
||||
cmd: 'OidbSvcTrpcTcp.0xb5d_44',
|
||||
oidbCmd: 0xB5D, subCmd: 44,
|
||||
request: { schema: OidbFriendRequestActionSchema, value: { accept: approve ? 3 : 5, targetUid } },
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteFriend(bridge: Bridge, userId: number, block = false): Promise<void> {
|
||||
const targetUid = await bridge.resolveUserUid(userId);
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0x126b_0', 0x126B, 0,
|
||||
{
|
||||
field1: {
|
||||
targetUid,
|
||||
field2: {
|
||||
field1: 130,
|
||||
field2: 109,
|
||||
field3: {
|
||||
field1: 8,
|
||||
field2: 8,
|
||||
field3: 50,
|
||||
await runOidb(bridge, {
|
||||
cmd: 'OidbSvcTrpcTcp.0x126b_0',
|
||||
oidbCmd: 0x126B, subCmd: 0,
|
||||
request: {
|
||||
schema: OidbDeleteFriendSchema,
|
||||
value: {
|
||||
field1: {
|
||||
targetUid,
|
||||
field2: {
|
||||
field1: 130,
|
||||
field2: 109,
|
||||
field3: {
|
||||
field1: 8,
|
||||
field2: 8,
|
||||
field3: 50,
|
||||
},
|
||||
},
|
||||
block,
|
||||
field4: false,
|
||||
},
|
||||
block,
|
||||
field4: false,
|
||||
},
|
||||
},
|
||||
OidbDeleteFriendSchema);
|
||||
});
|
||||
|
||||
// Refresh friend cache after deletion so subsequent reads don't
|
||||
// surface a ghost entry. Best-effort: a transient OIDB hiccup here
|
||||
@@ -48,6 +56,9 @@ export async function deleteFriend(bridge: Bridge, userId: number, block = false
|
||||
|
||||
export async function setFriendRemark(bridge: Bridge, userId: number, remark: string): Promise<void> {
|
||||
const uid = await bridge.resolveUserUid(userId);
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0xb6e_2', 0xB6E, 2,
|
||||
{ targetUid: uid, remark }, OidbSetFriendRemarkSchema);
|
||||
await runOidb(bridge, {
|
||||
cmd: 'OidbSvcTrpcTcp.0xb6e_2',
|
||||
oidbCmd: 0xB6E, subCmd: 2,
|
||||
request: { schema: OidbSetFriendRemarkSchema, value: { targetUid: uid, remark } },
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user