mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 18:38:39 -06:00
adds filtering option in findChats to return a single conversation
This commit is contained in:
parent
33cdcd4959
commit
9b68299e20
@ -32,13 +32,18 @@ export class KwikController {
|
|||||||
skip: number,
|
skip: number,
|
||||||
sort: any,
|
sort: any,
|
||||||
messageTimestamp: number,
|
messageTimestamp: number,
|
||||||
|
remoteJid?: string,
|
||||||
) {
|
) {
|
||||||
const db = configService.get<Database>('DATABASE');
|
const db = configService.get<Database>('DATABASE');
|
||||||
const connection = dbserver.getClient().db(db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api');
|
const connection = dbserver.getClient().db(db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api');
|
||||||
const messages = connection.collection('messages');
|
const messages = connection.collection('messages');
|
||||||
|
let match: { owner: string; 'key.remoteJid'?: string } = { owner: instanceName };
|
||||||
|
if (remoteJid) {
|
||||||
|
match = { ...match, 'key.remoteJid': remoteJid };
|
||||||
|
}
|
||||||
const pipeline: Document[] = [
|
const pipeline: Document[] = [
|
||||||
{ $sort: { 'key.remoteJid': -1, messageTimestamp: -1 } },
|
{ $sort: { 'key.remoteJid': -1, messageTimestamp: -1 } },
|
||||||
{ $match: { owner: instanceName } },
|
{ $match: match },
|
||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
_id: '$key.remoteJid',
|
_id: '$key.remoteJid',
|
||||||
|
@ -30,6 +30,7 @@ export class KwikRouter extends RouterBroker {
|
|||||||
Number(req.query.skip),
|
Number(req.query.skip),
|
||||||
req.query.sort,
|
req.query.sort,
|
||||||
Number(req.query.messageTimestamp),
|
Number(req.query.messageTimestamp),
|
||||||
|
req.query.remoteJid ? req.query.remoteJid.toString() : null,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user