fix: handle when buffered tasks fail

This commit is contained in:
Adhiraj Singh
2022-08-18 10:15:27 +05:30
parent dc07d31dc7
commit 8d6e00eab6
3 changed files with 51 additions and 48 deletions

View File

@@ -313,8 +313,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
}
}
const resyncAppState = async(collections: readonly WAPatchName[], recvChats: InitialReceivedChatsState | undefined) => {
const startedBuffer = ev.buffer()
const resyncAppState = ev.createBufferedFunction(async(collections: readonly WAPatchName[], recvChats: InitialReceivedChatsState | undefined) => {
const { onMutation } = newAppStateChunkHandler(recvChats)
// we use this to determine which events to fire
// otherwise when we resync from scratch -- all notifications will fire
@@ -426,12 +425,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
}
}
)
// flush everything if we started the buffer here
if(startedBuffer) {
await ev.flush()
}
}
})
/**
* fetch the profile picture of a user/group
@@ -700,8 +694,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
])
}
const upsertMessage = async(msg: WAMessage, type: MessageUpsertType) => {
const startedBuffer = ev.buffer()
const upsertMessage = ev.createBufferedFunction(async(msg: WAMessage, type: MessageUpsertType) => {
ev.emit('messages.upsert', { messages: [msg], type })
if(!!msg.pushName) {
@@ -739,11 +732,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
logger.debug('restarting app sync timeout')
appStateSyncTimeout.start()
}
if(startedBuffer) {
await ev.flush()
}
}
})
ws.on('CB:presence', handlePresenceUpdate)
ws.on('CB:chatstate', handlePresenceUpdate)

View File

@@ -147,7 +147,7 @@ export const makeGroupsSocket = (config: SocketConfig) => {
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
* @param inviteMessage the message to accept
*/
groupAcceptInviteV4: async(key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => {
groupAcceptInviteV4: ev.createBufferedFunction(async(key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => {
key = typeof key === 'string' ? { remoteJid: key } : key
const results = await groupQuery(inviteMessage.groupJid!, 'set', [{
tag: 'accept',
@@ -158,7 +158,6 @@ export const makeGroupsSocket = (config: SocketConfig) => {
}
}])
const started = ev.buffer()
// if we have the full message key
// update the invite message to be expired
if(key.id) {
@@ -197,12 +196,8 @@ export const makeGroupsSocket = (config: SocketConfig) => {
'notify'
)
if(started) {
await ev.flush()
}
return results.attrs.from
},
}),
groupGetInviteInfo: async(code: string) => {
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
return extractGroupMetadata(results)