Skip to content

Commit

Permalink
fix: get host
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Nov 24, 2021
1 parent cd62707 commit 0e055ae
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
}
},
"compile-hero.disable-compile-files-on-did-save-code": false
}
31 changes: 27 additions & 4 deletions src/api/layers/retriever.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
});
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/lib/wapi/functions/get-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
70 changes: 47 additions & 23 deletions src/lib/wapi/serializers/serielize-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
);
};

0 comments on commit 0e055ae

Please sign in to comment.