Skip to content

Commit fd95c53

Browse files
committed
fix(getChat): resolve LID for unknown contacts via WAWebContactSyncUtils (wwebjs#3834)
When sendMessage is called for a contact not yet synced, findOrCreateLatestChat fails with "No LID for user". This adds a third fallback in getChat that uses WAWebContactSyncUtils.constructUsyncDeltaQuery to resolve the phone number to a LID via WhatsApp servers, then retries findOrCreateLatestChat with the resolved LID. The fix preserves the existing behavior: - 1st: fast in-memory cache lookup via Store.Chat.get() - 2nd: async findOrCreateLatestChat with the original WID - 3rd (new): LID resolution + retry (only when both above fail)
1 parent 9ba93d6 commit fd95c53

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/util/Injected/Utils.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,25 @@ exports.LoadUtils = () => {
581581
chat = null;
582582
}
583583
} else {
584-
chat = window.Store.Chat.get(chatWid) || (await window.Store.FindOrCreateChat.findOrCreateLatestChat(chatWid))?.chat;
584+
chat = window.Store.Chat.get(chatWid);
585+
if (!chat) {
586+
chat = (await window.Store.FindOrCreateChat.findOrCreateLatestChat(chatWid).catch(() => null))?.chat;
587+
}
588+
if (!chat) {
589+
try {
590+
const query = window.require('WAWebContactSyncUtils').constructUsyncDeltaQuery([{
591+
type: 'add',
592+
phoneNumber: chatWid.user
593+
}]);
594+
const result = await query.execute();
595+
if (result?.list?.[0]?.lid) {
596+
const chatLid = window.Store.WidFactory.createWid(result.list[0].lid);
597+
chat = (await window.Store.FindOrCreateChat.findOrCreateLatestChat(chatLid).catch(() => null))?.chat;
598+
}
599+
} catch (e) {
600+
// LID resolution failed, chat remains undefined
601+
}
602+
}
585603
}
586604

587605
return getAsModel && chat

0 commit comments

Comments
 (0)