gifted-baileys 1.5.4 → 1.5.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/LICENSE +1 -1
- package/WAProto/WAProto.proto +88 -969
- package/WAProto/index.d.ts +1256 -13195
- package/WAProto/index.js +74730 -125106
- package/package.json +9 -27
- package/src/Defaults/baileys-version.json +3 -0
- package/{lib → src}/Defaults/index.js +14 -7
- package/src/Defaults/index.ts +131 -0
- package/src/README.md +1 -0
- package/src/Signal/libsignal.js +180 -0
- package/src/Signal/libsignal.ts +141 -0
- package/src/Socket/Client/abstract-socket-client.ts +19 -0
- package/{lib → src}/Socket/Client/index.js +3 -2
- package/src/Socket/Client/index.ts +3 -0
- package/src/Socket/Client/mobile-socket-client.js +78 -0
- package/src/Socket/Client/mobile-socket-client.ts +66 -0
- package/src/Socket/Client/web-socket-client.js +75 -0
- package/src/Socket/Client/web-socket-client.ts +57 -0
- package/{lib → src}/Socket/business.js +33 -28
- package/src/Socket/business.ts +281 -0
- package/{lib → src}/Socket/chats.js +176 -174
- package/src/Socket/chats.ts +1030 -0
- package/{lib → src}/Socket/groups.js +68 -80
- package/src/Socket/groups.ts +356 -0
- package/{lib → src}/Socket/index.js +1 -4
- package/src/Socket/index.ts +13 -0
- package/{lib → src}/Socket/messages-recv.js +211 -378
- package/src/Socket/messages-recv.ts +985 -0
- package/{lib → src}/Socket/messages-send.js +177 -452
- package/src/Socket/messages-send.ts +871 -0
- package/{lib → src}/Socket/newsletter.js +98 -107
- package/src/Socket/newsletter.ts +282 -0
- package/{lib → src}/Socket/registration.js +48 -56
- package/src/Socket/registration.ts +250 -0
- package/{lib → src}/Socket/socket.js +77 -77
- package/src/Socket/socket.ts +777 -0
- package/src/Store/index.ts +3 -0
- package/{lib → src}/Store/make-cache-manager-store.js +34 -25
- package/src/Store/make-cache-manager-store.ts +100 -0
- package/{lib → src}/Store/make-in-memory-store.js +32 -36
- package/src/Store/make-in-memory-store.ts +475 -0
- package/src/Store/make-ordered-dictionary.ts +86 -0
- package/{lib → src}/Store/object-repository.js +1 -1
- package/src/Store/object-repository.ts +32 -0
- package/src/Tests/test.app-state-sync.js +204 -0
- package/src/Tests/test.app-state-sync.ts +207 -0
- package/src/Tests/test.event-buffer.js +270 -0
- package/src/Tests/test.event-buffer.ts +319 -0
- package/src/Tests/test.key-store.js +76 -0
- package/src/Tests/test.key-store.ts +92 -0
- package/src/Tests/test.libsignal.js +141 -0
- package/src/Tests/test.libsignal.ts +186 -0
- package/src/Tests/test.media-download.js +93 -0
- package/src/Tests/test.media-download.ts +76 -0
- package/src/Tests/test.messages.js +33 -0
- package/src/Tests/test.messages.ts +37 -0
- package/src/Tests/utils.js +34 -0
- package/src/Tests/utils.ts +36 -0
- package/src/Types/Auth.ts +113 -0
- package/src/Types/Call.ts +15 -0
- package/src/Types/Chat.ts +106 -0
- package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
- package/src/Types/Events.ts +93 -0
- package/src/Types/GroupMetadata.ts +53 -0
- package/src/Types/Label.ts +36 -0
- package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
- package/src/Types/Message.ts +288 -0
- package/src/Types/Newsletter.ts +98 -0
- package/src/Types/Product.ts +85 -0
- package/src/Types/Signal.ts +68 -0
- package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -61
- package/src/Types/State.ts +29 -0
- package/src/Types/index.ts +59 -0
- package/{lib → src}/Utils/auth-utils.js +90 -73
- package/src/Utils/auth-utils.ts +222 -0
- package/src/Utils/baileys-event-stream.js +92 -0
- package/src/Utils/baileys-event-stream.ts +66 -0
- package/{lib → src}/Utils/business.js +43 -15
- package/src/Utils/business.ts +275 -0
- package/{lib → src}/Utils/chat-utils.js +94 -87
- package/src/Utils/chat-utils.ts +860 -0
- package/{lib → src}/Utils/crypto.js +2 -4
- package/src/Utils/crypto.ts +131 -0
- package/src/Utils/decode-wa-message.js +211 -0
- package/src/Utils/decode-wa-message.ts +228 -0
- package/{lib → src}/Utils/event-buffer.js +13 -4
- package/src/Utils/event-buffer.ts +613 -0
- package/{lib → src}/Utils/generics.js +86 -67
- package/src/Utils/generics.ts +434 -0
- package/{lib → src}/Utils/history.js +39 -13
- package/src/Utils/history.ts +112 -0
- package/src/Utils/index.ts +17 -0
- package/{lib → src}/Utils/link-preview.js +54 -17
- package/src/Utils/link-preview.ts +122 -0
- package/src/Utils/logger.ts +3 -0
- package/src/Utils/lt-hash.ts +61 -0
- package/{lib → src}/Utils/make-mutex.js +13 -4
- package/src/Utils/make-mutex.ts +44 -0
- package/{lib → src}/Utils/messages-media.js +255 -193
- package/src/Utils/messages-media.ts +847 -0
- package/{lib → src}/Utils/messages.js +118 -588
- package/src/Utils/messages.ts +956 -0
- package/src/Utils/noise-handler.ts +197 -0
- package/{lib → src}/Utils/process-message.js +30 -27
- package/src/Utils/process-message.ts +414 -0
- package/{lib → src}/Utils/signal.js +42 -25
- package/src/Utils/signal.ts +177 -0
- package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -27
- package/src/Utils/use-multi-file-auth-state.ts +90 -0
- package/{lib → src}/Utils/validate-connection.js +9 -40
- package/src/Utils/validate-connection.ts +238 -0
- package/src/WABinary/constants.ts +42 -0
- package/src/WABinary/decode.ts +265 -0
- package/{lib → src}/WABinary/encode.js +10 -16
- package/src/WABinary/encode.ts +236 -0
- package/src/WABinary/generic-utils.ts +121 -0
- package/src/WABinary/index.ts +5 -0
- package/src/WABinary/jid-utils.ts +68 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.ts +15382 -0
- package/src/WAM/encode.ts +174 -0
- package/src/WAM/index.ts +3 -0
- package/{lib → src}/index.js +0 -1
- package/src/index.ts +13 -0
- package/README.md +0 -1645
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -284
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Signal/libsignal.js +0 -161
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/types.d.ts +0 -17
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.d.ts +0 -12
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/business.d.ts +0 -170
- package/lib/Socket/chats.d.ts +0 -81
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -172
- package/lib/Socket/messages-recv.d.ts +0 -158
- package/lib/Socket/messages-send.d.ts +0 -155
- package/lib/Socket/newsletter.d.ts +0 -132
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/socket.d.ts +0 -44
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -109
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -107
- package/lib/Types/Events.d.ts +0 -172
- package/lib/Types/GroupMetadata.d.ts +0 -56
- package/lib/Types/Label.d.ts +0 -46
- package/lib/Types/Message.d.ts +0 -433
- package/lib/Types/Newsletter.d.ts +0 -92
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -70
- package/lib/Utils/crypto.d.ts +0 -40
- package/lib/Utils/decode-wa-message.d.ts +0 -36
- package/lib/Utils/decode-wa-message.js +0 -226
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -88
- package/lib/Utils/history.d.ts +0 -19
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -2
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -113
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -33
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/decode.d.ts +0 -6
- package/lib/WABinary/encode.d.ts +0 -2
- package/lib/WABinary/generic-utils.d.ts +0 -14
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -8
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -2
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/index.js +0 -20
- package/lib/WAUSync/USyncQuery.d.ts +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -79
- package/lib/WAUSync/USyncUser.d.ts +0 -10
- package/lib/WAUSync/USyncUser.js +0 -22
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -19
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
- /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{lib → src}/Store/index.js +0 -0
- /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
- /package/{lib → src}/Types/Auth.js +0 -0
- /package/{lib → src}/Types/Call.js +0 -0
- /package/{lib → src}/Types/Chat.js +0 -0
- /package/{lib → src}/Types/Contact.js +0 -0
- /package/{lib → src}/Types/Events.js +0 -0
- /package/{lib → src}/Types/GroupMetadata.js +0 -0
- /package/{lib → src}/Types/Label.js +0 -0
- /package/{lib → src}/Types/LabelAssociation.js +0 -0
- /package/{lib → src}/Types/Message.js +0 -0
- /package/{lib → src}/Types/Newsletter.js +0 -0
- /package/{lib → src}/Types/Product.js +0 -0
- /package/{lib → src}/Types/Signal.js +0 -0
- /package/{lib → src}/Types/Socket.js +0 -0
- /package/{lib → src}/Types/State.js +0 -0
- /package/{lib → src}/Types/index.js +0 -0
- /package/{lib → src}/Utils/index.js +0 -0
- /package/{lib → src}/Utils/logger.js +0 -0
- /package/{lib → src}/Utils/lt-hash.js +0 -0
- /package/{lib → src}/Utils/noise-handler.js +0 -0
- /package/{lib → src}/WABinary/constants.js +0 -0
- /package/{lib → src}/WABinary/decode.js +0 -0
- /package/{lib → src}/WABinary/generic-utils.js +0 -0
- /package/{lib → src}/WABinary/index.js +0 -0
- /package/{lib → src}/WABinary/jid-utils.js +0 -0
- /package/{lib → src}/WABinary/types.js +0 -0
- /package/{lib → src}/WAM/BinaryInfo.js +0 -0
- /package/{lib → src}/WAM/constants.js +0 -0
- /package/{lib → src}/WAM/encode.js +0 -0
- /package/{lib → src}/WAM/index.js +0 -0
- /package/{lib → src}/gifted +0 -0
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -12,26 +21,25 @@ const Utils_1 = require("../Utils");
|
|
|
12
21
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
13
22
|
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
14
23
|
const WABinary_1 = require("../WABinary");
|
|
15
|
-
const
|
|
16
|
-
const usync_1 = require("./usync");
|
|
24
|
+
const socket_1 = require("./socket");
|
|
17
25
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
18
26
|
const makeChatsSocket = (config) => {
|
|
19
27
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
20
|
-
const sock = (0,
|
|
21
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
|
|
28
|
+
const sock = (0, socket_1.makeSocket)(config);
|
|
29
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
|
|
22
30
|
let privacySettings;
|
|
23
31
|
let needToFlushWithAppStateSync = false;
|
|
24
32
|
let pendingAppStateSync = false;
|
|
25
33
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
26
34
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
27
35
|
/** helper function to fetch the given app state sync key */
|
|
28
|
-
const getAppStateSyncKey =
|
|
29
|
-
const { [keyId]: key } =
|
|
36
|
+
const getAppStateSyncKey = (keyId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const { [keyId]: key } = yield authState.keys.get('app-state-sync-key', [keyId]);
|
|
30
38
|
return key;
|
|
31
|
-
};
|
|
32
|
-
const fetchPrivacySettings =
|
|
39
|
+
});
|
|
40
|
+
const fetchPrivacySettings = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (force = false) {
|
|
33
41
|
if (!privacySettings || force) {
|
|
34
|
-
const { content } =
|
|
42
|
+
const { content } = yield query({
|
|
35
43
|
tag: 'iq',
|
|
36
44
|
attrs: {
|
|
37
45
|
xmlns: 'privacy',
|
|
@@ -45,10 +53,10 @@ const makeChatsSocket = (config) => {
|
|
|
45
53
|
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
|
|
46
54
|
}
|
|
47
55
|
return privacySettings;
|
|
48
|
-
};
|
|
56
|
+
});
|
|
49
57
|
/** helper function to run a privacy IQ query */
|
|
50
|
-
const privacyQuery =
|
|
51
|
-
|
|
58
|
+
const privacyQuery = (name, value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
yield query({
|
|
52
60
|
tag: 'iq',
|
|
53
61
|
attrs: {
|
|
54
62
|
xmlns: 'privacy',
|
|
@@ -66,27 +74,27 @@ const makeChatsSocket = (config) => {
|
|
|
66
74
|
]
|
|
67
75
|
}]
|
|
68
76
|
});
|
|
69
|
-
};
|
|
70
|
-
const updateLastSeenPrivacy =
|
|
71
|
-
|
|
72
|
-
};
|
|
73
|
-
const updateOnlinePrivacy =
|
|
74
|
-
|
|
75
|
-
};
|
|
76
|
-
const updateProfilePicturePrivacy =
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
const updateStatusPrivacy =
|
|
80
|
-
|
|
81
|
-
};
|
|
82
|
-
const updateReadReceiptsPrivacy =
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
const updateGroupsAddPrivacy =
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
const updateDefaultDisappearingMode =
|
|
89
|
-
|
|
77
|
+
});
|
|
78
|
+
const updateLastSeenPrivacy = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
yield privacyQuery('last', value);
|
|
80
|
+
});
|
|
81
|
+
const updateOnlinePrivacy = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
yield privacyQuery('online', value);
|
|
83
|
+
});
|
|
84
|
+
const updateProfilePicturePrivacy = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
yield privacyQuery('profile', value);
|
|
86
|
+
});
|
|
87
|
+
const updateStatusPrivacy = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
yield privacyQuery('status', value);
|
|
89
|
+
});
|
|
90
|
+
const updateReadReceiptsPrivacy = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
yield privacyQuery('readreceipts', value);
|
|
92
|
+
});
|
|
93
|
+
const updateGroupsAddPrivacy = (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
yield privacyQuery('groupadd', value);
|
|
95
|
+
});
|
|
96
|
+
const updateDefaultDisappearingMode = (duration) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
yield query({
|
|
90
98
|
tag: 'iq',
|
|
91
99
|
attrs: {
|
|
92
100
|
xmlns: 'disappearing_mode',
|
|
@@ -100,10 +108,10 @@ const makeChatsSocket = (config) => {
|
|
|
100
108
|
}
|
|
101
109
|
}]
|
|
102
110
|
});
|
|
103
|
-
};
|
|
111
|
+
});
|
|
104
112
|
/** helper function to run a generic IQ query */
|
|
105
|
-
const interactiveQuery =
|
|
106
|
-
const result =
|
|
113
|
+
const interactiveQuery = (userNodes, queryNode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
const result = yield query({
|
|
107
115
|
tag: 'iq',
|
|
108
116
|
attrs: {
|
|
109
117
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -139,58 +147,40 @@ const makeChatsSocket = (config) => {
|
|
|
139
147
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
|
|
140
148
|
const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
|
|
141
149
|
return users;
|
|
142
|
-
};
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
|
|
150
|
+
});
|
|
151
|
+
const onWhatsApp = (...jids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
|
+
const query = { tag: 'contact', attrs: {} };
|
|
153
|
+
const list = jids.map((jid) => {
|
|
154
|
+
// insures only 1 + is there
|
|
155
|
+
const content = `+${jid.replace('+', '')}`;
|
|
156
|
+
return {
|
|
146
157
|
tag: 'user',
|
|
147
|
-
attrs: {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
attrs: {},
|
|
159
|
+
content: [{
|
|
160
|
+
tag: 'contact',
|
|
161
|
+
attrs: {},
|
|
162
|
+
content,
|
|
163
|
+
}],
|
|
164
|
+
};
|
|
152
165
|
});
|
|
166
|
+
const results = yield interactiveQuery(list, query);
|
|
167
|
+
return results.map(user => {
|
|
168
|
+
const contact = (0, WABinary_1.getBinaryNodeChild)(user, 'contact');
|
|
169
|
+
return { exists: (contact === null || contact === void 0 ? void 0 : contact.attrs.type) === 'in', jid: user.attrs.jid };
|
|
170
|
+
}).filter(item => item.exists);
|
|
171
|
+
});
|
|
172
|
+
const fetchStatus = (jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
+
const [result] = yield interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
|
|
153
174
|
if (result) {
|
|
154
|
-
const
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
160
|
-
.withContactProtocol();
|
|
161
|
-
for (const jid of jids) {
|
|
162
|
-
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
163
|
-
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
164
|
-
}
|
|
165
|
-
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
166
|
-
if (results) {
|
|
167
|
-
return results.list.filter((a) => !!a.contact).map(({ contact, id }) => ({ jid: id, exists: contact }));
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
const fetchStatus = async (...jids) => {
|
|
171
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
172
|
-
.withStatusProtocol();
|
|
173
|
-
for (const jid of jids) {
|
|
174
|
-
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
175
|
-
}
|
|
176
|
-
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
177
|
-
if (result) {
|
|
178
|
-
return result.list;
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
const fetchDisappearingDuration = async (...jids) => {
|
|
182
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
183
|
-
.withDisappearingModeProtocol();
|
|
184
|
-
for (const jid of jids) {
|
|
185
|
-
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
186
|
-
}
|
|
187
|
-
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
188
|
-
if (result) {
|
|
189
|
-
return result.list;
|
|
175
|
+
const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
|
|
176
|
+
return {
|
|
177
|
+
status: status === null || status === void 0 ? void 0 : status.content.toString(),
|
|
178
|
+
setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
|
|
179
|
+
};
|
|
190
180
|
}
|
|
191
|
-
};
|
|
181
|
+
});
|
|
192
182
|
/** update the profile picture for yourself or a group */
|
|
193
|
-
const updateProfilePicture =
|
|
183
|
+
const updateProfilePicture = (jid, content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
194
184
|
let targetJid;
|
|
195
185
|
if (!jid) {
|
|
196
186
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
@@ -198,8 +188,8 @@ const makeChatsSocket = (config) => {
|
|
|
198
188
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
199
189
|
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
200
190
|
}
|
|
201
|
-
const { img } =
|
|
202
|
-
|
|
191
|
+
const { img } = yield (0, Utils_1.generateProfilePicture)(content);
|
|
192
|
+
yield query({
|
|
203
193
|
tag: 'iq',
|
|
204
194
|
attrs: {
|
|
205
195
|
target: targetJid,
|
|
@@ -215,9 +205,9 @@ const makeChatsSocket = (config) => {
|
|
|
215
205
|
}
|
|
216
206
|
]
|
|
217
207
|
});
|
|
218
|
-
};
|
|
208
|
+
});
|
|
219
209
|
/** remove the profile picture for yourself or a group */
|
|
220
|
-
const removeProfilePicture =
|
|
210
|
+
const removeProfilePicture = (jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
211
|
let targetJid;
|
|
222
212
|
if (!jid) {
|
|
223
213
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
@@ -225,7 +215,7 @@ const makeChatsSocket = (config) => {
|
|
|
225
215
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
226
216
|
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
227
217
|
}
|
|
228
|
-
|
|
218
|
+
yield query({
|
|
229
219
|
tag: 'iq',
|
|
230
220
|
attrs: {
|
|
231
221
|
target: targetJid,
|
|
@@ -234,10 +224,10 @@ const makeChatsSocket = (config) => {
|
|
|
234
224
|
xmlns: 'w:profile:picture'
|
|
235
225
|
}
|
|
236
226
|
});
|
|
237
|
-
};
|
|
227
|
+
});
|
|
238
228
|
/** update the profile status for yourself */
|
|
239
|
-
const updateProfileStatus =
|
|
240
|
-
|
|
229
|
+
const updateProfileStatus = (status) => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
|
+
yield query({
|
|
241
231
|
tag: 'iq',
|
|
242
232
|
attrs: {
|
|
243
233
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -252,12 +242,12 @@ const makeChatsSocket = (config) => {
|
|
|
252
242
|
}
|
|
253
243
|
]
|
|
254
244
|
});
|
|
255
|
-
};
|
|
256
|
-
const updateProfileName =
|
|
257
|
-
|
|
258
|
-
};
|
|
259
|
-
const fetchBlocklist =
|
|
260
|
-
const result =
|
|
245
|
+
});
|
|
246
|
+
const updateProfileName = (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
247
|
+
yield chatModify({ pushNameSetting: name }, '');
|
|
248
|
+
});
|
|
249
|
+
const fetchBlocklist = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
250
|
+
const result = yield query({
|
|
261
251
|
tag: 'iq',
|
|
262
252
|
attrs: {
|
|
263
253
|
xmlns: 'blocklist',
|
|
@@ -268,9 +258,9 @@ const makeChatsSocket = (config) => {
|
|
|
268
258
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
269
259
|
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
270
260
|
.map(n => n.attrs.jid);
|
|
271
|
-
};
|
|
272
|
-
const updateBlockStatus =
|
|
273
|
-
|
|
261
|
+
});
|
|
262
|
+
const updateBlockStatus = (jid, action) => __awaiter(void 0, void 0, void 0, function* () {
|
|
263
|
+
yield query({
|
|
274
264
|
tag: 'iq',
|
|
275
265
|
attrs: {
|
|
276
266
|
xmlns: 'blocklist',
|
|
@@ -287,10 +277,10 @@ const makeChatsSocket = (config) => {
|
|
|
287
277
|
}
|
|
288
278
|
]
|
|
289
279
|
});
|
|
290
|
-
};
|
|
291
|
-
const getBusinessProfile =
|
|
280
|
+
});
|
|
281
|
+
const getBusinessProfile = (jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
292
282
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
293
|
-
const results =
|
|
283
|
+
const results = yield query({
|
|
294
284
|
tag: 'iq',
|
|
295
285
|
attrs: {
|
|
296
286
|
to: 's.whatsapp.net',
|
|
@@ -332,10 +322,10 @@ const makeChatsSocket = (config) => {
|
|
|
332
322
|
}
|
|
333
323
|
};
|
|
334
324
|
}
|
|
335
|
-
};
|
|
336
|
-
const cleanDirtyBits =
|
|
325
|
+
});
|
|
326
|
+
const cleanDirtyBits = (type, fromTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
337
327
|
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
338
|
-
|
|
328
|
+
yield sendNode({
|
|
339
329
|
tag: 'iq',
|
|
340
330
|
attrs: {
|
|
341
331
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -346,14 +336,11 @@ const makeChatsSocket = (config) => {
|
|
|
346
336
|
content: [
|
|
347
337
|
{
|
|
348
338
|
tag: 'clean',
|
|
349
|
-
attrs: {
|
|
350
|
-
type,
|
|
351
|
-
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
|
|
352
|
-
}
|
|
339
|
+
attrs: Object.assign({ type }, (fromTimestamp ? { timestamp: fromTimestamp.toString() } : null))
|
|
353
340
|
}
|
|
354
341
|
]
|
|
355
342
|
});
|
|
356
|
-
};
|
|
343
|
+
});
|
|
357
344
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
358
345
|
return {
|
|
359
346
|
onMutation(mutation) {
|
|
@@ -361,12 +348,12 @@ const makeChatsSocket = (config) => {
|
|
|
361
348
|
}
|
|
362
349
|
};
|
|
363
350
|
};
|
|
364
|
-
const resyncAppState = ev.createBufferedFunction(
|
|
351
|
+
const resyncAppState = ev.createBufferedFunction((collections, isInitialSync) => __awaiter(void 0, void 0, void 0, function* () {
|
|
365
352
|
// we use this to determine which events to fire
|
|
366
353
|
// otherwise when we resync from scratch -- all notifications will fire
|
|
367
354
|
const initialVersionMap = {};
|
|
368
355
|
const globalMutationMap = {};
|
|
369
|
-
|
|
356
|
+
yield authState.keys.transaction(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
370
357
|
var _a;
|
|
371
358
|
const collectionsToHandle = new Set(collections);
|
|
372
359
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
@@ -378,7 +365,7 @@ const makeChatsSocket = (config) => {
|
|
|
378
365
|
const states = {};
|
|
379
366
|
const nodes = [];
|
|
380
367
|
for (const name of collectionsToHandle) {
|
|
381
|
-
const result =
|
|
368
|
+
const result = yield authState.keys.get('app-state-sync-version', [name]);
|
|
382
369
|
let state = result[name];
|
|
383
370
|
if (state) {
|
|
384
371
|
if (typeof initialVersionMap[name] === 'undefined') {
|
|
@@ -400,7 +387,7 @@ const makeChatsSocket = (config) => {
|
|
|
400
387
|
}
|
|
401
388
|
});
|
|
402
389
|
}
|
|
403
|
-
const result =
|
|
390
|
+
const result = yield query({
|
|
404
391
|
tag: 'iq',
|
|
405
392
|
attrs: {
|
|
406
393
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -416,24 +403,24 @@ const makeChatsSocket = (config) => {
|
|
|
416
403
|
]
|
|
417
404
|
});
|
|
418
405
|
// extract from binary node
|
|
419
|
-
const decoded =
|
|
406
|
+
const decoded = yield (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
420
407
|
for (const key in decoded) {
|
|
421
408
|
const name = key;
|
|
422
409
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
423
410
|
try {
|
|
424
411
|
if (snapshot) {
|
|
425
|
-
const { state: newState, mutationMap } =
|
|
412
|
+
const { state: newState, mutationMap } = yield (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
426
413
|
states[name] = newState;
|
|
427
414
|
Object.assign(globalMutationMap, mutationMap);
|
|
428
415
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
429
|
-
|
|
416
|
+
yield authState.keys.set({ 'app-state-sync-version': {
|
|
430
417
|
[name]: newState
|
|
431
418
|
} });
|
|
432
419
|
}
|
|
433
420
|
// only process if there are syncd patches
|
|
434
421
|
if (patches.length) {
|
|
435
|
-
const { state: newState, mutationMap } =
|
|
436
|
-
|
|
422
|
+
const { state: newState, mutationMap } = yield (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
423
|
+
yield authState.keys.set({ 'app-state-sync-version': {
|
|
437
424
|
[name]: newState
|
|
438
425
|
} });
|
|
439
426
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
@@ -454,7 +441,7 @@ const makeChatsSocket = (config) => {
|
|
|
454
441
|
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
455
442
|
error.name === 'TypeError';
|
|
456
443
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
457
|
-
|
|
444
|
+
yield authState.keys.set({ 'app-state-sync-version': {
|
|
458
445
|
[name]: null
|
|
459
446
|
} });
|
|
460
447
|
// increment number of retries
|
|
@@ -466,18 +453,36 @@ const makeChatsSocket = (config) => {
|
|
|
466
453
|
}
|
|
467
454
|
}
|
|
468
455
|
}
|
|
469
|
-
});
|
|
456
|
+
}));
|
|
470
457
|
const { onMutation } = newAppStateChunkHandler(isInitialSync);
|
|
471
458
|
for (const key in globalMutationMap) {
|
|
472
459
|
onMutation(globalMutationMap[key]);
|
|
473
460
|
}
|
|
474
|
-
});
|
|
461
|
+
}));
|
|
475
462
|
/**
|
|
476
463
|
* fetch the profile picture of a user/group
|
|
477
464
|
* type = "preview" for a low res picture
|
|
478
465
|
* type = "image for the high res picture"
|
|
479
466
|
*/
|
|
480
|
-
const
|
|
467
|
+
const profilePictureUrl = (jid_1, ...args_1) => __awaiter(void 0, [jid_1, ...args_1], void 0, function* (jid, type = 'preview', timeoutMs) {
|
|
468
|
+
var _a;
|
|
469
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
470
|
+
const result = yield query({
|
|
471
|
+
tag: 'iq',
|
|
472
|
+
attrs: {
|
|
473
|
+
target: jid,
|
|
474
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
475
|
+
type: 'get',
|
|
476
|
+
xmlns: 'w:profile:picture'
|
|
477
|
+
},
|
|
478
|
+
content: [
|
|
479
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
480
|
+
]
|
|
481
|
+
}, timeoutMs);
|
|
482
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
483
|
+
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
484
|
+
});
|
|
485
|
+
const sendPresenceUpdate = (type, toJid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
481
486
|
const me = authState.creds.me;
|
|
482
487
|
if (type === 'available' || type === 'unavailable') {
|
|
483
488
|
if (!me.name) {
|
|
@@ -485,7 +490,7 @@ const makeChatsSocket = (config) => {
|
|
|
485
490
|
return;
|
|
486
491
|
}
|
|
487
492
|
ev.emit('connection.update', { isOnline: type === 'available' });
|
|
488
|
-
|
|
493
|
+
yield sendNode({
|
|
489
494
|
tag: 'presence',
|
|
490
495
|
attrs: {
|
|
491
496
|
name: me.name,
|
|
@@ -494,7 +499,7 @@ const makeChatsSocket = (config) => {
|
|
|
494
499
|
});
|
|
495
500
|
}
|
|
496
501
|
else {
|
|
497
|
-
|
|
502
|
+
yield sendNode({
|
|
498
503
|
tag: 'chatstate',
|
|
499
504
|
attrs: {
|
|
500
505
|
from: me.id,
|
|
@@ -508,7 +513,7 @@ const makeChatsSocket = (config) => {
|
|
|
508
513
|
]
|
|
509
514
|
});
|
|
510
515
|
}
|
|
511
|
-
};
|
|
516
|
+
});
|
|
512
517
|
/**
|
|
513
518
|
* @param toJid the jid to subscribe to
|
|
514
519
|
* @param tcToken token for subscription, use if present
|
|
@@ -564,7 +569,7 @@ const makeChatsSocket = (config) => {
|
|
|
564
569
|
} });
|
|
565
570
|
}
|
|
566
571
|
};
|
|
567
|
-
const appPatch =
|
|
572
|
+
const appPatch = (patchCreate) => __awaiter(void 0, void 0, void 0, function* () {
|
|
568
573
|
const name = patchCreate.type;
|
|
569
574
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
570
575
|
if (!myAppStateKeyId) {
|
|
@@ -572,13 +577,13 @@ const makeChatsSocket = (config) => {
|
|
|
572
577
|
}
|
|
573
578
|
let initial;
|
|
574
579
|
let encodeResult;
|
|
575
|
-
|
|
576
|
-
|
|
580
|
+
yield processingMutex.mutex(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
581
|
+
yield authState.keys.transaction(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
577
582
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
578
|
-
|
|
579
|
-
const { [name]: currentSyncVersion } =
|
|
583
|
+
yield resyncAppState([name], false);
|
|
584
|
+
const { [name]: currentSyncVersion } = yield authState.keys.get('app-state-sync-version', [name]);
|
|
580
585
|
initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
|
|
581
|
-
encodeResult =
|
|
586
|
+
encodeResult = yield (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
582
587
|
const { patch, state } = encodeResult;
|
|
583
588
|
const node = {
|
|
584
589
|
tag: 'iq',
|
|
@@ -611,24 +616,24 @@ const makeChatsSocket = (config) => {
|
|
|
611
616
|
}
|
|
612
617
|
]
|
|
613
618
|
};
|
|
614
|
-
|
|
615
|
-
|
|
619
|
+
yield query(node);
|
|
620
|
+
yield authState.keys.set({ 'app-state-sync-version': {
|
|
616
621
|
[name]: state
|
|
617
622
|
} });
|
|
618
|
-
});
|
|
619
|
-
});
|
|
623
|
+
}));
|
|
624
|
+
}));
|
|
620
625
|
if (config.emitOwnEvents) {
|
|
621
626
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
622
|
-
const { mutationMap } =
|
|
627
|
+
const { mutationMap } = yield (0, Utils_1.decodePatches)(name, [Object.assign(Object.assign({}, encodeResult.patch), { version: { version: encodeResult.state.version } })], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
623
628
|
for (const key in mutationMap) {
|
|
624
629
|
onMutation(mutationMap[key]);
|
|
625
630
|
}
|
|
626
631
|
}
|
|
627
|
-
};
|
|
632
|
+
});
|
|
628
633
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
629
|
-
const fetchProps =
|
|
634
|
+
const fetchProps = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
630
635
|
var _a, _b;
|
|
631
|
-
const resultNode =
|
|
636
|
+
const resultNode = yield query({
|
|
632
637
|
tag: 'iq',
|
|
633
638
|
attrs: {
|
|
634
639
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -654,7 +659,7 @@ const makeChatsSocket = (config) => {
|
|
|
654
659
|
}
|
|
655
660
|
logger.debug('fetched props');
|
|
656
661
|
return props;
|
|
657
|
-
};
|
|
662
|
+
});
|
|
658
663
|
/**
|
|
659
664
|
* modify a chat -- mark unread, read etc.
|
|
660
665
|
* lastMessages must be sorted in reverse chronologically
|
|
@@ -721,14 +726,14 @@ const makeChatsSocket = (config) => {
|
|
|
721
726
|
* queries need to be fired on connection open
|
|
722
727
|
* help ensure parity with WA Web
|
|
723
728
|
* */
|
|
724
|
-
const executeInitQueries =
|
|
725
|
-
|
|
729
|
+
const executeInitQueries = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
730
|
+
yield Promise.all([
|
|
726
731
|
fetchProps(),
|
|
727
732
|
fetchBlocklist(),
|
|
728
733
|
fetchPrivacySettings(),
|
|
729
734
|
]);
|
|
730
|
-
};
|
|
731
|
-
const upsertMessage = ev.createBufferedFunction(
|
|
735
|
+
});
|
|
736
|
+
const upsertMessage = ev.createBufferedFunction((msg, type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
732
737
|
var _a, _b, _c;
|
|
733
738
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
734
739
|
if (!!msg.pushName) {
|
|
@@ -739,7 +744,7 @@ const makeChatsSocket = (config) => {
|
|
|
739
744
|
}
|
|
740
745
|
// update our pushname too
|
|
741
746
|
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
742
|
-
ev.emit('creds.update', { me: {
|
|
747
|
+
ev.emit('creds.update', { me: Object.assign(Object.assign({}, authState.creds.me), { name: msg.pushName }) });
|
|
743
748
|
}
|
|
744
749
|
}
|
|
745
750
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
@@ -751,14 +756,14 @@ const makeChatsSocket = (config) => {
|
|
|
751
756
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
752
757
|
pendingAppStateSync = true;
|
|
753
758
|
}
|
|
754
|
-
|
|
755
|
-
(
|
|
759
|
+
yield Promise.all([
|
|
760
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
756
761
|
if (historyMsg &&
|
|
757
762
|
authState.creds.myAppStateKeyId) {
|
|
758
763
|
pendingAppStateSync = false;
|
|
759
|
-
|
|
764
|
+
yield doAppStateSync();
|
|
760
765
|
}
|
|
761
|
-
})(),
|
|
766
|
+
}))(),
|
|
762
767
|
(0, process_message_1.default)(msg, {
|
|
763
768
|
shouldProcessHistoryMsg,
|
|
764
769
|
ev,
|
|
@@ -771,25 +776,27 @@ const makeChatsSocket = (config) => {
|
|
|
771
776
|
]);
|
|
772
777
|
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
|
|
773
778
|
pendingAppStateSync) {
|
|
774
|
-
|
|
779
|
+
yield doAppStateSync();
|
|
775
780
|
pendingAppStateSync = false;
|
|
776
781
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
782
|
+
function doAppStateSync() {
|
|
783
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
784
|
+
if (!authState.creds.accountSyncCounter) {
|
|
785
|
+
logger.info('doing initial app state sync');
|
|
786
|
+
yield resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
787
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
788
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
789
|
+
if (needToFlushWithAppStateSync) {
|
|
790
|
+
logger.debug('flushing with app state sync');
|
|
791
|
+
ev.flush();
|
|
792
|
+
}
|
|
786
793
|
}
|
|
787
|
-
}
|
|
794
|
+
});
|
|
788
795
|
}
|
|
789
|
-
});
|
|
796
|
+
}));
|
|
790
797
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
791
798
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
792
|
-
ws.on('CB:ib,,dirty',
|
|
799
|
+
ws.on('CB:ib,,dirty', (node) => __awaiter(void 0, void 0, void 0, function* () {
|
|
793
800
|
const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
|
|
794
801
|
const type = attrs.type;
|
|
795
802
|
switch (type) {
|
|
@@ -797,7 +804,7 @@ const makeChatsSocket = (config) => {
|
|
|
797
804
|
if (attrs.timestamp) {
|
|
798
805
|
let { lastAccountSyncTimestamp } = authState.creds;
|
|
799
806
|
if (lastAccountSyncTimestamp) {
|
|
800
|
-
|
|
807
|
+
yield cleanDirtyBits('account_sync', lastAccountSyncTimestamp);
|
|
801
808
|
}
|
|
802
809
|
lastAccountSyncTimestamp = +attrs.timestamp;
|
|
803
810
|
ev.emit('creds.update', { lastAccountSyncTimestamp });
|
|
@@ -810,7 +817,7 @@ const makeChatsSocket = (config) => {
|
|
|
810
817
|
logger.info({ node }, 'received unknown sync');
|
|
811
818
|
break;
|
|
812
819
|
}
|
|
813
|
-
});
|
|
820
|
+
}));
|
|
814
821
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
815
822
|
var _a;
|
|
816
823
|
if (connection === 'open') {
|
|
@@ -831,20 +838,16 @@ const makeChatsSocket = (config) => {
|
|
|
831
838
|
}
|
|
832
839
|
}
|
|
833
840
|
});
|
|
834
|
-
return {
|
|
835
|
-
...sock,
|
|
836
|
-
interactiveQuery,
|
|
837
|
-
processingMutex,
|
|
841
|
+
return Object.assign(Object.assign({}, sock), { processingMutex,
|
|
838
842
|
fetchPrivacySettings,
|
|
839
843
|
upsertMessage,
|
|
840
844
|
appPatch,
|
|
841
|
-
fetchUserLid,
|
|
842
845
|
sendPresenceUpdate,
|
|
843
846
|
presenceSubscribe,
|
|
847
|
+
profilePictureUrl,
|
|
844
848
|
onWhatsApp,
|
|
845
849
|
fetchBlocklist,
|
|
846
850
|
fetchStatus,
|
|
847
|
-
fetchDisappearingDuration,
|
|
848
851
|
updateProfilePicture,
|
|
849
852
|
removeProfilePicture,
|
|
850
853
|
updateProfileStatus,
|
|
@@ -865,7 +868,6 @@ const makeChatsSocket = (config) => {
|
|
|
865
868
|
removeChatLabel,
|
|
866
869
|
addMessageLabel,
|
|
867
870
|
removeMessageLabel,
|
|
868
|
-
star
|
|
869
|
-
};
|
|
871
|
+
star });
|
|
870
872
|
};
|
|
871
873
|
exports.makeChatsSocket = makeChatsSocket;
|