diff --git a/.vscode/settings.json b/.vscode/settings.json index 370a15c61..759390b69 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,6 @@ }, "[typescript]": { "editor.defaultFormatter": "vscode.typescript-language-features" - } + }, + "compile-hero.disable-compile-files-on-did-save-code": false } diff --git a/src/api/layers/retriever.layer.ts b/src/api/layers/retriever.layer.ts index 6d03e5bbd..90a35ec0c 100644 --- a/src/api/layers/retriever.layer.ts +++ b/src/api/layers/retriever.layer.ts @@ -57,6 +57,7 @@ import { CreateConfig } from '../../config/create-config'; import { tokenSession } from '../../config/tokenSession.config'; import { WhatsappProfile } from '../model'; import { SenderLayer } from './sender.layer'; +import { checkValuesSender } from '../helpers/layers-interface'; export class RetrieverLayer extends SenderLayer { constructor(public page: Page, session?: string, options?: CreateConfig) { @@ -276,10 +277,32 @@ export class RetrieverLayer extends SenderLayer { * @returns contact detial as promise */ public async getNumberProfile(contactId: string) { - return this.page.evaluate( - (contactId) => WAPI.getNumberProfile(contactId), - contactId - ); + return new Promise(async (resolve, reject) => { + const typeFunction = 'getNumberProfile'; + const type = 'string'; + const check = [ + { + param: 'contactId', + type: type, + value: contactId, + function: typeFunction, + isUser: true + } + ]; + const validating = checkValuesSender(check); + if (typeof validating === 'object') { + return reject(validating); + } + const result = this.page.evaluate( + (contactId: string) => WAPI.getNumberProfile(contactId), + contactId + ); + if (result['erro'] == true) { + reject(result); + } else { + resolve(result); + } + }); } /** diff --git a/src/lib/wapi/functions/get-host.js b/src/lib/wapi/functions/get-host.js index f7ea5711c..d4aa20d43 100644 --- a/src/lib/wapi/functions/get-host.js +++ b/src/lib/wapi/functions/get-host.js @@ -53,5 +53,8 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM */ export async function getHost() { - return Store.Me.attributes; + const fromwWid = await Store.MaybeMeUser.getMaybeMeUser(); + const idUser = await WAPI.sendExist(fromwWid._serialized); + const infoUser = await Store.MyStatus.getStatus(idUser); + return await WAPI._serializeMeObj(infoUser); } diff --git a/src/lib/wapi/serializers/serielize-me.js b/src/lib/wapi/serializers/serielize-me.js index 16ceda6ef..9e59d423b 100644 --- a/src/lib/wapi/serializers/serielize-me.js +++ b/src/lib/wapi/serializers/serielize-me.js @@ -3,35 +3,59 @@ export const _serializeMeObj = async (obj) => { return null; } - let appsImage = undefined; - const status = await Store.MyStatus.getStatus(obj.wid._serialized); - await Store.Profile.profilePicFind(obj.wid._serialized) - .then((e) => { - appsImage = e; - }) - .catch(() => {}); - const connection = await window.Store.State.default.state; + const connection = await window.Store.State.Socket.state; + let PicThumb = undefined; + + if (!obj.id.contact.profilePicThumb) { + PicThumb = await window.Store.ProfilePicThumb.get(obj.id.id._serialized); + } return Object.assign( {}, { - battery: obj.battery, - locales: obj.locales, + id: obj.id.id, + email: obj.id.email, + description: obj.id.description, statusConnection: connection, - phone: { - device_manufacturer: obj.phone.device_manufacturer, - device_model: obj.phone.device_model, - os_version: obj.phone.os_version, - wa_version: obj.phone.wa_version + businessHours: { + timezone: + obj.id.businessHours && obj.id.businessHours.timezone + ? obj.id.businessHours.timezone + : null }, - pushname: obj.pushname, - status: status.status, - appsImage: appsImage && appsImage.eurl ? appsImage.eurl : undefined, - wid: { - server: obj.wid.server, - user: obj.wid.user, - _serialized: obj.wid._serialized - } + pushname: + obj.id.contact && obj.id.contact.pushname + ? obj.id.contact.pushname + : null, + website: obj.id.website, + formattedTitle: obj.id.formattedTitle, + categories: obj.id.categories, + displayName: obj.id.contact.displayName, + isBusiness: obj.id.contact.isBusiness, + imgUrl: + obj.id.contact && + obj.id.contact.profilePicThumb && + obj.id.contact.profilePicThumb.eurl + ? obj.id.contact.profilePicThumb.eurl + : PicThumb && PicThumb.eurl + ? PicThumb.eurl + : null, + imgFull: + obj.id.contact && + obj.id.contact.profilePicThumb && + obj.id.contact.profilePicThumb.imgFull + ? obj.id.contact.profilePicThumb.imgFull + : PicThumb && PicThumb.imgFull + ? PicThumb.imgFull + : null, + previewEurl: + obj.id.contact && + obj.id.contact.profilePicThumb && + obj.id.contact.profilePicThumb.previewEurl + ? obj.id.contact.profilePicThumb.previewEurl + : PicThumb && PicThumb.imgs + ? PicThumb.imgs + : null } ); };