Skip to content

Commit 4a1a06b

Browse files
committed
socket: fix onWhatsApp for LIDs and map any new LID pairs
1 parent acd7b75 commit 4a1a06b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Socket/socket.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
encodeBinaryNode,
4141
getBinaryNodeChild,
4242
getBinaryNodeChildren,
43+
isLidUser,
4344
jidEncode,
4445
S_WHATSAPP_NET
4546
} from '../WABinary'
@@ -256,16 +257,28 @@ export const makeSocket = (config: SocketConfig) => {
256257
}
257258

258259
const onWhatsApp = async (...jids: string[]) => {
259-
const usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol()
260+
const usyncQuery = new USyncQuery().withLIDProtocol()
260261

262+
// .withContactProtocol() when dealing with phone
263+
// .withId simply with LIDs and WIDs
261264
for (const jid of jids) {
262-
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`
263-
usyncQuery.withUser(new USyncUser().withPhone(phone))
265+
if (isLidUser(jid)) {
266+
usyncQuery.withUser(new USyncUser().withId(jid)) // intentional
267+
} else {
268+
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`
269+
usyncQuery.withUser(new USyncUser().withPhone(phone))
270+
}
264271
}
265272

266273
const results = await executeUSyncQuery(usyncQuery)
267274

268275
if (results) {
276+
if (results.list.filter(a => a.lid).length > 0) {
277+
const lidMapping = signalRepository.getLIDMappingStore()
278+
const lidOnly = results.list.filter(a => a.lid)
279+
await lidMapping.storeLIDPNMappings(lidOnly.map(a => ({ pn: a.id, lid: a.lid as string })))
280+
}
281+
269282
return results.list
270283
.filter(a => !!a.contact)
271284
.map(({ contact, id, lid }) => ({ jid: id, exists: contact as boolean, lid: lid as string }))

0 commit comments

Comments
 (0)