Skip to content

Commit

Permalink
feat: get_group_list, get_friend_list no_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuchen committed May 1, 2024
1 parent c3781ca commit 18b7df9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/onebot11/action/group/GetGroupList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { Group } from '@/core/entities';
import { log } from '@/common/utils/log';

interface Payload {
no_cache: boolean;
no_cache: boolean | string;
}

class GetGroupList extends BaseAction<Payload, OB11Group[]> {
actionName = ActionName.GetGroupList;

protected async _handle(payload: Payload) {
let groupList: Group[] = Array.from(groups.values());
if (groupList.length === 0 || payload?.no_cache === true) {
if (groupList.length === 0 || payload?.no_cache === true || payload?.no_cache === 'true') {
groupList = await NTQQGroupApi.getGroups(true);
// log('get groups', groups);
}
Expand Down
21 changes: 17 additions & 4 deletions src/onebot11/action/user/GetFriendList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ import { OB11Constructor } from '../../constructor';
import { friends } from '@/core/data';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQFriendApi } from '@/core';


class GetFriendList extends BaseAction<null, OB11User[]> {
interface Payload{
no_cache: boolean | string
}

export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
actionName = ActionName.GetFriendList;

protected async _handle(payload: null) {
protected async _handle(payload: Payload) {
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()));
}
}

export default GetFriendList;

0 comments on commit 18b7df9

Please sign in to comment.