Merge pull request #421 from judsonjuniorr/Groups-participant-names

Refactor fetching participants for group in WhatsApp service
This commit is contained in:
Davidson Gomes 2024-02-16 08:29:21 -03:00 committed by GitHub
commit cd00effcfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4081,7 +4081,19 @@ export class WAStartupService {
this.logger.verbose('Fetching participants for group: ' + id.groupJid);
try {
const participants = (await this.client.groupMetadata(id.groupJid)).participants;
return { participants };
const contacts = await this.repository.contact.findManyById({
owner: this.instance.name,
ids: participants.map((p) => p.id),
});
const parsedParticipants = participants.map((participant) => {
const contact = contacts.find((c) => c.id === participant.id);
return {
...participant,
name: participant.name ?? contact?.pushName,
imgUrl: participant.imgUrl ?? contact?.profilePictureUrl,
};
});
return { participants: parsedParticipants };
} catch (error) {
throw new NotFoundException('No participants', error.toString());
}