Skip to content

fix(store): resolve LID JIDs to phone JIDs for unified message history - #16

Merged
vicentereig merged 1 commit into
vicentereig:mainfrom
dortort:fix/lid-jid-resolution
Apr 14, 2026
Merged

vicentereig merged 1 commit into
vicentereig:mainfrom
dortort:fix/lid-jid-resolution

Conversation

@dortort

@dortort dortort commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #15 — messages from contacts whose WhatsApp sessions have migrated to the new LID (Linked Identity) format are invisible in messages list.

  • Add LIDResolver that reads whatsmeow's whatsmeow_lid_map table to transparently map between @lid and @s.whatsapp.net JIDs
  • On storage (StoreChat, StoreMessage): normalize @lid JIDs to @s.whatsapp.net so all messages for a contact live under one canonical JID
  • On query (ListMessages): when filtering by phone JID, also match the corresponding @lid JID (for messages already stored pre-fix)
  • Wire up the resolver in NewApp using the existing whatsapp.db

Background

WhatsApp is actively migrating contacts from phone-based JIDs to LID-based JIDs as a privacy initiative. The whatsmeow library already maintains the PN↔LID mapping in whatsmeow_lid_map, but whatsapp-cli was not consulting it. This caused the same contact to appear as two separate chats with newer messages invisible to queries by phone number.

Design decisions

  • Read-only access to whatsapp.db (mode=ro) — the resolver never writes to whatsmeow's database
  • Backwards-compatible — if no LID mapping exists or whatsapp.db is unavailable, behavior is unchanged
  • Dual-path query — ListMessages matches both JID variants to surface messages stored under either format, handling both pre-fix and post-fix data

Test plan

  • All existing tests pass (go test ./...)
  • Verified with real database: messages list --chat <phone>@s.whatsapp.net now returns messages stored under both the phone JID and the LID JID
  • Edge case: contact with no LID mapping — should behave identically to before
  • Edge case: query by @lid JID directly — should resolve to phone JID and return all messages

🤖 Generated with Claude Code

WhatsApp is migrating contacts from phone-based JIDs (@s.whatsapp.net)
to LID-based JIDs (@lid). Messages arriving under the new LID format
were stored separately and invisible when querying by phone JID.

Add a LIDResolver that reads whatsmeow's whatsmeow_lid_map table to
transparently map between LID and phone JIDs. Applied on both the
storage path (normalize to phone JID) and query path (match both JIDs
for already-stored LID messages).

Fixes vicentereig#15

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vicentereig
vicentereig merged commit d87f778 into vicentereig:main Apr 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Messages from contacts using @lid JIDs are invisible in messages list

2 participants