fix(onebot): restore doubt-request account ids from the native list
get_doubt_friends_add_request was rereading the uid as a number, so uid came back empty and user_id was wrong. Keep the uid string and the account number as separate fields. Fixes #410
This commit is contained in:
2 files changed
+27
-27
No files matched your search
@@ -1,27 +1,17 @@
|
|||||||
// 0xd69_0 — getDoubtBuddyReq: list the "doubtful" friend-add requests
|
// 0xd69_0 — getDoubtBuddyReq: list the "doubtful" friend-add requests
|
||||||
// (可能认识的人 / 被过滤的好友申请). RE'd from QQNT doubt_codec.cc.
|
// (可能认识的人 / 被过滤的好友申请). RE'd from QQNT doubt_codec.cc.
|
||||||
// Request {1:1, 2:{1:num, 2:uk}} (reqId is NOT on the wire). Response body
|
// Request {1:1, 2:{1:num, 2:uk}} (reqId is NOT on the wire). Response body
|
||||||
// holds a repeated item list; we surface the fields NapCat exposes.
|
// holds a repeated item list. DecodePullDoubtReq maps uid as a string and
|
||||||
// READ-only: the string field names (nick/source/msg) are MEDIUM confidence
|
// the account number as a separate integer field; do not reread the uid
|
||||||
// (generic serializer), so a mislabel is cosmetic, never a wire/ban risk.
|
// field as a number. String names (nick/source/msg) are MEDIUM confidence.
|
||||||
// uid (tag1) and reqTime (tag9) are HIGH confidence.
|
|
||||||
|
|
||||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
import type { pb, pb_repeated, uint_32, uint_64 } from '@snowluma/proton';
|
|
||||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||||
import type {
|
import type {
|
||||||
OidbDoubtGetReq, OidbDoubtGetResp,
|
OidbDoubtGetReq, OidbDoubtGetResp,
|
||||||
} from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
|
} from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
|
||||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||||
|
|
||||||
interface OidbDoubtItemAccountOnTag1 {
|
|
||||||
uin?: pb<1, uint_64>;
|
|
||||||
}
|
|
||||||
interface OidbDoubtGetRespAccountOnTag1 {
|
|
||||||
status?: pb<1, uint_32>;
|
|
||||||
body?: pb<2, { list?: pb_repeated<1, OidbDoubtItemAccountOnTag1> }>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DoubtBuddyRequest {
|
export interface DoubtBuddyRequest {
|
||||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||||
/** Opaque uid — pass back as `flag` to set_doubt_friends_add_request. */
|
/** Opaque uid — pass back as `flag` to set_doubt_friends_add_request. */
|
||||||
@@ -63,20 +53,8 @@ export namespace GetDoubtBuddyReq {
|
|||||||
export const encode = (env: OidbBase<OidbDoubtGetReq>): Uint8Array =>
|
export const encode = (env: OidbBase<OidbDoubtGetReq>): Uint8Array =>
|
||||||
protobuf_encode<OidbBase<OidbDoubtGetReq>>(env);
|
protobuf_encode<OidbBase<OidbDoubtGetReq>>(env);
|
||||||
|
|
||||||
export const decode = (bytes: Uint8Array): OidbBase<OidbDoubtGetResp> => {
|
export const decode = (bytes: Uint8Array): OidbBase<OidbDoubtGetResp> =>
|
||||||
const decoded = protobuf_decode<OidbBase<OidbDoubtGetResp>>(bytes);
|
protobuf_decode<OidbBase<OidbDoubtGetResp>>(bytes);
|
||||||
const numeric = protobuf_decode<OidbBase<OidbDoubtGetRespAccountOnTag1>>(bytes);
|
|
||||||
const items = decoded.body?.body?.list ?? [];
|
|
||||||
const numericItems = numeric.body?.body?.list ?? [];
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
|
||||||
const item = items[i];
|
|
||||||
if (!item) continue;
|
|
||||||
if ((item.uin ?? 0n) === 0n && numericItems[i]?.uin) {
|
|
||||||
item.uin = numericItems[i]!.uin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return decoded;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const invoke = (deps: Deps, params: Params): Promise<DoubtBuddyRequest[]> =>
|
export const invoke = (deps: Deps, params: Params): Promise<DoubtBuddyRequest[]> =>
|
||||||
invokeOidb(deps, GetDoubtBuddyReq, params);
|
invokeOidb(deps, GetDoubtBuddyReq, params);
|
||||||
|
|||||||
@@ -59,4 +59,26 @@ describe('GetDoubtBuddyReq namespace', () => {
|
|||||||
it('deserialize returns [] when the body has no list', () => {
|
it('deserialize returns [] when the body has no list', () => {
|
||||||
expect(GetDoubtBuddyReq.deserialize({} as any, { status: 1 })).toEqual([]);
|
expect(GetDoubtBuddyReq.deserialize({} as any, { status: 1 })).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps the uid string and does not reread it as the account number', async () => {
|
||||||
|
const respEnv: OidbBase<OidbDoubtGetResp> = {
|
||||||
|
command: 0xD69, subCommand: 0,
|
||||||
|
body: { status: 1, body: { list: [
|
||||||
|
{ uid: 'u_alice', nick: 'Alice', msg: 'hi', source: 'QQ号查找', reason: 'caution' },
|
||||||
|
] } },
|
||||||
|
};
|
||||||
|
const sender = {
|
||||||
|
sendRawPacket: vi.fn(async () => ({
|
||||||
|
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||||
|
responseData: Buffer.from(protobuf_encode<OidbBase<OidbDoubtGetResp>>(respEnv)),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
const list = await GetDoubtBuddyReq.invoke(sender, { count: 10 });
|
||||||
|
expect(list).toEqual([
|
||||||
|
{
|
||||||
|
uid: 'u_alice', user_id: 0, nick: 'Alice', source: 'QQ号查找',
|
||||||
|
reason: 'caution', msg: 'hi', group_code: '', reqTime: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user