mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add clean message util before calling "messages.upsert"
This commit is contained in:
@@ -4,7 +4,7 @@ import { KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT } from '../Defaults'
|
||||
import { BaileysEventMap, MessageReceiptType, MessageUserReceipt, SocketConfig, WACallEvent, WAMessageStubType } from '../Types'
|
||||
import { debouncedTimeout, decodeMessageStanza, delay, encodeBigEndian, generateSignalPubKey, getCallStatusFromNode, getNextPreKeys, getStatusFromReceiptType, normalizeMessageContent, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils'
|
||||
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex'
|
||||
import processMessage from '../Utils/process-message'
|
||||
import processMessage, { cleanMessage } from '../Utils/process-message'
|
||||
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary'
|
||||
import { makeChatsSocket } from './chats'
|
||||
import { extractGroupMetadata } from './groups'
|
||||
@@ -505,7 +505,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
await sendReceipt(msg.key.remoteJid!, participant, [msg.key.id!], type)
|
||||
}
|
||||
|
||||
msg.key.remoteJid = jidNormalizedUser(msg.key.remoteJid!)
|
||||
cleanMessage(msg)
|
||||
ev.emit('messages.upsert', { messages: [msg], type: stanza.attrs.offline ? 'append' : 'notify' })
|
||||
}
|
||||
)
|
||||
|
||||
@@ -490,7 +490,7 @@ export const getContentType = (content: WAProto.IMessage | undefined) => {
|
||||
* @param content
|
||||
* @returns
|
||||
*/
|
||||
export const normalizeMessageContent = (content: WAMessageContent): WAMessageContent => {
|
||||
export const normalizeMessageContent = (content: WAMessageContent | undefined): WAMessageContent => {
|
||||
content = content?.ephemeralMessage?.message?.viewOnceMessage?.message ||
|
||||
content?.ephemeralMessage?.message ||
|
||||
content?.viewOnceMessage?.message ||
|
||||
|
||||
@@ -21,6 +21,21 @@ const MSG_MISSED_CALL_TYPES = new Set([
|
||||
WAMessageStubType.CALL_MISSED_VOICE
|
||||
])
|
||||
|
||||
/** Cleans a received message to further processing */
|
||||
export const cleanMessage = (message: proto.IWebMessageInfo) => {
|
||||
// ensure remoteJid doesn't have device or agent in it
|
||||
message.key.remoteJid = jidNormalizedUser(message.key.remoteJid!)
|
||||
const content = normalizeMessageContent(message.message)
|
||||
if(content) {
|
||||
// if the message has a reaction, ensure fromMe & remoteJid are from our perspective
|
||||
const msgKey = content.reactionMessage!.key!
|
||||
if(!message.key.fromMe) {
|
||||
msgKey.remoteJid = message.key.remoteJid
|
||||
msgKey.fromMe = !msgKey.fromMe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const processMessage = async(
|
||||
message: proto.IWebMessageInfo,
|
||||
{ downloadHistory, historyCache, meId, keyStore, accountSettings, logger, treatCiphertextMessagesAsReal }: ProcessMessageContext
|
||||
@@ -124,13 +139,11 @@ const processMessage = async(
|
||||
key: message.key,
|
||||
}
|
||||
const operation = content.reactionMessage?.text ? 'add' : 'remove'
|
||||
const msgKey = content.reactionMessage!.key!
|
||||
if(!message.key.fromMe) {
|
||||
msgKey.remoteJid = message.key.remoteJid
|
||||
msgKey.fromMe = !msgKey.fromMe
|
||||
map['messages.reaction'] = {
|
||||
reaction,
|
||||
key: content.reactionMessage!.key!,
|
||||
operation
|
||||
}
|
||||
|
||||
map['messages.reaction'] = { reaction, key: msgKey, operation }
|
||||
} else if(message.messageStubType) {
|
||||
const jid = message.key!.remoteJid!
|
||||
//let actor = whatsappID (message.participant)
|
||||
|
||||
Reference in New Issue
Block a user