fix(protocol): restore unidirectional friend lookup

Read the unidirectional friend list correctly and preserve service errors instead of returning an empty list for rejected requests.

Fixes #608
This commit is contained in:
DrSmoothl committed 2026-10-31 18:28:05 +08:00
1 parent bd14b0a98e
commit 26639ffef7
4 files changed
+123 -99

No files matched your search

@@ -1,28 +1,22 @@
// 0xE17_0 — fetch the unidirectional friend block list. Wire name is
// non-standard (`MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0`) — uses
// the `wireName` override to bypass the default
// `OidbSvcTrpcTcp.0xNNNN_N` scheme.
//
// Request and response carry a JSON-encoded string in a single
// protobuf field, so the namespace's `serialize` / `deserialize` do
// the JSON marshalling.
import type { OidbBase } from '@snowluma/proto-defs/oidb';
// This service uses its own JSON transport rather than the standard OIDB envelope.
import type { Oidb0xe17Req, Oidb0xe17Resp } from '@snowluma/proto-defs/oidb-actions/base';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { BridgeContext } from '../../bridge-context';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import { OidbError, type OidbSender } from '../../oidb-service';
import { requirePacketResponse } from '../../msg-push/packet-response';
export interface UnidirectionalFriendEntry {
[key: string]: import('@snowluma/common/json').JsonValue;
}
function isObject(value: unknown): value is UnidirectionalFriendEntry {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}
export namespace GetUnidirectionalFriendList {
export const command = 0xe17;
export const subCommand = 0;
/** Wire name override — this cmd lives outside the standard
* `OidbSvcTrpcTcp.0xNNNN_N` namespace. */
export const wireName = (): string => 'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0';
export interface Params {}
@@ -36,26 +30,45 @@ export namespace GetUnidirectionalFriendList {
uint32_req_num: 99,
bytes_cookies: '',
};
return { jsonBody: JSON.stringify(reqObj) };
return { subCommand, jsonBody: JSON.stringify(reqObj) };
};
export const deserialize = (_ctx: Deps, body: Oidb0xe17Resp): UnidirectionalFriendEntry[] => {
if (body.errorCode) {
throw new OidbError(body.errorCode, body.errorMessage ?? '', command, subCommand);
}
if (!body || !body.jsonBody) {
throw new Error('get unidirectional friend list empty');
}
const parsed = JSON.parse(body.jsonBody) as {
rpt_block_list?: UnidirectionalFriendEntry[];
};
return parsed.rpt_block_list || [];
const parsed: unknown = JSON.parse(body.jsonBody);
if (!isObject(parsed)) {
throw new Error('get unidirectional friend list invalid response');
}
if (parsed.ActionStatus !== 'OK' || parsed.ErrorCode !== 0) {
const code = typeof parsed.ErrorCode === 'number' ? parsed.ErrorCode : 'missing';
const message = typeof parsed.ErrorInfo === 'string' ? parsed.ErrorInfo : '';
throw new Error(`get unidirectional friend list failed: ${code} ${message}`.trim());
}
if (!Array.isArray(parsed.rpt_block_list) || !parsed.rpt_block_list.every(isObject)) {
throw new Error('get unidirectional friend list invalid block list');
}
return parsed.rpt_block_list;
};
export const encode = (env: OidbBase<Oidb0xe17Req>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0xe17Req>>(env);
export const encode = (request: Oidb0xe17Req): Uint8Array =>
protobuf_encode<Oidb0xe17Req>(request);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xe17Resp> =>
protobuf_decode<OidbBase<Oidb0xe17Resp>>(bytes);
export const decode = (bytes: Uint8Array): Oidb0xe17Resp =>
protobuf_decode<Oidb0xe17Resp>(bytes);
export const invoke = (deps: Deps): Promise<UnidirectionalFriendEntry[]> =>
invokeOidb(deps, GetUnidirectionalFriendList, {});
export const invoke = async (deps: Deps): Promise<UnidirectionalFriendEntry[]> => {
const result = await deps.sendRawPacket(wireName(), encode(serialize(deps, {})));
return deserialize(deps, decode(requirePacketResponse(result, wireName())));
};
}