Adjust search for chats, messages and contacts

This commit is contained in:
Davidson Gomes
2024-06-09 09:28:15 -03:00
parent 620cd8b06b
commit 585bf84af4
3 changed files with 109 additions and 54 deletions

View File

@@ -2621,15 +2621,25 @@ export class BaileysStartupService extends ChannelStartupService {
}
public async getLastMessage(number: string) {
const messages = await this.fetchMessages({
where: {
key: {
remoteJid: number,
},
owner: this.instance.name,
const where: any = {
key: {
remoteJid: number,
},
instanceId: this.instance.id,
};
const messages = await this.prismaRepository.message.findMany({
where,
orderBy: {
messageTimestamp: 'desc',
},
take: 1,
});
if (messages.length === 0) {
throw new NotFoundException('Messages not found');
}
let lastMessage = messages.pop();
for (const message of messages) {