refactor(oidb): thread ctx into serialize/deserialize for self-contained namespaces
The first pass at namespace-per-cmd left a smell: namespaces that
needed identity/uid resolution had to declare `Deps` AND then rewrite
their own spec inside `invoke` via a closure-over-resolved-value:
// before
export const serialize = (p: Params, targetUid: string) => ({...});
export const invoke = async (deps, params) => {
const targetUid = await deps.resolveUserUid(params.userId);
return invokeOidb(deps, {
...Self,
serialize: p => serialize(p, targetUid), // ← escape hatch
}, params);
};
Reading "what does this cmd do on the wire?" required reading the
namespace AND the closure rewrite — the namespace wasn't really
self-contained, just a forwarder of two pure functions.
Fix: thread `ctx` (the namespace's full capability surface) into
`serialize` and `deserialize` directly. `serialize` may now return
`Promise<TReq>` so identity / uid lookups happen in place:
// after
export const serialize = async (ctx: Deps, p: Params) => ({
groupUin: p.groupId, type: 1,
body: {
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
duration: p.duration,
},
});
export const invoke = (deps, params) => invokeOidb(deps, Self, params);
OidbCallSpec gains a `TCtx extends OidbSender` generic; invokeOidb's
first arg becomes `ctx: TCtx` (the sender capability is just a slice
of ctx now). buildOidbRequest / parseOidbResponse follow the same
shape. Async serialize is awaited inside invokeOidb.
17 namespaces had closure rewrites; all 17 collapse to plain
`invokeOidb(deps, Self, params)` invokes. Only one closure remains —
`fetch-user-profile` binds `params.uin` into deserialize as a server-
echo fallback; kept as a documented exception (the rare case where
deserialize wants request context, not ctx).
Wire bytes preserved across all migrations. 326 bridge tests + 302
core tests pass; lint clean.
This commit is contained in:
80 files changed
+416
-397
No files matched your search
@@ -17,6 +17,16 @@
|
||||
// - tests mock only what's used (typically just `sendRawPacket`)
|
||||
// - changes to BridgeContext don't bleed into services
|
||||
// - the dep list IS the documentation of side-effects
|
||||
//
|
||||
// Why `ctx` threads into serialize/deserialize:
|
||||
// - the namespace is then genuinely self-contained — "what does this
|
||||
// cmd do on the wire + what state does it touch" lives in one file
|
||||
// - earlier shape forced an `invoke = { ...Self, serialize: p =>
|
||||
// localSerialize(p, await ctx.resolveUserUid(...)) }` rewrite for
|
||||
// every cmd that needed identity/uid resolution; ctx-aware
|
||||
// serialize collapses that to a single async serialize.
|
||||
// - serialize is now `TReq | Promise<TReq>` so async lookups
|
||||
// (resolveUserUid, identity reads) happen in place.
|
||||
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbBaseMeta } from '@snowluma/proto-defs/oidb';
|
||||
@@ -38,10 +48,14 @@ export interface OidbSender {
|
||||
* namespace whose top-level exports match these names + types IS an
|
||||
* `OidbCallSpec` — no `implements` clause needed.
|
||||
*
|
||||
* `TCtx` is the namespace's capability surface — always at least
|
||||
* `OidbSender` (so `invokeOidb` can dispatch through it) plus any
|
||||
* `Pick<BridgeContext, ...>` slices the cmd actually needs.
|
||||
*
|
||||
* One of `subCommand` (static) or `resolveSubCommand` (dynamic from
|
||||
* params) must be present. `resolveSubCommand` wins if both are given.
|
||||
*/
|
||||
export interface OidbCallSpec<TReq, TResp, TParams, TResult> {
|
||||
export interface OidbCallSpec<TCtx extends OidbSender, TReq, TResp, TParams, TResult> {
|
||||
command: number;
|
||||
subCommand?: number;
|
||||
resolveSubCommand?(params: TParams): number;
|
||||
@@ -53,10 +67,11 @@ export interface OidbCallSpec<TReq, TResp, TParams, TResult> {
|
||||
* 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;
|
||||
/** Business params → wire-shaped request body. May be async (e.g.
|
||||
* when ctx.resolveUserUid hits the cache or the network). */
|
||||
serialize(ctx: TCtx, params: TParams): TReq | Promise<TReq>;
|
||||
/** Wire-shaped response body → business result. */
|
||||
deserialize(body: TResp): TResult;
|
||||
deserialize(ctx: TCtx, body: TResp): TResult;
|
||||
/** Per-type protobuf encoder — concrete generic call so the Vite plugin can monomorphize. */
|
||||
encode(env: OidbBase<TReq>): Uint8Array;
|
||||
/** Per-type protobuf decoder. */
|
||||
@@ -77,28 +92,31 @@ export class OidbError extends Error {
|
||||
|
||||
/**
|
||||
* Template method for every OIDB call. Builds the envelope, encodes it,
|
||||
* sends through the supplied minimal sender capability, validates the
|
||||
* envelope's `errorCode`, decodes the body, and hands the wire-shaped
|
||||
* response to the spec's `deserialize` for transformation into the
|
||||
* business result.
|
||||
* sends through the ctx's `sendRawPacket`, validates the envelope's
|
||||
* `errorCode`, decodes the body, and hands the wire-shaped response to
|
||||
* the spec's `deserialize` for transformation into the business result.
|
||||
*
|
||||
* `ctx` is threaded into both `serialize` and `deserialize` so the
|
||||
* namespace can do uid resolution / identity reads in-place rather
|
||||
* than forcing the caller to pre-bake values into the params.
|
||||
*/
|
||||
export async function invokeOidb<TReq, TResp, TParams, TResult>(
|
||||
sender: OidbSender,
|
||||
spec: OidbCallSpec<TReq, TResp, TParams, TResult>,
|
||||
export async function invokeOidb<TCtx extends OidbSender, TReq, TResp, TParams, TResult>(
|
||||
ctx: TCtx,
|
||||
spec: OidbCallSpec<TCtx, TReq, TResp, TParams, TResult>,
|
||||
params: TParams,
|
||||
timeoutMs?: number,
|
||||
): Promise<TResult> {
|
||||
const subCommand = spec.resolveSubCommand
|
||||
? spec.resolveSubCommand(params)
|
||||
: spec.subCommand!;
|
||||
const reqBody = spec.serialize(params);
|
||||
const reqBody = await spec.serialize(ctx, params);
|
||||
const env = makeOidbEnvelope(spec.command, subCommand, reqBody, spec.uinForm ?? false);
|
||||
const reqBytes = spec.encode(env);
|
||||
const wireName = spec.wireName
|
||||
? spec.wireName(spec.command, subCommand)
|
||||
: `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
|
||||
|
||||
const result = await sender.sendRawPacket(wireName, reqBytes, timeoutMs);
|
||||
const result = await ctx.sendRawPacket(wireName, reqBytes, timeoutMs);
|
||||
if (!result.success) throw new Error(result.errorMessage || 'packet send failed');
|
||||
if (!result.gotResponse) throw new Error(result.errorMessage || 'no response');
|
||||
|
||||
@@ -117,22 +135,24 @@ export async function invokeOidb<TReq, TResp, TParams, TResult>(
|
||||
// always receives a defined object; specs that read fields off the
|
||||
// body must already guard with `?? []` etc.
|
||||
const respBody = spec.decode(respBytes).body ?? ({} as TResp);
|
||||
return spec.deserialize(respBody);
|
||||
return spec.deserialize(ctx, respBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the request wire bytes for a spec without sending — useful for
|
||||
* wire dump debugging, capability probing, and unit tests of the
|
||||
* encode path.
|
||||
* encode path. Threads `ctx` because `serialize` may want it (and
|
||||
* because matching `invokeOidb`'s shape avoids two call patterns).
|
||||
*/
|
||||
export function buildOidbRequest<TReq, TResp, TParams, TResult>(
|
||||
spec: OidbCallSpec<TReq, TResp, TParams, TResult>,
|
||||
export async function buildOidbRequest<TCtx extends OidbSender, TReq, TResp, TParams, TResult>(
|
||||
ctx: TCtx,
|
||||
spec: OidbCallSpec<TCtx, TReq, TResp, TParams, TResult>,
|
||||
params: TParams,
|
||||
): { wireName: string; bytes: Uint8Array } {
|
||||
): Promise<{ wireName: string; bytes: Uint8Array }> {
|
||||
const subCommand = spec.resolveSubCommand
|
||||
? spec.resolveSubCommand(params)
|
||||
: spec.subCommand!;
|
||||
const reqBody = spec.serialize(params);
|
||||
const reqBody = await spec.serialize(ctx, params);
|
||||
const env = makeOidbEnvelope(spec.command, subCommand, reqBody, spec.uinForm ?? false);
|
||||
const bytes = spec.encode(env);
|
||||
const wireName = spec.wireName
|
||||
@@ -145,9 +165,10 @@ export function buildOidbRequest<TReq, TResp, TParams, TResult>(
|
||||
* Decode raw wire bytes into the business result via a spec's
|
||||
* deserialize path — symmetric debug helper for buildOidbRequest.
|
||||
*/
|
||||
export function parseOidbResponse<TReq, TResp, TParams, TResult>(
|
||||
spec: OidbCallSpec<TReq, TResp, TParams, TResult>,
|
||||
export function parseOidbResponse<TCtx extends OidbSender, TReq, TResp, TParams, TResult>(
|
||||
ctx: TCtx,
|
||||
spec: OidbCallSpec<TCtx, TReq, TResp, TParams, TResult>,
|
||||
bytes: Uint8Array,
|
||||
): TResult {
|
||||
return spec.deserialize(spec.decode(bytes).body ?? ({} as TResp));
|
||||
return spec.deserialize(ctx, spec.decode(bytes).body ?? ({} as TResp));
|
||||
}
|
||||
@@ -21,7 +21,7 @@ export namespace FetchDownloadRkeys {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_: Params): NTV2RichMediaReq => ({
|
||||
export const serialize = (_ctx: Deps, _: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 202 },
|
||||
scene: { requestType: 2, businessType: 1, sceneType: 0 },
|
||||
@@ -32,7 +32,7 @@ export namespace FetchDownloadRkeys {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: NTV2RichMediaResp): NTV2RichMediaResp => {
|
||||
export const deserialize = (_ctx: Deps, body: NTV2RichMediaResp): NTV2RichMediaResp => {
|
||||
// Propagate server-side OIDB-equivalent error via the embedded
|
||||
// respHead.retCode — bytes-level OIDB errorCode would already
|
||||
// have thrown OidbError before deserialize was called.
|
||||
|
||||
@@ -22,7 +22,7 @@ export namespace FetchFriendListPage {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbFriendListRequest => {
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbFriendListRequest => {
|
||||
const body: any = {
|
||||
friendCount: 300,
|
||||
field4: 0,
|
||||
@@ -41,7 +41,7 @@ export namespace FetchFriendListPage {
|
||||
return body;
|
||||
};
|
||||
|
||||
export const deserialize = (body: OidbSvcTrpcTcp0xFD4_1Response): OidbSvcTrpcTcp0xFD4_1Response => body;
|
||||
export const deserialize = (_ctx: Deps, body: OidbSvcTrpcTcp0xFD4_1Response): OidbSvcTrpcTcp0xFD4_1Response => body;
|
||||
|
||||
export const encode = (env: OidbBase<OidbFriendListRequest>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbFriendListRequest>>(env);
|
||||
|
||||
@@ -24,7 +24,7 @@ export namespace FetchGroupList {
|
||||
|
||||
const allTrue = true;
|
||||
|
||||
export const serialize = (_: Params): OidbGroupListRequest => ({
|
||||
export const serialize = (_ctx: Deps, _: Params): OidbGroupListRequest => ({
|
||||
config: {
|
||||
config1: {
|
||||
groupOwner: allTrue, field2: allTrue, memberMax: allTrue, memberCount: allTrue,
|
||||
@@ -44,7 +44,7 @@ export namespace FetchGroupList {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbSvcTrpcTcp0xFE5_2Response): OidbSvcTrpcTcp0xFE5_2Response => body;
|
||||
export const deserialize = (_ctx: Deps, body: OidbSvcTrpcTcp0xFE5_2Response): OidbSvcTrpcTcp0xFE5_2Response => body;
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupListRequest>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupListRequest>>(env);
|
||||
|
||||
@@ -24,7 +24,7 @@ export namespace FetchGroupMemberListPage {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupMemberListRequest => {
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupMemberListRequest => {
|
||||
const body: any = {
|
||||
groupUin: p.groupId,
|
||||
field2: 5,
|
||||
@@ -41,7 +41,7 @@ export namespace FetchGroupMemberListPage {
|
||||
return body;
|
||||
};
|
||||
|
||||
export const deserialize = (body: OidbSvcTrpcTcp0xFE7_3Response): OidbSvcTrpcTcp0xFE7_3Response => body;
|
||||
export const deserialize = (_ctx: Deps, body: OidbSvcTrpcTcp0xFE7_3Response): OidbSvcTrpcTcp0xFE7_3Response => body;
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupMemberListRequest>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupMemberListRequest>>(env);
|
||||
|
||||
@@ -22,12 +22,12 @@ export namespace FetchGroupRequests {
|
||||
|
||||
export const resolveSubCommand = (p: Params): number => p.filtered ? 2 : 1;
|
||||
|
||||
export const serialize = (_: Params): OidbGroupRequestList => ({
|
||||
export const serialize = (_ctx: Deps, _: Params): OidbGroupRequestList => ({
|
||||
count: 20,
|
||||
field2: 0,
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbSvcTrpcTcp0x10C0Response): OidbSvcTrpcTcp0x10C0Response => body;
|
||||
export const deserialize = (_ctx: Deps, body: OidbSvcTrpcTcp0x10C0Response): OidbSvcTrpcTcp0x10C0Response => body;
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupRequestList>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupRequestList>>(env);
|
||||
|
||||
@@ -43,12 +43,18 @@ export namespace FetchUserProfile {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbUserInfoRequest => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbUserInfoRequest => ({
|
||||
uin: p.uin,
|
||||
keys: REQUESTED_KEYS.map(k => ({ key: k })),
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbUserInfoResponse, requestedUin: number): UserProfileInfo => {
|
||||
/** Defaults the response uin to `requestedUin` because the server
|
||||
* sometimes elides its echo. `invoke` below binds `params.uin` via
|
||||
* the spec override so the namespace's call surface still takes
|
||||
* only `(ctx, body)`. */
|
||||
export const deserializeWithFallback = (
|
||||
body: OidbUserInfoResponse, requestedUin: number,
|
||||
): UserProfileInfo => {
|
||||
if (!body.body) throw new Error('user info response body missing');
|
||||
|
||||
const info: UserProfileInfo = {
|
||||
@@ -89,6 +95,12 @@ export namespace FetchUserProfile {
|
||||
return info;
|
||||
};
|
||||
|
||||
// Default deserialize uses uin=0 fallback — invoke() rewires it to
|
||||
// the requested uin via the per-call spec override below. Tests
|
||||
// that call deserialize directly should use deserializeWithFallback.
|
||||
export const deserialize = (_ctx: Deps, body: OidbUserInfoResponse): UserProfileInfo =>
|
||||
deserializeWithFallback(body, 0);
|
||||
|
||||
export const encode = (env: OidbBase<OidbUserInfoRequest>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbUserInfoRequest>>(env);
|
||||
|
||||
@@ -98,8 +110,6 @@ export namespace FetchUserProfile {
|
||||
export const invoke = (deps: Deps, params: Params): Promise<UserProfileInfo> =>
|
||||
invokeOidb(deps, {
|
||||
...FetchUserProfile,
|
||||
// Bind the original `params.uin` into deserialize so the
|
||||
// namespace can default to it when the server omits its echo.
|
||||
deserialize: body => deserialize(body, params.uin),
|
||||
deserialize: (_ctx, body) => deserializeWithFallback(body, params.uin),
|
||||
}, params);
|
||||
}
|
||||
@@ -31,12 +31,12 @@ export namespace FetchAiVoiceList {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbAiVoiceListReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbAiVoiceListReq => ({
|
||||
groupUin: p.groupId,
|
||||
chatType: p.chatType,
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbAiVoiceListResp): AiVoiceCategory[] =>
|
||||
export const deserialize = (_ctx: Deps, body: OidbAiVoiceListResp): AiVoiceCategory[] =>
|
||||
(body.content as AiVoiceCategory[] | undefined) ?? [];
|
||||
|
||||
export const encode = (env: OidbBase<OidbAiVoiceListReq>): Uint8Array =>
|
||||
|
||||
@@ -44,7 +44,7 @@ export namespace FetchAiVoice {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbAiVoiceReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbAiVoiceReq => ({
|
||||
groupUin: p.groupId,
|
||||
voiceId: p.voiceId,
|
||||
text: p.text,
|
||||
@@ -52,7 +52,7 @@ export namespace FetchAiVoice {
|
||||
session: { sessionId: p.sessionId },
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbAiVoiceResp): AiVoiceMediaIndex | null => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbAiVoiceResp): AiVoiceMediaIndex | null => {
|
||||
const node = body.msgInfo?.msgInfoBody?.[0]?.index as AiVoiceMediaIndex | undefined;
|
||||
return node ?? null;
|
||||
};
|
||||
|
||||
@@ -33,12 +33,12 @@ export namespace GetStrangerStatus {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbStrangerStatusReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbStrangerStatusReq => ({
|
||||
uin: p.uin,
|
||||
key: [{ key: 27372 }],
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbStrangerStatusResp): StrangerStatus | null => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbStrangerStatusResp): StrangerStatus | null => {
|
||||
const raw = body.data?.status?.value;
|
||||
if (raw === undefined || raw === null) return null;
|
||||
const extBig = typeof raw === 'bigint' ? raw : BigInt(raw as any);
|
||||
|
||||
@@ -30,12 +30,12 @@ export namespace GroupTodo {
|
||||
|
||||
export const resolveSubCommand = (p: Params): number => ACTION_TO_SUBCMD[p.action];
|
||||
|
||||
export const serialize = (p: Params): OidbGroupTodo => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupTodo => ({
|
||||
groupUin: p.groupId,
|
||||
msgSeq: p.msgSeq,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupTodo>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupTodo>>(env);
|
||||
|
||||
@@ -27,9 +27,9 @@ export namespace DeleteFriend {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): OidbDeleteFriend => ({
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<OidbDeleteFriend> => ({
|
||||
field1: {
|
||||
targetUid,
|
||||
targetUid: await ctx.resolveUserUid(p.userId),
|
||||
field2: {
|
||||
field1: 130,
|
||||
field2: 109,
|
||||
@@ -40,7 +40,7 @@ export namespace DeleteFriend {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbDeleteFriend>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbDeleteFriend>>(env);
|
||||
@@ -48,11 +48,6 @@ export namespace DeleteFriend {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const targetUid = await deps.resolveUserUid(params.userId);
|
||||
await invokeOidb(deps, {
|
||||
...DeleteFriend,
|
||||
serialize: p => serialize(p, targetUid),
|
||||
}, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, DeleteFriend, params);
|
||||
}
|
||||
@@ -22,14 +22,19 @@ export namespace HandleFriendRequest {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): OidbFriendRequestAction => ({
|
||||
// Server discriminator: 3 = accept, 5 = reject. Pre-fix values
|
||||
// verified against current production behaviour.
|
||||
accept: p.approve ? 3 : 5,
|
||||
targetUid,
|
||||
});
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<OidbFriendRequestAction> => {
|
||||
const targetUid = /^\d+$/.test(p.uidOrFlag)
|
||||
? await ctx.resolveUserUid(parseInt(p.uidOrFlag, 10))
|
||||
: p.uidOrFlag;
|
||||
return {
|
||||
// Server discriminator: 3 = accept, 5 = reject. Pre-fix values
|
||||
// verified against current production behaviour.
|
||||
accept: p.approve ? 3 : 5,
|
||||
targetUid,
|
||||
};
|
||||
};
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbFriendRequestAction>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbFriendRequestAction>>(env);
|
||||
@@ -37,14 +42,6 @@ export namespace HandleFriendRequest {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
let targetUid = params.uidOrFlag;
|
||||
if (/^\d+$/.test(params.uidOrFlag)) {
|
||||
targetUid = await deps.resolveUserUid(parseInt(params.uidOrFlag, 10));
|
||||
}
|
||||
await invokeOidb(deps, {
|
||||
...HandleFriendRequest,
|
||||
serialize: p => serialize(p, targetUid),
|
||||
}, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, HandleFriendRequest, params);
|
||||
}
|
||||
@@ -18,12 +18,12 @@ export namespace SetFriendRemark {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): OidbSetFriendRemark => ({
|
||||
targetUid,
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<OidbSetFriendRemark> => ({
|
||||
targetUid: await ctx.resolveUserUid(p.userId),
|
||||
remark: p.remark,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbSetFriendRemark>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbSetFriendRemark>>(env);
|
||||
@@ -31,11 +31,6 @@ export namespace SetFriendRemark {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const targetUid = await deps.resolveUserUid(params.userId);
|
||||
await invokeOidb(deps, {
|
||||
...SetFriendRemark,
|
||||
serialize: p => serialize(p, targetUid),
|
||||
}, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SetFriendRemark, params);
|
||||
}
|
||||
@@ -28,16 +28,16 @@ export namespace GetAtAllRemain {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
|
||||
|
||||
export const serialize = (p: Params, botUin: string): Oidb0x8a7Req => ({
|
||||
export const serialize = (ctx: Deps, p: Params): Oidb0x8a7Req => ({
|
||||
basic1: 1,
|
||||
basic2: 2,
|
||||
basic3: 1,
|
||||
uin: BigInt(botUin),
|
||||
uin: BigInt(ctx.identity.uin),
|
||||
groupId: BigInt(p.groupId),
|
||||
type: 0,
|
||||
});
|
||||
|
||||
export const deserialize = (body: Oidb0x8a7Resp): AtAllRemain => {
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0x8a7Resp): AtAllRemain => {
|
||||
// Cast numbers to plain Number: the OIDB layer may surface uint32
|
||||
// as BigInt and the WebUI JSON serializer chokes on those.
|
||||
return {
|
||||
@@ -54,8 +54,5 @@ export namespace GetAtAllRemain {
|
||||
protobuf_decode<OidbBase<Oidb0x8a7Resp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<AtAllRemain> =>
|
||||
invokeOidb(deps, {
|
||||
...GetAtAllRemain,
|
||||
serialize: p => serialize(p, deps.identity.uin),
|
||||
}, params);
|
||||
invokeOidb(deps, GetAtAllRemain, params);
|
||||
}
|
||||
@@ -22,14 +22,14 @@ export namespace KickMember {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): OidbKickMember => ({
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<OidbKickMember> => ({
|
||||
groupUin: p.groupId,
|
||||
targetUid,
|
||||
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
|
||||
rejectAddRequest: p.reject,
|
||||
reason: p.reason ?? '',
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbKickMember>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbKickMember>>(env);
|
||||
@@ -37,8 +37,6 @@ export namespace KickMember {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const targetUid = await deps.resolveUserUid(params.userId, params.groupId);
|
||||
await invokeOidb(deps, { ...KickMember, serialize: p => serialize(p, targetUid) }, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, KickMember, params);
|
||||
}
|
||||
@@ -20,15 +20,15 @@ export namespace KickMembers {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUids: string[]): Oidb0x8a0Req => ({
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<Oidb0x8a0Req> => ({
|
||||
groupId: BigInt(p.groupId),
|
||||
targetUids,
|
||||
targetUids: await Promise.all(p.userIds.map(uid => ctx.resolveUserUid(uid, p.groupId))),
|
||||
rejectAddRequest: p.reject ? 1 : 0,
|
||||
kickReason: new Uint8Array(0),
|
||||
field12: 0,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0x8a0Req>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0x8a0Req>>(env);
|
||||
@@ -36,10 +36,6 @@ export namespace KickMembers {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const targetUids = await Promise.all(
|
||||
params.userIds.map(userId => deps.resolveUserUid(userId, params.groupId)),
|
||||
);
|
||||
await invokeOidb(deps, { ...KickMembers, serialize: p => serialize(p, targetUids) }, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, KickMembers, params);
|
||||
}
|
||||
@@ -12,8 +12,8 @@ export namespace LeaveGroup {
|
||||
export interface Params { groupId: number; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbLeaveGroup => ({ groupUin: p.groupId });
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbLeaveGroup => ({ groupUin: p.groupId });
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
export const encode = (env: OidbBase<OidbLeaveGroup>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbLeaveGroup>>(env);
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
|
||||
@@ -16,12 +16,12 @@ export namespace MuteAll {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbMuteAll => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbMuteAll => ({
|
||||
groupUin: p.groupId,
|
||||
muteState: { state: p.enable ? 0xFFFFFFFF : 0 },
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbMuteAll>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbMuteAll>>(env);
|
||||
|
||||
@@ -15,12 +15,15 @@ export namespace MuteMember {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): OidbMuteMember => ({
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<OidbMuteMember> => ({
|
||||
groupUin: p.groupId, type: 1,
|
||||
body: { targetUid, duration: p.duration },
|
||||
body: {
|
||||
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
|
||||
duration: p.duration,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbMuteMember>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbMuteMember>>(env);
|
||||
@@ -28,8 +31,6 @@ export namespace MuteMember {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const targetUid = await deps.resolveUserUid(params.userId, params.groupId);
|
||||
await invokeOidb(deps, { ...MuteMember, serialize: p => serialize(p, targetUid) }, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, MuteMember, params);
|
||||
}
|
||||
@@ -15,13 +15,13 @@ export namespace SetAddOption {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): Oidb0x89a_0AddOption => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0AddOption => ({
|
||||
groupUin: BigInt(p.groupId),
|
||||
settings: { addType: p.addType },
|
||||
field12: 0,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0x89a_0AddOption>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0x89a_0AddOption>>(env);
|
||||
|
||||
@@ -26,7 +26,7 @@ export namespace SetAddRequest {
|
||||
|
||||
export const resolveSubCommand = (p: Params): number => p.filtered ? 2 : 1;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupRequestAction => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupRequestAction => ({
|
||||
accept: p.approve ? 1 : 2,
|
||||
body: {
|
||||
sequence: BigInt(p.sequence),
|
||||
@@ -36,7 +36,7 @@ export namespace SetAddRequest {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupRequestAction>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupRequestAction>>(env);
|
||||
|
||||
@@ -13,18 +13,18 @@ export namespace SetAdmin {
|
||||
export interface Params { groupId: number; userId: number; enable: boolean; }
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, uid: string): OidbSetAdmin => ({
|
||||
groupUin: p.groupId, uid, isAdmin: p.enable,
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<OidbSetAdmin> => ({
|
||||
groupUin: p.groupId,
|
||||
uid: await ctx.resolveUserUid(p.userId, p.groupId),
|
||||
isAdmin: p.enable,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
export const encode = (env: OidbBase<OidbSetAdmin>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbSetAdmin>>(env);
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const uid = await deps.resolveUserUid(params.userId, params.groupId);
|
||||
await invokeOidb(deps, { ...SetAdmin, serialize: p => serialize(p, uid) }, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SetAdmin, params);
|
||||
}
|
||||
@@ -12,11 +12,11 @@ export namespace SetGroupName {
|
||||
export interface Params { groupId: number; name: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbRenameGroup => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbRenameGroup => ({
|
||||
groupUin: p.groupId, body: { targetName: p.name },
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
export const encode = (env: OidbBase<OidbRenameGroup>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbRenameGroup>>(env);
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
|
||||
@@ -13,12 +13,12 @@ export namespace SetGroupRemark {
|
||||
export interface Params { groupId: number; remark: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): Oidb0xf16Req => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0xf16Req => ({
|
||||
inner: { groupId: BigInt(p.groupId), remark: p.remark },
|
||||
field12: 0,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
export const encode = (env: OidbBase<Oidb0xf16Req>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0xf16Req>>(env);
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
|
||||
@@ -13,18 +13,20 @@ export namespace SetMemberCard {
|
||||
export interface Params { groupId: number; userId: number; card: string; }
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): OidbRenameMember => ({
|
||||
groupUin: p.groupId, body: { targetUid, targetName: p.card },
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<OidbRenameMember> => ({
|
||||
groupUin: p.groupId,
|
||||
body: {
|
||||
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
|
||||
targetName: p.card,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
export const encode = (env: OidbBase<OidbRenameMember>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbRenameMember>>(env);
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const targetUid = await deps.resolveUserUid(params.userId, params.groupId);
|
||||
await invokeOidb(deps, { ...SetMemberCard, serialize: p => serialize(p, targetUid) }, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SetMemberCard, params);
|
||||
}
|
||||
@@ -14,13 +14,13 @@ export namespace SetSearch {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): Oidb0x89a_0Search => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0Search => ({
|
||||
groupUin: BigInt(p.groupId),
|
||||
settings: new Uint8Array(0),
|
||||
field12: 0,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0x89a_0Search>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0x89a_0Search>>(env);
|
||||
|
||||
@@ -14,19 +14,21 @@ export namespace SetSpecialTitle {
|
||||
export interface Params { groupId: number; userId: number; title: string; }
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
|
||||
|
||||
export const serialize = (p: Params, targetUid: string): OidbSpecialTitle => ({
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<OidbSpecialTitle> => ({
|
||||
groupUin: p.groupId,
|
||||
body: { targetUid, specialTitle: p.title, expireTime: -1 },
|
||||
body: {
|
||||
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
|
||||
specialTitle: p.title,
|
||||
expireTime: -1,
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
export const encode = (env: OidbBase<OidbSpecialTitle>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbSpecialTitle>>(env);
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = async (deps: Deps, params: Params): Promise<void> => {
|
||||
const targetUid = await deps.resolveUserUid(params.userId, params.groupId);
|
||||
await invokeOidb(deps, { ...SetSpecialTitle, serialize: p => serialize(p, targetUid) }, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SetSpecialTitle, params);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export namespace CreateGroupFolder {
|
||||
export interface Params { groupId: number; parentId: string; folderName: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileFolderReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileFolderReq => ({
|
||||
create: {
|
||||
groupUin: p.groupId,
|
||||
rootDirectory: p.parentId,
|
||||
@@ -25,7 +25,7 @@ export namespace CreateGroupFolder {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileFolderResp): void => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileFolderResp): void => {
|
||||
const result = body.create;
|
||||
if (!result) throw new Error('group folder create response missing');
|
||||
ensureRetCodeZero('group folder create', result.retcode, result.retMsg, result.clientWording);
|
||||
|
||||
@@ -16,7 +16,7 @@ export namespace DeleteGroupFile {
|
||||
export interface Params { groupId: number; fileId: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileReq => ({
|
||||
delete: {
|
||||
groupUin: p.groupId,
|
||||
busId: 102,
|
||||
@@ -24,7 +24,7 @@ export namespace DeleteGroupFile {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileResp): void => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileResp): void => {
|
||||
const result = body.delete;
|
||||
if (!result) throw new Error('group file delete response missing');
|
||||
ensureRetCodeZero('group file delete', result.retCode, result.retMsg, result.clientWording);
|
||||
|
||||
@@ -17,11 +17,11 @@ export namespace DeleteGroupFolder {
|
||||
export interface Params { groupId: number; folderId: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileFolderReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileFolderReq => ({
|
||||
delete: { groupUin: p.groupId, folderId: p.folderId },
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileFolderResp): void => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileFolderResp): void => {
|
||||
const result = body.delete;
|
||||
if (!result) throw new Error('group folder delete response missing');
|
||||
ensureRetCodeZero('group folder delete', result.retcode, result.retMsg, result.clientWording);
|
||||
|
||||
@@ -22,11 +22,11 @@ export namespace GetGroupFileCount {
|
||||
export interface Params { groupId: number; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileCountViewReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileCountViewReq => ({
|
||||
count: { groupUin: p.groupId, appId: 7, busId: 0 },
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileCountViewResp): GroupFileCount => ({
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileCountViewResp): GroupFileCount => ({
|
||||
fileCount: Number(body.count?.fileCount ?? 0),
|
||||
maxCount: Number(body.count?.maxCount ?? 10000),
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ export namespace GetGroupFileUrl {
|
||||
export interface Params { groupId: number; fileId: string; busId: number; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileReq => ({
|
||||
download: {
|
||||
groupUin: p.groupId,
|
||||
appId: 7,
|
||||
@@ -27,7 +27,7 @@ export namespace GetGroupFileUrl {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileResp): OidbGroupFileDownloadResp => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileResp): OidbGroupFileDownloadResp => {
|
||||
const download = body.download;
|
||||
if (!download) throw new Error('group file url response missing');
|
||||
return download;
|
||||
|
||||
@@ -19,7 +19,7 @@ export namespace GetGroupPttUrl {
|
||||
export interface Params { groupId: number; node: NtMediaIndex; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): NTV2RichMediaReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 4, command: 200 },
|
||||
scene: {
|
||||
@@ -36,7 +36,7 @@ export namespace GetGroupPttUrl {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = parseNtv2DownloadUrl;
|
||||
export const deserialize = (_ctx: Deps, body: NTV2RichMediaResp): string => parseNtv2DownloadUrl(body);
|
||||
|
||||
export const encode = (env: OidbBase<NTV2RichMediaReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<NTV2RichMediaReq>>(env);
|
||||
|
||||
@@ -18,7 +18,7 @@ export namespace GetGroupVideoUrl {
|
||||
export interface Params { groupId: number; node: NtMediaIndex; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): NTV2RichMediaReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
@@ -35,7 +35,7 @@ export namespace GetGroupVideoUrl {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = parseNtv2DownloadUrl;
|
||||
export const deserialize = (_ctx: Deps, body: NTV2RichMediaResp): string => parseNtv2DownloadUrl(body);
|
||||
|
||||
export const encode = (env: OidbBase<NTV2RichMediaReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<NTV2RichMediaReq>>(env);
|
||||
|
||||
@@ -23,7 +23,7 @@ export namespace GetPrivateFileUrl {
|
||||
export interface Params { selfUid: string; fileId: string; fileHash: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbPrivateFileDownloadReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbPrivateFileDownloadReq => ({
|
||||
subCommand: 1200,
|
||||
field2: 1,
|
||||
body: {
|
||||
@@ -39,7 +39,7 @@ export namespace GetPrivateFileUrl {
|
||||
field99999: new Uint8Array([0xC0, 0x85, 0x2C, 0x01]),
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbPrivateFileDownloadResp): OidbPrivateFileDownloadRespResult => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbPrivateFileDownloadResp): OidbPrivateFileDownloadRespResult => {
|
||||
const result = body.body?.result;
|
||||
if (!result) throw new Error('private file url response invalid');
|
||||
return result;
|
||||
|
||||
@@ -18,7 +18,7 @@ export namespace GetPrivatePttUrl {
|
||||
export interface Params { selfUid: string; node: NtMediaIndex; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): NTV2RichMediaReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
@@ -35,7 +35,7 @@ export namespace GetPrivatePttUrl {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = parseNtv2DownloadUrl;
|
||||
export const deserialize = (_ctx: Deps, body: NTV2RichMediaResp): string => parseNtv2DownloadUrl(body);
|
||||
|
||||
export const encode = (env: OidbBase<NTV2RichMediaReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<NTV2RichMediaReq>>(env);
|
||||
|
||||
@@ -18,7 +18,7 @@ export namespace GetPrivateVideoUrl {
|
||||
export interface Params { selfUid: string; node: NtMediaIndex; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): NTV2RichMediaReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): NTV2RichMediaReq => ({
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 200 },
|
||||
scene: {
|
||||
@@ -35,7 +35,7 @@ export namespace GetPrivateVideoUrl {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = parseNtv2DownloadUrl;
|
||||
export const deserialize = (_ctx: Deps, body: NTV2RichMediaResp): string => parseNtv2DownloadUrl(body);
|
||||
|
||||
export const encode = (env: OidbBase<NTV2RichMediaReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<NTV2RichMediaReq>>(env);
|
||||
|
||||
@@ -24,7 +24,7 @@ export namespace ListGroupFilesPage {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileViewReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileViewReq => ({
|
||||
list: {
|
||||
groupUin: p.groupId,
|
||||
appId: 7,
|
||||
@@ -40,7 +40,7 @@ export namespace ListGroupFilesPage {
|
||||
/** Returns the list body directly so the facade can inspect
|
||||
* `items`, `isEnd`, and `retCode` in one place. Returns null when
|
||||
* the server elides the list entirely (end-of-stream sentinel). */
|
||||
export const deserialize = (body: OidbGroupFileViewResp): OidbGroupFileListResp | null => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileViewResp): OidbGroupFileListResp | null => {
|
||||
return body.list ?? null;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ export namespace MoveGroupFile {
|
||||
}
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileReq => ({
|
||||
move: {
|
||||
groupUin: p.groupId,
|
||||
appId: 7,
|
||||
@@ -30,7 +30,7 @@ export namespace MoveGroupFile {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileResp): void => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileResp): void => {
|
||||
const result = body.move;
|
||||
if (!result) throw new Error('group file move response missing');
|
||||
ensureRetCodeZero('group file move', result.retCode, result.retMsg, result.clientWording);
|
||||
|
||||
@@ -21,7 +21,7 @@ export namespace PublishGroupFile {
|
||||
export interface Params { groupId: number; fileId: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupSendFileReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupSendFileReq => ({
|
||||
body: {
|
||||
groupUin: p.groupId,
|
||||
type: 2,
|
||||
@@ -34,7 +34,7 @@ export namespace PublishGroupFile {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupSendFileReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupSendFileReq>>(env);
|
||||
|
||||
@@ -18,7 +18,7 @@ export namespace RenameGroupFolder {
|
||||
export interface Params { groupId: number; folderId: string; newFolderName: string; }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileFolderReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileFolderReq => ({
|
||||
rename: {
|
||||
groupUin: p.groupId,
|
||||
folderId: p.folderId,
|
||||
@@ -26,7 +26,7 @@ export namespace RenameGroupFolder {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileFolderResp): void => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileFolderResp): void => {
|
||||
const result = body.rename;
|
||||
if (!result) throw new Error('group folder rename response missing');
|
||||
ensureRetCodeZero('group folder rename', result.retcode, result.retMsg, result.clientWording);
|
||||
|
||||
@@ -35,7 +35,7 @@ export namespace UploadGroupFileRequest {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupFileReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileReq => ({
|
||||
file: {
|
||||
groupUin: p.groupId,
|
||||
appId: 4,
|
||||
@@ -52,7 +52,7 @@ export namespace UploadGroupFileRequest {
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGroupFileResp): OidbGroupFileUploadResp => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupFileResp): OidbGroupFileUploadResp => {
|
||||
const upload = body.upload;
|
||||
if (!upload) throw new Error('group file upload response missing');
|
||||
return upload;
|
||||
|
||||
@@ -34,7 +34,7 @@ export namespace UploadPrivateFileRequest {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbPrivateFileUploadReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbPrivateFileUploadReq => ({
|
||||
command: 1700,
|
||||
seq: 0,
|
||||
upload: {
|
||||
@@ -53,7 +53,7 @@ export namespace UploadPrivateFileRequest {
|
||||
flagSupportMediaPlatform: 1,
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbPrivateFileUploadResp): OidbPrivateFileUploadRespBody => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbPrivateFileUploadResp): OidbPrivateFileUploadRespBody => {
|
||||
const upload = body.upload;
|
||||
if (!upload) throw new Error('private file upload response missing');
|
||||
return upload;
|
||||
|
||||
@@ -19,12 +19,12 @@ export namespace SendLike {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbLike => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbLike => ({
|
||||
targetUin: p.userId,
|
||||
count: p.count,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbLike>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbLike>>(env);
|
||||
|
||||
@@ -28,14 +28,14 @@ export namespace SendPoke {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbPoke => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbPoke => ({
|
||||
uin: p.targetUin ?? p.peerUin,
|
||||
groupUin: p.isGroup ? p.peerUin : 0,
|
||||
friendUin: p.isGroup ? 0 : p.peerUin,
|
||||
ext: 0,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbPoke>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbPoke>>(env);
|
||||
|
||||
@@ -25,13 +25,13 @@ export namespace SetEssence {
|
||||
|
||||
export const resolveSubCommand = (p: Params): number => p.enable ? 1 : 2;
|
||||
|
||||
export const serialize = (p: Params): OidbEssence => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbEssence => ({
|
||||
groupUin: p.groupId,
|
||||
sequence: p.sequence,
|
||||
random: p.random,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbEssence>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbEssence>>(env);
|
||||
|
||||
@@ -30,7 +30,7 @@ export namespace ClickInlineKeyboardButton {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): Oidb0x112eReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0x112eReq => ({
|
||||
botAppid: BigInt(p.botAppid),
|
||||
msgSeq: BigInt(p.msgSeq),
|
||||
buttonId: String(p.buttonId),
|
||||
@@ -40,7 +40,7 @@ export namespace ClickInlineKeyboardButton {
|
||||
unknown9: 1,
|
||||
});
|
||||
|
||||
export const deserialize = (body: Oidb0x112eResp): InlineButtonClickResult => ({
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0x112eResp): InlineButtonClickResult => ({
|
||||
result: Number(body.result || 0),
|
||||
errMsg: body.errMsg || '',
|
||||
status: 0,
|
||||
|
||||
@@ -27,15 +27,15 @@ export namespace SendGroupSign {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
|
||||
|
||||
export const serialize = (p: Params, uin: string): Oidb0xeb7Req => ({
|
||||
export const serialize = (ctx: Deps, p: Params): Oidb0xeb7Req => ({
|
||||
signInInfo: {
|
||||
uin,
|
||||
uin: String(ctx.identity.uin),
|
||||
groupId: String(p.groupId),
|
||||
version: '9.0.90',
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_: Oidb0xeb7Resp): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: Oidb0xeb7Resp): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0xeb7Req>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0xeb7Req>>(env);
|
||||
@@ -43,11 +43,6 @@ export namespace SendGroupSign {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xeb7Resp> =>
|
||||
protobuf_decode<OidbBase<Oidb0xeb7Resp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> => {
|
||||
const uin = String(deps.identity.uin);
|
||||
return invokeOidb(deps, {
|
||||
...SendGroupSign,
|
||||
serialize: p => serialize(p, uin),
|
||||
}, params);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SendGroupSign, params);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export namespace TranslateEnToZh {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): Oidb0x990Req => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0x990Req => ({
|
||||
translateReq: {
|
||||
srcLang: 'en',
|
||||
dstLang: 'zh',
|
||||
@@ -28,7 +28,7 @@ export namespace TranslateEnToZh {
|
||||
tag12: 1,
|
||||
});
|
||||
|
||||
export const deserialize = (body: Oidb0x990Resp): string[] => {
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0x990Resp): string[] => {
|
||||
const resp = body.translateResp;
|
||||
if (!resp) throw new Error('translate response empty');
|
||||
return resp.dstWords || [];
|
||||
|
||||
@@ -40,16 +40,22 @@ export namespace GetLike {
|
||||
|
||||
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 serialize = async (ctx: Deps, p: Params): Promise<Oidb0x7edReq> => {
|
||||
const targetUid = p.userId
|
||||
? await ctx.resolveUserUid(p.userId)
|
||||
: await resolveSelf(ctx);
|
||||
if (!targetUid) throw new Error('target uid not found');
|
||||
return {
|
||||
targetUid,
|
||||
basic: 1,
|
||||
vote: 1,
|
||||
favorite: 1,
|
||||
start: p.start ?? 0,
|
||||
limit: p.limit ?? 10,
|
||||
};
|
||||
};
|
||||
|
||||
export const deserialize = (body: Oidb0x7edResp): LikeInfo => {
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0x7edResp): LikeInfo => {
|
||||
const data = body.userLikeInfos?.[0];
|
||||
if (!data) throw new Error('get profile like info empty');
|
||||
return {
|
||||
@@ -77,17 +83,8 @@ export namespace GetLike {
|
||||
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);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<LikeInfo> =>
|
||||
invokeOidb(deps, GetLike, params);
|
||||
}
|
||||
|
||||
async function resolveSelf(deps: Pick<BridgeContext, 'identity' | 'resolveUserUid'>): Promise<string> {
|
||||
|
||||
@@ -25,9 +25,9 @@ export namespace GetUnidirectionalFriendList {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
|
||||
|
||||
export const serialize = (_: Params, uin: string): Oidb0xe17Req => {
|
||||
export const serialize = (ctx: Deps, _p: Params): Oidb0xe17Req => {
|
||||
const reqObj = {
|
||||
uint64_uin: uin,
|
||||
uint64_uin: String(ctx.identity.uin),
|
||||
uint64_top: 0,
|
||||
uint32_req_num: 99,
|
||||
bytes_cookies: '',
|
||||
@@ -35,7 +35,7 @@ export namespace GetUnidirectionalFriendList {
|
||||
return { jsonBody: JSON.stringify(reqObj) };
|
||||
};
|
||||
|
||||
export const deserialize = (body: Oidb0xe17Resp): unknown[] => {
|
||||
export const deserialize = (_ctx: Deps, 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 || [];
|
||||
@@ -47,11 +47,6 @@ export namespace GetUnidirectionalFriendList {
|
||||
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),
|
||||
}, {});
|
||||
};
|
||||
export const invoke = (deps: Deps): Promise<unknown[]> =>
|
||||
invokeOidb(deps, GetUnidirectionalFriendList, {});
|
||||
}
|
||||
@@ -22,15 +22,19 @@ export namespace SetInputStatus {
|
||||
|
||||
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 serialize = async (ctx: Deps, p: Params): Promise<Oidb0xcd4Req> => {
|
||||
const targetUid = await ctx.resolveUserUid(p.userId);
|
||||
if (!targetUid) throw new Error('target uid not found');
|
||||
return {
|
||||
reqBody: {
|
||||
uid: targetUid,
|
||||
chatType: 0,
|
||||
eventType: p.eventType,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const deserialize = (_: Oidb0xcd4Resp): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: Oidb0xcd4Resp): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0xcd4Req>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0xcd4Req>>(env);
|
||||
@@ -38,12 +42,6 @@ export namespace SetInputStatus {
|
||||
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);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SetInputStatus, params);
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
//
|
||||
// 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.
|
||||
// (fieldId, value) tuples. The `invoke` short-circuits when both
|
||||
// inputs are undefined so the facade's historic no-op-on-no-input
|
||||
// behaviour is preserved (no wasted SSO round-trip).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
@@ -24,14 +24,14 @@ export namespace SetProfile {
|
||||
/** Needs identity to read `uin` for the request body. */
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
|
||||
|
||||
export const serialize = (p: Params, uin: bigint): OidbSetProfile => {
|
||||
export const serialize = (ctx: Deps, p: Params): 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 };
|
||||
return { uin: BigInt(ctx.identity.uin), stringProfiles };
|
||||
};
|
||||
|
||||
export const deserialize = (_: Oidb0x112aResp): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: Oidb0x112aResp): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbSetProfile>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbSetProfile>>(env);
|
||||
@@ -45,13 +45,6 @@ export namespace SetProfile {
|
||||
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);
|
||||
return invokeOidb(deps, SetProfile, params);
|
||||
};
|
||||
}
|
||||
@@ -21,12 +21,12 @@ export namespace SetSelfLongNick {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
|
||||
|
||||
export const serialize = (p: Params, uin: bigint): Oidb0x112aReq => ({
|
||||
uin,
|
||||
export const serialize = (ctx: Deps, p: Params): Oidb0x112aReq => ({
|
||||
uin: BigInt(ctx.identity.uin),
|
||||
profile: { tag: 102, value: String(p.longNick) },
|
||||
});
|
||||
|
||||
export const deserialize = (_: Oidb0x112aResp): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: Oidb0x112aResp): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<Oidb0x112aReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<Oidb0x112aReq>>(env);
|
||||
@@ -34,11 +34,6 @@ export namespace SetSelfLongNick {
|
||||
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);
|
||||
};
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, SetSelfLongNick, params);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export namespace FetchReactionSummary {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): Oidb0x9084Req => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0x9084Req => ({
|
||||
groupId: BigInt(p.groupId),
|
||||
sequence: BigInt(p.sequence),
|
||||
emojiId: '',
|
||||
@@ -46,7 +46,7 @@ export namespace FetchReactionSummary {
|
||||
field12: 1,
|
||||
});
|
||||
|
||||
export const deserialize = (body: Oidb0x9084Resp): ReactionSummaryEntry[] => {
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0x9084Resp): ReactionSummaryEntry[] => {
|
||||
const out: ReactionSummaryEntry[] = [];
|
||||
for (const e of body.entries ?? []) {
|
||||
const count = e.count ?? 0;
|
||||
|
||||
@@ -41,7 +41,7 @@ export namespace GetEmojiLikes {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): Oidb0x9083Req => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): Oidb0x9083Req => ({
|
||||
groupId: BigInt(p.groupId),
|
||||
sequence: BigInt(p.sequence),
|
||||
emojiId: p.emojiId,
|
||||
@@ -52,7 +52,7 @@ export namespace GetEmojiLikes {
|
||||
field12: 1,
|
||||
});
|
||||
|
||||
export const deserialize = (body: Oidb0x9083Resp): Result => {
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0x9083Resp): Result => {
|
||||
const users: Array<{ uin: number }> = (body.inner?.userInfo ?? [])
|
||||
.map(u => ({ uin: Number(u?.uin ?? 0) }))
|
||||
.filter(u => u.uin > 0);
|
||||
|
||||
@@ -32,7 +32,7 @@ export namespace SetReaction {
|
||||
|
||||
export const resolveSubCommand = (p: Params): number => p.isSet ? 1 : 2;
|
||||
|
||||
export const serialize = (p: Params): OidbGroupReaction => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupReaction => ({
|
||||
groupUin: p.groupId,
|
||||
sequence: p.sequence,
|
||||
code: p.code,
|
||||
@@ -41,7 +41,7 @@ export namespace SetReaction {
|
||||
field7: false,
|
||||
});
|
||||
|
||||
export const deserialize = (_: OidbEmpty): void => {};
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupReaction>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupReaction>>(env);
|
||||
|
||||
@@ -24,9 +24,9 @@ export namespace ForceFetchClientKey {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_: Params): OidbClientKeyReq => ({});
|
||||
export const serialize = (_ctx: Deps, _: Params): OidbClientKeyReq => ({});
|
||||
|
||||
export const deserialize = (body: OidbClientKeyResp): ClientKeyInfo => ({
|
||||
export const deserialize = (_ctx: Deps, body: OidbClientKeyResp): ClientKeyInfo => ({
|
||||
clientKey: body.clientKey || '',
|
||||
keyIndex: String(body.keyIndex || '19'),
|
||||
expireTime: String(body.expireTime || '1800'),
|
||||
|
||||
@@ -21,11 +21,11 @@ export namespace GetPskey {
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (p: Params): OidbGetPskeyReq => ({
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGetPskeyReq => ({
|
||||
domainList: p.domainList,
|
||||
});
|
||||
|
||||
export const deserialize = (body: OidbGetPskeyResp): Result => {
|
||||
export const deserialize = (_ctx: Deps, body: OidbGetPskeyResp): Result => {
|
||||
const domainPskeyMap = new Map<string, string>();
|
||||
if (body.pskeyItems && Array.isArray(body.pskeyItems)) {
|
||||
for (const item of body.pskeyItems) {
|
||||
|
||||
@@ -16,12 +16,12 @@ import {
|
||||
// Reused minimal spec — encodes a group-reaction-shaped request and
|
||||
// reads back a void result. Exercises every spec branch.
|
||||
const reactionSpec: OidbCallSpec<
|
||||
OidbGroupReaction, OidbEmpty,
|
||||
OidbSender, OidbGroupReaction, OidbEmpty,
|
||||
{ groupId: number; sequence: number; code: string; isSet: boolean }, void
|
||||
> = {
|
||||
command: 0x9082,
|
||||
resolveSubCommand: p => p.isSet ? 1 : 2,
|
||||
serialize: p => ({
|
||||
serialize: (_ctx, p) => ({
|
||||
groupUin: p.groupId,
|
||||
sequence: p.sequence,
|
||||
code: p.code,
|
||||
@@ -35,10 +35,10 @@ const reactionSpec: OidbCallSpec<
|
||||
};
|
||||
|
||||
// Static-subCommand variant for the branch test.
|
||||
const staticSubSpec: OidbCallSpec<OidbGroupReaction, OidbEmpty, { groupId: number }, void> = {
|
||||
const staticSubSpec: OidbCallSpec<OidbSender, OidbGroupReaction, OidbEmpty, { groupId: number }, void> = {
|
||||
command: 0xEAC,
|
||||
subCommand: 1,
|
||||
serialize: p => ({ groupUin: p.groupId, sequence: 0, code: '', type: 1, field6: false, field7: false }),
|
||||
serialize: (_ctx, p) => ({ groupUin: p.groupId, sequence: 0, code: '', type: 1, field6: false, field7: false }),
|
||||
deserialize: () => {},
|
||||
encode: env => protobuf_encode<OidbBase<OidbGroupReaction>>(env),
|
||||
decode: bytes => protobuf_decode<OidbBase<OidbEmpty>>(bytes),
|
||||
@@ -81,13 +81,9 @@ describe('invokeOidb', () => {
|
||||
const sender = makeSender();
|
||||
await invokeOidb(sender, reactionSpec, { groupId: 12345, sequence: 99, code: '76', isSet: true });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
// First two top-level varint fields of the envelope should be the
|
||||
// cmd (0x9082) and the resolved subcmd (1).
|
||||
const env = protobuf_decode<OidbBase<OidbGroupReaction>>(bytes);
|
||||
expect(env.command).toBe(0x9082);
|
||||
expect(env.subCommand).toBe(1);
|
||||
// proto3 default-false bool fields aren't serialized — they come back
|
||||
// as null/undefined on decode, not the literal `false` we passed.
|
||||
expect(env.body).toMatchObject({
|
||||
groupUin: 12345, sequence: 99, code: '76', type: 1,
|
||||
});
|
||||
@@ -95,15 +91,14 @@ describe('invokeOidb', () => {
|
||||
|
||||
it('passes the body through deserialize for transformation', async () => {
|
||||
type Echo = { tag: number };
|
||||
const spec: OidbCallSpec<OidbGroupReaction, OidbGroupReaction, { code: string }, Echo> = {
|
||||
const spec: OidbCallSpec<OidbSender, OidbGroupReaction, OidbGroupReaction, { code: string }, Echo> = {
|
||||
command: 0x9082,
|
||||
subCommand: 1,
|
||||
serialize: p => ({ code: p.code }),
|
||||
deserialize: b => ({ tag: b.type ?? 99 }),
|
||||
serialize: (_ctx, p) => ({ code: p.code }),
|
||||
deserialize: (_ctx, b) => ({ tag: b.type ?? 99 }),
|
||||
encode: env => protobuf_encode<OidbBase<OidbGroupReaction>>(env),
|
||||
decode: bytes => protobuf_decode<OidbBase<OidbGroupReaction>>(bytes),
|
||||
};
|
||||
// Server response: an OidbBase envelope whose body has type=5.
|
||||
const responseEnvelope = protobuf_encode<OidbBase<OidbGroupReaction>>({
|
||||
command: 0x9082, subCommand: 1,
|
||||
body: { type: 5 } as OidbGroupReaction,
|
||||
@@ -114,21 +109,59 @@ describe('invokeOidb', () => {
|
||||
});
|
||||
|
||||
it('substitutes an empty body when the envelope has no field 4', async () => {
|
||||
// Envelope with only command + errorCode = 0, no body.
|
||||
const envBytes = protobuf_encode<OidbBase<OidbEmpty>>({ command: 0x9082, subCommand: 1 });
|
||||
const sender = makeSender({ responseData: Buffer.from(envBytes) });
|
||||
const deserialize = vi.fn(() => undefined);
|
||||
const spec: OidbCallSpec<OidbGroupReaction, OidbEmpty, { code: string }, void> = {
|
||||
const spec: OidbCallSpec<OidbSender, OidbGroupReaction, OidbEmpty, { code: string }, void> = {
|
||||
command: 0x9082, subCommand: 1,
|
||||
serialize: p => ({ code: p.code }),
|
||||
serialize: (_ctx, p) => ({ code: p.code }),
|
||||
deserialize,
|
||||
encode: env => protobuf_encode<OidbBase<OidbGroupReaction>>(env),
|
||||
decode: bytes => protobuf_decode<OidbBase<OidbEmpty>>(bytes),
|
||||
};
|
||||
await invokeOidb(sender, spec, { code: 'x' });
|
||||
// deserialize must still receive a defined object (the substituted {}).
|
||||
expect(deserialize).toHaveBeenCalledOnce();
|
||||
expect(deserialize.mock.calls[0]![0]).toEqual({});
|
||||
// deserialize now receives (ctx, body) — body is the second arg.
|
||||
expect(deserialize.mock.calls[0]![1]).toEqual({});
|
||||
});
|
||||
|
||||
it('awaits async serialize before sending', async () => {
|
||||
// ctx-aware serialize may need to resolve a uid first; invokeOidb
|
||||
// must await it before encoding the envelope.
|
||||
const sender = makeSender();
|
||||
const spec: OidbCallSpec<OidbSender, OidbGroupReaction, OidbEmpty, { code: string }, void> = {
|
||||
command: 0x9082, subCommand: 1,
|
||||
serialize: async (_ctx, p) => {
|
||||
await new Promise(r => setTimeout(r, 5));
|
||||
return { code: p.code, sequence: 42 };
|
||||
},
|
||||
deserialize: () => {},
|
||||
encode: env => protobuf_encode<OidbBase<OidbGroupReaction>>(env),
|
||||
decode: bytes => protobuf_decode<OidbBase<OidbEmpty>>(bytes),
|
||||
};
|
||||
await invokeOidb(sender, spec, { code: 'async' });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbGroupReaction>>(bytes);
|
||||
expect(env.body?.code).toBe('async');
|
||||
expect(env.body?.sequence).toBe(42);
|
||||
});
|
||||
|
||||
it('threads ctx into serialize so namespaces can read identity / resolve uids in place', async () => {
|
||||
const sender = makeSender();
|
||||
// Extend the ctx with an arbitrary capability the spec uses.
|
||||
type Ctx = OidbSender & { tag: string };
|
||||
const ctx: Ctx = { ...sender, tag: 'from-ctx' };
|
||||
const spec: OidbCallSpec<Ctx, OidbGroupReaction, OidbEmpty, { code: string }, void> = {
|
||||
command: 0x9082, subCommand: 1,
|
||||
serialize: (c, p) => ({ code: `${c.tag}/${p.code}` }),
|
||||
deserialize: () => {},
|
||||
encode: env => protobuf_encode<OidbBase<OidbGroupReaction>>(env),
|
||||
decode: bytes => protobuf_decode<OidbBase<OidbEmpty>>(bytes),
|
||||
};
|
||||
await invokeOidb(ctx, spec, { code: 'x' });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbGroupReaction>>(bytes);
|
||||
expect(env.body?.code).toBe('from-ctx/x');
|
||||
});
|
||||
|
||||
it('propagates timeoutMs to sendRawPacket', async () => {
|
||||
@@ -175,16 +208,12 @@ describe('invokeOidb', () => {
|
||||
});
|
||||
|
||||
it('skips OidbError check when response payload is empty', async () => {
|
||||
// Server returns success=true but with zero-length payload (a
|
||||
// legitimate "ack-only" response). invokeOidb must NOT try to
|
||||
// decode envelope meta on empty bytes.
|
||||
const sender = makeSender({ responseData: Buffer.alloc(0) });
|
||||
// Should not throw.
|
||||
await expect(invokeOidb(sender, staticSubSpec, { groupId: 1 })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('honours uinForm=true by flipping OIDB envelope reserved to 1', async () => {
|
||||
const spec: OidbCallSpec<OidbGroupReaction, OidbEmpty, { groupId: number }, void> = {
|
||||
const spec: OidbCallSpec<OidbSender, OidbGroupReaction, OidbEmpty, { groupId: number }, void> = {
|
||||
...staticSubSpec,
|
||||
uinForm: true,
|
||||
};
|
||||
@@ -200,7 +229,6 @@ describe('invokeOidb', () => {
|
||||
await invokeOidb(sender, staticSubSpec, { groupId: 1 });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<OidbGroupReaction>>(bytes);
|
||||
// proto3 default 0 may be omitted on the wire — expect either 0 or undefined.
|
||||
expect(env.reserved ?? 0).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -211,38 +239,42 @@ describe('buildOidbRequest', () => {
|
||||
await invokeOidb(sender, reactionSpec, { groupId: 12345, sequence: 99, code: '128516', isSet: true });
|
||||
const sentBytes = sender.sendRawPacket.mock.calls[0]![1];
|
||||
|
||||
const built = buildOidbRequest(reactionSpec, { groupId: 12345, sequence: 99, code: '128516', isSet: true });
|
||||
const built = await buildOidbRequest(sender, reactionSpec, { groupId: 12345, sequence: 99, code: '128516', isSet: true });
|
||||
expect(built.wireName).toBe('OidbSvcTrpcTcp.0x9082_1');
|
||||
expect(Buffer.from(built.bytes).equals(Buffer.from(sentBytes))).toBe(true);
|
||||
});
|
||||
|
||||
it('uses static subCommand when resolveSubCommand is absent', () => {
|
||||
const built = buildOidbRequest(staticSubSpec, { groupId: 1 });
|
||||
it('uses static subCommand when resolveSubCommand is absent', async () => {
|
||||
const sender = makeSender();
|
||||
const built = await buildOidbRequest(sender, staticSubSpec, { groupId: 1 });
|
||||
expect(built.wireName).toBe('OidbSvcTrpcTcp.0xeac_1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseOidbResponse', () => {
|
||||
it('decodes wire bytes via spec.decode and runs spec.deserialize on the body', () => {
|
||||
const sender = makeSender();
|
||||
const envBytes = protobuf_encode<OidbBase<OidbGroupReaction>>({
|
||||
command: 0x9082, subCommand: 1, body: { type: 7 } as OidbGroupReaction,
|
||||
});
|
||||
type Echo = { type: number };
|
||||
const spec: OidbCallSpec<OidbGroupReaction, OidbGroupReaction, void, Echo> = {
|
||||
const spec: OidbCallSpec<OidbSender, OidbGroupReaction, OidbGroupReaction, void, Echo> = {
|
||||
command: 0x9082, subCommand: 1,
|
||||
serialize: () => ({} as OidbGroupReaction),
|
||||
deserialize: b => ({ type: b.type ?? 0 }),
|
||||
deserialize: (_ctx, b) => ({ type: b.type ?? 0 }),
|
||||
encode: env => protobuf_encode<OidbBase<OidbGroupReaction>>(env),
|
||||
decode: bytes => protobuf_decode<OidbBase<OidbGroupReaction>>(bytes),
|
||||
};
|
||||
expect(parseOidbResponse(spec, envBytes)).toEqual({ type: 7 });
|
||||
expect(parseOidbResponse(sender, spec, envBytes)).toEqual({ type: 7 });
|
||||
});
|
||||
|
||||
it('substitutes empty body when the envelope lacks one', () => {
|
||||
const sender = makeSender();
|
||||
const envBytes = protobuf_encode<OidbBase<OidbEmpty>>({ command: 0x9082, subCommand: 1 });
|
||||
const deserialize = vi.fn(() => ({ ok: true }));
|
||||
parseOidbResponse({ ...staticSubSpec, deserialize } as any, envBytes);
|
||||
expect(deserialize).toHaveBeenCalledWith({});
|
||||
parseOidbResponse(sender, { ...staticSubSpec, deserialize } as any, envBytes);
|
||||
// deserialize now receives (ctx, body) — body is the second arg.
|
||||
expect(deserialize.mock.calls[0]![1]).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ describe('FetchDownloadRkeys namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('requests the (private=10, group=20, fallback=2) image scopes', () => {
|
||||
const out = FetchDownloadRkeys.serialize({});
|
||||
const out = FetchDownloadRkeys.serialize({} as any, {});
|
||||
expect(out.downloadRkey?.types).toEqual([10, 20, 2]);
|
||||
});
|
||||
|
||||
it('packages the fixed reqHead { common, scene, client }', () => {
|
||||
const out = FetchDownloadRkeys.serialize({});
|
||||
const out = FetchDownloadRkeys.serialize({} as any, {});
|
||||
expect(out.reqHead).toEqual({
|
||||
common: { requestId: 1, command: 202 },
|
||||
scene: { requestType: 2, businessType: 1, sceneType: 0 },
|
||||
@@ -39,18 +39,18 @@ describe('FetchDownloadRkeys namespace', () => {
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('throws when respHead.retCode is non-zero', () => {
|
||||
expect(() => FetchDownloadRkeys.deserialize({
|
||||
expect(() => FetchDownloadRkeys.deserialize({} as any, {
|
||||
respHead: { retCode: 42, message: 'bad' },
|
||||
} as any)).toThrow('bad');
|
||||
});
|
||||
|
||||
it('passes through on retCode = 0', () => {
|
||||
const body = { respHead: { retCode: 0 }, downloadRkey: { rkeys: [] } };
|
||||
expect(FetchDownloadRkeys.deserialize(body as any)).toBe(body);
|
||||
expect(FetchDownloadRkeys.deserialize({} as any, body as any)).toBe(body);
|
||||
});
|
||||
|
||||
it('falls back to a generic message when none is provided', () => {
|
||||
expect(() => FetchDownloadRkeys.deserialize({
|
||||
expect(() => FetchDownloadRkeys.deserialize({} as any, {
|
||||
respHead: { retCode: 1 },
|
||||
} as any)).toThrow('fetch download rkey failed');
|
||||
});
|
||||
|
||||
@@ -22,19 +22,19 @@ describe('FetchFriendListPage namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('omits nextUin on the first page', () => {
|
||||
const out = FetchFriendListPage.serialize({ nextUin: null }) as any;
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: null }) as any;
|
||||
expect(out.nextUin).toBeUndefined();
|
||||
expect(out.friendCount).toBe(300);
|
||||
expect(out.field4).toBe(0);
|
||||
});
|
||||
|
||||
it('includes nextUin sub-message on follow-up pages', () => {
|
||||
const out = FetchFriendListPage.serialize({ nextUin: 10001 }) as any;
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: 10001 }) as any;
|
||||
expect(out.nextUin).toEqual({ uin: 10001 });
|
||||
});
|
||||
|
||||
it('emits the verbatim property request list (codes 100/101/102/103/20002/27394)', () => {
|
||||
const out = FetchFriendListPage.serialize({ nextUin: null }) as any;
|
||||
const out = FetchFriendListPage.serialize({} as any, { nextUin: null }) as any;
|
||||
expect(out.body).toEqual([
|
||||
{ type: 1, number: { numbers: [103, 102, 20002, 27394] } },
|
||||
{ type: 4, number: { numbers: [100, 101, 102] } },
|
||||
|
||||
@@ -19,18 +19,18 @@ describe('FetchGroupMemberListPage namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('omits the token on the first page', () => {
|
||||
const out = FetchGroupMemberListPage.serialize({ groupId: 12345, token: '' }) as any;
|
||||
const out = FetchGroupMemberListPage.serialize({} as any, { groupId: 12345, token: '' }) as any;
|
||||
expect(out.token).toBeUndefined();
|
||||
expect(out.groupUin).toBe(12345);
|
||||
});
|
||||
|
||||
it('threads the server-issued token into follow-up pages', () => {
|
||||
const out = FetchGroupMemberListPage.serialize({ groupId: 12345, token: 'next-cursor' }) as any;
|
||||
const out = FetchGroupMemberListPage.serialize({} as any, { groupId: 12345, token: 'next-cursor' }) as any;
|
||||
expect(out.token).toBe('next-cursor');
|
||||
});
|
||||
|
||||
it('always requests the full member-field projection', () => {
|
||||
const out = FetchGroupMemberListPage.serialize({ groupId: 1, token: '' }) as any;
|
||||
const out = FetchGroupMemberListPage.serialize({} as any, { groupId: 1, token: '' }) as any;
|
||||
expect(out.body).toMatchObject({
|
||||
memberName: true, memberCard: true, level: true,
|
||||
joinTimestamp: true, lastMsgTimestamp: true, shutUpTimestamp: true,
|
||||
|
||||
@@ -27,8 +27,8 @@ describe('FetchGroupRequests namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('always sends count=20 / field2=0', () => {
|
||||
expect(FetchGroupRequests.serialize({ filtered: false })).toEqual({ count: 20, field2: 0 });
|
||||
expect(FetchGroupRequests.serialize({ filtered: true })).toEqual({ count: 20, field2: 0 });
|
||||
expect(FetchGroupRequests.serialize({} as any, { filtered: false })).toEqual({ count: 20, field2: 0 });
|
||||
expect(FetchGroupRequests.serialize({} as any, { filtered: true })).toEqual({ count: 20, field2: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('FetchAiVoiceList namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('passes groupUin / chatType verbatim', () => {
|
||||
expect(FetchAiVoiceList.serialize({ groupId: 4242, chatType: 1 })).toEqual({
|
||||
expect(FetchAiVoiceList.serialize({} as any, { groupId: 4242, chatType: 1 })).toEqual({
|
||||
groupUin: 4242, chatType: 1,
|
||||
});
|
||||
});
|
||||
@@ -30,7 +30,7 @@ describe('FetchAiVoiceList namespace', () => {
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('returns content array verbatim', () => {
|
||||
const out = FetchAiVoiceList.deserialize({
|
||||
const out = FetchAiVoiceList.deserialize({} as any, {
|
||||
content: [
|
||||
{ category: 'cute', voices: [{ voiceId: 'v1', voiceDisplayName: 'V1', voiceExampleUrl: 'http://x' }] },
|
||||
],
|
||||
@@ -41,7 +41,7 @@ describe('FetchAiVoiceList namespace', () => {
|
||||
});
|
||||
|
||||
it('returns [] when content is omitted', () => {
|
||||
expect(FetchAiVoiceList.deserialize({})).toEqual([]);
|
||||
expect(FetchAiVoiceList.deserialize({} as any, {})).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('FetchAiVoice namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('packages every field including sessionId into session sub-message', () => {
|
||||
const out = FetchAiVoice.serialize({
|
||||
const out = FetchAiVoice.serialize({} as any, {
|
||||
groupId: 100, voiceId: 'v', text: 'hi', chatType: 1, sessionId: 0xCAFE,
|
||||
});
|
||||
expect(out).toEqual({
|
||||
@@ -35,15 +35,15 @@ describe('FetchAiVoice namespace', () => {
|
||||
describe('deserialize', () => {
|
||||
it('returns the first msgInfoBody index when present', () => {
|
||||
const node = { fileUuid: 'uuid', subType: 1 };
|
||||
expect(FetchAiVoice.deserialize({
|
||||
expect(FetchAiVoice.deserialize({} as any, {
|
||||
msgInfo: { msgInfoBody: [{ index: node }] },
|
||||
} as any)).toMatchObject(node);
|
||||
});
|
||||
|
||||
it('returns null when msgInfo is empty / missing', () => {
|
||||
expect(FetchAiVoice.deserialize({} as any)).toBeNull();
|
||||
expect(FetchAiVoice.deserialize({ msgInfo: {} } as any)).toBeNull();
|
||||
expect(FetchAiVoice.deserialize({ msgInfo: { msgInfoBody: [] } } as any)).toBeNull();
|
||||
expect(FetchAiVoice.deserialize({} as any, {} as any)).toBeNull();
|
||||
expect(FetchAiVoice.deserialize({} as any, { msgInfo: {} } as any)).toBeNull();
|
||||
expect(FetchAiVoice.deserialize({} as any, { msgInfo: { msgInfoBody: [] } } as any)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -23,27 +23,27 @@ describe('GetStrangerStatus namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('always queries only key 27372 (status property)', () => {
|
||||
const out = GetStrangerStatus.serialize({ uin: 100200 });
|
||||
const out = GetStrangerStatus.serialize({} as any, { uin: 100200 });
|
||||
expect(out).toEqual({ uin: 100200, key: [{ key: 27372 }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('low-band (≤10) values map to (value*10, 0)', () => {
|
||||
expect(GetStrangerStatus.deserialize({ data: { status: { value: 7n } } })).toEqual({ status: 70, ext_status: 0 });
|
||||
expect(GetStrangerStatus.deserialize({ data: { status: { value: 10n } } })).toEqual({ status: 100, ext_status: 0 });
|
||||
expect(GetStrangerStatus.deserialize({} as any, { data: { status: { value: 7n } } })).toEqual({ status: 70, ext_status: 0 });
|
||||
expect(GetStrangerStatus.deserialize({} as any, { data: { status: { value: 10n } } })).toEqual({ status: 100, ext_status: 0 });
|
||||
});
|
||||
|
||||
it('high-band values decompose into (0xff00 + (>>16 & 0xff)) ext_status', () => {
|
||||
// 0x42F100 → bits 8..15 = 0xF1<<8 = 0xF100, bits 16..23 = 0x42 → 0xF142
|
||||
expect(GetStrangerStatus.deserialize({ data: { status: { value: 0x42F100n } } }))
|
||||
expect(GetStrangerStatus.deserialize({} as any, { data: { status: { value: 0x42F100n } } }))
|
||||
.toEqual({ status: 10, ext_status: 0xF142 });
|
||||
});
|
||||
|
||||
it('returns null when status field is missing', () => {
|
||||
expect(GetStrangerStatus.deserialize({})).toBeNull();
|
||||
expect(GetStrangerStatus.deserialize({ data: {} })).toBeNull();
|
||||
expect(GetStrangerStatus.deserialize({ data: { status: {} } })).toBeNull();
|
||||
expect(GetStrangerStatus.deserialize({} as any, {})).toBeNull();
|
||||
expect(GetStrangerStatus.deserialize({} as any, { data: {} })).toBeNull();
|
||||
expect(GetStrangerStatus.deserialize({} as any, { data: { status: {} } })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('GroupTodo namespace', () => {
|
||||
describe('serialize', () => {
|
||||
it('packages groupUin + msgSeq verbatim regardless of action', () => {
|
||||
for (const action of ['set', 'complete', 'cancel'] as const) {
|
||||
const out = GroupTodo.serialize({ groupId: 12345, msgSeq: 9876543210n, action });
|
||||
const out = GroupTodo.serialize({} as any, { groupId: 12345, msgSeq: 9876543210n, action });
|
||||
expect(out).toEqual({ groupUin: 12345, msgSeq: 9876543210n });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('SendLike namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('passes userId / count through verbatim', () => {
|
||||
expect(SendLike.serialize({ userId: 10001, count: 3 })).toEqual({ targetUin: 10001, count: 3 });
|
||||
expect(SendLike.serialize({} as any, { userId: 10001, count: 3 })).toEqual({ targetUin: 10001, count: 3 });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -19,32 +19,32 @@ describe('SendPoke namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('group poke: groupUin = peer, friendUin = 0, uin = targetUin', () => {
|
||||
expect(SendPoke.serialize({ isGroup: true, peerUin: 12345, targetUin: 67890 })).toEqual({
|
||||
expect(SendPoke.serialize({} as any, { isGroup: true, peerUin: 12345, targetUin: 67890 })).toEqual({
|
||||
uin: 67890, groupUin: 12345, friendUin: 0, ext: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('group poke without targetUin: uin defaults to peer', () => {
|
||||
expect(SendPoke.serialize({ isGroup: true, peerUin: 12345 })).toEqual({
|
||||
expect(SendPoke.serialize({} as any, { isGroup: true, peerUin: 12345 })).toEqual({
|
||||
uin: 12345, groupUin: 12345, friendUin: 0, ext: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('friend poke: friendUin = peer, groupUin = 0, uin = targetUin', () => {
|
||||
expect(SendPoke.serialize({ isGroup: false, peerUin: 67890, targetUin: 11111 })).toEqual({
|
||||
expect(SendPoke.serialize({} as any, { isGroup: false, peerUin: 67890, targetUin: 11111 })).toEqual({
|
||||
uin: 11111, groupUin: 0, friendUin: 67890, ext: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('friend poke without targetUin: uin defaults to peer', () => {
|
||||
expect(SendPoke.serialize({ isGroup: false, peerUin: 67890 })).toEqual({
|
||||
expect(SendPoke.serialize({} as any, { isGroup: false, peerUin: 67890 })).toEqual({
|
||||
uin: 67890, groupUin: 0, friendUin: 67890, ext: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('always sets ext = 0', () => {
|
||||
expect(SendPoke.serialize({ isGroup: true, peerUin: 1 }).ext).toBe(0);
|
||||
expect(SendPoke.serialize({ isGroup: false, peerUin: 1 }).ext).toBe(0);
|
||||
expect(SendPoke.serialize({} as any, { isGroup: true, peerUin: 1 }).ext).toBe(0);
|
||||
expect(SendPoke.serialize({} as any, { isGroup: false, peerUin: 1 }).ext).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('SetEssence namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('passes groupId / sequence / random through verbatim', () => {
|
||||
expect(SetEssence.serialize({ groupId: 12345, sequence: 99, random: 0xCAFEBABE, enable: true })).toEqual({
|
||||
expect(SetEssence.serialize({} as any, { groupId: 12345, sequence: 99, random: 0xCAFEBABE, enable: true })).toEqual({
|
||||
groupUin: 12345, sequence: 99, random: 0xCAFEBABE,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('ClickInlineKeyboardButton namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('widens numeric ids to BigInt for uint_64 fields', () => {
|
||||
const out = ClickInlineKeyboardButton.serialize({
|
||||
const out = ClickInlineKeyboardButton.serialize({} as any, {
|
||||
groupId: 12345, botAppid: 67890, buttonId: 'btn', callbackData: 'data', msgSeq: 100,
|
||||
});
|
||||
expect(out.groupId).toBe(12345n);
|
||||
@@ -31,7 +31,7 @@ describe('ClickInlineKeyboardButton namespace', () => {
|
||||
});
|
||||
|
||||
it('always sends unknown7=0 / unknown9=1 magic values', () => {
|
||||
const out = ClickInlineKeyboardButton.serialize({
|
||||
const out = ClickInlineKeyboardButton.serialize({} as any, {
|
||||
groupId: 1, botAppid: 1, buttonId: 'x', callbackData: 'y', msgSeq: 1,
|
||||
});
|
||||
expect(out.unknown7).toBe(0);
|
||||
@@ -39,7 +39,7 @@ describe('ClickInlineKeyboardButton namespace', () => {
|
||||
});
|
||||
|
||||
it('coerces buttonId / callbackData to strings (defensive)', () => {
|
||||
const out = ClickInlineKeyboardButton.serialize({
|
||||
const out = ClickInlineKeyboardButton.serialize({} as any, {
|
||||
groupId: 1, botAppid: 1, buttonId: 123 as any, callbackData: null as any, msgSeq: 1,
|
||||
});
|
||||
expect(out.buttonId).toBe('123');
|
||||
@@ -49,7 +49,7 @@ describe('ClickInlineKeyboardButton namespace', () => {
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('shapes the response with status/promptType/promptIcon = 0', () => {
|
||||
expect(ClickInlineKeyboardButton.deserialize({
|
||||
expect(ClickInlineKeyboardButton.deserialize({} as any, {
|
||||
result: 1, errMsg: 'ok', promptText: 'hi',
|
||||
} as Oidb0x112eResp)).toEqual({
|
||||
result: 1, errMsg: 'ok', status: 0, promptText: 'hi', promptType: 0, promptIcon: 0,
|
||||
@@ -57,7 +57,7 @@ describe('ClickInlineKeyboardButton namespace', () => {
|
||||
});
|
||||
|
||||
it('defaults result/errMsg/promptText when omitted', () => {
|
||||
expect(ClickInlineKeyboardButton.deserialize({} as Oidb0x112eResp)).toEqual({
|
||||
expect(ClickInlineKeyboardButton.deserialize({} as any, {} as Oidb0x112eResp)).toEqual({
|
||||
result: 0, errMsg: '', status: 0, promptText: '', promptType: 0, promptIcon: 0,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('TranslateEnToZh namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('hardcodes en → zh and tag10/12 = 1', () => {
|
||||
const out = TranslateEnToZh.serialize({ words: ['hello'] });
|
||||
const out = TranslateEnToZh.serialize({} as any, { words: ['hello'] });
|
||||
expect(out).toEqual({
|
||||
translateReq: { srcLang: 'en', dstLang: 'zh', words: ['hello'] },
|
||||
tag10: 1,
|
||||
@@ -31,24 +31,24 @@ describe('TranslateEnToZh namespace', () => {
|
||||
});
|
||||
|
||||
it('passes the words array verbatim', () => {
|
||||
const out = TranslateEnToZh.serialize({ words: ['a', 'b', 'c'] });
|
||||
const out = TranslateEnToZh.serialize({} as any, { words: ['a', 'b', 'c'] });
|
||||
expect(out.translateReq?.words).toEqual(['a', 'b', 'c']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('returns dstWords when translateResp is present', () => {
|
||||
expect(TranslateEnToZh.deserialize({
|
||||
expect(TranslateEnToZh.deserialize({} as any, {
|
||||
translateResp: { dstWords: ['你好', '世界'] },
|
||||
} as Oidb0x990Resp)).toEqual(['你好', '世界']);
|
||||
});
|
||||
|
||||
it('returns [] when dstWords is omitted but translateResp exists', () => {
|
||||
expect(TranslateEnToZh.deserialize({ translateResp: {} } as Oidb0x990Resp)).toEqual([]);
|
||||
expect(TranslateEnToZh.deserialize({} as any, { translateResp: {} } as Oidb0x990Resp)).toEqual([]);
|
||||
});
|
||||
|
||||
it('throws when translateResp is missing', () => {
|
||||
expect(() => TranslateEnToZh.deserialize({} as Oidb0x990Resp))
|
||||
expect(() => TranslateEnToZh.deserialize({} as any, {} as Oidb0x990Resp))
|
||||
.toThrow('translate response empty');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -104,7 +104,7 @@ describe('GetLike namespace', () => {
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('shapes favorite + vote info with the expected key names', () => {
|
||||
const out = GetLike.deserialize({
|
||||
const out = GetLike.deserialize({} as any, {
|
||||
userLikeInfos: [{
|
||||
uid: 'u', time: 1700000000n,
|
||||
favoriteInfo: { totalCount: 5, lastTime: 1n, newCount: 1 },
|
||||
@@ -122,12 +122,12 @@ describe('GetLike namespace', () => {
|
||||
});
|
||||
|
||||
it('throws when there are no userLikeInfos', () => {
|
||||
expect(() => GetLike.deserialize({})).toThrow('get profile like info empty');
|
||||
expect(() => GetLike.deserialize({ userLikeInfos: [] })).toThrow('get profile like info empty');
|
||||
expect(() => GetLike.deserialize({} as any, {})).toThrow('get profile like info empty');
|
||||
expect(() => GetLike.deserialize({} as any, { userLikeInfos: [] })).toThrow('get profile like info empty');
|
||||
});
|
||||
|
||||
it('defaults all count fields to 0 when omitted', () => {
|
||||
const out = GetLike.deserialize({ userLikeInfos: [{ uid: 'u', time: 0n }] });
|
||||
const out = GetLike.deserialize({} as any, { userLikeInfos: [{ uid: 'u', time: 0n }] });
|
||||
expect(out.favoriteInfo.total_count).toBe(0);
|
||||
expect(out.voteInfo.total_count).toBe(0);
|
||||
});
|
||||
|
||||
@@ -49,20 +49,20 @@ describe('GetUnidirectionalFriendList namespace', () => {
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('parses the embedded JSON body and returns rpt_block_list', () => {
|
||||
const out = GetUnidirectionalFriendList.deserialize({
|
||||
const out = GetUnidirectionalFriendList.deserialize({} as any, {
|
||||
jsonBody: JSON.stringify({ rpt_block_list: [{ uin: 10001 }, { uin: 10002 }] }),
|
||||
});
|
||||
expect(out).toEqual([{ uin: 10001 }, { uin: 10002 }]);
|
||||
});
|
||||
|
||||
it('returns [] when rpt_block_list is absent', () => {
|
||||
const out = GetUnidirectionalFriendList.deserialize({ jsonBody: JSON.stringify({}) });
|
||||
const out = GetUnidirectionalFriendList.deserialize({} as any, { jsonBody: JSON.stringify({}) });
|
||||
expect(out).toEqual([]);
|
||||
});
|
||||
|
||||
it('throws when jsonBody is empty / missing', () => {
|
||||
expect(() => GetUnidirectionalFriendList.deserialize({})).toThrow('get unidirectional friend list empty');
|
||||
expect(() => GetUnidirectionalFriendList.deserialize({ jsonBody: '' })).toThrow('get unidirectional friend list empty');
|
||||
expect(() => GetUnidirectionalFriendList.deserialize({} as any, {})).toThrow('get unidirectional friend list empty');
|
||||
expect(() => GetUnidirectionalFriendList.deserialize({} as any, { jsonBody: '' })).toThrow('get unidirectional friend list empty');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -22,13 +22,13 @@ describe('FetchReactionSummary namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('encodes groupId/sequence as BigInt for uint_64 fields', () => {
|
||||
const out = FetchReactionSummary.serialize({ groupId: 1022489779, sequence: 1730183 });
|
||||
const out = FetchReactionSummary.serialize({} as any, { groupId: 1022489779, sequence: 1730183 });
|
||||
expect(out.groupId).toBe(1022489779n);
|
||||
expect(out.sequence).toBe(1730183n);
|
||||
});
|
||||
|
||||
it('passes empty / default values for the unused filter fields', () => {
|
||||
const out = FetchReactionSummary.serialize({ groupId: 1, sequence: 1 });
|
||||
const out = FetchReactionSummary.serialize({} as any, { groupId: 1, sequence: 1 });
|
||||
expect(out.emojiId).toBe('');
|
||||
expect(out.emojiType).toBe(0);
|
||||
expect(out.count).toBe(0);
|
||||
@@ -36,7 +36,7 @@ describe('FetchReactionSummary namespace', () => {
|
||||
});
|
||||
|
||||
it('emits a 0-length cookie buffer (no continuation)', () => {
|
||||
const out = FetchReactionSummary.serialize({ groupId: 1, sequence: 1 });
|
||||
const out = FetchReactionSummary.serialize({} as any, { groupId: 1, sequence: 1 });
|
||||
expect(out.cookie).toBeInstanceOf(Uint8Array);
|
||||
expect(out.cookie!.length).toBe(0);
|
||||
});
|
||||
@@ -50,7 +50,7 @@ describe('FetchReactionSummary namespace', () => {
|
||||
{ lastReactionTime: 1779456962n, count: 1, emojiType: 1, emojiId: '124' },
|
||||
],
|
||||
};
|
||||
expect(FetchReactionSummary.deserialize(body)).toEqual([
|
||||
expect(FetchReactionSummary.deserialize({} as any, body)).toEqual([
|
||||
{ emojiId: '76', emojiType: 1, count: 3, lastReactionTime: 1779456439 },
|
||||
{ emojiId: '124', emojiType: 1, count: 1, lastReactionTime: 1779456962 },
|
||||
]);
|
||||
@@ -64,20 +64,20 @@ describe('FetchReactionSummary namespace', () => {
|
||||
{ emojiType: 1, emojiId: '66' }, // catalog entry
|
||||
],
|
||||
};
|
||||
const out = FetchReactionSummary.deserialize(body);
|
||||
const out = FetchReactionSummary.deserialize({} as any, body);
|
||||
expect(out).toHaveLength(1);
|
||||
expect(out[0]!.emojiId).toBe('76');
|
||||
});
|
||||
|
||||
it('returns an empty array when the response has no entries', () => {
|
||||
expect(FetchReactionSummary.deserialize({})).toEqual([]);
|
||||
expect(FetchReactionSummary.deserialize({} as any, {})).toEqual([]);
|
||||
});
|
||||
|
||||
it('defaults emojiId / emojiType to safe values when omitted', () => {
|
||||
const body: Oidb0x9084Resp = {
|
||||
entries: [{ count: 5, lastReactionTime: 1700000000n }],
|
||||
};
|
||||
const [entry] = FetchReactionSummary.deserialize(body);
|
||||
const [entry] = FetchReactionSummary.deserialize({} as any, body);
|
||||
expect(entry).toEqual({
|
||||
emojiId: '', emojiType: 1, count: 5, lastReactionTime: 1700000000,
|
||||
});
|
||||
@@ -85,7 +85,7 @@ describe('FetchReactionSummary namespace', () => {
|
||||
|
||||
it('reports lastReactionTime=0 when omitted on a used entry (degenerate but defensive)', () => {
|
||||
const body: Oidb0x9084Resp = { entries: [{ count: 2, emojiId: 'x', emojiType: 1 }] };
|
||||
expect(FetchReactionSummary.deserialize(body)[0]!.lastReactionTime).toBe(0);
|
||||
expect(FetchReactionSummary.deserialize({} as any, body)[0]!.lastReactionTime).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('GetEmojiLikes namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('encodes groupId/sequence as BigInt for uint_64 fields', () => {
|
||||
const out = GetEmojiLikes.serialize({
|
||||
const out = GetEmojiLikes.serialize({} as any, {
|
||||
groupId: 12345, sequence: 99, emojiId: '76',
|
||||
});
|
||||
expect(out.groupId).toBe(12345n);
|
||||
@@ -30,44 +30,44 @@ describe('GetEmojiLikes namespace', () => {
|
||||
});
|
||||
|
||||
it('passes emojiId through unchanged', () => {
|
||||
const out = GetEmojiLikes.serialize({ groupId: 1, sequence: 1, emojiId: '128516' });
|
||||
const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: '128516' });
|
||||
expect(out.emojiId).toBe('128516');
|
||||
});
|
||||
|
||||
it('defaults emojiType to 1 when omitted', () => {
|
||||
const out = GetEmojiLikes.serialize({ groupId: 1, sequence: 1, emojiId: 'x' });
|
||||
const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x' });
|
||||
expect(out.emojiType).toBe(1);
|
||||
});
|
||||
|
||||
it('uses caller-supplied emojiType when present', () => {
|
||||
const out = GetEmojiLikes.serialize({ groupId: 1, sequence: 1, emojiId: 'x', emojiType: 2 });
|
||||
const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x', emojiType: 2 });
|
||||
expect(out.emojiType).toBe(2);
|
||||
});
|
||||
|
||||
it('defaults count to 10 when omitted', () => {
|
||||
const out = GetEmojiLikes.serialize({ groupId: 1, sequence: 1, emojiId: 'x' });
|
||||
const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x' });
|
||||
expect(out.count).toBe(10);
|
||||
});
|
||||
|
||||
it('uses caller-supplied count when present', () => {
|
||||
const out = GetEmojiLikes.serialize({ groupId: 1, sequence: 1, emojiId: 'x', count: 50 });
|
||||
const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x', count: 50 });
|
||||
expect(out.count).toBe(50);
|
||||
});
|
||||
|
||||
it('decodes base64 cookie into the bytes field for continuation', () => {
|
||||
const cookie = Buffer.from([0xCA, 0xFE]).toString('base64');
|
||||
const out = GetEmojiLikes.serialize({ groupId: 1, sequence: 1, emojiId: 'x', cookie });
|
||||
const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x', cookie });
|
||||
expect(out.cookie).toBeInstanceOf(Uint8Array);
|
||||
expect(Buffer.from(out.cookie!).equals(Buffer.from([0xCA, 0xFE]))).toBe(true);
|
||||
});
|
||||
|
||||
it('emits a 0-length cookie buffer for the first page (no cookie supplied)', () => {
|
||||
const out = GetEmojiLikes.serialize({ groupId: 1, sequence: 1, emojiId: 'x' });
|
||||
const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x' });
|
||||
expect(out.cookie!.length).toBe(0);
|
||||
});
|
||||
|
||||
it('sets field7=0 and field12=1 (magic values matching the historic wire shape)', () => {
|
||||
const out = GetEmojiLikes.serialize({ groupId: 1, sequence: 1, emojiId: 'x' });
|
||||
const out = GetEmojiLikes.serialize({} as any, { groupId: 1, sequence: 1, emojiId: 'x' });
|
||||
expect(out.field7).toBe(0);
|
||||
expect(out.field12).toBe(1);
|
||||
});
|
||||
@@ -75,7 +75,7 @@ describe('GetEmojiLikes namespace', () => {
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('extracts users from inner.userInfo and base64-encodes the cookie', () => {
|
||||
const result = GetEmojiLikes.deserialize({
|
||||
const result = GetEmojiLikes.deserialize({} as any, {
|
||||
inner: { userInfo: [{ uin: 10001n }, { uin: 20002n }] },
|
||||
cookie: new Uint8Array([0xCA, 0xFE]),
|
||||
});
|
||||
@@ -85,28 +85,28 @@ describe('GetEmojiLikes namespace', () => {
|
||||
});
|
||||
|
||||
it('filters out users with uin=0 (placeholder / zero-value)', () => {
|
||||
const result = GetEmojiLikes.deserialize({
|
||||
const result = GetEmojiLikes.deserialize({} as any, {
|
||||
inner: { userInfo: [{ uin: 10001n }, { uin: 0n }, { uin: 20002n }] },
|
||||
});
|
||||
expect(result.users).toEqual([{ uin: 10001 }, { uin: 20002 }]);
|
||||
});
|
||||
|
||||
it('returns empty users + empty cookie + isLast=true when body has nothing', () => {
|
||||
const result = GetEmojiLikes.deserialize({});
|
||||
const result = GetEmojiLikes.deserialize({} as any, {});
|
||||
expect(result.users).toEqual([]);
|
||||
expect(result.cookie).toBe('');
|
||||
expect(result.isLast).toBe(true);
|
||||
});
|
||||
|
||||
it('returns isLast=true when cookie is absent (final page)', () => {
|
||||
const result = GetEmojiLikes.deserialize({
|
||||
const result = GetEmojiLikes.deserialize({} as any, {
|
||||
inner: { userInfo: [{ uin: 10001n }] },
|
||||
});
|
||||
expect(result.isLast).toBe(true);
|
||||
});
|
||||
|
||||
it('handles missing userInfo entries field', () => {
|
||||
const result = GetEmojiLikes.deserialize({ inner: {} });
|
||||
const result = GetEmojiLikes.deserialize({} as any, { inner: {} });
|
||||
expect(result.users).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,31 +26,31 @@ describe('SetReaction namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('produces type=1 for short QQ-face codes (≤3 chars)', () => {
|
||||
const out = SetReaction.serialize({ groupId: 12345, sequence: 99, code: '76', isSet: true });
|
||||
const out = SetReaction.serialize({} as any, { groupId: 12345, sequence: 99, code: '76', isSet: true });
|
||||
expect(out).toEqual({
|
||||
groupUin: 12345, sequence: 99, code: '76', type: 1, field6: false, field7: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('produces type=1 for exactly 3-character codes (boundary)', () => {
|
||||
const out = SetReaction.serialize({ groupId: 1, sequence: 1, code: '999', isSet: true });
|
||||
const out = SetReaction.serialize({} as any, { groupId: 1, sequence: 1, code: '999', isSet: true });
|
||||
expect(out.type).toBe(1);
|
||||
});
|
||||
|
||||
it('produces type=2 for codes longer than 3 chars (unicode codepoint)', () => {
|
||||
const out = SetReaction.serialize({ groupId: 1, sequence: 1, code: '128516', isSet: false });
|
||||
const out = SetReaction.serialize({} as any, { groupId: 1, sequence: 1, code: '128516', isSet: false });
|
||||
expect(out.type).toBe(2);
|
||||
});
|
||||
|
||||
it('passes through groupId/sequence/code verbatim', () => {
|
||||
const out = SetReaction.serialize({ groupId: 999, sequence: 42, code: 'abc', isSet: true });
|
||||
const out = SetReaction.serialize({} as any, { groupId: 999, sequence: 42, code: 'abc', isSet: true });
|
||||
expect(out.groupUin).toBe(999);
|
||||
expect(out.sequence).toBe(42);
|
||||
expect(out.code).toBe('abc');
|
||||
});
|
||||
|
||||
it('always sets field6/field7 to false (deferred behaviour)', () => {
|
||||
const out = SetReaction.serialize({ groupId: 1, sequence: 1, code: 'x', isSet: true });
|
||||
const out = SetReaction.serialize({} as any, { groupId: 1, sequence: 1, code: 'x', isSet: true });
|
||||
expect(out.field6).toBe(false);
|
||||
expect(out.field7).toBe(false);
|
||||
});
|
||||
@@ -58,7 +58,7 @@ describe('SetReaction namespace', () => {
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('always returns void regardless of body content', () => {
|
||||
expect(SetReaction.deserialize({})).toBeUndefined();
|
||||
expect(SetReaction.deserialize({} as any, {})).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -22,14 +22,14 @@ describe('GetPskey namespace', () => {
|
||||
|
||||
describe('serialize', () => {
|
||||
it('passes the domainList through verbatim', () => {
|
||||
const out = GetPskey.serialize({ domainList: ['qun.qq.com', 'qzone.qq.com'] });
|
||||
const out = GetPskey.serialize({} as any, { domainList: ['qun.qq.com', 'qzone.qq.com'] });
|
||||
expect(out.domainList).toEqual(['qun.qq.com', 'qzone.qq.com']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('builds a Map from server pskeyItems', () => {
|
||||
const { domainPskeyMap } = GetPskey.deserialize({
|
||||
const { domainPskeyMap } = GetPskey.deserialize({} as any, {
|
||||
pskeyItems: [
|
||||
{ domain: 'qun.qq.com', pskey: 'pskey-qun' },
|
||||
{ domain: 'qzone.qq.com', pskey: 'pskey-qzone' },
|
||||
@@ -40,7 +40,7 @@ describe('GetPskey namespace', () => {
|
||||
});
|
||||
|
||||
it('drops entries with missing domain or pskey', () => {
|
||||
const { domainPskeyMap } = GetPskey.deserialize({
|
||||
const { domainPskeyMap } = GetPskey.deserialize({} as any, {
|
||||
pskeyItems: [
|
||||
{ domain: 'qun.qq.com', pskey: 'ok' },
|
||||
{ domain: 'missing-pskey.com' },
|
||||
@@ -52,7 +52,7 @@ describe('GetPskey namespace', () => {
|
||||
});
|
||||
|
||||
it('returns empty Map when pskeyItems is absent', () => {
|
||||
const { domainPskeyMap } = GetPskey.deserialize({});
|
||||
const { domainPskeyMap } = GetPskey.deserialize({} as any, {});
|
||||
expect(domainPskeyMap.size).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user