mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add replace type for messages.upsert
This commit is contained in:
@@ -98,12 +98,12 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
|
||||
const attrs = response.attrs
|
||||
Object.assign(content, attrs) // update message
|
||||
|
||||
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }])
|
||||
ev.emit('messages.upsert', { messages: [message], type: 'replace' })
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
const onMessage = (message: WAMessage, type: MessageUpdateType | 'update') => {
|
||||
const onMessage = (message: WAMessage, type: MessageUpdateType) => {
|
||||
const jid = message.key.remoteJid!
|
||||
// store chat updates in this
|
||||
const chatUpdate: Partial<Chat> = {
|
||||
@@ -213,11 +213,8 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
|
||||
if(Object.keys(chatUpdate).length > 1) {
|
||||
ev.emit('chats.update', [chatUpdate])
|
||||
}
|
||||
if(type === 'update') {
|
||||
ev.emit('messages.update', [ { update: message, key: message.key } ])
|
||||
} else {
|
||||
ev.emit('messages.upsert', { messages: [message], type })
|
||||
}
|
||||
|
||||
ev.emit('messages.upsert', { messages: [message], type })
|
||||
}
|
||||
|
||||
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn)
|
||||
@@ -306,11 +303,12 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
|
||||
onMessage(msg, 'notify')
|
||||
}
|
||||
})
|
||||
// If a message has been updated (usually called when a video message gets its upload url, or live locations)
|
||||
// If a message has been updated
|
||||
// usually called when a video message gets its upload url, or live locations or ciphertext message gets fixed
|
||||
socketEvents.on ('CB:action,add:update,message', (node: BinaryNode) => {
|
||||
const msgs = getBinaryNodeMessages(node)
|
||||
for(const msg of msgs) {
|
||||
onMessage(msg, 'update')
|
||||
onMessage(msg, 'replace')
|
||||
}
|
||||
})
|
||||
// message status updates
|
||||
|
||||
@@ -165,7 +165,7 @@ export type MessageContentGenerationOptions = MediaGenerationOptions & {
|
||||
}
|
||||
export type MessageGenerationOptions = MessageContentGenerationOptions & MessageGenerationOptionsFromContent
|
||||
|
||||
export type MessageUpdateType = 'append' | 'notify' | 'prepend' | 'last'
|
||||
export type MessageUpdateType = 'append' | 'notify' | 'prepend' | 'last' | 'replace'
|
||||
|
||||
export type MessageInfoEventMap = { [jid: string]: Date }
|
||||
export interface MessageInfo {
|
||||
|
||||
Reference in New Issue
Block a user