@queenanya/baileys 8.2.5 → 8.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/messages-send.js +1 -3
- package/lib/Socket/usync.js +10 -15
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +17 -13
- package/package.json +1 -1
|
@@ -38,7 +38,7 @@ class WebSocketClient extends types_1.AbstractSocketClient {
|
|
|
38
38
|
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
39
39
|
handshakeTimeout: this.config.connectTimeoutMs,
|
|
40
40
|
timeout: this.config.connectTimeoutMs,
|
|
41
|
-
agent: this.config.agent
|
|
41
|
+
agent: this.config.agent
|
|
42
42
|
});
|
|
43
43
|
this.socket.setMaxListeners(0);
|
|
44
44
|
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
@@ -139,9 +139,7 @@ const makeMessagesSocket = (config) => {
|
|
|
139
139
|
if (!toFetch.length) {
|
|
140
140
|
return deviceResults;
|
|
141
141
|
}
|
|
142
|
-
const query = new WAUSync_1.USyncQuery()
|
|
143
|
-
.withContext('message')
|
|
144
|
-
.withDeviceProtocol();
|
|
142
|
+
const query = new WAUSync_1.USyncQuery().withContext('message').withDeviceProtocol();
|
|
145
143
|
for (const jid of toFetch) {
|
|
146
144
|
query.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
147
145
|
}
|
package/lib/Socket/usync.js
CHANGED
|
@@ -6,7 +6,7 @@ const WABinary_1 = require("../WABinary");
|
|
|
6
6
|
const socket_1 = require("./socket");
|
|
7
7
|
const makeUSyncSocket = (config) => {
|
|
8
8
|
const sock = (0, socket_1.makeSocket)(config);
|
|
9
|
-
const { generateMessageTag, query
|
|
9
|
+
const { generateMessageTag, query } = sock;
|
|
10
10
|
const executeUSyncQuery = async (usyncQuery) => {
|
|
11
11
|
if (usyncQuery.protocols.length === 0) {
|
|
12
12
|
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
|
@@ -14,15 +14,13 @@ const makeUSyncSocket = (config) => {
|
|
|
14
14
|
// todo: validate users, throw WARNING on no valid users
|
|
15
15
|
// variable below has only validated users
|
|
16
16
|
const validUsers = usyncQuery.users;
|
|
17
|
-
const userNodes = validUsers.map(
|
|
17
|
+
const userNodes = validUsers.map(user => {
|
|
18
18
|
return {
|
|
19
19
|
tag: 'user',
|
|
20
20
|
attrs: {
|
|
21
|
-
jid: !user.phone ? user.id : undefined
|
|
21
|
+
jid: !user.phone ? user.id : undefined
|
|
22
22
|
},
|
|
23
|
-
content: usyncQuery.protocols
|
|
24
|
-
.map((a) => a.getUserElement(user))
|
|
25
|
-
.filter(a => a !== null)
|
|
23
|
+
content: usyncQuery.protocols.map(a => a.getUserElement(user)).filter(a => a !== null)
|
|
26
24
|
};
|
|
27
25
|
});
|
|
28
26
|
const listNode = {
|
|
@@ -33,14 +31,14 @@ const makeUSyncSocket = (config) => {
|
|
|
33
31
|
const queryNode = {
|
|
34
32
|
tag: 'query',
|
|
35
33
|
attrs: {},
|
|
36
|
-
content: usyncQuery.protocols.map(
|
|
34
|
+
content: usyncQuery.protocols.map(a => a.getQueryElement())
|
|
37
35
|
};
|
|
38
36
|
const iq = {
|
|
39
37
|
tag: 'iq',
|
|
40
38
|
attrs: {
|
|
41
39
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
42
40
|
type: 'get',
|
|
43
|
-
xmlns: 'usync'
|
|
41
|
+
xmlns: 'usync'
|
|
44
42
|
},
|
|
45
43
|
content: [
|
|
46
44
|
{
|
|
@@ -50,21 +48,18 @@ const makeUSyncSocket = (config) => {
|
|
|
50
48
|
mode: usyncQuery.mode,
|
|
51
49
|
sid: generateMessageTag(),
|
|
52
50
|
last: 'true',
|
|
53
|
-
index: '0'
|
|
51
|
+
index: '0'
|
|
54
52
|
},
|
|
55
|
-
content: [
|
|
56
|
-
queryNode,
|
|
57
|
-
listNode
|
|
58
|
-
]
|
|
53
|
+
content: [queryNode, listNode]
|
|
59
54
|
}
|
|
60
|
-
]
|
|
55
|
+
]
|
|
61
56
|
};
|
|
62
57
|
const result = await query(iq);
|
|
63
58
|
return usyncQuery.parseUSyncQueryResult(result);
|
|
64
59
|
};
|
|
65
60
|
return {
|
|
66
61
|
...sock,
|
|
67
|
-
executeUSyncQuery
|
|
62
|
+
executeUSyncQuery
|
|
68
63
|
};
|
|
69
64
|
};
|
|
70
65
|
exports.makeUSyncSocket = makeUSyncSocket;
|
|
@@ -9,7 +9,7 @@ class USyncContactProtocol {
|
|
|
9
9
|
getQueryElement() {
|
|
10
10
|
return {
|
|
11
11
|
tag: 'contact',
|
|
12
|
-
attrs: {}
|
|
12
|
+
attrs: {}
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
getUserElement(user) {
|
|
@@ -17,7 +17,7 @@ class USyncContactProtocol {
|
|
|
17
17
|
return {
|
|
18
18
|
tag: 'contact',
|
|
19
19
|
attrs: {},
|
|
20
|
-
content: user.phone
|
|
20
|
+
content: user.phone
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
parser(node) {
|
|
@@ -9,7 +9,7 @@ class USyncDisappearingModeProtocol {
|
|
|
9
9
|
getQueryElement() {
|
|
10
10
|
return {
|
|
11
11
|
tag: 'disappearing_mode',
|
|
12
|
-
attrs: {}
|
|
12
|
+
attrs: {}
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
getUserElement() {
|
|
@@ -22,7 +22,7 @@ class USyncDisappearingModeProtocol {
|
|
|
22
22
|
const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
|
|
23
23
|
return {
|
|
24
24
|
duration,
|
|
25
|
-
setAt
|
|
25
|
+
setAt
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -9,7 +9,7 @@ class USyncStatusProtocol {
|
|
|
9
9
|
getQueryElement() {
|
|
10
10
|
return {
|
|
11
11
|
tag: 'status',
|
|
12
|
-
attrs: {}
|
|
12
|
+
attrs: {}
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
getUserElement() {
|
|
@@ -34,7 +34,7 @@ class USyncStatusProtocol {
|
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
36
|
status,
|
|
37
|
-
setAt
|
|
37
|
+
setAt
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -28,13 +28,13 @@ class USyncQuery {
|
|
|
28
28
|
if (result.attrs.type !== 'result') {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
const protocolMap = Object.fromEntries(this.protocols.map(
|
|
31
|
+
const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
|
|
32
32
|
return [protocol.name, protocol.parser];
|
|
33
33
|
}));
|
|
34
34
|
const queryResult = {
|
|
35
35
|
// TODO: implement errors etc.
|
|
36
36
|
list: [],
|
|
37
|
-
sideList: []
|
|
37
|
+
sideList: []
|
|
38
38
|
};
|
|
39
39
|
const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
|
|
40
40
|
//TODO: implement error backoff, refresh etc.
|
|
@@ -42,18 +42,22 @@ class USyncQuery {
|
|
|
42
42
|
//const resultNode = getBinaryNodeChild(usyncNode, 'result')
|
|
43
43
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
|
|
44
44
|
if (Array.isArray(listNode === null || listNode === void 0 ? void 0 : listNode.content) && typeof listNode !== 'undefined') {
|
|
45
|
-
queryResult.list = listNode.content.map(
|
|
45
|
+
queryResult.list = listNode.content.map(node => {
|
|
46
46
|
const id = node === null || node === void 0 ? void 0 : node.attrs.jid;
|
|
47
|
-
const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content)
|
|
48
|
+
? Object.fromEntries(node.content
|
|
49
|
+
.map(content => {
|
|
50
|
+
const protocol = content.tag;
|
|
51
|
+
const parser = protocolMap[protocol];
|
|
52
|
+
if (parser) {
|
|
53
|
+
return [protocol, parser(content)];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return [protocol, null];
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.filter(([, b]) => b !== null))
|
|
60
|
+
: {};
|
|
57
61
|
return { ...data, id };
|
|
58
62
|
});
|
|
59
63
|
}
|