Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/services/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ export class ChannelStartupService {
...timestampFilter,
AND: [
keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {},
keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {},
keyFilters?.fromMe !== undefined ? { key: { path: ['fromMe'], equals: keyFilters.fromMe } } : {},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · False sender filters are ignored

When a message query is handled by the Baileys provider with fromMe: false, BaileysStartupService.fetchMessages uses truthy checks for fromMe in both its count and result queries, so it omits the filter and returns messages from both sender directions with an unfiltered count.

Update both Baileys query checks to include fromMe whenever it is not undefined.

Also at src/api/services/channel.service.ts:651-652.

Prompt for AI agents
In `src/api/services/channel.service.ts` at line 627:

**False sender filters are ignored**

When a message query is handled by the Baileys provider with `fromMe: false`, `BaileysStartupService.fetchMessages` uses truthy checks for `fromMe` in both its count and result queries, so it omits the filter and returns messages from both sender directions with an unfiltered count.

Update both Baileys query checks to include `fromMe` whenever it is not `undefined`.

Also at `src/api/services/channel.service.ts:651-652`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟑 Medium · Null filters fail message lookup

When a request supplies fromMe: null alongside an unrecognized key in where.key, keyFilters.fromMe is null, so the new condition includes equals: null in the Prisma JSON filter; Prisma rejects null for this JSON filter and the lookup fails instead of returning messages.

Reject null fromMe values in validation or exclude null as well as undefined when building the filter.

Also at src/api/services/channel.service.ts:652.

Prompt for AI agents
In `src/api/services/channel.service.ts` at line 627:

**Null filters fail message lookup**

When a request supplies `fromMe: null` alongside an unrecognized key in `where.key`, `keyFilters.fromMe` is null, so the new condition includes `equals: null` in the Prisma JSON filter; Prisma rejects null for this JSON filter and the lookup fails instead of returning messages.

Reject null `fromMe` values in validation or exclude null as well as undefined when building the filter.

Also at `src/api/services/channel.service.ts:652`.

keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {},
keyFilters?.participants ? { key: { path: ['participants'], equals: keyFilters?.participants } } : {},
],
Expand All @@ -648,7 +648,7 @@ export class ChannelStartupService {
...timestampFilter,
AND: [
keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {},
keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {},
keyFilters?.fromMe !== undefined ? { key: { path: ['fromMe'], equals: keyFilters.fromMe } } : {},
keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {},
keyFilters?.participants ? { key: { path: ['participants'], equals: keyFilters?.participants } } : {},
],
Expand Down