diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index fe0f3d4..ab9bb04 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -286,9 +286,9 @@ exports.LoadUtils = () => { let vcardOptions = {}; if (options.contactCard) { - let contact = window + let contact = await window .require('WAWebCollections') - .Contact.get(options.contactCard); + .Contact.find(options.contactCard); vcardOptions = { body: window .require('WAWebFrontendVcardUtils') @@ -298,8 +298,10 @@ exports.LoadUtils = () => { }; delete options.contactCard; } else if (options.contactCardList) { - let contacts = options.contactCardList.map((c) => - window.require('WAWebCollections').Contact.get(c), + let contacts = await Promise.all( + options.contactCardList.map((c) => + window.require('WAWebCollections').Contact.find(c), + ), ); let vcards = contacts.map((c) => window @@ -956,14 +958,12 @@ exports.LoadUtils = () => { window.require('WAWebCollections').GroupMetadata || window.require('WAWebCollections').WAWebGroupMetadataCollection; await groupMetadata.update(chatWid); - chat.groupMetadata.participants._models - .filter((x) => x.id?._serialized?.endsWith('@lid')) - .forEach( - (x) => - x.contact?.phoneNumber && - (x.id = x.contact.phoneNumber), - ); - model.groupMetadata = chat.groupMetadata.serialize(); + const { toPn } = window.require('WAWebLidMigrationUtils'); + const serializedMetadata = chat.groupMetadata.serialize(); + for (const p of serializedMetadata.participants || []) { + p.id = toPn(p.id) ?? p.id; + } + model.groupMetadata = serializedMetadata; model.isReadOnly = chat.groupMetadata.announce; } @@ -1007,6 +1007,14 @@ exports.LoadUtils = () => { window.WWebJS.getContactModel = (contact) => { let res = contact.serialize(); + + const wid = window + .require('WAWebWidFactory') + .createWidFromWidLike(contact.id); + if (wid.isLid() && contact.phoneNumber) { + res.id = contact.phoneNumber; + } + res.isBusiness = contact.isBusiness === undefined ? false : contact.isBusiness; @@ -1039,17 +1047,18 @@ exports.LoadUtils = () => { }; window.WWebJS.getContact = async (contactId) => { - const wid = window.require('WAWebWidFactory').createWid(contactId); - let contact = await window + const contactWid = window + .require('WAWebWidFactory') + .createWid(contactId); + const contact = await window .require('WAWebCollections') - .Contact.find(wid); - if (contact.id._serialized.endsWith('@lid')) { - contact.id = contact.phoneNumber; + .Contact.find(contactWid); + if (contact.isBusiness || contact.isEnterprise) { + const bizProfile = await window + .require('WAWebCollections') + .BusinessProfile.find(contactWid); + bizProfile.profileOptions && (contact.businessProfile = bizProfile); } - const bizProfile = await window - .require('WAWebCollections') - .BusinessProfile.fetchBizProfile(wid); - bizProfile.profileOptions && (contact.businessProfile = bizProfile); return window.WWebJS.getContactModel(contact); };