mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 04:02:54 -06:00
Merge pull request #1334 from adaptwebtech/fix_and_add_name_to_find_chats_and_paginate_get_contacts_and_get_chats
Corrigindo um bug no endpoint de findChats e permitindo paginação nos endpoints de findChats e findContacts
This commit is contained in:
commit
b89f1144b4
@ -1223,7 +1223,8 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
existingChat &&
|
existingChat &&
|
||||||
received.pushName &&
|
received.pushName &&
|
||||||
existingChat.name !== received.pushName &&
|
existingChat.name !== received.pushName &&
|
||||||
received.pushName.trim().length > 0
|
received.pushName.trim().length > 0 &&
|
||||||
|
!received.key.remoteJid.includes('@g.us')
|
||||||
) {
|
) {
|
||||||
this.sendDataWebhook(Events.CHATS_UPSERT, [{ ...existingChat, name: received.pushName }]);
|
this.sendDataWebhook(Events.CHATS_UPSERT, [{ ...existingChat, name: received.pushName }]);
|
||||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
|
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
|
||||||
|
@ -503,9 +503,17 @@ export class ChannelStartupService {
|
|||||||
where['remoteJid'] = remoteJid;
|
where['remoteJid'] = remoteJid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.prismaRepository.contact.findMany({
|
const contactFindManyArgs: Prisma.ContactFindManyArgs = {
|
||||||
where,
|
where,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (query.offset) contactFindManyArgs.take = query.offset;
|
||||||
|
if (query.page) {
|
||||||
|
const validPage = Math.max(query.page as number, 1);
|
||||||
|
contactFindManyArgs.skip = query.offset * (validPage - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.prismaRepository.contact.findMany(contactFindManyArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public cleanMessageData(message: any) {
|
public cleanMessageData(message: any) {
|
||||||
@ -674,6 +682,13 @@ export class ChannelStartupService {
|
|||||||
: createJid(query.where?.remoteJid)
|
: createJid(query.where?.remoteJid)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
const limit =
|
||||||
|
query.offset && !query.page
|
||||||
|
? Prisma.sql` LIMIT ${query.offset}`
|
||||||
|
: query.offset && query.page
|
||||||
|
? Prisma.sql` LIMIT ${query.offset} OFFSET ${((query.page as number) - 1) * query.offset}`
|
||||||
|
: Prisma.sql``;
|
||||||
|
|
||||||
const where = {
|
const where = {
|
||||||
instanceId: this.instanceId,
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
@ -700,6 +715,7 @@ export class ChannelStartupService {
|
|||||||
to_timestamp("Message"."messageTimestamp"::double precision),
|
to_timestamp("Message"."messageTimestamp"::double precision),
|
||||||
"Contact"."updatedAt"
|
"Contact"."updatedAt"
|
||||||
) as "updatedAt",
|
) as "updatedAt",
|
||||||
|
"Chat"."name" as "chatName",
|
||||||
"Chat"."createdAt" as "windowStart",
|
"Chat"."createdAt" as "windowStart",
|
||||||
"Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires",
|
"Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires",
|
||||||
CASE
|
CASE
|
||||||
@ -730,6 +746,7 @@ export class ChannelStartupService {
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
"Contact"."remoteJid",
|
"Contact"."remoteJid",
|
||||||
"Message"."messageTimestamp" DESC
|
"Message"."messageTimestamp" DESC
|
||||||
|
${limit}
|
||||||
)
|
)
|
||||||
SELECT * FROM rankedMessages
|
SELECT * FROM rankedMessages
|
||||||
ORDER BY "updatedAt" DESC NULLS LAST;
|
ORDER BY "updatedAt" DESC NULLS LAST;
|
||||||
@ -758,6 +775,7 @@ export class ChannelStartupService {
|
|||||||
id: contact.id,
|
id: contact.id,
|
||||||
remoteJid: contact.remoteJid,
|
remoteJid: contact.remoteJid,
|
||||||
pushName: contact.pushName,
|
pushName: contact.pushName,
|
||||||
|
chatName: contact.chatName,
|
||||||
profilePicUrl: contact.profilePicUrl,
|
profilePicUrl: contact.profilePicUrl,
|
||||||
updatedAt: contact.updatedAt,
|
updatedAt: contact.updatedAt,
|
||||||
windowStart: contact.windowStart,
|
windowStart: contact.windowStart,
|
||||||
|
Loading…
Reference in New Issue
Block a user