mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
refactor: chats.set event
This commit is contained in:
@@ -192,7 +192,7 @@ const makeChatsSocket = (config: LegacySocketConfig) => {
|
||||
})
|
||||
|
||||
logger.info(`got ${chats.length} chats, extracted ${contacts.length} contacts with name`)
|
||||
ev.emit('chats.set', { chats, messages: [], contacts })
|
||||
ev.emit('chats.set', { chats, isLatest: true })
|
||||
}
|
||||
})
|
||||
// got all contacts from phone
|
||||
@@ -208,7 +208,7 @@ const makeChatsSocket = (config: LegacySocketConfig) => {
|
||||
})
|
||||
|
||||
logger.info(`got ${contacts.length} contacts`)
|
||||
ev.emit('chats.set', { chats: [], messages: [], contacts })
|
||||
ev.emit('contacts.set', { contacts })
|
||||
}
|
||||
})
|
||||
// status updates
|
||||
|
||||
@@ -287,15 +287,15 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
|
||||
}
|
||||
|
||||
// messages received
|
||||
const messagesUpdate = (node: BinaryNode, type: 'prepend' | 'last') => {
|
||||
const messagesUpdate = (node: BinaryNode, isLatest: boolean) => {
|
||||
const messages = getBinaryNodeMessages(node)
|
||||
messages.reverse()
|
||||
ev.emit('messages.upsert', { messages, type })
|
||||
ev.emit('messages.set', { messages, isLatest })
|
||||
}
|
||||
|
||||
socketEvents.on('CB:action,add:last', json => messagesUpdate(json, 'last'))
|
||||
socketEvents.on('CB:action,add:unread', json => messagesUpdate(json, 'prepend'))
|
||||
socketEvents.on('CB:action,add:before', json => messagesUpdate(json, 'prepend'))
|
||||
socketEvents.on('CB:action,add:last', json => messagesUpdate(json, true))
|
||||
socketEvents.on('CB:action,add:unread', json => messagesUpdate(json, false))
|
||||
socketEvents.on('CB:action,add:before', json => messagesUpdate(json, false))
|
||||
|
||||
// new messages
|
||||
socketEvents.on('CB:action,add:relay,message', (node: BinaryNode) => {
|
||||
|
||||
Reference in New Issue
Block a user