From 26d7533e0f5800fdff865ab2f2ad7692917e1076 Mon Sep 17 00:00:00 2001 From: Shxiao Date: Tue, 29 Sep 2026 16:18:10 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20get=5Ffriend=5Fmsg=5Fhistory=20=E6=9C=AA?= =?UTF-8?q?=E9=80=8F=E4=BC=A0=20quick=5Freply=20=E5=8F=82=E6=95=B0=20(#207?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit payload schema 声明了 quick_reply,但 _handle 调用 parseMessage 时 没有传入,字段被静默忽略;与 get_group_msg_history 行为不一致。 将 payload.quick_reply 作为第 5 个参数透传,并补充回归测试。 --- .../action/go-cqhttp/GetFriendMsgHistory.ts | 2 +- .../getFriendMsgHistoryQuickReply.test.ts | 89 +++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 packages/napcat-test/getFriendMsgHistoryQuickReply.test.ts diff --git a/packages/napcat-onebot/action/go-cqhttp/GetFriendMsgHistory.ts b/packages/napcat-onebot/action/go-cqhttp/GetFriendMsgHistory.ts index dc38a3422..feb2218fb 100644 --- a/packages/napcat-onebot/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/packages/napcat-onebot/action/go-cqhttp/GetFriendMsgHistory.ts @@ -55,7 +55,7 @@ export default class GetFriendMsgHistory extends OneBotAction this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat, payload.parse_mult_msg, payload.disable_get_url))) + msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat, payload.parse_mult_msg, payload.disable_get_url, payload.quick_reply))) ).filter((msg): msg is OB11Message => msg !== undefined); return { messages: ob11MsgList }; } diff --git a/packages/napcat-test/getFriendMsgHistoryQuickReply.test.ts b/packages/napcat-test/getFriendMsgHistoryQuickReply.test.ts new file mode 100644 index 000000000..a166fa35a --- /dev/null +++ b/packages/napcat-test/getFriendMsgHistoryQuickReply.test.ts @@ -0,0 +1,89 @@ +// StreamBasic must be evaluated before OneBotAction: the two modules import each other, +// and loading OneBotAction first leaves BasicStream extending an uninitialized binding. +import '../napcat-onebot/action/stream/StreamBasic'; +import { afterEach, describe, expect, test, vi } from 'vitest'; +import type { NetworkAdapterConfig } from '../napcat-onebot/config/config'; + +import GetFriendMsgHistory from '../napcat-onebot/action/go-cqhttp/GetFriendMsgHistory'; + +// `GetFriendMsgHistory` imports `napcat-core/types` via the bare package subpath, +// which Node exports resolution cannot map in this workspace (`./*` pattern cannot +// target an extensionless directory). Remap it onto the aliased source tree. +vi.mock('napcat-core/types', async () => await vi.importActual('@/napcat-core/types/index')); +vi.mock('napcat-common/src/message-unique', async () => await vi.importActual('@/napcat-common/src/message-unique')); + +const SAMPLE_MSG = { + msgId: '100', + msgSeq: '1', + chatType: 1, + peerUid: 'friend-uid', + peerUin: '42', + senderUin: '42', + msgTime: '1700000000', + msgRandom: '1', + elements: [], +} as never; + +const TEST_ADAPTER = 'test'; +const TEST_CONFIG = { messagePostFormat: 'array' } as NetworkAdapterConfig; + +function createHistoryAction () { + const parseMessage = vi.fn().mockResolvedValue({ message: [], raw_message: '' }); + const core = { + selfInfo: { uid: 'self-uid', uin: '1' }, + apis: { + UserApi: { getUidByUinV2: vi.fn().mockResolvedValue('friend-uid') }, + FriendApi: { isBuddy: vi.fn().mockResolvedValue(true) }, + MsgApi: { + getAioFirstViewLatestMsgs: vi.fn().mockResolvedValue({ msgList: [SAMPLE_MSG] }), + }, + }, + }; + const obContext = { + apis: { MsgApi: { parseMessage } }, + }; + const action = new GetFriendMsgHistory(obContext as never, core as never); + return { action, parseMessage }; +} + +describe('get_friend_msg_history quick_reply forwarding', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + test('forwards quick_reply: true to parseMessage', async () => { + const { action, parseMessage } = createHistoryAction(); + + await action._handle( + { user_id: '42', count: 20, reverse_order: false, disable_get_url: false, parse_mult_msg: true, quick_reply: true, reverseOrder: false }, + TEST_ADAPTER, + TEST_CONFIG + ); + + expect(parseMessage).toHaveBeenCalledWith( + SAMPLE_MSG, + 'array', + true, + false, + true + ); + }); + + test('forwards quick_reply: false (default) to parseMessage', async () => { + const { action, parseMessage } = createHistoryAction(); + + await action._handle( + { user_id: '42', count: 20, reverse_order: false, disable_get_url: false, parse_mult_msg: true, quick_reply: false, reverseOrder: false }, + TEST_ADAPTER, + TEST_CONFIG + ); + + expect(parseMessage).toHaveBeenCalledWith( + SAMPLE_MSG, + 'array', + true, + false, + false + ); + }); +});