From 3c2ea5c67c3f07a24812e64f2da0c942fb91b117 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Sun, 2 Feb 2025 16:42:17 -0300 Subject: [PATCH] feat: Re-enable group metadata caching in Baileys service - Restore group metadata caching mechanisms - Uncomment cache-related methods for group updates and participants - Implement conditional group metadata retrieval based on cache configuration --- .../whatsapp/whatsapp.baileys.service.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index cd6fac51..10feb7ce 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -668,7 +668,7 @@ export class BaileysStartupService extends ChannelStartupService { shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => { return this.historySyncNotification(msg); }, - // cachedGroupMetadata: this.getGroupMetadataCache, + cachedGroupMetadata: this.getGroupMetadataCache, userDevicesCache: this.userDevicesCache, transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 }, patchMessageBeforeSending(message) { @@ -1562,11 +1562,11 @@ export class BaileysStartupService extends ChannelStartupService { 'groups.update': (groupMetadataUpdate: Partial[]) => { this.sendDataWebhook(Events.GROUPS_UPDATE, groupMetadataUpdate); - // groupMetadataUpdate.forEach((group) => { - // if (isJidGroup(group.id)) { - // this.updateGroupMetadataCache(group.id); - // } - // }); + groupMetadataUpdate.forEach((group) => { + if (isJidGroup(group.id)) { + this.updateGroupMetadataCache(group.id); + } + }); }, 'group-participants.update': (participantsUpdate: { @@ -1576,7 +1576,7 @@ export class BaileysStartupService extends ChannelStartupService { }) => { this.sendDataWebhook(Events.GROUP_PARTICIPANTS_UPDATE, participantsUpdate); - // this.updateGroupMetadataCache(participantsUpdate.id); + this.updateGroupMetadataCache(participantsUpdate.id); }, }; @@ -2160,10 +2160,10 @@ export class BaileysStartupService extends ChannelStartupService { if (isJidGroup(sender)) { let group; try { - // const cache = this.configService.get('CACHE'); - // if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner'); - // else group = await this.getGroupMetadataCache(sender); - group = await this.findGroup({ groupJid: sender }, 'inner'); + const cache = this.configService.get('CACHE'); + if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner'); + else group = await this.getGroupMetadataCache(sender); + // group = await this.findGroup({ groupJid: sender }, 'inner'); } catch (error) { throw new NotFoundException('Group not found'); }