fix: cleanMessage for reaction messages

This commit is contained in:
Adhiraj Singh
2022-05-23 12:46:34 +05:30
parent ebec02908c
commit 4ea2c33cfa
2 changed files with 7 additions and 6 deletions

View File

@@ -505,7 +505,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
await sendReceipt(msg.key.remoteJid!, participant, [msg.key.id!], type) await sendReceipt(msg.key.remoteJid!, participant, [msg.key.id!], type)
} }
cleanMessage(msg) cleanMessage(msg, authState.creds.me!.id)
ev.emit('messages.upsert', { messages: [msg], type: stanza.attrs.offline ? 'append' : 'notify' }) ev.emit('messages.upsert', { messages: [msg], type: stanza.attrs.offline ? 'append' : 'notify' })
} }
) )

View File

@@ -22,16 +22,17 @@ const MSG_MISSED_CALL_TYPES = new Set([
]) ])
/** Cleans a received message to further processing */ /** Cleans a received message to further processing */
export const cleanMessage = (message: proto.IWebMessageInfo) => { export const cleanMessage = (message: proto.IWebMessageInfo, meId: string) => {
// ensure remoteJid doesn't have device or agent in it // ensure remoteJid doesn't have device or agent in it
message.key.remoteJid = jidNormalizedUser(message.key.remoteJid!) message.key.remoteJid = jidNormalizedUser(message.key.remoteJid!)
const content = normalizeMessageContent(message.message) const content = normalizeMessageContent(message.message)
if(content) { // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
// if the message has a reaction, ensure fromMe & remoteJid are from our perspective if(content?.reactionMessage) {
const msgKey = content.reactionMessage!.key! const msgKey = content.reactionMessage.key!
if(!message.key.fromMe) { if(!message.key.fromMe) {
msgKey.fromMe = areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId)
msgKey.remoteJid = message.key.remoteJid msgKey.remoteJid = message.key.remoteJid
msgKey.fromMe = !msgKey.fromMe msgKey.participant = msgKey.participant || message.key.participant
} }
} }
} }