fix: optimize send message from group with mentions

This commit is contained in:
Davidson Gomes 2023-07-13 20:05:26 -03:00
parent 2565b934a5
commit 8f062fab7d

View File

@ -1405,17 +1405,6 @@ export class WAStartupService {
const sender = isJidGroup(jid) ? jid : isWA.jid; const sender = isJidGroup(jid) ? jid : isWA.jid;
if (isJidGroup(sender)) {
try {
this.logger.verbose('Getting group metadata');
const metadata = await this.client.groupMetadata(sender);
console.log('metadata', metadata);
} catch (error) {
throw new NotFoundException('Group not found');
}
}
try { try {
if (options?.delay) { if (options?.delay) {
this.logger.verbose('Delaying message'); this.logger.verbose('Delaying message');
@ -1443,29 +1432,39 @@ export class WAStartupService {
} }
let mentions: string[]; let mentions: string[];
if (isJidGroup(sender)) {
if (options?.mentions) { try {
this.logger.verbose('Mentions defined'); this.logger.verbose('Getting group metadata');
if (!Array.isArray(options.mentions.mentioned) && !options.mentions.everyOne) {
throw new BadRequestException('Mentions must be an array');
}
if (options.mentions.everyOne) {
this.logger.verbose('Mentions everyone');
const groupMetadata = await this.client.groupMetadata(sender); const groupMetadata = await this.client.groupMetadata(sender);
mentions = groupMetadata.participants.map((participant) => participant.id);
this.logger.verbose('Getting group metadata for mentions'); if (options?.mentions) {
} else { this.logger.verbose('Mentions defined');
this.logger.verbose('Mentions manually defined');
mentions = options.mentions.mentioned.map((mention) => { if (
const jid = this.createJid(mention); !Array.isArray(options.mentions.mentioned) &&
if (isJidGroup(jid)) { !options.mentions.everyOne
throw new BadRequestException('Mentions must be a number'); ) {
throw new BadRequestException('Mentions must be an array');
} }
return jid;
}); if (options.mentions.everyOne) {
this.logger.verbose('Mentions everyone');
mentions = groupMetadata.participants.map((participant) => participant.id);
this.logger.verbose('Getting group metadata for mentions');
} else {
this.logger.verbose('Mentions manually defined');
mentions = options.mentions.mentioned.map((mention) => {
const jid = this.createJid(mention);
if (isJidGroup(jid)) {
throw new BadRequestException('Mentions must be a number');
}
return jid;
});
}
}
} catch (error) {
throw new NotFoundException('Group not found');
} }
} }