Skip to content

Commit

Permalink
fix: get me and State
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Nov 24, 2021
1 parent 0e055ae commit c1fac1b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/api/helpers/scrape-desconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ declare global {
}
export async function scrapeDesconnected(page: Page): Promise<boolean> {
const result = await page.evaluate(() => {
const scrape = window.Store.State.default.on('change:state');
const scrape = window.Store.State.Socket.on('change:state');
if (
scrape.__x_stream === 'DISCONNECTED' &&
scrape.__x_state === 'CONNECTED'
Expand Down
2 changes: 1 addition & 1 deletion src/api/layers/host.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class HostLayer {
public async getConnectionState(): Promise<SocketState> {
return await this.page.evaluate(() => {
//@ts-ignore
return Store.State.default.state;
return Store.State.Socket.state;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/check-number-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function checkNumberStatus(id, conn = true) {
}

if (conn === true) {
const connection = window.Store.State.default.state;
const connection = window.Store.State.Socket.state;
if (connection !== 'CONNECTED') {
Object.assign(err, {
text: 'No connection with WhatsApp',
Expand Down
8 changes: 6 additions & 2 deletions src/lib/wapi/functions/check-send-exist.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export function scope(id, erro, status, text = null, result = null) {
const object = {
me: Store.Me.attributes,
me: WAPI.getHost(),
to: id,
erro: erro,
text: text,
Expand Down Expand Up @@ -154,7 +154,11 @@ export async function sendExist(chatId, returnChat = true, Send = true) {
}
let ck = await window.WAPI.checkNumberStatus(chatId, false);

if (ck.status === 404 && !chatId.includes('@g.us')) {
if (
ck.status === 404 &&
!chatId.includes('@g.us') &&
!chatId.includes('@broadcast')
) {
return WAPI.scope(chatId, true, ck.status, 'The number does not exist');
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/wapi/listeners/add-on-state-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
export function addOnStateChange() {
let initialized = false;
const getData = () => {
return window.Store.State.default.state;
return window.Store.State.Socket.state;
};

window.WAPI.onStateChange = function (callback) {
window.WAPI.waitForStore('State', () => {
window.Store.State.default.on('change:state', () => callback(getData()));
window.Store.State.Socket.on('change:state', () => callback(getData()));
if (!initialized) {
initialized = true;
callback(getData());
Expand All @@ -74,12 +74,12 @@ export function addOnStateChange() {
export function addOnStreamChange() {
let initialized = false;
let getData = () => {
return window.Store.State.default.stream;
return window.Store.State.Socket.stream;
};

window.WAPI.onStreamChange = function (callback) {
window.WAPI.waitForStore('State', () => {
window.Store.State.default.on('change:stream', () => callback(getData()));
window.Store.State.Socket.on('change:stream', () => callback(getData()));
if (!initialized) {
initialized = true;
callback(getData());
Expand Down

1 comment on commit c1fac1b

@jonalan7
Copy link
Contributor Author

@jonalan7 jonalan7 commented on c1fac1b Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.