chore Api

This commit is contained in:
手瓜一十雪
2024-08-09 18:17:45 +08:00
parent 3f49b81a4d
commit 1c4bb3398b
5 changed files with 40 additions and 45 deletions

View File

@@ -1,12 +1,8 @@
import { OB11User } from '../../types';
import { OB11Constructor } from '../../constructor';
import { friends } from '@/core/data';
import { OB11Constructor } from '../../helper/data';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQFriendApi } from '@/core';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { requireMinNTQQBuild } from '@/common/utils/QQBasicInfo';
// no_cache get时传字符串
const SchemaData = {
@@ -21,20 +17,8 @@ export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
actionName = ActionName.GetFriendList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
if (requireMinNTQQBuild('26702')) {
//全新逻辑
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true'));
}
if (friends.size === 0 || payload?.no_cache === true || payload?.no_cache === 'true') {
const _friends = await NTQQFriendApi.getFriends(true);
// log('强制刷新好友列表,结果: ', _friends)
if (_friends.length > 0) {
friends.clear();
for (const friend of _friends) {
friends.set(friend.uid, friend);
}
}
}
return OB11Constructor.friends(Array.from(friends.values()));
}
}

View File

@@ -2,8 +2,7 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQMsgApi, NTQQUserApi } from '@/core';
import { OB11Constructor } from '@/onebot11/constructor';
import { OB11Constructor } from '@/onebot/helper/data';
const SchemaData = {
type: 'object',
@@ -18,12 +17,14 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
actionName = ActionName.GetRecentContact;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
const ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString()));
const data = await Promise.all(ret.info.changedList.map(async (t) => {
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
if (FastMsg.msgList.length > 0) {
//扩展ret.info.changedList
const lastestMsg = await OB11Constructor.message(FastMsg.msgList[0]);
const lastestMsg = await OB11Constructor.message(this.CoreContext, FastMsg.msgList[0], "array");
return {
lastestMsg: lastestMsg,
peerUin: t.peerUin,