Skip to content

Commit 6995e8a

Browse files
committed
Refactor fetching participants for group in WhatsApp service
1 parent 525daff commit 6995e8a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/whatsapp/services/whatsapp.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4077,7 +4077,19 @@ export class WAStartupService {
40774077
this.logger.verbose('Fetching participants for group: ' + id.groupJid);
40784078
try {
40794079
const participants = (await this.client.groupMetadata(id.groupJid)).participants;
4080-
return { participants };
4080+
const contacts = await this.repository.contact.findManyById({
4081+
owner: this.instance.name,
4082+
ids: participants.map((p) => p.id),
4083+
});
4084+
const parsedParticipants = participants.map((participant) => {
4085+
const contact = contacts.find((c) => c.id === participant.id);
4086+
return {
4087+
...participant,
4088+
name: participant.name ?? contact?.pushName,
4089+
imgUrl: participant.imgUrl ?? contact?.profilePictureUrl,
4090+
};
4091+
});
4092+
return { participants: parsedParticipants };
40814093
} catch (error) {
40824094
throw new NotFoundException('No participants', error.toString());
40834095
}

0 commit comments

Comments
 (0)