Skip to content

Commit

Permalink
fix: forwardMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Feb 28, 2021
1 parent 9657865 commit 3570b9e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ const browserSessionToken = await client.getSessionTokenBrowser();
const getBlockList = await client.getBlockList();

// Retrieve messages in chat
//chatID chat id
//includeMe will be by default true, if you do not want to pass false
//includeNotifications will be by default true, if you do not want to pass false
//const Messages = await client.getAllMessagesInChat(chatID, includeMe, includeNotifications)
const Messages = await client.getAllMessagesInChat('[email protected]');

// Retrieve more chat message
Expand Down
48 changes: 38 additions & 10 deletions src/lib/wapi/functions/forward-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,51 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
import { getMessageById } from './get-message-by-id';

export async function forwardMessages(to, messages, skipMyMessages) {
export async function forwardMessages(chatId, messages, skipMyMessages) {
var chat = await WAPI.sendExist(chatId);

if (!Array.isArray(messages)) {
messages = [messages];
}
const toForward = (
var toForward = (
await Promise.all(
messages.map(async (msg) => {
if (typeof msg === 'string') {
return await getMessageById(msg, null, false);
} else {
return await getMessageById(msg.id, null, false);
}
return await getMessageById(msg, null, false);
})
)
).filter((msg) => (skipMyMessages ? !msg.__x_isSentByMe : true));

// const userId = new window.Store.UserConstructor(to);
const conversation = window.Store.Chat.get(to);
return conversation.forwardMessages(toForward);
if (chat.id) {
await Promise.each(toForward, async (e) => {
let conversation = await window.Store.Chat.get(chatId);
let newId = await window.WAPI.getNewMessageId(chat.id);
let tempMsg = await Object.create(
chat.msgs.filter((msg) => msg.__x_isSentByMe)
)[0];
let toFor = await Object.assign(e);
let extend = {
id: newId,
from: Store.Me.wid,
t: parseInt(new Date().getTime() / 1000),
to: chat.__x_contact.__x_id,
ack: 0,
participant: void 0,
local: !0,
self: 'out',
isNewMsg: !0,
star: !1,
isForwarded: toFor.isForwarded || !toFor.isSentByMe,
forwardedFromWeb: !0,
forwardingScore: 21,
multicast: false,
};
Object.assign(tempMsg, toFor);
Object.assign(tempMsg, extend);

return await Store.addAndSendMsgToChat(conversation, tempMsg);
}).then(async (t) => {
let result = await Promise.all(t);
console.log(result);
});
}
}

0 comments on commit 3570b9e

Please sign in to comment.