Skip to content

Commit

Permalink
fix: sendContactVcardList
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Jun 23, 2021
1 parent 27bb10c commit e6518cc
Showing 1 changed file with 47 additions and 25 deletions.
72 changes: 47 additions & 25 deletions src/lib/wapi/functions/send-contact-vcard-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,62 +54,84 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export async function sendContactVcardList(chatId, contacts) {
if (typeof chatId != 'string') {
var text =
"incorrect parameter, insert an string. Example: '222222222222@c.us'";
return WAPI.scope(chatId, true, null, text);
return WAPI.scope(
chatId,
true,
null,
"incorrect parameter, insert an string. Example: '222222222222@c.us'"
);
}

if (!Array.isArray(contacts)) {
var text =
"incorrect parameter, insert an array. Example: ['222222222222@c.us', '333333333333@c.us, ... ]";
return WAPI.scope(chatId, true, null, text);
return WAPI.scope(
chatId,
true,
null,
"incorrect parameter, insert an array. Example: ['222222222222@c.us', '333333333333@c.us, ... ]"
);
}

if (contacts.length === 1) {
var text =
"Enter more than one number to send. Example: ['222222222222@c.us', '333333333333@c.us, ... ]";
return WAPI.scope(chatId, true, null, text);
return WAPI.scope(
chatId,
true,
null,
"Enter more than one number to send. Example: ['222222222222@c.us', '333333333333@c.us, ... ]"
);
}
var chat = await WAPI.sendExist(chatId);

const chat = await WAPI.sendExist(chatId);

if (!chat.erro) {
var tempMsg = Object.create(
Store.Msg.models.filter(
(msg) => msg.__x_isSentByMe && !msg.quotedMsg
)[0]
),
conta = contacts.map(async (e) => {
return await WAPI.sendExist(e);
});
var conta = contacts.map(async (e) => {
return await WAPI.sendExist(e);
});

var ar = await Promise.all(conta);
var cont = new Array();

for (var key in ar) {
cont.push(ar[key].__x_contact);
if (typeof ar[key] === 'object') {
cont.push(ar[key].__x_contact);
}
}

var vcard = cont.map(async (e) => {
return await window.Store.Vcard.vcardFromContactModel(e);
if (typeof e === 'object') {
return await window.Store.Vcard.vcardFromContactModel(e);
}
});

var newMsgId = await window.WAPI.getNewMessageId(chatId);
const fromwWid = await window.Store.Conn.wid;
let inChat = await WAPI.getchatId(chatId).catch(() => {});

if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
chat.lastReceivedKey.id = inChat.id;
}

var Vcards = await Promise.all(vcard);
var extend = {

const message = {
id: newMsgId,
ack: 0,
from: chatId,
from: fromwWid,
local: !0,
self: 'out',
self: 'in',
t: parseInt(new Date().getTime() / 1000),
to: chatId,
type: 'multi_vcard',
vcardList: Vcards,
isNewMsg: !0,
vcardFormattedName: ' 2 contatos',
};
Object.assign(tempMsg, extend);

var result =
(await Promise.all(Store.addAndSendMsgToChat(chat, tempMsg)))[1] || '';
(await Promise.all(Store.addAndSendMsgToChat(chat, message)))[1] || '';

var m = { from: contacts, type: 'multi_vcard' };

if (result === 'success' || result === 'OK') {
var obj = WAPI.scope(newMsgId, false, result, null);
Object.assign(obj, m);
Expand Down

0 comments on commit e6518cc

Please sign in to comment.