forked from danielcardeenas/sulla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reply.js
37 lines (34 loc) Β· 951 Bytes
/
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
import { getNewMessageId } from './get-new-message-id';
/**
* Replys to message of given chat id
* @param {string} chatId
* @param {string} body
* @param {string | Message} quotedMsg Message id or message object
*/
export async function reply(chatId, body, quotedMsg) {
if (typeof quotedMsg !== 'object') {
quotedMsg = Store.Msg.get(quotedMsg);
}
const chat = Store.Chat.get(chatId);
const extras = {
quotedParticipant: quotedMsg.author || quotedMsg.from,
quotedStanzaID: quotedMsg.id.id,
};
let tempMsg = Object.create(chat.msgs.filter((msg) => msg.__x_isSentByMe)[0]);
const newId = getNewMessageId(chatId);
const extend = {
ack: 0,
id: newId,
local: !0,
self: 'out',
t: parseInt(new Date().getTime() / 1000),
to: chatId,
isNewMsg: !0,
type: 'chat',
quotedMsg,
body,
...extras,
};
Object.assign(tempMsg, extend);
await Store.addAndSendMsgToChat(chat, tempMsg);
}