From bd86f95a9cf7b90814bf899e74eb734e43ba1628 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Sat, 17 Jul 2021 23:21:56 +0530 Subject: [PATCH] bug fixes --- src/Connection/chats.ts | 13 ++++++++++--- src/Connection/socket.ts | 15 ++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Connection/chats.ts b/src/Connection/chats.ts index cb83450..00ffe36 100644 --- a/src/Connection/chats.ts +++ b/src/Connection/chats.ts @@ -79,6 +79,13 @@ const makeChatsSocket = (config: SocketConfig) => { ) ev.emit('messages.update', updates) break + case 'mute': + if(attributes.mute === '0') { + ev.emit('chats.update', [{ jid, mute: null }]) + } else { + ev.emit('chats.update', [{ jid, mute: attributes.mute }]) + } + break default: logger.warn({ node }, `received unrecognized chat update`) break @@ -251,7 +258,7 @@ const makeChatsSocket = (config: SocketConfig) => { ...sock, sendChatsQuery, fetchImageUrl, - chatRead: async(jid: string, count: number, fromMessage: WAMessageKey) => { + chatRead: async(fromMessage: WAMessageKey, count: number) => { if(count < 0) { count = -2 } @@ -260,7 +267,7 @@ const makeChatsSocket = (config: SocketConfig) => { new BinaryNode( 'read', { - jid, + jid: fromMessage.remoteJid, count: count.toString(), index: fromMessage.id, owner: fromMessage.fromMe ? 'true' : 'false' @@ -269,7 +276,7 @@ const makeChatsSocket = (config: SocketConfig) => { ], [ WAMetric.read, WAFlag.ignore ] ) - ev.emit ('chats.update', [{ jid, count: count < 0 ? -1 : 0 }]) + ev.emit ('chats.update', [{ jid: fromMessage.remoteJid, count: count < 0 ? -1 : 0 }]) }, /** * Modify a given chat (archive, pin etc.) diff --git a/src/Connection/socket.ts b/src/Connection/socket.ts index 858ff3f..2332fd5 100644 --- a/src/Connection/socket.ts +++ b/src/Connection/socket.ts @@ -256,7 +256,7 @@ export const makeSocket = ({ if(expect200 && Math.floor(responseStatusCode/100) !== 2) { const message = STATUS_CODES[responseStatusCode] || 'unknown' throw new Boom( - `Unexpected status in '${Object.values(json)[0] || 'query'}': ${message}(${responseStatusCode})`, + `Unexpected status in '${Array.isArray(json) ? json[0] : (json?.header || 'query')}': ${message}(${responseStatusCode})`, { data: { query: json, message }, statusCode: response.status } ) } @@ -345,19 +345,16 @@ export const makeSocket = ({ waitForMessage, query, /** Generic function for action, set queries */ - setQuery: async(nodes: BinaryNode[], binaryTag: WATag = [WAMetric.group, WAFlag.ignore], tag?: string) => ( - query({ - json: new BinaryNode( - 'action', - { epoch: epoch.toString(), type: 'set' }, - nodes - ), + setQuery: async(nodes: BinaryNode[], binaryTag: WATag = [WAMetric.group, WAFlag.ignore], tag?: string) => { + const json = new BinaryNode('action', { epoch: epoch.toString(), type: 'set' }, nodes) + return query({ + json, binaryTag, tag, expect200: true, requiresPhoneConnection: true }) as Promise<{ status: number }> - ), + }, currentEpoch: () => epoch, end }