Skip to content

Patch/lid history and sync progress#2627

Open
vraj-sondagar-ridgelabs wants to merge 8 commits into
evolution-foundation:mainfrom
vraj-sondagar-ridgelabs:patch/lid-history-and-sync-progress
Open

Patch/lid history and sync progress#2627
vraj-sondagar-ridgelabs wants to merge 8 commits into
evolution-foundation:mainfrom
vraj-sondagar-ridgelabs:patch/lid-history-and-sync-progress

Conversation

@vraj-sondagar-ridgelabs

Copy link
Copy Markdown

📋 Description

🔗 Related Issue

Closes #(issue_number)

🧪 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧹 Code cleanup
  • 🔒 Security fix

🧪 Testing

  • Manual testing completed
  • Functionality verified in development environment
  • No breaking changes introduced
  • Tested with different connection types (if applicable)

📸 Screenshots (if applicable)

✅ Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have manually tested my changes thoroughly
  • I have verified the changes work with different scenarios
  • Any dependent changes have been merged and published

📝 Additional Notes

vrajboulder-creator and others added 4 commits July 7, 2026 16:38
Two local patches on top of evolution-api v2.3.7:

1. @lid-history bridge (whatsapp.baileys.service.ts)
   The messages.upsert (live) path rewrites @lid -> real phone via
   remoteJidAlt, but messaging-history.set (bulk history) did not, so
   old @lid chats had no phone/name bridge. Preserve remoteJidAlt on
   history message keys (from itself or senderPn/participantAlt/
   participantPn fallbacks) so a downstream resolver can map an old
   @lid chat to the saved contact name/number.

2. Real history-sync progress (whatsapp.baileys.service.ts +
   monitor.service.ts)
   Baileys emits a real 0-100 `progress` + `isLatest` on
   messaging-history.set, previously only wired to Chatwoot import.
   Record it on a public historySync field and surface it on the
   instanceInfo/fetchInstances response so clients can show a true
   progress bar instead of inferring from row counts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
logoutInstance() called `await this.client.logout()` unguarded. When the
WhatsApp socket is already down (user removed the device from their phone,
or a dropped connection), client.logout() throws "Connection Closed",
which aborted the function BEFORE the credential-purge block that deletes
the Baileys auth (Session row). The creds survived, so recreating the
same-named instance silently reconnected without a QR — "logout didn't
work / still reconnects".

Wrap client.logout() (and ws.close()) in try/catch so the credential
purge ALWAYS runs. A failed WS logout on an already-closed socket is
harmless.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add POST /chat/requestHistory/:instance { remoteJid, count? } which calls
Baileys' fetchMessageHistory(count, oldestKey, oldestTimestamp) anchored on
the oldest stored message of the chat. WhatsApp's initial multi-device sync
only delivers a bounded window per chat, so old messages of a specific chat
can be missing even when the DB holds years of other chats. Results arrive
async via the messaging-history.set ON_DEMAND path and get persisted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add POST /chat/resolveLid/:instance { lids: string[] } -> { "<lid>": "<phone>|null" }.
Uses signalRepository.lidMapping.getPNForLID to recover the real phone for
@lid privacy/business chats that carry no remoteJidAlt in any stored message
(so the message-key and picture bridges can't resolve them). Last-resort
phone bridge for the "empty contact number" case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@sourcery-ai sourcery-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.

Sorry @vraj-sondagar-ridgelabs, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

vrajboulder-creator and others added 4 commits July 7, 2026 17:28
Each synced Baileys Contact carries both its phone JID (contact.id =
<phone>@s.whatsapp.net) and its @lid (contact.lid), but upstream discarded
contact.lid — so an @lid chat could never be mapped back to the phone, and
thus to the user's saved address-book name (chats showed the contact's own
profile name like "." or an emoji instead of "Sahil Boulder").

Now on contacts.upsert we:
  1. feed every (lid, pn) pair into Baileys' lidMapping store
     (signalRepository.lidMapping.storeLIDPNMappings) so getPNForLID()
     resolves them afterwards, and
  2. persist an @lid Contact row mirroring the saved pushName, so the DB
     name-resolver bridges @lid -> saved name directly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Evolution's publish_docker_image*.yml workflows try to build + push to
Docker Hub on every push and fail (no DOCKERHUB secrets in this fork),
spamming Actions failure emails. We build the image locally, so drop the
CI entirely.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
getPNForLID returns the PN as '<phone>:0@s.whatsapp.net'. Stripping only
'@...' left the ':0' whose colon got removed by replace(/\D/g), producing
a spurious trailing '0' (919408740590 -> 9194087405900). Split on ':' too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When the live lidMapping has no PN for an @lid, fall back to ONE raw SQL
over the chat's entire stored history, checking every field WhatsApp can
leak the phone in: key.remoteJidAlt / senderPn / participantAlt /
participantPn and contextInfo.participant. Also reject junk (<8 digit)
results so a bare device index never renders as '+0'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant