diff --git a/src/Signal/lid-mapping.ts b/src/Signal/lid-mapping.ts index 2e3176fb..dba3e07c 100644 --- a/src/Signal/lid-mapping.ts +++ b/src/Signal/lid-mapping.ts @@ -522,7 +522,7 @@ export class LIDMappingStore { for (const [pnUser, items] of pendingByPnUser.entries()) { const lidUser = this.mappingCache.get(`pn:${pnUser}`) for (const { pn, decoded } of items) { - if (lidUser) { + if (lidUser && decoded) { const lidUserString = lidUser.toString() if (!lidUserString) { this.logger.warn({ pn, lidUser }, 'Invalid or empty LID user') @@ -548,6 +548,8 @@ export class LIDMappingStore { failedPns.add(pn) } + if (!decoded) continue + // Need to fetch from USync if (this.config.debugLogging) { this.logger.trace({ pnUser }, 'No LID mapping found, queuing for USync') diff --git a/src/__tests__/Utils/process-message.test.ts b/src/__tests__/Utils/process-message.test.ts index e4922dfb..fd530003 100644 --- a/src/__tests__/Utils/process-message.test.ts +++ b/src/__tests__/Utils/process-message.test.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals' import type { WAMessage } from '../../Types' import type { SignalRepositoryWithLIDStore } from '../../Types' import { cleanMessage, normalizeMessageJids } from '../../Utils/process-message' @@ -139,14 +140,17 @@ describe('cleanMessage', () => { }) describe('normalizeMessageJids', () => { - const signalRepository = { - lidMapping: { - getPNForLID: jest.fn() - } - } as unknown as SignalRepositoryWithLIDStore + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let mockGetPNForLID: any + let signalRepository: SignalRepositoryWithLIDStore beforeEach(() => { - jest.clearAllMocks() + mockGetPNForLID = jest.fn() + signalRepository = { + lidMapping: { + getPNForLID: mockGetPNForLID + } + } as unknown as SignalRepositoryWithLIDStore }) it('should resolve remoteJid LID to PN when mapping exists', async () => { @@ -154,7 +158,7 @@ describe('normalizeMessageJids', () => { remoteJid: '123456789@lid' }) - signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue('5511999999999@s.whatsapp.net') + mockGetPNForLID.mockResolvedValue('5511999999999@s.whatsapp.net') await normalizeMessageJids(message, signalRepository) @@ -166,7 +170,7 @@ describe('normalizeMessageJids', () => { remoteJid: '123456789@lid' }) - signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue(null) + mockGetPNForLID.mockResolvedValue(null) await normalizeMessageJids(message, signalRepository) @@ -178,7 +182,7 @@ describe('normalizeMessageJids', () => { participant: '999999999@lid' }) - signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue('5511888888888@s.whatsapp.net') + mockGetPNForLID.mockResolvedValue('5511888888888@s.whatsapp.net') await normalizeMessageJids(message, signalRepository)