Repository navigation
fix(channel): update fromMe filter to check for undefined - #2806
kavindu-udara wants to merge 1 commit into
Conversation
Reviewer's GuideImplementationInclude the
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Linked issuesChecked at commit d66066f #2796 [BUG] /chat/findMessages ignores where.key.fromMe when value is false · 1 of 1 met
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/api/services/channel.service.ts" line_range="627" />
<code_context>
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 } } : {},
</code_context>
<issue_to_address>
**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`.
</issue_to_address>
### Comment 2
<location path="src/api/services/channel.service.ts" line_range="627" />
<code_context>
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 } } : {},
</code_context>
<issue_to_address>
**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`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: src/api/services/channel.service.ts:627, src/api/services/channel.service.ts:627
| 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 } } : {}, |
There was a problem hiding this comment.
🟠 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`.| 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 } } : {}, |
There was a problem hiding this comment.
🟡 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`.
📋 Description
This pull request makes a small but important change to the
ChannelStartupServiceinsrc/api/services/channel.service.ts. The change ensures that thefromMefilter is correctly applied even if its value isfalse, rather than being ignored as before.fromMefilter in the query to check for!== undefinedinstead of a truthy check, so thatfalsevalues are correctly included in the filter conditions. [1] [2]🔗 Related Issue
Closes #2796
🧪 Type of Change
🧪 Testing
📸 Screenshots (if applicable)
✅ Checklist
📝 Additional Notes
Summary by Sourcery
Bug Fixes:
fromMeis explicitly set tofalse.