Skip to content

Commit

Permalink
fix: sendContactVcard
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Jul 1, 2021
1 parent 3278bff commit e9ecd0c
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/lib/wapi/functions/send-contact-vcard.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
export async function sendContactVcard(chatId, contact, name) {
var chat = await WAPI.sendExist(chatId);
var cont = await WAPI.sendExist(contact);
const chat = await WAPI.sendExist(chatId);
const cont = await WAPI.sendExist(contact);

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

if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
chat.lastReceivedKey.id = inChat.id;
}
var tempMsg = Object.create(
Store.Msg.models.filter((msg) => msg.__x_isSentByMe && !msg.quotedMsg)[0]
);
var bod = await window.Store.Vcard.vcardFromContactModel(cont.__x_contact);

const fromwWid = await window.Store.Conn.wid;
var body = await window.Store.Vcard.vcardFromContactModel(cont.__x_contact);
name = !name ? cont.__x_formattedTitle : name;
var extend = {
ack: 0,
body: bod.vcard,
from: cont.__x_contact,
local: !0,
self: 'out',
var message = {
id: newMsgId,
ack: 0,
body: body.vcard,
from: fromwWid,
self: 'in',
vcardFormattedName: name,
isNewMsg: true,
t: parseInt(new Date().getTime() / 1000),
to: chatId,
to: chat.id,
type: 'vcard',
isNewMsg: !0,
};
Object.assign(tempMsg, extend);
var result =
(await Promise.all(Store.addAndSendMsgToChat(chat, tempMsg)))[1] || '';

const result = (
await Promise.all(window.Store.addAndSendMsgToChat(chat, message))
)[1];

var m = { from: contact, type: 'vcard' };
if (result === 'success' || result === 'OK') {
var obj = WAPI.scope(newMsgId, false, result, null);
Expand Down

0 comments on commit e9ecd0c

Please sign in to comment.