Skip to content

Commit

Permalink
fix: Send with more digits
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Nov 16, 2021
1 parent dc6e5db commit 14e2fea
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/lib/wapi/functions/check-number-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export async function checkNumberStatus(id, conn = true) {

throw err;
} catch (e) {
console.log(e);
return {
status: e.error,
text: e.text
Expand Down
24 changes: 10 additions & 14 deletions src/lib/wapi/functions/check-send-exist.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,24 @@ export function scope(id, erro, status, text = null, result = null) {
}
export async function getchatId(chatId) {
if (chatId) {
var to = await WAPI.getChatById(chatId);
let to = await WAPI.getChatById(chatId);
if (to && typeof to === 'object') {
var objTo = to.lastReceivedKey,
extend = {
let objTo = to.lastReceivedKey;
if (objTo && typeof objTo === 'object') {
let extend = {
formattedName: to.contact.formattedName,
isBusiness: to.contact.isBusiness,
isMyContact: to.contact.isMyContact,
verifiedName: to.contact.verifiedName,
pushname: to.contact.pushname,
isOnline: to.isOnline
};
Object.assign(objTo, extend);
return objTo;
Object.assign(objTo, extend);
return objTo;
}
}
return undefined;
}
return undefined;
}

export function sendCheckType(chatId = undefined) {
Expand Down Expand Up @@ -150,15 +152,9 @@ export async function sendExist(chatId, returnChat = true, Send = true) {
if (!!checkType && checkType.status === 404) {
return checkType;
}
let ck = await window.WAPI.checkNumberStatus(chatId);
let ck = await window.WAPI.checkNumberStatus(chatId, false);

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

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/forward-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function forwardMessages(chatId, messages, skipMyMessages) {

return new Promise(async (resolve, reject) => {
if (chat.id) {
let newMsgId = await window.WAPI.getNewMessageId(chat.id);
let newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
let inChat = await WAPI.getchatId(chat.id).catch(() => {});
if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
Expand Down
15 changes: 12 additions & 3 deletions src/lib/wapi/functions/get-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,23 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export function getChat(id) {
if (!id) return false;
if (!id) {
return false;
}
id = typeof id == 'string' ? id : id._serialized;
const found = window.Store.Chat.get(id);
if (found)
let found = Store.Chat.get(id);
if (!found) {
const ConstructChat = new window.Store.UserConstructor(id, {
intentionallyUsePrivateConstructor: !0
});
found = Store.Chat.find(ConstructChat) || false;
}
if (found) {
found.sendMessage = found.sendMessage
? found.sendMessage
: function () {
return window.Store.sendMessage.apply(this, arguments);
};
}
return found;
}
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/get-new-message-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function getNewMessageId(chatId) {
const newMsgId = new Object();
newMsgId.fromMe = true;
newMsgId.id = await WAPI.getNewId().toUpperCase();
newMsgId.remote = new Store.WidFactory.createWid(chatId);
newMsgId.remote = new Store.WidFactory.createWid(chat.id._serialized);
newMsgId._serialized = `${newMsgId.fromMe}_${newMsgId.remote}_${newMsgId.id}`;
const Msgkey = new Store.MsgKey(newMsgId);
return Msgkey;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function sendButtons(to, title, buttons, subtitle) {
const chat = await WAPI.sendExist(to);

if (chat && chat.status != 404 && chat.id) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();

const message = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-contact-vcard-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function sendContactVcardList(chatId, contacts) {
}
});

var newMsgId = await window.WAPI.getNewMessageId(chat.id);
var newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
let inChat = await WAPI.getchatId(chat.id).catch(() => {});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-contact-vcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function sendContactVcard(chatId, contact, name) {
const cont = await WAPI.sendExist(contact);

if (chat.id && cont.id) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const inChat = await WAPI.getchatId(chat.id).catch(() => {});

if (inChat) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-link-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function sendLinkPreview(chatId, url, text) {
var chat = await WAPI.sendExist(chatId);
if (!chat.erro) {
const linkPreview = await Store.WapQuery.queryLinkPreview(url);
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
let inChat = await WAPI.getchatId(chat.id).catch(() => {});
if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-list-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function sendListMenu(
const chat = await WAPI.sendExist(to);

if (chat && chat.status != 404 && chat.id) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
const inChat = await WAPI.getchatId(chat.id).catch(() => {});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function sendLocation(
const chat = await WAPI.sendExist(chatId);

if (chat && chat.status != 404 && chat.id) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const inChat = await WAPI.getchatId(chat.id).catch(() => {});
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();

Expand Down
3 changes: 2 additions & 1 deletion src/lib/wapi/functions/send-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export async function sendMessage(to, content) {

if (chat && chat.status != 404 && chat.id) {
const m = { type: 'sendText', text: content };
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();

let inChat = await WAPI.getchatId(chat.id).catch(() => {
return WAPI.scope(chat.id, true, 404, 'Error to number ' + to);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/sendMessageOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export async function sendMessageOptions(chatId, content, options = {}) {
options = { ...options, ...preview };
}
}
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
const message = {
...options,
Expand Down

0 comments on commit 14e2fea

Please sign in to comment.