mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 10:28:38 -06:00
adds filtering of old messages in fetchChats endpoint
This commit is contained in:
parent
a26e062936
commit
58ef0cb3ac
@ -14,7 +14,13 @@ export class KwikController {
|
||||
private isTextMessage(messageType: any) {
|
||||
return ['senderKeyDistributionMessage', 'conversation', 'extendedTextMessage'].includes(messageType);
|
||||
}
|
||||
public async fetchChats({ instanceName }: InstanceDto, limit: number, skip: number, sort: any) {
|
||||
public async fetchChats(
|
||||
{ instanceName }: InstanceDto,
|
||||
limit: number,
|
||||
skip: number,
|
||||
sort: any,
|
||||
messageTimestamp: number,
|
||||
) {
|
||||
const db = configService.get<Database>('DATABASE');
|
||||
const connection = dbserver.getClient().db(db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api');
|
||||
const messages = connection.collection('messages');
|
||||
@ -30,7 +36,7 @@ export class KwikController {
|
||||
fromMe: { $first: '$key.fromMe' },
|
||||
},
|
||||
},
|
||||
{ $match: { owner: instanceName } },
|
||||
{ $match: { owner: instanceName, lastAllMsgTimestamp: { $gte: messageTimestamp } } },
|
||||
{ $sort: { lastAllMsgTimestamp: -1 } },
|
||||
];
|
||||
|
||||
@ -120,7 +126,6 @@ export class KwikController {
|
||||
const messageUpdate = connection.collection('messageUpdate');
|
||||
const chats = connection.collection('chats');
|
||||
const contacts = connection.collection('contacts');
|
||||
logger.error('DELETEME: Deleting messages for instance ' + instanceName);
|
||||
const x = messages.deleteMany({ owner: instanceName });
|
||||
logger.error(x);
|
||||
const y = chats.deleteMany({ owner: instanceName });
|
||||
|
@ -24,7 +24,13 @@ export class KwikRouter extends RouterBroker {
|
||||
schema: null,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) =>
|
||||
kwikController.fetchChats(instance, Number(req.query.limit), Number(req.query.skip), req.query.sort),
|
||||
kwikController.fetchChats(
|
||||
instance,
|
||||
Number(req.query.limit),
|
||||
Number(req.query.skip),
|
||||
req.query.sort,
|
||||
Number(req.query.messageTimestamp),
|
||||
),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
|
Loading…
Reference in New Issue
Block a user