Skip to content

Commit

Permalink
feat: checkNumber - state
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Sep 30, 2021
1 parent bfc191a commit d617640
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
37 changes: 27 additions & 10 deletions src/lib/wapi/functions/check-number-status.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
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) {
data.numberExists = true;
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),
});
}
}
4 changes: 1 addition & 3 deletions src/lib/wapi/functions/check-send-exist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/wapi/serializers/serialize-number-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);
};

0 comments on commit d617640

Please sign in to comment.