From 9ea23a2d12e1ffd799461b6f0ea8588e82dd0789 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Sat, 17 Jul 2021 00:23:07 +0530 Subject: [PATCH] bug fixes --- src/BinaryNode/encode.ts | 6 ++++-- src/Connection/chats.ts | 5 ++--- src/Connection/socket.ts | 8 ++++++-- src/Utils/messages.ts | 14 +++++++------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/BinaryNode/encode.ts b/src/BinaryNode/encode.ts index 7fe785e..db29abf 100644 --- a/src/BinaryNode/encode.ts +++ b/src/BinaryNode/encode.ts @@ -92,8 +92,10 @@ const encode = ({ header, attributes, data }: BinaryNode, buffer: number[] = []) writeString(header) validAttributes.forEach((key) => { - writeString(key) - writeString(attributes[key]) + if(typeof attributes[key] === 'string') { + writeString(key) + writeString(attributes[key]) + } }) if(data instanceof proto.WebMessageInfo && !Buffer.isBuffer(data)) { diff --git a/src/Connection/chats.ts b/src/Connection/chats.ts index a55719b..cb83450 100644 --- a/src/Connection/chats.ts +++ b/src/Connection/chats.ts @@ -263,14 +263,13 @@ const makeChatsSocket = (config: SocketConfig) => { jid, count: count.toString(), index: fromMessage.id, - owner: fromMessage.fromMe ? 'true' : 'false', - participant: fromMessage.participant + owner: fromMessage.fromMe ? 'true' : 'false' } ) ], [ WAMetric.read, WAFlag.ignore ] ) - ev.emit ('chats.update', [{ jid, count: count }]) + ev.emit ('chats.update', [{ jid, 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 d6ae622..858ff3f 100644 --- a/src/Connection/socket.ts +++ b/src/Connection/socket.ts @@ -139,7 +139,7 @@ export const makeSocket = ({ /* Check if this is a response to a message we are expecting */ const l0 = json.header || json[0] || '' const l1 = json?.attributes || json?.[1] || { } - const l2 = ((json.data || json[2] || [])[0] || [])[0] || '' + const l2 = json?.data?.[0]?.header || json[2]?.[0] || '' Object.keys(l1).forEach(key => { anyTriggered = socketEvents.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, json) || anyTriggered @@ -347,7 +347,11 @@ export const makeSocket = ({ /** Generic function for action, set queries */ setQuery: async(nodes: BinaryNode[], binaryTag: WATag = [WAMetric.group, WAFlag.ignore], tag?: string) => ( query({ - json: ['action', { epoch: epoch.toString(), type: 'set' }, nodes], + json: new BinaryNode( + 'action', + { epoch: epoch.toString(), type: 'set' }, + nodes + ), binaryTag, tag, expect200: true, diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index 9025e90..6bb1b4a 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -49,12 +49,12 @@ const MIMETYPE_MAP: { [T in MediaType]: string } = { } const MessageTypeProto = { - 'imageMessage': WAMessageProto.ImageMessage, - 'videoMessage': WAMessageProto.VideoMessage, - 'audioMessage': WAMessageProto.AudioMessage, - 'stickerMessage': WAMessageProto.StickerMessage, - 'documentMessage': WAMessageProto.DocumentMessage, -} + 'image': WAMessageProto.ImageMessage, + 'video': WAMessageProto.VideoMessage, + 'audio': WAMessageProto.AudioMessage, + 'sticker': WAMessageProto.StickerMessage, + 'document': WAMessageProto.DocumentMessage, +} as const const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP) as MediaType[] @@ -160,7 +160,7 @@ export const prepareWAMessageMedia = async( ) delete uploadData.media const content = { - [mediaType]: MessageTypeProto[mediaType].fromObject( + [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject( { url: mediaUrl, mediaKey,