mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 03:56:54 -06:00
Fix and improve fetch chats
This commit is contained in:
parent
96e1802148
commit
10aeeebb53
@ -614,9 +614,7 @@ export class ChannelStartupService {
|
|||||||
: this.createJid(query.where?.remoteJid)
|
: this.createJid(query.where?.remoteJid)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
let result;
|
const result = await this.prismaRepository.$queryRaw`
|
||||||
if (remoteJid) {
|
|
||||||
result = await this.prismaRepository.$queryRaw`
|
|
||||||
SELECT
|
SELECT
|
||||||
"Chat"."id",
|
"Chat"."id",
|
||||||
"Chat"."remoteJid",
|
"Chat"."remoteJid",
|
||||||
@ -625,13 +623,13 @@ export class ChannelStartupService {
|
|||||||
"Chat"."createdAt",
|
"Chat"."createdAt",
|
||||||
"Chat"."updatedAt",
|
"Chat"."updatedAt",
|
||||||
"Contact"."pushName",
|
"Contact"."pushName",
|
||||||
"Contact"."profilePicUrl"
|
"Contact"."profilePicUrl",
|
||||||
"Contact"."unreadMessages"
|
"Contact"."unreadMessages"
|
||||||
FROM "Chat"
|
FROM "Chat"
|
||||||
INNER JOIN "Message" ON "Chat"."remoteJid" = "Message"."key"->>'remoteJid'
|
INNER JOIN "Message" ON "Chat"."remoteJid" = "Message"."key"->>'remoteJid'
|
||||||
LEFT JOIN "Contact" ON "Chat"."remoteJid" = "Contact"."remoteJid"
|
LEFT JOIN "Contact" ON "Chat"."remoteJid" = "Contact"."remoteJid"
|
||||||
WHERE "Chat"."instanceId" = ${this.instanceId}
|
WHERE "Chat"."instanceId" = ${this.instanceId}
|
||||||
AND "Chat"."remoteJid" = ${remoteJid}
|
${remoteJid ? 'AND "Chat"."remoteJid" = ${remoteJid}' : ''}
|
||||||
GROUP BY
|
GROUP BY
|
||||||
"Chat"."id",
|
"Chat"."id",
|
||||||
"Chat"."remoteJid",
|
"Chat"."remoteJid",
|
||||||
@ -644,35 +642,6 @@ export class ChannelStartupService {
|
|||||||
"Contact"."unreadMessages"
|
"Contact"."unreadMessages"
|
||||||
ORDER BY "Chat"."updatedAt" DESC;
|
ORDER BY "Chat"."updatedAt" DESC;
|
||||||
`;
|
`;
|
||||||
} else {
|
|
||||||
result = await this.prismaRepository.$queryRaw`
|
|
||||||
SELECT
|
|
||||||
"Chat"."id",
|
|
||||||
"Chat"."remoteJid",
|
|
||||||
"Chat"."name",
|
|
||||||
"Chat"."labels",
|
|
||||||
"Chat"."createdAt",
|
|
||||||
"Chat"."updatedAt",
|
|
||||||
"Contact"."pushName",
|
|
||||||
"Contact"."profilePicUrl"
|
|
||||||
"Contact"."unreadMessages"
|
|
||||||
FROM "Chat"
|
|
||||||
INNER JOIN "Message" ON "Chat"."remoteJid" = "Message"."key"->>'remoteJid'
|
|
||||||
LEFT JOIN "Contact" ON "Chat"."remoteJid" = "Contact"."remoteJid"
|
|
||||||
WHERE "Chat"."instanceId" = ${this.instanceId}
|
|
||||||
GROUP BY
|
|
||||||
"Chat"."id",
|
|
||||||
"Chat"."remoteJid",
|
|
||||||
"Chat"."name",
|
|
||||||
"Chat"."labels",
|
|
||||||
"Chat"."createdAt",
|
|
||||||
"Chat"."updatedAt",
|
|
||||||
"Contact"."pushName",
|
|
||||||
"Contact"."profilePicUrl"
|
|
||||||
"Contact"."unreadMessages"
|
|
||||||
ORDER BY "Chat"."updatedAt" DESC;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user