bug fixes

This commit is contained in:
Adhiraj Singh
2021-07-17 00:23:07 +05:30
parent e65f060664
commit 9ea23a2d12
4 changed files with 19 additions and 14 deletions

View File

@@ -92,8 +92,10 @@ const encode = ({ header, attributes, data }: BinaryNode, buffer: number[] = [])
writeString(header) writeString(header)
validAttributes.forEach((key) => { validAttributes.forEach((key) => {
writeString(key) if(typeof attributes[key] === 'string') {
writeString(attributes[key]) writeString(key)
writeString(attributes[key])
}
}) })
if(data instanceof proto.WebMessageInfo && !Buffer.isBuffer(data)) { if(data instanceof proto.WebMessageInfo && !Buffer.isBuffer(data)) {

View File

@@ -263,14 +263,13 @@ const makeChatsSocket = (config: SocketConfig) => {
jid, jid,
count: count.toString(), count: count.toString(),
index: fromMessage.id, index: fromMessage.id,
owner: fromMessage.fromMe ? 'true' : 'false', owner: fromMessage.fromMe ? 'true' : 'false'
participant: fromMessage.participant
} }
) )
], ],
[ WAMetric.read, WAFlag.ignore ] [ 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.) * Modify a given chat (archive, pin etc.)

View File

@@ -139,7 +139,7 @@ export const makeSocket = ({
/* Check if this is a response to a message we are expecting */ /* Check if this is a response to a message we are expecting */
const l0 = json.header || json[0] || '' const l0 = json.header || json[0] || ''
const l1 = json?.attributes || json?.[1] || { } 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 => { Object.keys(l1).forEach(key => {
anyTriggered = socketEvents.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, json) || anyTriggered 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 */ /** Generic function for action, set queries */
setQuery: async(nodes: BinaryNode[], binaryTag: WATag = [WAMetric.group, WAFlag.ignore], tag?: string) => ( setQuery: async(nodes: BinaryNode[], binaryTag: WATag = [WAMetric.group, WAFlag.ignore], tag?: string) => (
query({ query({
json: ['action', { epoch: epoch.toString(), type: 'set' }, nodes], json: new BinaryNode(
'action',
{ epoch: epoch.toString(), type: 'set' },
nodes
),
binaryTag, binaryTag,
tag, tag,
expect200: true, expect200: true,

View File

@@ -49,12 +49,12 @@ const MIMETYPE_MAP: { [T in MediaType]: string } = {
} }
const MessageTypeProto = { const MessageTypeProto = {
'imageMessage': WAMessageProto.ImageMessage, 'image': WAMessageProto.ImageMessage,
'videoMessage': WAMessageProto.VideoMessage, 'video': WAMessageProto.VideoMessage,
'audioMessage': WAMessageProto.AudioMessage, 'audio': WAMessageProto.AudioMessage,
'stickerMessage': WAMessageProto.StickerMessage, 'sticker': WAMessageProto.StickerMessage,
'documentMessage': WAMessageProto.DocumentMessage, 'document': WAMessageProto.DocumentMessage,
} } as const
const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP) as MediaType[] const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP) as MediaType[]
@@ -160,7 +160,7 @@ export const prepareWAMessageMedia = async(
) )
delete uploadData.media delete uploadData.media
const content = { const content = {
[mediaType]: MessageTypeProto[mediaType].fromObject( [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject(
{ {
url: mediaUrl, url: mediaUrl,
mediaKey, mediaKey,