fix(example): convert messageTimestamp to ms in fetchMessageHistory call#2616
fix(example): convert messageTimestamp to ms in fetchMessageHistory call#2616zomars wants to merge 1 commit into
Conversation
The `HistorySyncOnDemandRequest` proto field is `oldestMsgTimestampMs` (milliseconds) but `WAMessage.messageTimestamp` is seconds. The canonical example was passing seconds where milliseconds are expected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe ChangesTimestamp Conversion for Message History Fetch
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks for opening this pull request and contributing to the project! The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch. In the meantime, anyone in the community is encouraged to test this pull request and provide feedback. ✅ How to confirm it worksIf you’ve tested this PR, please comment below with: This helps us speed up the review and merge process. 📦 To test this PR locally:If you encounter any issues or have feedback, feel free to comment as well. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Example/example.ts`:
- Around line 150-152: Guard against a null/undefined messageTimestamp before
converting: replace the non-null assertion on msg.messageTimestamp with a
nullish check (e.g., if (msg.messageTimestamp == null) { /* handle missing
timestamp: skip, log, or return */ }) and only then assign tsRaw and compute
tsMs using the existing conversion logic ((typeof tsRaw === 'number' ? tsRaw :
tsRaw.toNumber()) * 1000); update the call to sock.fetchMessageHistory to use
that validated tsMs; reference msg.messageTimestamp, tsRaw, tsMs,
sock.fetchMessageHistory and msg.key when making the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Summary
HistorySyncOnDemandRequestproto field isoldestMsgTimestampMs(ms), butWAMessage.messageTimestampis seconds.Example/example.tswas passing seconds directly into that field, silently mismatching units.Found while investigating #2452.
Test plan
yarn examplestill type-checks and runsonDemandHistSyncfrom an old chat now logs atsMsvalue in the ~1.7e12 range (correct ms) instead of ~1.7e9 (seconds)Note: this fix alone does not resolve #2452 — the on-demand history response from WA still doesn't arrive (see comment thread on that issue). But the canonical example should be correct so others investigating don't burn time on this red herring.
Summary by cubic
Convert
WAMessage.messageTimestamp(seconds) to milliseconds before callingsock.fetchMessageHistoryinExample/example.ts, matchingHistorySyncOnDemandRequest.oldestMsgTimestampMs. This fixes the seconds/ms mismatch so on‑demand history requests send a valid timestamp.Written for commit 61f0ca3. Summary will update on new commits.
Summary by CodeRabbit