Skip to content

Commit

Permalink
fix: Fixed ninth digit problem (close #370)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Dec 1, 2020
1 parent a9623cd commit ee970dd
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 100 deletions.
31 changes: 13 additions & 18 deletions src/lib/wapi/functions/fix-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,24 @@ export async function pinChat(chatId, type = true, notExist = false) {
let typeFix = type ? 'pin' : 'unpin',
retult = void 0;
var chat = await WAPI.sendExist(chatId, true, notExist);
if (chat.erro === false || chat.__x_id) {
var ListChat = await Store.Chat.get(chatId);
if (!chat.erro) {
var m = {
type: 'pinChat',
typefix: typeFix,
},
To = await WAPI.getchatId(chat.id);
Promise.all(
ListChat
? await Store.pinChat
.setPin(chat, type)
.then((_) => {
var obj = WAPI.scope(To, false, 'OK', null);
Object.assign(obj, m);
retult = obj;
})
.catch((error) => {
var obj = WAPI.scope(To, true, error, 'Pin Chat first');
Object.assign(obj, m);
retult = obj;
})
: ''
);
await Store.pinChat
.setPin(chat, type)
.then((_) => {
var obj = WAPI.scope(To, false, 'OK', null);
Object.assign(obj, m);
retult = obj;
})
.catch((error) => {
var obj = WAPI.scope(To, true, error, 'Pin Chat first');
Object.assign(obj, m);
retult = obj;
});
return retult;
} else {
return chat;
Expand Down
13 changes: 5 additions & 8 deletions src/lib/wapi/functions/send-contact-vcard-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ export async function sendContactVcardList(chatId, contacts) {
return WAPI.scope(chatId, true, null, text);
}
var chat = await WAPI.sendExist(chatId);
if (chat.erro === false || chat.__x_id) {
var ListChat = await Store.Chat.get(chatId),
tempMsg = Object.create(
if (!chat.erro) {
var tempMsg = Object.create(
Store.Msg.models.filter(
(msg) => msg.__x_isSentByMe && !msg.quotedMsg
)[0]
Expand Down Expand Up @@ -102,13 +101,11 @@ export async function sendContactVcardList(chatId, contacts) {
isNewMsg: !0,
};
Object.assign(tempMsg, extend);
var result = await Promise.all(
ListChat ? Store.addAndSendMsgToChat(chat, tempMsg) : ''
);
var result = (await Store.addAndSendMsgToChat(chat, tempMsg)) || '';
var m = { from: contacts, type: 'multi_vcard' },
To = await WAPI.getchatId(chat.id);
if (result[1] === 'success' || result[1] === 'OK') {
var obj = WAPI.scope(To, false, result[1], null);
if (result === 'success' || result === 'OK') {
var obj = WAPI.scope(To, false, result, null);
Object.assign(obj, m);
return obj;
} else {
Expand Down
13 changes: 5 additions & 8 deletions src/lib/wapi/functions/send-contact-vcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export async function sendContactVcard(chatId, contact, name) {
var chat = await WAPI.sendExist(chatId);
var cont = await WAPI.sendExist(contact);
if (chat.id && cont.id) {
var ListChat = await Store.Chat.get(chatId);
var newId = window.WAPI.getNewMessageId(chatId);
var newId = window.WAPI.getNewMessageId(chat.id);
var tempMsg = Object.create(
Store.Msg.models.filter((msg) => msg.__x_isSentByMe && !msg.quotedMsg)[0]
);
Expand All @@ -77,17 +76,15 @@ export async function sendContactVcard(chatId, contact, name) {
isNewMsg: !0,
};
Object.assign(tempMsg, extend);
var result = await Promise.all(
ListChat ? Store.addAndSendMsgToChat(chat, tempMsg) : ''
);
var result = (await Store.addAndSendMsgToChat(chat, tempMsg)) || '';
var m = { from: contact, type: 'vcard' },
To = await WAPI.getchatId(chat.id);
if (result[1] === 'success' || result[1] === 'OK') {
var obj = WAPI.scope(To, false, result[1], null);
if (result === 'success' || result === 'OK') {
var obj = WAPI.scope(To, false, result, null);
Object.assign(obj, m);
return obj;
} else {
var obj = WAPI.scope(To, true, result[1], null);
var obj = WAPI.scope(To, true, result, null);
Object.assign(obj, m);
return obj;
}
Expand Down
10 changes: 3 additions & 7 deletions src/lib/wapi/functions/send-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,11 @@ export async function sendFile(imgBase64, chatid, filename, caption, type) {
mime = mime[1];
}
var chat = await WAPI.sendExist(chatid);
if (chat.erro === false || chat.__x_id) {
var ListChat = await Store.Chat.get(chatid);
if (!chat.erro) {
var mediaBlob = base64ToFile(imgBase64, filename),
mediaCollection = await processFiles(chat, mediaBlob),
media = mediaCollection.models[0],
result = await Promise.all(
ListChat ? await media.sendToChat(chat, { caption: caption }) : ''
);
result = result.join('');
media = mediaCollection.models[0];
var result = (await media.sendToChat(chat, { caption: caption })) || '';
var m = { type: type, filename: filename, text: caption, mimeType: mime },
To = await WAPI.getchatId(chat.id);
if (result === 'success' || result === 'OK') {
Expand Down
18 changes: 6 additions & 12 deletions src/lib/wapi/functions/send-link-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export async function sendLinkPreview(chatId, url, text) {
text = text || null;
text = text || '';
const _Path = {
Protocol: '^(https?:\\/\\/)?',
Domain: '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|',
Expand All @@ -79,18 +79,12 @@ export async function sendLinkPreview(chatId, url, text) {
return WAPI.scope(chatId, true, null, text);
}
var chat = await WAPI.sendExist(chatId);
if (chat.erro === false || chat.__x_id) {
var ListChat = await Store.Chat.get(chatId);
if (!chat.erro) {
const linkPreview = await Store.WapQuery.queryLinkPreview(url);
var result = Promise.all(
ListChat
? await chat.sendMessage(
text.includes(url) ? text : `${url}\n${text}`,
{ linkPreview }
)
: ''
);
result = result._value.join('');
var result =
(await chat.sendMessage(text.includes(url) ? text : `${url}\n${text}`, {
linkPreview,
})) || '';
var m = { type: 'LinkPreview', url: url, text: text },
To = await WAPI.getchatId(chat.id);
if (result === 'success' || result === 'OK') {
Expand Down
13 changes: 5 additions & 8 deletions src/lib/wapi/functions/send-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export async function sendLocation(
) {
var chat = await WAPI.sendExist(chatId);

if (chat.erro === false || chat.__x_id) {
var ListChat = await Store.Chat.get(chatId);
if (!chat.erro) {
var tempMsg = await Object.create(
Store.Msg.models.filter((msg) => msg.__x_isSentByMe && !msg.quotedMsg)[0]
);
Expand Down Expand Up @@ -96,9 +95,7 @@ export async function sendLocation(
};

Object.assign(tempMsg, extend);
var result = await Promise.all(
ListChat ? Store.addAndSendMsgToChat(chat, tempMsg) : ''
);
var result = (await Store.addAndSendMsgToChat(chat, tempMsg)) || '';
var m = {
latitude: latitude,
longitude: longitude,
Expand All @@ -107,12 +104,12 @@ export async function sendLocation(
},
obj,
To = await WAPI.getchatId(chat.id);
if (result[1] == 'success' || result[1] == 'OK') {
obj = WAPI.scope(To, false, result[1], null);
if (result == 'success' || result == 'OK') {
obj = WAPI.scope(To, false, result, null);
Object.assign(obj, m);
return obj;
} else {
obj = WAPI.scope(To, true, result[1], null);
obj = WAPI.scope(To, true, result, null);
Object.assign(obj, m);
return obj;
}
Expand Down
47 changes: 21 additions & 26 deletions src/lib/wapi/functions/send-mute.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export async function sendMute(chatId, time, type) {
var chat = await WAPI.sendExist(chatId);
if (chat.erro === false || chat.__x_id) {
if (!chat.erro) {
let TimeInt = null;
var result = null,
remove = null,
texto = null;
var ListChat = await Store.Chat.get(chatId),
To = await WAPI.getchatId(chat.id),
isMute = await window.Store.Mute.get(chatId),
var To = await WAPI.getchatId(chat.id),
isMute = await window.Store.Mute.get(chat.id),
m = { type: 'sendMute', time: time, timeType: type };
if (typeof time === 'number' && typeof type === 'string') {
switch (type) {
Expand All @@ -87,30 +86,26 @@ export async function sendMute(chatId, time, type) {
);
break;
}
ListChat
? await window.Store.SendMute.sendConversationMute(chatId, TimeInt, 0)
.then((e) => {
result = e;
})
.catch((e) => {
result = e;
})
: '';
await window.Store.SendMute.sendConversationMute(chat.id, TimeInt, 0)
.then((e) => {
result = e;
})
.catch((e) => {
result = e;
});
} else {
remove = true;
ListChat
? await window.Store.SendMute.sendConversationMute(
chatId,
0,
isMute.__x_expiration
)
.then((e) => {
result = e;
})
.catch((e) => {
result = e;
})
: '';
await window.Store.SendMute.sendConversationMute(
chat.id,
0,
isMute.__x_expiration
)
.then((e) => {
result = e;
})
.catch((e) => {
result = e;
});
}
if (result.status === 200) {
if (remove) {
Expand Down
21 changes: 8 additions & 13 deletions src/lib/wapi/functions/send-sticker.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
export async function sendSticker(sticker, chatId, metadata, type) {
var chat = await WAPI.sendExist(chatId);

if (chat.erro === false || chat.__x_id) {
var ListChat = await Store.Chat.get(chatId),
stick = new window.Store.Sticker.default.modelClass();
if (!chat.erro) {
var stick = new window.Store.Sticker.default.modelClass();

stick.__x_clientUrl = sticker.clientUrl;
stick.__x_filehash = sticker.filehash;
Expand All @@ -72,18 +71,14 @@ export async function sendSticker(sticker, chatId, metadata, type) {

await stick.initialize();

var result = await Promise.all(
ListChat
? await stick.sendToChat(chat, {
stickerIsFirstParty: false,
stickerSendOrigin: 6,
})
: ''
);
result = result.join('');
var result =
(await stick.sendToChat(chat, {
stickerIsFirstParty: false,
stickerSendOrigin: 6,
})) || '';
var m = { type: type },
obj,
To = await WAPI.getchatId(chatId);
To = await WAPI.getchatId(chat.id);
if (result === 'OK') {
obj = WAPI.scope(To, false, result, null);
Object.assign(obj, m);
Expand Down

0 comments on commit ee970dd

Please sign in to comment.