feat: add replace type for messages.upsert

This commit is contained in:
Adhiraj Singh
2021-12-23 10:54:17 +05:30
parent 8c37ccf525
commit 5ae0b98636
2 changed files with 8 additions and 10 deletions

View File

@@ -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

View File

@@ -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 {