socket: fix onWhatsApp for LIDs and map any new LID pairs
This commit is contained in:
+16
-3
@@ -40,6 +40,7 @@ import {
|
|||||||
encodeBinaryNode,
|
encodeBinaryNode,
|
||||||
getBinaryNodeChild,
|
getBinaryNodeChild,
|
||||||
getBinaryNodeChildren,
|
getBinaryNodeChildren,
|
||||||
|
isLidUser,
|
||||||
jidEncode,
|
jidEncode,
|
||||||
S_WHATSAPP_NET
|
S_WHATSAPP_NET
|
||||||
} from '../WABinary'
|
} from '../WABinary'
|
||||||
@@ -256,16 +257,28 @@ export const makeSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onWhatsApp = async (...jids: string[]) => {
|
const onWhatsApp = async (...jids: string[]) => {
|
||||||
const usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol()
|
const usyncQuery = new USyncQuery().withLIDProtocol()
|
||||||
|
|
||||||
|
// .withContactProtocol() when dealing with phone
|
||||||
|
// .withId simply with LIDs and WIDs
|
||||||
for (const jid of jids) {
|
for (const jid of jids) {
|
||||||
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`
|
if (isLidUser(jid)) {
|
||||||
usyncQuery.withUser(new USyncUser().withPhone(phone))
|
usyncQuery.withUser(new USyncUser().withId(jid)) // intentional
|
||||||
|
} else {
|
||||||
|
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`
|
||||||
|
usyncQuery.withUser(new USyncUser().withPhone(phone))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const results = await executeUSyncQuery(usyncQuery)
|
const results = await executeUSyncQuery(usyncQuery)
|
||||||
|
|
||||||
if (results) {
|
if (results) {
|
||||||
|
if (results.list.filter(a => a.lid).length > 0) {
|
||||||
|
const lidMapping = signalRepository.getLIDMappingStore()
|
||||||
|
const lidOnly = results.list.filter(a => a.lid)
|
||||||
|
await lidMapping.storeLIDPNMappings(lidOnly.map(a => ({ pn: a.id, lid: a.lid as string })))
|
||||||
|
}
|
||||||
|
|
||||||
return results.list
|
return results.list
|
||||||
.filter(a => !!a.contact)
|
.filter(a => !!a.contact)
|
||||||
.map(({ contact, id, lid }) => ({ jid: id, exists: contact as boolean, lid: lid as string }))
|
.map(({ contact, id, lid }) => ({ jid: id, exists: contact as boolean, lid: lid as string }))
|
||||||
|
|||||||
Reference in New Issue
Block a user