forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reply.js
100 lines (94 loc) · 2.43 KB
/
reply.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
97
98
99
100
export async function reply(chatId, content, quotedMessageId) {
if (typeof chatId != 'string') {
return WAPI.scope(
null,
true,
404,
'enter the chatid variable as an string'
);
}
if (typeof content != 'string') {
return WAPI.scope(
null,
true,
404,
'enter the content variable as an string'
);
}
if (typeof quotedMessageId != 'string') {
return WAPI.scope(
null,
true,
404,
'enter the content variable as an string'
);
}
const chat = await WAPI.sendExist(chatId);
if (chat && chat.status != 404) {
let To = chat.id;
const m = { type: 'deleteMessages' };
let quotedMsgOptions = {};
let quotedMessage = await WAPI.getMessageById(quotedMessageId, null, false);
if (quotedMessage.erro == undefined) {
let checkID = await WAPI.checkIdMessage(
quotedMessage.to._serialized,
quotedMessageId
);
if (checkID.erro == true) {
return checkID;
}
} else {
let obj = WAPI.scope(
To,
true,
404,
`The id ${quotedMessageId} does not exist!`
);
Object.assign(obj, m);
return obj;
}
quotedMsgOptions = quotedMessage.msgContextInfo(chat);
let checkID = await WAPI.checkIdMessage(chatId, quotedMessageId);
if (checkID.erro == true) {
return checkID;
}
const 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;
}
const message = {
id: newMsgId,
ack: 0,
body: content,
from: fromwWid,
to: chat.id,
local: !0,
self: 'out',
t: parseInt(new Date().getTime() / 1000),
isNewMsg: !0,
type: 'chat',
...quotedMsgOptions
};
const result = (
await Promise.all(window.Store.addAndSendMsgToChat(chat, message))
)[1];
if (
result === 'success' ||
result === 'OK' ||
result.messageSendResult === 'OK'
) {
let obj = WAPI.scope(newMsgId, false, result, '');
Object.assign(obj, m);
return obj;
} else {
let obj = WAPI.scope(newMsgId, true, result, '');
Object.assign(obj, m);
return obj;
}
} else {
return chat;
}
}