fix: 移出精华消息时 msg_random 与 msg_seq 参数顺序错误 (#2064)
This commit is contained in:
1 parent
2049e64260
commit
46e505f4ba
2 files changed
+54
-1
No files matched your search
@@ -48,7 +48,7 @@ export default class DelEssenceMsg extends OneBotAction<PayloadType, ReturnType>
|
|||||||
const data = this.core.apis.GroupApi.essenceLRU.getValue(+payload.message_id);
|
const data = this.core.apis.GroupApi.essenceLRU.getValue(+payload.message_id);
|
||||||
if (!data) throw new Error('消息不存在');
|
if (!data) throw new Error('消息不存在');
|
||||||
const { msg_seq, msg_random, group_id } = JSON.parse(data) as { msg_seq: string, msg_random: string, group_id: string; };
|
const { msg_seq, msg_random, group_id } = JSON.parse(data) as { msg_seq: string, msg_random: string, group_id: string; };
|
||||||
return await this.core.apis.GroupApi.removeGroupEssenceBySeq(group_id, msg_seq, msg_random);
|
return await this.core.apis.GroupApi.removeGroupEssenceBySeq(group_id, msg_random, msg_seq);
|
||||||
}
|
}
|
||||||
return await this.core.apis.GroupApi.removeGroupEssence(
|
return await this.core.apis.GroupApi.removeGroupEssence(
|
||||||
msg.Peer.peerUid,
|
msg.Peer.peerUid,
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// 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 { MessageUnique } from '../napcat-common/src/message-unique';
|
||||||
|
import DelEssenceMsg from '../napcat-onebot/action/group/DelEssenceMsg';
|
||||||
|
|
||||||
|
function createAction (essenceLRUValue: string | undefined) {
|
||||||
|
const removeGroupEssenceBySeq = vi.fn().mockResolvedValue({ result: 0 });
|
||||||
|
const action = new DelEssenceMsg(
|
||||||
|
undefined as never,
|
||||||
|
{
|
||||||
|
apis: {
|
||||||
|
GroupApi: {
|
||||||
|
essenceLRU: { getValue: vi.fn().mockReturnValue(essenceLRUValue) },
|
||||||
|
removeGroupEssenceBySeq,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as never
|
||||||
|
);
|
||||||
|
return { action, removeGroupEssenceBySeq };
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('delete_essence_msg argument order', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('passes msg_random before msg_seq for explicitly supplied parameters', async () => {
|
||||||
|
const { action, removeGroupEssenceBySeq } = createAction(undefined);
|
||||||
|
|
||||||
|
await action._handle({ group_id: '33', msg_seq: '11', msg_random: '22' });
|
||||||
|
|
||||||
|
// GroupApi.removeGroupEssenceBySeq(groupCode, msgRandom, msgSeq)
|
||||||
|
expect(removeGroupEssenceBySeq).toHaveBeenCalledWith('33', '22', '11');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('passes msg_random before msg_seq for the essence LRU fallback', async () => {
|
||||||
|
// get_essence_msg_list stores this payload under a synthetic message_id when the
|
||||||
|
// original message can no longer be resolved from the local message cache.
|
||||||
|
const { action, removeGroupEssenceBySeq } = createAction(JSON.stringify({
|
||||||
|
msg_seq: '11',
|
||||||
|
msg_random: '22',
|
||||||
|
group_id: '33',
|
||||||
|
}));
|
||||||
|
vi.spyOn(MessageUnique, 'getMsgIdAndPeerByShortId').mockReturnValue(undefined);
|
||||||
|
|
||||||
|
await action._handle({ message_id: 12345 });
|
||||||
|
|
||||||
|
// GroupApi.removeGroupEssenceBySeq(groupCode, msgRandom, msgSeq)
|
||||||
|
expect(removeGroupEssenceBySeq).toHaveBeenCalledWith('33', '22', '11');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user