Merge branch 'master' into patch-1

This commit is contained in:
Rajeh Taher
2024-01-01 01:02:48 +02:00
committed by GitHub
14 changed files with 90 additions and 117 deletions

View File

@@ -2,7 +2,7 @@ import { Boom } from '@hapi/boom'
import { Logger } from 'pino'
import { proto } from '../../WAProto'
import { SignalRepository, WAMessageKey } from '../Types'
import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidStatusBroadcast, isJidUser } from '../WABinary'
import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary'
import { unpadRandomMax16 } from './generics'
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
@@ -15,7 +15,8 @@ type MessageType = 'chat' | 'peer_broadcast' | 'other_broadcast' | 'group' | 'di
*/
export function decodeMessageNode(
stanza: BinaryNode,
meId: string
meId: string,
meLid: string
) {
let msgType: MessageType
let chatId: string
@@ -27,6 +28,7 @@ export function decodeMessageNode(
const recipient: string | undefined = stanza.attrs.recipient
const isMe = (jid: string) => areJidsSameUser(jid, meId)
const isMeLid = (jid: string) => areJidsSameUser(jid, meLid)
if(isJidUser(from)) {
if(recipient) {
@@ -39,6 +41,19 @@ export function decodeMessageNode(
chatId = from
}
msgType = 'chat'
author = from
} else if(isLidUser(from)) {
if(recipient) {
if(!isMeLid(from)) {
throw new Boom('receipient present, but msg not from me', { data: stanza })
}
chatId = recipient
} else {
chatId = from
}
msgType = 'chat'
author = from
} else if(isJidGroup(from)) {
@@ -67,7 +82,7 @@ export function decodeMessageNode(
throw new Boom('Unknown message type', { data: stanza })
}
const fromMe = isMe(stanza.attrs.participant || stanza.attrs.from)
const fromMe = (isLidUser(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from)
const pushname = stanza.attrs.notify
const key: WAMessageKey = {
@@ -98,10 +113,11 @@ export function decodeMessageNode(
export const decryptMessageNode = (
stanza: BinaryNode,
meId: string,
meLid: string,
repository: SignalRepository,
logger: Logger
) => {
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId)
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
return {
fullMessage,
category: stanza.attrs.category,
@@ -183,4 +199,4 @@ export const decryptMessageNode = (
}
}
}
}
}

View File

@@ -449,6 +449,12 @@ export const generateWAMessageContent = async(
selectableOptionsCount: message.poll.selectableCount,
options: message.poll.values.map(optionName => ({ optionName })),
}
} else if('sharePhoneNumber' in message) {
m.protocolMessage = {
type: proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
}
} else if('requestPhoneNumber' in message) {
m.requestPhoneNumberMessage = {}
} else {
m = await prepareWAMessageMedia(
message,

View File

@@ -263,6 +263,22 @@ const processMessage = async(
ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
ephemeralExpiration: protocolMsg.ephemeralExpiration || null
})
break
case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
const response = protocolMsg.peerDataOperationRequestResponseMessage!
if(response) {
const { peerDataOperationResult } = response
for(const result of peerDataOperationResult!) {
const { placeholderMessageResendResponse: retryResponse } = result
if(retryResponse) {
const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes!)
ev.emit('messages.update', [
{ key: webMessageInfo.key, update: { message: webMessageInfo.message } }
])
}
}
}
break
}
} else if(content?.reactionMessage) {
@@ -387,4 +403,4 @@ const processMessage = async(
}
}
export default processMessage
export default processMessage