-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathsend-contact-vcard-list.js
96 lines (82 loc) · 2.27 KB
/
send-contact-vcard-list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
export async function sendContactVcardList(chatId, contacts) {
if (typeof chatId != 'string') {
return WAPI.scope(
chatId,
true,
null,
"incorrect parameter, insert an string. Example: '[email protected]'"
);
}
if (!Array.isArray(contacts)) {
return WAPI.scope(
chatId,
true,
null,
"incorrect parameter, insert an array. Example: ['[email protected]', '[email protected], ... ]"
);
}
if (contacts.length === 1) {
return WAPI.scope(
chatId,
true,
null,
"Enter more than one number to send. Example: ['[email protected]', '[email protected], ... ]"
);
}
const chat = await WAPI.sendExist(chatId);
if (!chat.erro) {
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) {
if (typeof ar[key] === 'object') {
cont.push(ar[key].__x_contact);
}
}
var vcard = cont.map(async (e) => {
if (typeof e === 'object') {
return await window.Store.Vcard.vcardFromContactModel(e);
}
});
var newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
let inChat = await WAPI.getchatId(chat.id).catch(() => {});
if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
chat.lastReceivedKey.id = inChat.id;
}
var Vcards = await Promise.all(vcard);
const message = {
id: newMsgId,
ack: 0,
from: fromwWid,
local: !0,
self: 'in',
t: parseInt(new Date().getTime() / 1000),
to: chat.id,
type: 'multi_vcard',
vcardList: Vcards,
isNewMsg: !0
};
var result =
(await Promise.all(Store.addAndSendMsgToChat(chat, message)))[1] || '';
var m = { from: contacts, type: 'multi_vcard' };
if (
result === 'success' ||
result === 'OK' ||
result.messageSendResult === 'OK'
) {
var obj = WAPI.scope(newMsgId, false, result, null);
Object.assign(obj, m);
return obj;
} else {
var obj = WAPI.scope(newMsgId, true, result, null);
Object.assign(obj, m);
return obj;
}
} else {
return chat;
}
}