Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,8 @@ export class BaileysStartupService extends ChannelStartupService {
existingChat &&
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 }]);
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
Expand Down
19 changes: 17 additions & 2 deletions src/api/services/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,14 @@ export class ChannelStartupService {
where['remoteJid'] = remoteJid;
}

return await this.prismaRepository.contact.findMany({
const contactFindManyArgs: Prisma.ContactFindManyArgs = {
where,
});
};

if (query.offset) contactFindManyArgs.take = query.offset;
if (query.page) contactFindManyArgs.skip = query.offset * ((query.page as number) - 1);
Comment thread
pedro-php marked this conversation as resolved.
Outdated

return await this.prismaRepository.contact.findMany(contactFindManyArgs);
}

public cleanMessageData(message: any) {
Expand Down Expand Up @@ -674,6 +679,13 @@ export class ChannelStartupService {
: createJid(query.where?.remoteJid)
: 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 = {
instanceId: this.instanceId,
};
Expand All @@ -700,6 +712,7 @@ export class ChannelStartupService {
to_timestamp("Message"."messageTimestamp"::double precision),
"Contact"."updatedAt"
) as "updatedAt",
"Chat"."name" as "chatName",
"Chat"."createdAt" as "windowStart",
"Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires",
CASE
Expand Down Expand Up @@ -730,6 +743,7 @@ export class ChannelStartupService {
ORDER BY
"Contact"."remoteJid",
"Message"."messageTimestamp" DESC
${limit}
)
SELECT * FROM rankedMessages
ORDER BY "updatedAt" DESC NULLS LAST;
Expand Down Expand Up @@ -758,6 +772,7 @@ export class ChannelStartupService {
id: contact.id,
remoteJid: contact.remoteJid,
pushName: contact.pushName,
chatName: contact.chatName,
profilePicUrl: contact.profilePicUrl,
updatedAt: contact.updatedAt,
windowStart: contact.windowStart,
Expand Down