feat: GetSendTime

This commit is contained in:
手瓜一十雪 2024-07-24 17:49:03 +08:00
parent 0a112d15e0
commit 6affd0eb68
3 changed files with 131 additions and 17 deletions

View File

@ -11,6 +11,14 @@ const __dirname = dirname(__filename);
export function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
export function PromiseTimer<T>(promise: Promise<T>, ms: number): Promise<T | undefined> {
return Promise.race([
promise,
new Promise<T>((_, reject) =>
setTimeout(() => reject(undefined), ms)
),
]).catch((error) => error);
}
export function getMd5(s: string) {

View File

@ -1,11 +1,12 @@
import { GroupMember, GroupRequestOperateTypes, GroupMemberRole, GroupNotify, Group, MemberExtSourceType, GroupNotifyTypes } from '../entities';
import { GroupMember, GroupRequestOperateTypes, GroupMemberRole, GroupNotify, Group, MemberExtSourceType, GroupNotifyTypes, ChatType } from '../entities';
import { GeneralCallResult, NTQQUserApi, napCatCore } from '@/core';
import { NTEventDispatch } from '@/common/utils/EventTask';
import { logDebug } from '@/common/utils/log';
// console.log(process.pid);
import { log } from '@/common/utils/log';
import { groupMembers } from '../data';
import { PromiseTimer } from '@/common/utils/helper';
// setTimeout(async () => {
// console.log(JSON.stringify(await NTQQGroupApi.getMemberExtInfo(), null, 2));
// }, 20000);
// console.log(JSON.stringify(await NTQQGroupApi.getGroupMemberLastestSendTime('726067488'), null, 2));
// }, 21000);
export class NTQQGroupApi {
static async setGroupAvatar(gc: string, filePath: string) {
return napCatCore.session.getGroupService().setHeader(gc, filePath);
@ -23,6 +24,77 @@ export class NTQQGroupApi {
);
return groupList;
}
static async getGroupMemberLastestSendTime(GroupCode: string) {
async function getdata(uid: string) {
let NTRet = await NTQQGroupApi.getLastestMsgByUids(GroupCode, [uid]);
if (NTRet.result != 0 && NTRet.msgList.length < 1) {
return undefined;
}
return { sendUin: NTRet.msgList[0].senderUin, sendTime: NTRet.msgList[0].msgTime }
}
let currentGroupMembers = groupMembers.get(GroupCode);
let PromiseData: Promise<({
sendUin: string;
sendTime: string;
} | undefined) | undefined>[] = [];
let ret: Map<string, string> = new Map();
if (!currentGroupMembers) {
return ret;
}
for (let member of currentGroupMembers.values()) {
PromiseData.push(PromiseTimer(getdata(member.uid), 2500));
}
let allRet = await Promise.all(PromiseData);
for (let PromiseDo of allRet) {
if (PromiseDo) {
ret.set(PromiseDo.sendUin, PromiseDo.sendTime)
}
}
return ret;
}
static async getLastestMsgByUids(GroupCode: string, uids: string[]) {
let ret = await napCatCore.session.getMsgService().queryMsgsWithFilterEx('0', '0', '0', {
chatInfo: {
peerUid: GroupCode,
chatType: ChatType.group,
},
filterMsgType: [],
filterSendersUid: uids,
filterMsgToTime: '0',
filterMsgFromTime: '0',
isReverseOrder: false,
isIncludeCurrent: true,
pageLimit: 1,
});
return ret;
}
static async getLastestMsg(GroupCode: string, uins: string[]) {
let uids: Array<string> = [];
for (let uin of uins) {
try {
let uid = await NTQQUserApi.getUidByUin(uin)
if (uid) {
uids.push(uid);
}
} catch (error) {
log("getLastestMsg--->", error)
}
}
let ret = await napCatCore.session.getMsgService().queryMsgsWithFilterEx('0', '0', '0', {
chatInfo: {
peerUid: GroupCode,
chatType: ChatType.group,
},
filterMsgType: [],
filterSendersUid: uids,
filterMsgToTime: '0',
filterMsgFromTime: '0',
isReverseOrder: false,
isIncludeCurrent: true,
pageLimit: 1,
});
return ret;
}
static async getGroupRecommendContactArkJson(GroupCode: string) {
return napCatCore.session.getGroupService().getGroupRecommendContactArkJson(GroupCode);
}

View File

@ -186,27 +186,48 @@ export interface NodeIKernelMsgService {
getSourceOfReplyMsgByClientSeqAndTime(...args: unknown[]): unknown;
getMsgsByTypeFilter(peer: Peer, msgId: string, cnt: unknown, queryOrder: boolean, typeFilters: unknown): unknown;
getMsgsByTypeFilter(peer: Peer, msgId: string, cnt: unknown, queryOrder: boolean, typeFilter: { type: number, subtype: Array<number> }): unknown;
getMsgsByTypeFilters(...args: unknown[]): unknown;
getMsgsByTypeFilters(peer: Peer, msgId: string, cnt: unknown, queryOrder: boolean, typeFilters: Array<{ type: number, subtype: Array<number> }>): unknown;
getMsgWithAbstractByFilterParam(...args: unknown[]): unknown;
queryMsgsWithFilter(...args: unknown[]): unknown;
/**
* @deprecated 使
* 使2
*
*
* Promise
*
* @param MsgId ID
* @param MsgTime
* @param param
* @param param.chatInfo ID
* @param param.filterMsgType
* @param param.filterSendersUid ID数组
* @param param.filterMsgFromTime
* @param param.filterMsgToTime
* @param param.pageLimit
* @param param.isReverseOrder
* @param param.isIncludeCurrent
* @returns Promise
*/
queryMsgsWithFilterVer2(MsgId: string, MsgTime: string, param: {
chatInfo: {
chatType: number,
peerUid: string
},
filterMsgType: [],
filterSendersUid: [],
filterSendersUid: Array<string>,
filterMsgFromTime: string,
filterMsgToTime: string,
pageLimit: number,
isReverseOrder: boolean,
isIncludeCurrent: boolean
}): Promise<unknown>;
// this.chatType = i2;
// this.peerUid = str;
@ -228,14 +249,15 @@ export interface NodeIKernelMsgService {
peerUid: string
},
filterMsgType: [],
filterSendersUid: [],
filterSendersUid: string[],
filterMsgFromTime: string,
filterMsgToTime: string,
pageLimit: number,
isReverseOrder: boolean,
isIncludeCurrent: boolean
}): Promise<unknown>;
}): Promise<GeneralCallResult & {
msgList: RawMessage[]
}>;
//queryMsgsWithFilterEx(this.$msgId, this.$msgTime, this.$msgSeq, this.$param)
queryFileMsgsDesktop(...args: unknown[]): unknown;
@ -261,7 +283,19 @@ export interface NodeIKernelMsgService {
queryTroopEmoticonMsgs(...args: unknown[]): unknown;
queryMsgsAndAbstractsWithFilter(...args: unknown[]): unknown;
queryMsgsAndAbstractsWithFilter(msgId: string, msgTime: string, megSeq: string, param: {
chatInfo: {
chatType: number,
peerUid: string
},
filterMsgType: [],
filterSendersUid: [],
filterMsgFromTime: string,
filterMsgToTime: string,
pageLimit: number,
isReverseOrder: boolean,
isIncludeCurrent: boolean
}): unknown;
setFocusOnGuild(...args: unknown[]): unknown;