Merge branch 'master' into call

This commit is contained in:
Rajeh Taher
2024-01-01 01:04:23 +02:00
committed by GitHub
16 changed files with 126 additions and 119 deletions

View File

@@ -777,6 +777,18 @@ export const makeChatsSocket = (config: SocketConfig) => {
return appPatch(patch)
}
/**
* Star or Unstar a message
*/
const star = (jid: string, messages: { id: string, fromMe?: boolean }[], star: boolean) => {
return chatModify({
star: {
messages,
star
}
}, jid)
}
/**
* Adds label for the chats
*/
@@ -999,6 +1011,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
addChatLabel,
removeChatLabel,
addMessageLabel,
removeMessageLabel
removeMessageLabel,
star
}
}

View File

@@ -398,7 +398,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
for(const { attrs } of blocklists) {
const blocklist = [attrs.jid]
const type = (attrs.action === 'block') ? 'add' : 'remove'
ev.emit('blocklist.update', { blocklist, type })
}
}
@@ -541,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)
@@ -664,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)

View File

@@ -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)

View File

@@ -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' })
})