diff --git a/src/lib/wapi/functions/check-number-status.js b/src/lib/wapi/functions/check-number-status.js index 5cebd0ebb..309690c6e 100644 --- a/src/lib/wapi/functions/check-number-status.js +++ b/src/lib/wapi/functions/check-number-status.js @@ -1,15 +1,30 @@ -export async function checkNumberStatus(id) { - const checkType = WAPI.sendCheckType(id); - if (!!checkType && checkType.status === 404) { - return checkType; - } +export async function checkNumberStatus(id, conn = true) { try { + const err = { error: 404 }; + const checkType = WAPI.sendCheckType(id); + if (!!checkType && checkType.status === 404) { + Object.assign(err, { text: checkType.text }); + throw err; + } + if (conn === true) { + const connection = window.Store.State.default.state; + if (connection !== "CONNECTED") { + Object.assign( + err, + { + text: "No connection with WhatsApp", + connection: connection + } + ); + throw err; + } + } const result = await window.Store.WapQuery.queryExist(id); if (result.status === 404) { - throw 404; + throw err; } if (result.jid === undefined) { - throw 404; + throw err; } const data = window.WAPI._serializeNumberStatusObj(result); if (data.status == 200) { @@ -17,10 +32,12 @@ export async function checkNumberStatus(id) { data.profilePic = await WAPI.getProfilePicFromServer(id); return data; } - } catch (error) { + } catch (e) { return window.WAPI._serializeNumberStatusObj({ - status: error, - jid: new window.Store.WidFactory.createWid(id) + status: e.error, + text: e.text, + connection: e.connection, + jid: !!e.text ? undefined : new window.Store.WidFactory.createWid(id), }); } } diff --git a/src/lib/wapi/functions/check-send-exist.js b/src/lib/wapi/functions/check-send-exist.js index be25dda58..537b12fd6 100644 --- a/src/lib/wapi/functions/check-send-exist.js +++ b/src/lib/wapi/functions/check-send-exist.js @@ -141,9 +141,7 @@ export function sendCheckType(chatId = undefined) { 'incorrect parameters! Use as an example: 00000000-000000@g.us' ); } - } else { - return WAPI.scope(chatId, true, 404, 'The number must be string!'); - } + } } export async function sendExist(chatId, returnChat = true, Send = true) { diff --git a/src/lib/wapi/serializers/serialize-number-status.js b/src/lib/wapi/serializers/serialize-number-status.js index 03c08a9dd..85dbd4bca 100644 --- a/src/lib/wapi/serializers/serialize-number-status.js +++ b/src/lib/wapi/serializers/serialize-number-status.js @@ -64,7 +64,10 @@ export const _serializeNumberStatusObj = (obj) => { status: obj.status, isBusiness: obj.biz === true, canReceiveMessage: obj.status === 200, - profilePic: undefined + text: !!obj.text? obj.text : undefined, + connection: !!obj.connection? obj.connection : undefined, + profilePic: undefined, } ); }; +