Skip to content

Commit c5c354f

Browse files
committed
fix_and_add_name_to_find_chats_and_paginate_get_contacts_and_get_chats
1 parent 427c994 commit c5c354f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,8 @@ export class BaileysStartupService extends ChannelStartupService {
11861186
existingChat &&
11871187
received.pushName &&
11881188
existingChat.name !== received.pushName &&
1189-
received.pushName.trim().length > 0
1189+
received.pushName.trim().length > 0 &&
1190+
!received.key.remoteJid.includes('@g.us')
11901191
) {
11911192
this.sendDataWebhook(Events.CHATS_UPSERT, [{ ...existingChat, name: received.pushName }]);
11921193
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {

src/api/services/channel.service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,14 @@ export class ChannelStartupService {
503503
where['remoteJid'] = remoteJid;
504504
}
505505

506-
return await this.prismaRepository.contact.findMany({
506+
const contactFindManyArgs: Prisma.ContactFindManyArgs = {
507507
where,
508-
});
508+
};
509+
510+
if (query.offset) contactFindManyArgs.take = query.offset;
511+
if (query.page) contactFindManyArgs.skip = query.offset * ((query.page as number) - 1);
512+
513+
return await this.prismaRepository.contact.findMany(contactFindManyArgs);
509514
}
510515

511516
public cleanMessageData(message: any) {
@@ -674,6 +679,13 @@ export class ChannelStartupService {
674679
: createJid(query.where?.remoteJid)
675680
: null;
676681

682+
const limit =
683+
query.offset && !query.page
684+
? Prisma.sql` LIMIT ${query.offset}`
685+
: query.offset && query.page
686+
? Prisma.sql` LIMIT ${query.offset} OFFSET ${((query.page as number) - 1) * query.offset}`
687+
: Prisma.sql``;
688+
677689
const where = {
678690
instanceId: this.instanceId,
679691
};
@@ -700,6 +712,7 @@ export class ChannelStartupService {
700712
to_timestamp("Message"."messageTimestamp"::double precision),
701713
"Contact"."updatedAt"
702714
) as "updatedAt",
715+
"Chat"."name" as "chatName",
703716
"Chat"."createdAt" as "windowStart",
704717
"Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires",
705718
CASE
@@ -730,6 +743,7 @@ export class ChannelStartupService {
730743
ORDER BY
731744
"Contact"."remoteJid",
732745
"Message"."messageTimestamp" DESC
746+
${limit}
733747
)
734748
SELECT * FROM rankedMessages
735749
ORDER BY "updatedAt" DESC NULLS LAST;
@@ -758,6 +772,7 @@ export class ChannelStartupService {
758772
id: contact.id,
759773
remoteJid: contact.remoteJid,
760774
pushName: contact.pushName,
775+
chatName: contact.chatName,
761776
profilePicUrl: contact.profilePicUrl,
762777
updatedAt: contact.updatedAt,
763778
windowStart: contact.windowStart,

0 commit comments

Comments
 (0)