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,18 +1432,24 @@ export class WAStartupService {
} }
let mentions: string[]; let mentions: string[];
if (isJidGroup(sender)) {
try {
this.logger.verbose('Getting group metadata');
const groupMetadata = await this.client.groupMetadata(sender);
if (options?.mentions) { if (options?.mentions) {
this.logger.verbose('Mentions defined'); this.logger.verbose('Mentions defined');
if (!Array.isArray(options.mentions.mentioned) && !options.mentions.everyOne) { if (
!Array.isArray(options.mentions.mentioned) &&
!options.mentions.everyOne
) {
throw new BadRequestException('Mentions must be an array'); throw new BadRequestException('Mentions must be an array');
} }
if (options.mentions.everyOne) { if (options.mentions.everyOne) {
this.logger.verbose('Mentions everyone'); this.logger.verbose('Mentions everyone');
const groupMetadata = await this.client.groupMetadata(sender);
mentions = groupMetadata.participants.map((participant) => participant.id); mentions = groupMetadata.participants.map((participant) => participant.id);
this.logger.verbose('Getting group metadata for mentions'); this.logger.verbose('Getting group metadata for mentions');
} else { } else {
@ -1468,6 +1463,10 @@ export class WAStartupService {
}); });
} }
} }
} catch (error) {
throw new NotFoundException('Group not found');
}
}
const messageSent = await (async () => { const messageSent = await (async () => {
const option = { const option = {