Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(search): honor a dateTo or dateFrom of 0

Yudhi Armyndharis746935060e66
diff --git a/src/modules/search/providers/builtin-fts.provider.spec.ts b/src/modules/search/providers/builtin-fts.provider.spec.ts
index 215ea45fb..84f35268b 100644
--- a/src/modules/search/providers/builtin-fts.provider.spec.ts
+++ b/src/modules/search/providers/builtin-fts.provider.spec.ts
@@ -114,6 +114,8 @@ describe('BuiltInFtsProvider (sqlite)', () => {
expect(await bodies({ type: 'image' })).toEqual(['hello picture']);
expect(await bodies({ type: ['text', 'image'] })).toEqual(['hello again', 'hello picture', 'hello world']);
expect(await bodies({ dateTo: 2000 })).toEqual(['hello picture', 'hello world']);
+ // Epoch 0 is a bound like any other, not "no bound": nothing is that old.
+ expect(await bodies({ dateTo: 0 })).toEqual([]);
const combined = { chatId: 'c1', from: '[email protected]', direction: MessageDirection.OUTGOING, type: 'text' as const };
expect(await bodies({ ...combined, dateTo: 1000 })).toEqual(['hello world']);
diff --git a/src/modules/search/providers/builtin-fts.provider.ts b/src/modules/search/providers/builtin-fts.provider.ts
index 979bde266..c6a81be79 100644
--- a/src/modules/search/providers/builtin-fts.provider.ts
+++ b/src/modules/search/providers/builtin-fts.provider.ts
@@ -377,11 +377,11 @@ export class BuiltInFtsProvider implements SearchProvider, OnModuleInit {
// (WhatsApp messageTimestamp — see the inbound mappers in the engine adapters). Bind ms→seconds
// at the boundary, otherwise `seconds >= ms` is false for every modern row and dateFrom/dateTo
// silently exclude all results.
- if (q.dateFrom) {
+ if (q.dateFrom != null) {
where.push(`${prefix}"timestamp" >= ${ph()}`);
params.push(Math.floor(q.dateFrom / 1000));
}
- if (q.dateTo) {
+ if (q.dateTo != null) {
where.push(`${prefix}"timestamp" <= ${ph()}`);
params.push(Math.floor(q.dateTo / 1000));
}