fix: correctly copy msg for forward

This commit is contained in:
Adhiraj Singh
2021-12-20 11:12:21 +05:30
parent ed4f234fd8
commit c1301deda0

View File

@@ -197,7 +197,8 @@ export const generateForwardMessageContent = (
) => { ) => {
let content = message.message let content = message.message
if (!content) throw new Boom('no content in message', { statusCode: 400 }) if (!content) throw new Boom('no content in message', { statusCode: 400 })
content = JSON.parse(JSON.stringify(content)) // hacky copy // hacky copy
content = proto.Message.decode(proto.Message.encode(message.message).finish())
let key = Object.keys(content)[0] as MessageType let key = Object.keys(content)[0] as MessageType
@@ -342,13 +343,13 @@ export const generateWAMessageFromContent = (
message: WAMessageContent, message: WAMessageContent,
options: MessageGenerationOptionsFromContent options: MessageGenerationOptionsFromContent
) => { ) => {
if (!options.timestamp) options.timestamp = new Date() // set timestamp to now if(!options.timestamp) options.timestamp = new Date() // set timestamp to now
const key = Object.keys(message)[0] const key = Object.keys(message)[0]
const timestamp = unixTimestampSeconds(options.timestamp) const timestamp = unixTimestampSeconds(options.timestamp)
const { quoted, userJid } = options const { quoted, userJid } = options
if (quoted) { if(quoted) {
const participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid) const participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid)
message[key].contextInfo = message[key].contextInfo || { } message[key].contextInfo = message[key].contextInfo || { }
@@ -358,7 +359,7 @@ export const generateWAMessageFromContent = (
// if a participant is quoted, then it must be a group // if a participant is quoted, then it must be a group
// hence, remoteJid of group must also be entered // hence, remoteJid of group must also be entered
if (quoted.key.participant || quoted.participant) { if(quoted.key.participant || quoted.participant) {
message[key].contextInfo.remoteJid = quoted.key.remoteJid message[key].contextInfo.remoteJid = quoted.key.remoteJid
} }
} }
@@ -380,8 +381,9 @@ export const generateWAMessageFromContent = (
message message
} }
} }
} }
message = WAProto.Message.fromObject (message)
message = WAProto.Message.fromObject(message)
const messageJSON = { const messageJSON = {
key: { key: {
@@ -395,7 +397,7 @@ export const generateWAMessageFromContent = (
participant: jid.includes('@g.us') ? userJid : undefined, participant: jid.includes('@g.us') ? userJid : undefined,
status: WAMessageStatus.PENDING status: WAMessageStatus.PENDING
} }
return WAProto.WebMessageInfo.fromObject (messageJSON) return WAProto.WebMessageInfo.fromObject(messageJSON)
} }
export const generateWAMessage = async( export const generateWAMessage = async(
jid: string, jid: string,