Skip to content

Commit

Permalink
fix: checkNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Feb 23, 2022
1 parent 22ba1c5 commit 0a20479
Show file tree
Hide file tree
Showing 9 changed files with 7,017 additions and 5,764 deletions.
8 changes: 8 additions & 0 deletions src/api/layers/retriever.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ export class RetrieverLayer extends SenderLayer {
});
}

/**
* check if it's beta
* @returns boolean
*/
public async isBeta() {
return await this.page.evaluate(() => WAPI.isBeta());
}

/**
* Retrieves all undread Messages
* @param includeMe
Expand Down
13 changes: 13 additions & 0 deletions src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,16 @@ export async function saveToken(

return token;
}

export async function isBeta(page: puppeteer.Page) {
return await page.evaluate(() => {
if (
window.localStorage.getItem('WASecretBundle') &&
window.localStorage.getItem('WAToken1') &&
window.localStorage.getItem('WAToken2')
) {
return true;
}
return false;
});
}
34 changes: 22 additions & 12 deletions src/controllers/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import { CreateConfig, defaultOptions } from '../config/create-config';
import { tokenSession } from '../config/tokenSession.config';
import { checkFileJson } from '../api/helpers/check-token-file';
import { SocketState, SocketStream } from '../api/model/enum';
import { SessionTokenCkeck, saveToken } from './auth';
import { SessionTokenCkeck, saveToken, isBeta } from './auth';
import { initWhatsapp, initBrowser } from './browser';
import { welcomeScreen } from './welcome';
/**
Expand Down Expand Up @@ -297,19 +297,29 @@ export async function create(

client.onStateChange(async (state) => {
if (state === SocketState.PAIRING) {
await page.waitForFunction(
() => {
if (document.querySelectorAll('._2Nr6U').length) {
return true;
const device = await page
.waitForFunction(
() => {
if (document.querySelectorAll('._2Nr6U').length) {
return true;
}
},
{
timeout: 0,
polling: 100
}
},
{
timeout: 0,
polling: 100
)
.catch();
if (device) {
const ckeckVersion = await isBeta(page);
if (ckeckVersion === false) {
await page.evaluate(async () => {
await window.Store.Login.triggerCriticalSyncLogout();
});
}
if (statusFind) {
statusFind('deviceNotConnected', session);
}
);
if (statusFind) {
statusFind('deviceNotConnected', session);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/lib/wapi/functions/check-beta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export async function isBeta() {
if (
!window.localStorage.getItem('WASecretBundle') &&
!window.localStorage.getItem('WAToken1') &&
!window.localStorage.getItem('WAToken2')
) {
return true;
}
return false;
}
3 changes: 1 addition & 2 deletions src/lib/wapi/functions/check-number-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export async function checkNumberStatus(id, conn = false) {
}
}

const checkBeta = document.querySelector('._3hcUV');
if (checkBeta && checkBeta.innerText === 'BETA') {
if (WAPI.isBeta()) {
return await Store.checkNumberBeta(id)
.then((result) => {
if (!!result && typeof result === 'object') {
Expand Down
1 change: 1 addition & 0 deletions src/lib/wapi/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ export { sendButtons } from './send-buttons';
export { sendListMenu } from './send-list-menu';
export { checkChat } from './check-chat';
export { checkNumberStatus } from './check-number-status';
export { isBeta } from './check-beta';
4 changes: 3 additions & 1 deletion src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ import {
sendListMenu,
checkChat,
checkNumberStatus,
sendCheckType
sendCheckType,
isBeta
} from './functions';
import {
base64ToFile,
Expand Down Expand Up @@ -243,6 +244,7 @@ if (typeof window.WAPI === 'undefined') {
window.WAPI.checkChat = checkChat;
window.WAPI.checkNumberStatus = checkNumberStatus;
window.WAPI.sendCheckType = sendCheckType;
window.WAPI.isBeta = isBeta;

//Profile
window.WAPI.setProfilePic = setProfilePic;
Expand Down
1 change: 1 addition & 0 deletions src/types/WAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ interface WAPI {
includeMe: boolean,
includeNotifications: boolean
) => Message[];
isBeta: () => boolean;
getAllNewMessages: () => Message[];
getAllUnreadMessages: () => PartialMessage[];
getBatteryLevel: () => number;
Expand Down
Loading

0 comments on commit 0a20479

Please sign in to comment.