@@ -503,9 +503,17 @@ 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 ) {
512+ const validPage = Math . max ( query . page as number , 1 ) ;
513+ contactFindManyArgs . skip = query . offset * ( validPage - 1 ) ;
514+ }
515+
516+ return await this . prismaRepository . contact . findMany ( contactFindManyArgs ) ;
509517 }
510518
511519 public cleanMessageData ( message : any ) {
@@ -674,6 +682,13 @@ export class ChannelStartupService {
674682 : createJid ( query . where ?. remoteJid )
675683 : null ;
676684
685+ const limit =
686+ query . offset && ! query . page
687+ ? Prisma . sql ` LIMIT ${ query . offset } `
688+ : query . offset && query . page
689+ ? Prisma . sql ` LIMIT ${ query . offset } OFFSET ${ ( ( query . page as number ) - 1 ) * query . offset } `
690+ : Prisma . sql `` ;
691+
677692 const where = {
678693 instanceId : this . instanceId ,
679694 } ;
@@ -700,6 +715,7 @@ export class ChannelStartupService {
700715 to_timestamp("Message"."messageTimestamp"::double precision),
701716 "Contact"."updatedAt"
702717 ) as "updatedAt",
718+ "Chat"."name" as "chatName",
703719 "Chat"."createdAt" as "windowStart",
704720 "Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires",
705721 CASE
@@ -730,6 +746,7 @@ export class ChannelStartupService {
730746 ORDER BY
731747 "Contact"."remoteJid",
732748 "Message"."messageTimestamp" DESC
749+ ${ limit }
733750 )
734751 SELECT * FROM rankedMessages
735752 ORDER BY "updatedAt" DESC NULLS LAST;
@@ -758,6 +775,7 @@ export class ChannelStartupService {
758775 id : contact . id ,
759776 remoteJid : contact . remoteJid ,
760777 pushName : contact . pushName ,
778+ chatName : contact . chatName ,
761779 profilePicUrl : contact . profilePicUrl ,
762780 updatedAt : contact . updatedAt ,
763781 windowStart : contact . windowStart ,
0 commit comments