mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Merge branch 'master' into patch-1
This commit is contained in:
@@ -540,7 +540,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
|
||||
const handleReceipt = async(node: BinaryNode) => {
|
||||
const { attrs, content } = node
|
||||
const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, authState.creds.me?.id)
|
||||
const isLid = attrs.from.includes('lid')
|
||||
const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id)
|
||||
const remoteJid = !isNodeFromMe || isJidGroup(attrs.from) ? attrs.from : attrs.recipient
|
||||
const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe)
|
||||
|
||||
@@ -663,9 +664,17 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(
|
||||
node,
|
||||
authState.creds.me!.id,
|
||||
authState.creds.me!.lid || '',
|
||||
signalRepository,
|
||||
logger,
|
||||
)
|
||||
|
||||
if(msg.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
|
||||
if(node.attrs.sender_pn) {
|
||||
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn })
|
||||
}
|
||||
}
|
||||
|
||||
if(shouldIgnoreJid(msg.key.remoteJid!)) {
|
||||
logger.debug({ key: msg.key }, 'ignored message')
|
||||
await sendMessageAck(node)
|
||||
|
||||
@@ -312,12 +312,13 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
const statusJid = 'status@broadcast'
|
||||
const isGroup = server === 'g.us'
|
||||
const isStatus = jid === statusJid
|
||||
const isLid = server === 'lid'
|
||||
|
||||
msgId = msgId || generateMessageID()
|
||||
useUserDevicesCache = useUserDevicesCache !== false
|
||||
|
||||
const participants: BinaryNode[] = []
|
||||
const destinationJid = (!isStatus) ? jidEncode(user, isGroup ? 'g.us' : 's.whatsapp.net') : statusJid
|
||||
const destinationJid = (!isStatus) ? jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid
|
||||
const binaryNodeContent: BinaryNode[] = []
|
||||
const devices: JidWithDevice[] = []
|
||||
|
||||
@@ -377,7 +378,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
devices.push(...additionalDevices)
|
||||
}
|
||||
|
||||
const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, 's.whatsapp.net', d.device)))
|
||||
const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)))
|
||||
const bytes = encodeWAMessage(patched)
|
||||
|
||||
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage(
|
||||
@@ -391,7 +392,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
const senderKeyJids: string[] = []
|
||||
// ensure a connection is established with every device
|
||||
for(const { user, device } of devices) {
|
||||
const jid = jidEncode(user, 's.whatsapp.net', device)
|
||||
const jid = jidEncode(user, isLid ? 'lid' : 's.whatsapp.net', device)
|
||||
if(!senderKeyMap[jid] || !!participant) {
|
||||
senderKeyJids.push(jid)
|
||||
// store that this person has had the sender keys sent to them
|
||||
@@ -444,8 +445,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
const meJids: string[] = []
|
||||
const otherJids: string[] = []
|
||||
for(const { user, device } of devices) {
|
||||
const jid = jidEncode(user, 's.whatsapp.net', device)
|
||||
const isMe = user === meUser
|
||||
const jid = jidEncode(isMe && isLid ? authState.creds?.me?.lid!.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
||||
if(isMe) {
|
||||
meJids.push(jid)
|
||||
} else {
|
||||
@@ -642,9 +643,10 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
relayMessage,
|
||||
sendReceipt,
|
||||
sendReceipts,
|
||||
getButtonArgs,
|
||||
readMessages,
|
||||
refreshMediaConn,
|
||||
waUploadToServer,
|
||||
waUploadToServer,
|
||||
fetchPrivacySettings,
|
||||
updateMediaMessage: async(message: proto.IWebMessageInfo) => {
|
||||
const content = assertMediaContent(message.message)
|
||||
|
||||
@@ -623,13 +623,15 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
}
|
||||
})
|
||||
// login complete
|
||||
ws.on('CB:success', async() => {
|
||||
ws.on('CB:success', async(node: BinaryNode) => {
|
||||
await uploadPreKeysToServerIfRequired()
|
||||
await sendPassiveIq('active')
|
||||
|
||||
logger.info('opened connection to WA')
|
||||
clearTimeout(qrTimer) // will never happen in all likelyhood -- but just in case WA sends success on first try
|
||||
|
||||
ev.emit('creds.update', { me: { id: authState.creds.me!.id, lid: node.attrs.lid } })
|
||||
|
||||
ev.emit('connection.update', { connection: 'open' })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user