adds filtering option in findChats to return a single conversation

This commit is contained in:
Pedro Howat 2024-10-15 12:59:38 -03:00
parent 33cdcd4959
commit 9b68299e20
2 changed files with 7 additions and 1 deletions

View File

@ -32,13 +32,18 @@ export class KwikController {
skip: number,
sort: any,
messageTimestamp: number,
remoteJid?: string,
) {
const db = configService.get<Database>('DATABASE');
const connection = dbserver.getClient().db(db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api');
const messages = connection.collection('messages');
let match: { owner: string; 'key.remoteJid'?: string } = { owner: instanceName };
if (remoteJid) {
match = { ...match, 'key.remoteJid': remoteJid };
}
const pipeline: Document[] = [
{ $sort: { 'key.remoteJid': -1, messageTimestamp: -1 } },
{ $match: { owner: instanceName } },
{ $match: match },
{
$group: {
_id: '$key.remoteJid',

View File

@ -30,6 +30,7 @@ export class KwikRouter extends RouterBroker {
Number(req.query.skip),
req.query.sort,
Number(req.query.messageTimestamp),
req.query.remoteJid ? req.query.remoteJid.toString() : null,
),
});