Introduce a new way to organise OIDB cmd implementations:
- one TypeScript namespace per (cmd, subcmd) tuple
- the namespace's exported members ARE the OidbCallSpec (structural
typing — no `implements` clause)
- a single invokeOidb() template method drives every call:
envelope build → encode → send → errorCode check → decode →
deserialize transformation
- each namespace declares its own minimal `Deps` capability via
Pick / intersection on BridgeContext (Interface Segregation):
most cmds need only OidbSender (the `sendRawPacket` method)
The facade Api classes (InteractionApi etc.) stay for now, with the
migrated methods reduced to one-line forwarders that hand off to the
namespace. Callers still write `bridge.apis.X.Y(...)`; the OIDB
wire-encoding work just moved to a self-contained file per cmd.
Vertical slice scope: 3 cmds (the reaction line)
- SetReaction (0x9082_1 / _2; dynamic subcmd)
- FetchReactionSummary (0x9084_1)
- GetEmojiLikes (0x9083_1; legacy stub)
Infrastructure:
- new packages/bridge/src/oidb-service.ts:
OidbSender (sendRawPacket-only capability),
OidbCallSpec<TReq, TResp, TParams, TResult>,
invokeOidb(), buildOidbRequest(), parseOidbResponse(), OidbError
- runOidb() refactored to accept OidbSender instead of BridgeContext
(structurally compatible — no caller changes anywhere)
- new OidbEmpty placeholder type in proto-defs/oidb.ts for cmds whose
response carries no body (proton needs a real message interface,
not `void` / `never`)
- empty-body responses substituted with {} in invokeOidb so
deserialize always receives a defined object
Tests (65 in @snowluma/bridge, all green):
- oidb-service.test.ts (20): every helper branch — static + dynamic
subcmd, uinForm flag, error code propagation as OidbError, empty
body substitution, sender failure modes (success=false /
gotResponse=false / both with and without errorMessage),
timeoutMs propagation
- set-reaction.test.ts: const declarations, dynamic subcmd both
ways, type=1/2 boundary on code length, e2e envelope inspection
- fetch-reaction-summary.test.ts: BigInt serialization, catalog-tail
filtering, default emojiId/Type/lastReactionTime
- get-emoji-likes.test.ts: BigInt serialization, default count /
emojiType, base64 cookie round-trip, uin=0 filtering, isLast
computation, e2e
Existing interaction.test.ts moved off the now-bypassed runOidb mock
onto sendRawPacket mock (the new invokeOidb path routes there).
Workspace-wide typecheck: green. Workspace test totals:
proton 99/99, bridge 65/65, core 302/302, onebot 257/257
(1 pre-existing onebot suite failure, network-manager native addon
load — unrelated to this change.)
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
// 0x9084_1 — fetch per-emoji reaction summary on a group message.
|
|
//
|
|
// Server returns the full summary unconditionally; the emoji_id /
|
|
// emoji_type / count fields in the request body are ignored by the
|
|
// summary handler but kept to mirror the working 0x9083_1 request shape
|
|
// (same `Pick` of fields the wire format prefers).
|
|
//
|
|
// "Used" entries carry (lastReactionTime, count, emojiType, emojiId).
|
|
// Catalog-tail entries (available reactions the server suggests but
|
|
// nobody has reacted with) carry only emojiType + emojiId — filtered
|
|
// out here so callers see only the meaningful subset.
|
|
|
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
import type {
|
|
Oidb0x9084Req, Oidb0x9084Resp,
|
|
} from '@snowluma/proto-defs/oidb-actions/base';
|
|
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
|
|
|
export namespace FetchReactionSummary {
|
|
export const command = 0x9084;
|
|
export const subCommand = 1;
|
|
|
|
export interface Params {
|
|
groupId: number;
|
|
sequence: number;
|
|
}
|
|
|
|
export interface ReactionSummaryEntry {
|
|
emojiId: string;
|
|
emojiType: number;
|
|
count: number;
|
|
/** Unix epoch seconds of the most recent reaction. */
|
|
lastReactionTime: number;
|
|
}
|
|
|
|
export type Deps = OidbSender;
|
|
|
|
export const serialize = (p: Params): Oidb0x9084Req => ({
|
|
groupId: BigInt(p.groupId),
|
|
sequence: BigInt(p.sequence),
|
|
emojiId: '',
|
|
emojiType: 0,
|
|
cookie: new Uint8Array(0),
|
|
count: 0,
|
|
field12: 1,
|
|
});
|
|
|
|
export const deserialize = (body: Oidb0x9084Resp): ReactionSummaryEntry[] => {
|
|
const out: ReactionSummaryEntry[] = [];
|
|
for (const e of body.entries ?? []) {
|
|
const count = e.count ?? 0;
|
|
if (count <= 0) continue; // skip catalog-tail entries
|
|
out.push({
|
|
emojiId: e.emojiId ?? '',
|
|
emojiType: e.emojiType ?? 1,
|
|
count,
|
|
lastReactionTime: Number(e.lastReactionTime ?? 0n),
|
|
});
|
|
}
|
|
return out;
|
|
};
|
|
|
|
export const encode = (env: OidbBase<Oidb0x9084Req>): Uint8Array =>
|
|
protobuf_encode<OidbBase<Oidb0x9084Req>>(env);
|
|
|
|
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x9084Resp> =>
|
|
protobuf_decode<OidbBase<Oidb0x9084Resp>>(bytes);
|
|
|
|
export const invoke = (deps: Deps, params: Params): Promise<ReactionSummaryEntry[]> =>
|
|
invokeOidb(deps, FetchReactionSummary, params);
|
|
}
|