Skip to content

Commit

Permalink
fix: Undefined or null to object sendMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Mar 1, 2021
1 parent f80467a commit 1b34977
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/lib/wapi/functions/send-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,28 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNMMNMNMMMNMMNNMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
async function isInsideTo(to) {
let err;
do {
try {
await new Promise((r) => setTimeout(r, 2000));
let chatTo = await WAPI.getchatId(to);
if (typeof chatTo !== 'undefined') {
err = false;
return chatTo;
} else {
throw 1;
}
} catch (e) {
err = true;
}
} while (err);
}
export async function sendMessage(to, content) {
const chat = !Store.Chat.get(to)
? await WAPI.sendExist(to)
: await Store.Chat.get(to);
if (typeof content != 'string' || content.length === 0) {
return WAPI.scope(to, true, 404, 'It is necessary to write a text!');
}
const chat = await WAPI.sendExist(to);
const m = { type: 'sendtext', text: content };
if (chat && chat.status != 404) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
Expand All @@ -75,7 +93,7 @@ export async function sendMessage(to, content) {
var result = (
await Promise.all(window.Store.addAndSendMsgToChat(chat, message))
)[1];
let To = await WAPI.getchatId(chat.id);
let To = await isInsideTo(chat.id);
if (result === 'success' || result === 'OK') {
let obj = WAPI.scope(To, false, result, content);
Object.assign(obj, m);
Expand Down

0 comments on commit 1b34977

Please sign in to comment.