Skip to content

Commit

Permalink
Merge pull request #421 from judsonjuniorr/Groups-participant-names
Browse files Browse the repository at this point in the history
Refactor fetching participants for group in WhatsApp service
  • Loading branch information
DavidsonGomes authored Feb 16, 2024
2 parents 1cd0334 + 6995e8a commit cd00eff
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit cd00eff

Please sign in to comment.