mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
exclude my device from message send
This commit is contained in:
@@ -124,11 +124,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
],
|
||||
}
|
||||
const result = await query(iq)
|
||||
let resultJids = extractDeviceJids(result)
|
||||
if(ignoreZeroDevices) {
|
||||
resultJids = resultJids.filter(item => item.device !== 0)
|
||||
}
|
||||
return resultJids
|
||||
const { device } = jidDecode(authState.creds.me!.id)
|
||||
return extractDeviceJids(result, device, ignoreZeroDevices)
|
||||
}
|
||||
|
||||
const assertSession = async(jid: string, force: boolean) => {
|
||||
|
||||
@@ -231,7 +231,7 @@ export const parseAndInjectE2ESession = async(node: BinaryNode, auth: Authentica
|
||||
await cipher.initOutgoing(device)
|
||||
}
|
||||
|
||||
export const extractDeviceJids = (result: BinaryNode) => {
|
||||
export const extractDeviceJids = (result: BinaryNode, myDeviceId: number, excludeZeroDevices: boolean) => {
|
||||
const extracted: { user: string, device?: number, agent?: number }[] = []
|
||||
for(const node of result.content as BinaryNode[]) {
|
||||
const list = getBinaryNodeChild(node, 'list')?.content
|
||||
@@ -242,8 +242,9 @@ export const extractDeviceJids = (result: BinaryNode) => {
|
||||
const deviceListNode = getBinaryNodeChild(devicesNode, 'device-list')
|
||||
if(Array.isArray(deviceListNode?.content)) {
|
||||
for(const { tag, attrs } of deviceListNode!.content) {
|
||||
if(tag === 'device') {
|
||||
extracted.push({ user, device: +attrs.id })
|
||||
const device = +attrs.id
|
||||
if(tag === 'device' && myDeviceId !== device && (!excludeZeroDevices || device !== 0)) {
|
||||
extracted.push({ user, device })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user