Fix contact lookup for WhatsApp LID (Linked Device ID) migration#209
Open
coucaj wants to merge 1 commit intolharries:mainfrom
Open
Fix contact lookup for WhatsApp LID (Linked Device ID) migration#209coucaj wants to merge 1 commit intolharries:mainfrom
coucaj wants to merge 1 commit intolharries:mainfrom
Conversation
d037a14 to
c87cd3c
Compare
WhatsApp migrated contacts from phone JIDs (155...@s.whatsapp.net) to internal LID JIDs (123...@lid) for privacy. This broke contact search and message lookup by phone number. Changes: - Add _normalize_phone: strip +, spaces, dashes - Add _resolve_phone_to_jids: returns all JID variants for a phone number by querying whatsmeow_lid_map in whatsapp.db. Uses suffix match (last 10 digits) to handle number format differences. - Add _get_contact_name: looks up name in whatsmeow_contacts table - Fix search_contacts: query whatsapp.db first (real names + LID), fall back to messages.db - Fix get_direct_chat_by_contact: use _resolve_phone_to_jids and resolve name from store DB - Fix list_messages: filter by all JID variants when sender_phone_number is provided - Fix list_messages: skip include_context expansion when filtering by phone to avoid duplicate messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
WhatsApp migrated contacts from phone-based JIDs (
155...@s.whatsapp.net) to internal LID JIDs (123...@lid) for privacy. This broke several functions inwhatsapp.py:search_contacts("Name")returned nothing even if the contact existedget_direct_chat_by_contact(phone)returnedNonelist_messages(sender_phone_number=phone)returned an empty listThe root cause:
whatsapp.pyonly usedmessages.dbfor contact lookup, butmessages.dbstores chats by LID and does not have real names for those contacts. The real mapping lives inwhatsapp.db(written by the Go bridge).Solution
Add three helpers and patch four functions to use the LID -> phone mapping from
whatsapp.db.New helpers
_normalize_phone(phone)— strips+, spaces, dashes_resolve_phone_to_jids(phone)— querieswhatsmeow_lid_mapto return all JID variants for a phone number; uses suffix match (last 10 digits) to handle number format differences (e.g.15550001234vs115550001234)_get_contact_name(phone)— looks upfull_name/push_nameinwhatsmeow_contactsFixed functions
search_contactswhatsapp.dbfirst (real names + LID support), fall back tomessages.dbget_direct_chat_by_contact_resolve_phone_to_jidsand resolve name from storelist_messagessender_phone_numberis providedlist_messagesinclude_contextexpansion when filtering by phone (prevents duplicate messages)Testing
Tested with an account where multiple contacts had migrated to LID JIDs. After the patch:
Notes
whatsapp.dbpath is derived relative to the script location (same pattern asmessages.db)