forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforward-messages.js
73 lines (66 loc) · 2.1 KB
/
forward-messages.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
export async function forwardMessages(chatId, messages, skipMyMessages) {
var chat = await WAPI.sendExist(chatId);
if (!Array.isArray(messages)) {
messages = [messages];
}
var toForward = (
await Promise.all(
messages.map(async (msg) => {
return await WAPI.getMessageById(msg, null, false);
})
)
).filter((msg) => (skipMyMessages ? !msg.__x_isSentByMe : true));
var m = { type: 'forwardMessages' };
return new Promise(async (resolve, reject) => {
let newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
let inChat = await WAPI.getchatId(chat.id).catch(() => {});
if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
chat.lastReceivedKey.id = inChat.id;
}
if (chat.id) {
await Promise.each(toForward, async (e) => {
if (typeof e.erro !== 'undefined' && e.erro === true) {
var obj = WAPI.scope(chatId, true, null, 'message not found');
Object.assign(obj, m);
reject(obj);
return;
}
let tempMsg = await Object.create(
chat.msgs.filter((msg) => msg.__x_isSentByMe)
)[0];
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
let toFor = await Object.assign(e);
let extend = {
id: newMsgId,
ack: 0,
from: fromwWid,
to: chat.id,
local: !0,
self: 'out',
t: parseInt(new Date().getTime() / 1000),
isNewMsg: !0,
isForwarded: true,
forwardingScore: 1,
multicast: true,
__x_isSentByMe: true
};
Object.assign(tempMsg, toFor);
Object.assign(tempMsg, extend);
return await Store.addAndSendMsgToChat(chat, tempMsg);
})
.then(async () => {
var obj = WAPI.scope(newMsgId, false, 200, null);
Object.assign(obj, m);
resolve(obj);
})
.catch(() => {
var obj = WAPI.scope(newMsgId, true, 404, null);
Object.assign(obj, m);
reject(obj);
});
} else {
reject(chat);
}
});
}