This commit is contained in:
Pedro Howat 2024-10-16 14:02:24 -03:00
commit 3f4ba1ac2a

View File

@ -867,7 +867,6 @@ export class BaileysStartupService extends ChannelStartupService {
'contacts.update': async (contacts: Partial<Contact>[], database: Database) => { 'contacts.update': async (contacts: Partial<Contact>[], database: Database) => {
this.logger.verbose('Event received: contacts.update'); this.logger.verbose('Event received: contacts.update');
this.logger.verbose('Verifying if contacts exists in database to update'); this.logger.verbose('Verifying if contacts exists in database to update');
const contactsRaw: ContactRaw[] = []; const contactsRaw: ContactRaw[] = [];
for await (const contact of contacts) { for await (const contact of contacts) {
@ -882,8 +881,9 @@ export class BaileysStartupService extends ChannelStartupService {
this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE'); this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE');
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw); this.sendDataWebhook(Events.CONTACTS_UPDATE, contactsRaw);
//REMOVING DUE TO CREATING NULL CONTACTS ( ADDING FILTER )
this.logger.verbose('Updating contacts in database'); this.logger.verbose('Updating contacts in database');
this.repository.contact.update(contactsRaw, this.instance.name, database.SAVE_DATA.CONTACTS); this.repository.contact.update(contactsRaw.filter(contact => contact.pushName), this.instance.name, database.SAVE_DATA.CONTACTS);
}, },
}; };
@ -1246,6 +1246,10 @@ export class BaileysStartupService extends ChannelStartupService {
owner: this.instance.name, owner: this.instance.name,
}; };
if (received?.key?.fromMe === true){
contactRaw.pushName = null
}
this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE'); this.logger.verbose('Sending data to webhook in event CONTACTS_UPDATE');
this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw); this.sendDataWebhook(Events.CONTACTS_UPDATE, contactRaw);
@ -1258,6 +1262,8 @@ export class BaileysStartupService extends ChannelStartupService {
} }
this.logger.verbose('Updating contact in database'); this.logger.verbose('Updating contact in database');
if(contactRaw.pushName)
await this.repository.contact.update([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS); await this.repository.contact.update([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS);
return; return;
} }
@ -1269,9 +1275,9 @@ export class BaileysStartupService extends ChannelStartupService {
this.logger.verbose('Inserting contact in database'); this.logger.verbose('Inserting contact in database');
if (received?.key?.fromMe === true) { if (received?.key?.fromMe === true)
contactRaw.pushName = null; contactRaw.pushName = null;
}
this.repository.contact.insert([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS); this.repository.contact.insert([contactRaw], this.instance.name, database.SAVE_DATA.CONTACTS);
} }
} catch (error) { } catch (error) {