Skip to content

Resolve LID for profile-picture contacts.update#2605

Open
manishkumar1601 wants to merge 2 commits into
WhiskeySockets:masterfrom
manishkumar1601:fix/picture-contact-update-lid
Open

Resolve LID for profile-picture contacts.update#2605
manishkumar1601 wants to merge 2 commits into
WhiskeySockets:masterfrom
manishkumar1601:fix/picture-contact-update-lid

Conversation

@manishkumar1601

@manishkumar1601 manishkumar1601 commented May 29, 2026

Copy link
Copy Markdown

For #2598 - Resolve LID for profile-picture contacts.update)


Summary by cubic

Resolves LID↔PN for profile-picture contacts.update events so clients can reliably match updates to cached contacts. Addresses Linear #2598.

  • Bug Fixes
    • For individual contacts, resolve and emit id plus optional lid and phoneNumber using resolveContactPictureIdentity.
    • Keep group icon updates unchanged and never resolve LID↔PN for groups.
    • Guard against bogus self-resolutions and skip hosted LID lookups.
    • Added unit tests for success, fallback, and error paths; relocated under src/__tests__/Utils and documented helper.

Written for commit f991b31. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved accuracy of individual contact picture updates by properly resolving and enriching notifications with correct identity data
    • Enhanced handling of contact profile picture changes with better identity matching
  • Tests

    • Added comprehensive test coverage for contact picture identity resolution, including successful mappings, fallback scenarios, self-identity guards, and error handling

Review Change Stack

@whiskeysockets-bot

whiskeysockets-bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

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 works

If you’ve tested this PR, please comment below with:

Tested and working ✅

This helps us speed up the review and merge process.

📦 To test this PR locally:

# NPM
npm install @whiskeysockets/baileys@manishkumar1601/Baileys#fix/picture-contact-update-lid

# Yarn (v2+)
yarn add @whiskeysockets/baileys@manishkumar1601/Baileys#fix/picture-contact-update-lid

# PNPM
pnpm add @whiskeysockets/baileys@manishkumar1601/Baileys#fix/picture-contact-update-lid

If you encounter any issues or have feedback, feel free to comment as well.

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a66bf25c-c939-4f77-98d1-621220e6e9f0

📥 Commits

Reviewing files that changed from the base of the PR and between d98f8fc and f991b31.

📒 Files selected for processing (1)
  • src/__tests__/Utils/contact-picture-identity.test.ts

📝 Walkthrough

Walkthrough

This PR introduces resolveContactPictureIdentity, a utility function for enriching contact picture notifications with canonical LID/PN identity data. The socket message receiver consolidates duplicate LID↔PN resolver bindings into a shared outer-scope reference and refactors picture notification handling to use the new helper for individual contact updates while preserving group-only handling. Tests validate cross-resolution, fallback, and self-identity-guard behavior.

Changes

Contact Picture Identity Resolution

Layer / File(s) Summary
ContactPictureIdentityContext type and resolveContactPictureIdentity helper
src/Utils/contact-picture-identity.ts
Introduces ContactPictureIdentityContext type with async resolvers (getPNForLID, getLIDForPN) and optional self fields. resolveContactPictureIdentity performs best-effort LID↔PN cross-resolution with a self-identity guard that discards resolutions pointing to the current user's PN unless the input matches ctx.meLid. Errors are silently caught and fallback to the raw input identity.
Utils barrel re-export
src/Utils/index.ts
Re-exports the new contact-picture-identity module to extend the Utils public API surface.
Socket picture notification handler refactoring and binding consolidation
src/Socket/messages-recv.ts
Imports resolveContactPictureIdentity and introduces a shared outer-scope getPNForLID binding from signalRepository.lidMapping. Reuses this binding across picture, tctoken, and privacy-token handlers, eliminating three redundant inner-scope bindings. Refactors picture notification handling: group updates continue emitting via group JID; individual updates call resolveContactPictureIdentity with context and emit contacts.update with resolved identity and imgUrl.
resolveContactPictureIdentity test suite
src/__tests__/Utils/contact-picture-identity.test.ts
Tests validate LID→PN resolution with correct output shape, PN→LID resolution with conditional field filling, self-identity guard behavior (discard other-user PN for stranger LID, preserve own PN for user's LID), null/error fallback, and hosted LID bypass (no resolver invocation).

Sequence Diagram

sequenceDiagram
  participant MessageHandler as message handler
  participant PictureResolver as resolveContactPictureIdentity
  participant LIDMapping as signalRepository.lidMapping
  participant ContactSignal as contacts signal
  
  MessageHandler->>PictureResolver: call with picture from/to, context
  PictureResolver->>LIDMapping: getPNForLID(from) or getLIDForPN(from)
  LIDMapping-->>PictureResolver: resolved identity
  PictureResolver-->>MessageHandler: {id, lid?, phoneNumber?}
  MessageHandler->>ContactSignal: emit update with resolved identity + imgUrl
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • WhiskeySockets/Baileys#2598: The new resolveContactPictureIdentity helper with shared getPNForLID binding directly addresses the unresolvable-LID contacts.update bug by enabling canonical LID/PN enrichment and self-identity guards.

Possibly related PRs

  • WhiskeySockets/Baileys#2339: Both PRs modify shared LID↔PN resolution plumbing (getLIDForPN/getPNForLID) used by tc-token reissue, privacy-token flows, and contact picture identity enrichment.

Suggested reviewers

  • purpshell

Poem

🐰 A picture's worth a thousand LIDs,
Now mapped to phones with open lids!
Self-guards stand tall, no bogus swaps,
One binding shared—no redundant hops. 🖼️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Resolve LID for profile-picture contacts.update' directly and clearly describes the main change: resolving LID (Linked Identity) for profile-picture contact updates, which is the core objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 `@src/__tests__/Socket/contact-picture-identity.test.ts`:
- Around line 1-5: Move the test file from
src/__tests__/Socket/contact-picture-identity.test.ts into
src/__tests__/Utils/contact-picture-identity.test.ts so it mirrors the source
module path (src/Utils/contact-picture-identity.ts); keep the existing imports
of resolveContactPictureIdentity and ContactPictureIdentityContext and adjust
any relative import paths if needed (they should remain valid), and ensure the
test filename and exports remain unchanged so jest still discovers tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b419be7e-b12b-48be-b4bf-5f31f18a3b06

📥 Commits

Reviewing files that changed from the base of the PR and between 78e7e4e and d98f8fc.

📒 Files selected for processing (4)
  • src/Socket/messages-recv.ts
  • src/Utils/contact-picture-identity.ts
  • src/Utils/index.ts
  • src/__tests__/Socket/contact-picture-identity.test.ts

Comment thread src/__tests__/Utils/contact-picture-identity.test.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 4 files

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Re-trigger cubic

@manishkumar1601

Copy link
Copy Markdown
Author

Tested and working ✅

@manishkumar1601 manishkumar1601 changed the title Resolve LID for profile-picture contacts.update) Resolve LID for profile-picture contacts.update May 29, 2026
…lper

Mirror the source module path (src/Utils/contact-picture-identity.ts) by relocating the spec to src/__tests__/Utils, and add a docstring to the test context helper to satisfy docstring-coverage. Addresses CodeRabbit review notes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
rsalcara added a commit to rsalcara/InfiniteAPI that referenced this pull request Jun 6, 2026
…rt PR WhiskeySockets#2605) (#506)

fix(contacts): resolve LID↔PN for profile-picture contacts.update (port PR WhiskeySockets#2605) (#506)
@manishkumar1601

Copy link
Copy Markdown
Author

@purpshell, could you please review the changes when you have a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants