Skip to content

Commit 9c4ee35

Browse files
matheusmartinsInspermatheusmartinsInsper
authored andcommitted
fix_and_add_name_to_find_chats_and_paginate_get_contacts_and_get_chats
1 parent 82ea7bd commit 9c4ee35

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,8 @@ export class BaileysStartupService extends ChannelStartupService {
998998
existingChat &&
999999
received.pushName &&
10001000
existingChat.name !== received.pushName &&
1001-
received.pushName.trim().length > 0
1001+
received.pushName.trim().length > 0 &&
1002+
!received.key.remoteJid.includes('@g.us')
10021003
) {
10031004
this.sendDataWebhook(Events.CHATS_UPSERT, [{ ...existingChat, name: received.pushName }]);
10041005
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
@@ -2371,7 +2372,7 @@ export class BaileysStartupService extends ChannelStartupService {
23712372
const lowerCaseImage = image.toLowerCase();
23722373

23732374
if (lowerCaseImage.includes('.gif')) return true;
2374-
2375+
23752376
if (lowerCaseImage.includes('.webp')) return this.isAnimatedWebp(buffer);
23762377
return false;
23772378
}

src/api/services/channel.service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,14 @@ export class ChannelStartupService {
330330
where['remoteJid'] = remoteJid;
331331
}
332332

333-
return await this.prismaRepository.contact.findMany({
333+
const contactFindManyArgs: Prisma.ContactFindManyArgs = {
334334
where,
335-
});
335+
};
336+
337+
if (query.offset) contactFindManyArgs.take = query.offset;
338+
if (query.page) contactFindManyArgs.skip = query.offset * ((query.page as number) - 1);
339+
340+
return await this.prismaRepository.contact.findMany(contactFindManyArgs);
336341
}
337342

338343
public cleanMessageData(message: any) {
@@ -501,6 +506,13 @@ export class ChannelStartupService {
501506
: createJid(query.where?.remoteJid)
502507
: null;
503508

509+
const limit =
510+
query.offset && !query.page
511+
? Prisma.sql` LIMIT ${query.offset}`
512+
: query.offset && query.page
513+
? Prisma.sql` LIMIT ${query.offset} OFFSET ${((query.page as number) - 1) * query.offset}`
514+
: Prisma.sql``;
515+
504516
const where = {
505517
instanceId: this.instanceId,
506518
};
@@ -527,6 +539,7 @@ export class ChannelStartupService {
527539
to_timestamp("Message"."messageTimestamp"::double precision),
528540
"Contact"."updatedAt"
529541
) as "updatedAt",
542+
"Chat"."name" as "chatName",
530543
"Chat"."createdAt" as "windowStart",
531544
"Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires",
532545
CASE
@@ -557,6 +570,7 @@ export class ChannelStartupService {
557570
ORDER BY
558571
"Contact"."remoteJid",
559572
"Message"."messageTimestamp" DESC
573+
${limit}
560574
)
561575
SELECT * FROM rankedMessages
562576
ORDER BY "updatedAt" DESC NULLS LAST;
@@ -585,6 +599,7 @@ export class ChannelStartupService {
585599
id: contact.id,
586600
remoteJid: contact.remoteJid,
587601
pushName: contact.pushName,
602+
chatName: contact.chatName,
588603
profilePicUrl: contact.profilePicUrl,
589604
updatedAt: contact.updatedAt,
590605
windowStart: contact.windowStart,

0 commit comments

Comments
 (0)