gifted-baileys 1.5.0 → 1.5.5
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/README.md +1429 -684
- package/package.json +11 -26
- package/src/Defaults/baileys-version.json +3 -0
- package/{lib → src}/Defaults/index.js +16 -8
- package/src/Defaults/index.ts +131 -0
- package/src/Defaults/phonenumber-mcc.json +223 -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/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 -27
- package/src/Socket/business.ts +281 -0
- package/{lib → src}/Socket/chats.js +197 -178
- package/src/Socket/chats.ts +1030 -0
- package/{lib → src}/Socket/groups.js +69 -79
- 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 +160 -108
- package/src/Socket/messages-recv.ts +985 -0
- package/{lib → src}/Socket/messages-send.js +183 -100
- package/src/Socket/messages-send.ts +871 -0
- package/src/Socket/newsletter.js +227 -0
- package/src/Socket/newsletter.ts +282 -0
- package/{lib → src}/Socket/registration.js +55 -63
- package/src/Socket/registration.ts +250 -0
- package/{lib → src}/Socket/socket.js +107 -66
- 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 +51 -61
- 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/{lib → src}/Types/Label.js +1 -1
- package/src/Types/Label.ts +36 -0
- package/{lib → src}/Types/LabelAssociation.js +1 -1
- package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
- package/src/Types/Message.ts +288 -0
- package/src/Types/Newsletter.js +32 -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 -56
- package/src/Types/State.ts +29 -0
- package/{lib → src}/Types/index.js +2 -1
- package/src/Types/index.ts +59 -0
- package/{lib → src}/Utils/auth-utils.js +95 -76
- 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 +45 -17
- package/src/Utils/business.ts +275 -0
- package/{lib → src}/Utils/chat-utils.js +74 -46
- package/src/Utils/chat-utils.ts +860 -0
- package/{lib → src}/Utils/crypto.js +31 -21
- 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 +98 -45
- package/src/Utils/generics.ts +434 -0
- package/{lib → src}/Utils/history.js +39 -10
- 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 +296 -192
- package/src/Utils/messages-media.ts +847 -0
- package/{lib → src}/Utils/messages.js +124 -113
- package/src/Utils/messages.ts +956 -0
- package/{lib → src}/Utils/noise-handler.js +16 -3
- package/src/Utils/noise-handler.ts +197 -0
- package/{lib → src}/Utils/process-message.js +33 -29
- package/src/Utils/process-message.ts +414 -0
- package/{lib → src}/Utils/signal.js +23 -14
- package/src/Utils/signal.ts +177 -0
- package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -19
- package/src/Utils/use-multi-file-auth-state.ts +90 -0
- package/{lib → src}/Utils/validate-connection.js +25 -42
- package/src/Utils/validate-connection.ts +238 -0
- package/src/WABinary/constants.ts +42 -0
- package/{lib → src}/WABinary/decode.js +17 -7
- package/src/WABinary/decode.ts +265 -0
- package/{lib → src}/WABinary/encode.js +17 -7
- package/src/WABinary/encode.ts +236 -0
- package/{lib → src}/WABinary/generic-utils.js +2 -2
- package/src/WABinary/generic-utils.ts +121 -0
- package/src/WABinary/index.ts +5 -0
- package/{lib → src}/WABinary/jid-utils.js +4 -1
- package/src/WABinary/jid-utils.ts +68 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.js +15350 -0
- package/src/WAM/constants.ts +15382 -0
- package/src/WAM/encode.js +155 -0
- package/src/WAM/encode.ts +174 -0
- package/src/WAM/index.js +19 -0
- package/src/WAM/index.ts +3 -0
- package/src/gifted +1 -0
- package/{lib → src}/index.js +1 -0
- package/src/index.ts +13 -0
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -284
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Signal/libsignal.js +0 -152
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/business.d.ts +0 -135
- package/lib/Socket/chats.d.ts +0 -79
- package/lib/Socket/groups.d.ts +0 -113
- package/lib/Socket/index.d.ts +0 -137
- package/lib/Socket/messages-recv.d.ts +0 -124
- package/lib/Socket/messages-send.d.ts +0 -119
- package/lib/Socket/registration.d.ts +0 -232
- package/lib/Socket/socket.d.ts +0 -42
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -117
- 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 -108
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -52
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -261
- 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/index.d.ts +0 -56
- 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 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/decode-wa-message.js +0 -174
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -94
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- 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 -107
- package/lib/Utils/messages.d.ts +0 -76
- 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 -32
- 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 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -29
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/index.d.ts +0 -10
- /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{lib → src}/Socket/Client/index.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/Message.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}/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}/WABinary/constants.js +0 -0
- /package/{lib → src}/WABinary/index.js +0 -0
- /package/{lib → src}/WABinary/types.js +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
|
};
|
|
@@ -24,13 +33,13 @@ const makeChatsSocket = (config) => {
|
|
|
24
33
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
25
34
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
26
35
|
/** helper function to fetch the given app state sync key */
|
|
27
|
-
const getAppStateSyncKey =
|
|
28
|
-
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]);
|
|
29
38
|
return key;
|
|
30
|
-
};
|
|
31
|
-
const fetchPrivacySettings =
|
|
39
|
+
});
|
|
40
|
+
const fetchPrivacySettings = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (force = false) {
|
|
32
41
|
if (!privacySettings || force) {
|
|
33
|
-
const { content } =
|
|
42
|
+
const { content } = yield query({
|
|
34
43
|
tag: 'iq',
|
|
35
44
|
attrs: {
|
|
36
45
|
xmlns: 'privacy',
|
|
@@ -44,10 +53,10 @@ const makeChatsSocket = (config) => {
|
|
|
44
53
|
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
|
|
45
54
|
}
|
|
46
55
|
return privacySettings;
|
|
47
|
-
};
|
|
56
|
+
});
|
|
48
57
|
/** helper function to run a privacy IQ query */
|
|
49
|
-
const privacyQuery =
|
|
50
|
-
|
|
58
|
+
const privacyQuery = (name, value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
yield query({
|
|
51
60
|
tag: 'iq',
|
|
52
61
|
attrs: {
|
|
53
62
|
xmlns: 'privacy',
|
|
@@ -65,27 +74,27 @@ const makeChatsSocket = (config) => {
|
|
|
65
74
|
]
|
|
66
75
|
}]
|
|
67
76
|
});
|
|
68
|
-
};
|
|
69
|
-
const updateLastSeenPrivacy =
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
const updateOnlinePrivacy =
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
const updateProfilePicturePrivacy =
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
const updateStatusPrivacy =
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
const updateReadReceiptsPrivacy =
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
const updateGroupsAddPrivacy =
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
const updateDefaultDisappearingMode =
|
|
88
|
-
|
|
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({
|
|
89
98
|
tag: 'iq',
|
|
90
99
|
attrs: {
|
|
91
100
|
xmlns: 'disappearing_mode',
|
|
@@ -99,10 +108,10 @@ const makeChatsSocket = (config) => {
|
|
|
99
108
|
}
|
|
100
109
|
}]
|
|
101
110
|
});
|
|
102
|
-
};
|
|
111
|
+
});
|
|
103
112
|
/** helper function to run a generic IQ query */
|
|
104
|
-
const interactiveQuery =
|
|
105
|
-
const result =
|
|
113
|
+
const interactiveQuery = (userNodes, queryNode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
const result = yield query({
|
|
106
115
|
tag: 'iq',
|
|
107
116
|
attrs: {
|
|
108
117
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -138,8 +147,8 @@ const makeChatsSocket = (config) => {
|
|
|
138
147
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
|
|
139
148
|
const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
|
|
140
149
|
return users;
|
|
141
|
-
};
|
|
142
|
-
const onWhatsApp =
|
|
150
|
+
});
|
|
151
|
+
const onWhatsApp = (...jids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
152
|
const query = { tag: 'contact', attrs: {} };
|
|
144
153
|
const list = jids.map((jid) => {
|
|
145
154
|
// insures only 1 + is there
|
|
@@ -154,14 +163,14 @@ const makeChatsSocket = (config) => {
|
|
|
154
163
|
}],
|
|
155
164
|
};
|
|
156
165
|
});
|
|
157
|
-
const results =
|
|
166
|
+
const results = yield interactiveQuery(list, query);
|
|
158
167
|
return results.map(user => {
|
|
159
168
|
const contact = (0, WABinary_1.getBinaryNodeChild)(user, 'contact');
|
|
160
169
|
return { exists: (contact === null || contact === void 0 ? void 0 : contact.attrs.type) === 'in', jid: user.attrs.jid };
|
|
161
170
|
}).filter(item => item.exists);
|
|
162
|
-
};
|
|
163
|
-
const fetchStatus =
|
|
164
|
-
const [result] =
|
|
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: {} });
|
|
165
174
|
if (result) {
|
|
166
175
|
const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
|
|
167
176
|
return {
|
|
@@ -169,14 +178,22 @@ const makeChatsSocket = (config) => {
|
|
|
169
178
|
setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
|
|
170
179
|
};
|
|
171
180
|
}
|
|
172
|
-
};
|
|
181
|
+
});
|
|
173
182
|
/** update the profile picture for yourself or a group */
|
|
174
|
-
const updateProfilePicture =
|
|
175
|
-
|
|
176
|
-
|
|
183
|
+
const updateProfilePicture = (jid, content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
+
let targetJid;
|
|
185
|
+
if (!jid) {
|
|
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');
|
|
187
|
+
}
|
|
188
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
189
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
190
|
+
}
|
|
191
|
+
const { img } = yield (0, Utils_1.generateProfilePicture)(content);
|
|
192
|
+
yield query({
|
|
177
193
|
tag: 'iq',
|
|
178
194
|
attrs: {
|
|
179
|
-
|
|
195
|
+
target: targetJid,
|
|
196
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
180
197
|
type: 'set',
|
|
181
198
|
xmlns: 'w:profile:picture'
|
|
182
199
|
},
|
|
@@ -188,21 +205,29 @@ const makeChatsSocket = (config) => {
|
|
|
188
205
|
}
|
|
189
206
|
]
|
|
190
207
|
});
|
|
191
|
-
};
|
|
208
|
+
});
|
|
192
209
|
/** remove the profile picture for yourself or a group */
|
|
193
|
-
const removeProfilePicture =
|
|
194
|
-
|
|
210
|
+
const removeProfilePicture = (jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
|
+
let targetJid;
|
|
212
|
+
if (!jid) {
|
|
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');
|
|
214
|
+
}
|
|
215
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
216
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
217
|
+
}
|
|
218
|
+
yield query({
|
|
195
219
|
tag: 'iq',
|
|
196
220
|
attrs: {
|
|
197
|
-
|
|
221
|
+
target: targetJid,
|
|
222
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
198
223
|
type: 'set',
|
|
199
224
|
xmlns: 'w:profile:picture'
|
|
200
225
|
}
|
|
201
226
|
});
|
|
202
|
-
};
|
|
227
|
+
});
|
|
203
228
|
/** update the profile status for yourself */
|
|
204
|
-
const updateProfileStatus =
|
|
205
|
-
|
|
229
|
+
const updateProfileStatus = (status) => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
|
+
yield query({
|
|
206
231
|
tag: 'iq',
|
|
207
232
|
attrs: {
|
|
208
233
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -217,12 +242,12 @@ const makeChatsSocket = (config) => {
|
|
|
217
242
|
}
|
|
218
243
|
]
|
|
219
244
|
});
|
|
220
|
-
};
|
|
221
|
-
const updateProfileName =
|
|
222
|
-
|
|
223
|
-
};
|
|
224
|
-
const fetchBlocklist =
|
|
225
|
-
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({
|
|
226
251
|
tag: 'iq',
|
|
227
252
|
attrs: {
|
|
228
253
|
xmlns: 'blocklist',
|
|
@@ -233,9 +258,9 @@ const makeChatsSocket = (config) => {
|
|
|
233
258
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
234
259
|
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
235
260
|
.map(n => n.attrs.jid);
|
|
236
|
-
};
|
|
237
|
-
const updateBlockStatus =
|
|
238
|
-
|
|
261
|
+
});
|
|
262
|
+
const updateBlockStatus = (jid, action) => __awaiter(void 0, void 0, void 0, function* () {
|
|
263
|
+
yield query({
|
|
239
264
|
tag: 'iq',
|
|
240
265
|
attrs: {
|
|
241
266
|
xmlns: 'blocklist',
|
|
@@ -252,10 +277,10 @@ const makeChatsSocket = (config) => {
|
|
|
252
277
|
}
|
|
253
278
|
]
|
|
254
279
|
});
|
|
255
|
-
};
|
|
256
|
-
const getBusinessProfile =
|
|
280
|
+
});
|
|
281
|
+
const getBusinessProfile = (jid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
282
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
258
|
-
const results =
|
|
283
|
+
const results = yield query({
|
|
259
284
|
tag: 'iq',
|
|
260
285
|
attrs: {
|
|
261
286
|
to: 's.whatsapp.net',
|
|
@@ -280,9 +305,9 @@ const makeChatsSocket = (config) => {
|
|
|
280
305
|
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
281
306
|
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
282
307
|
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
283
|
-
const businessHoursConfig = businessHours
|
|
284
|
-
|
|
285
|
-
|
|
308
|
+
const businessHoursConfig = businessHours ?
|
|
309
|
+
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
310
|
+
undefined;
|
|
286
311
|
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
287
312
|
return {
|
|
288
313
|
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
@@ -297,10 +322,10 @@ const makeChatsSocket = (config) => {
|
|
|
297
322
|
}
|
|
298
323
|
};
|
|
299
324
|
}
|
|
300
|
-
};
|
|
301
|
-
const cleanDirtyBits =
|
|
325
|
+
});
|
|
326
|
+
const cleanDirtyBits = (type, fromTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
327
|
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
303
|
-
|
|
328
|
+
yield sendNode({
|
|
304
329
|
tag: 'iq',
|
|
305
330
|
attrs: {
|
|
306
331
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -311,14 +336,11 @@ const makeChatsSocket = (config) => {
|
|
|
311
336
|
content: [
|
|
312
337
|
{
|
|
313
338
|
tag: 'clean',
|
|
314
|
-
attrs: {
|
|
315
|
-
type,
|
|
316
|
-
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
|
|
317
|
-
}
|
|
339
|
+
attrs: Object.assign({ type }, (fromTimestamp ? { timestamp: fromTimestamp.toString() } : null))
|
|
318
340
|
}
|
|
319
341
|
]
|
|
320
342
|
});
|
|
321
|
-
};
|
|
343
|
+
});
|
|
322
344
|
const newAppStateChunkHandler = (isInitialSync) => {
|
|
323
345
|
return {
|
|
324
346
|
onMutation(mutation) {
|
|
@@ -326,12 +348,12 @@ const makeChatsSocket = (config) => {
|
|
|
326
348
|
}
|
|
327
349
|
};
|
|
328
350
|
};
|
|
329
|
-
const resyncAppState = ev.createBufferedFunction(
|
|
351
|
+
const resyncAppState = ev.createBufferedFunction((collections, isInitialSync) => __awaiter(void 0, void 0, void 0, function* () {
|
|
330
352
|
// we use this to determine which events to fire
|
|
331
353
|
// otherwise when we resync from scratch -- all notifications will fire
|
|
332
354
|
const initialVersionMap = {};
|
|
333
355
|
const globalMutationMap = {};
|
|
334
|
-
|
|
356
|
+
yield authState.keys.transaction(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
335
357
|
var _a;
|
|
336
358
|
const collectionsToHandle = new Set(collections);
|
|
337
359
|
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
@@ -343,7 +365,7 @@ const makeChatsSocket = (config) => {
|
|
|
343
365
|
const states = {};
|
|
344
366
|
const nodes = [];
|
|
345
367
|
for (const name of collectionsToHandle) {
|
|
346
|
-
const result =
|
|
368
|
+
const result = yield authState.keys.get('app-state-sync-version', [name]);
|
|
347
369
|
let state = result[name];
|
|
348
370
|
if (state) {
|
|
349
371
|
if (typeof initialVersionMap[name] === 'undefined') {
|
|
@@ -365,7 +387,7 @@ const makeChatsSocket = (config) => {
|
|
|
365
387
|
}
|
|
366
388
|
});
|
|
367
389
|
}
|
|
368
|
-
const result =
|
|
390
|
+
const result = yield query({
|
|
369
391
|
tag: 'iq',
|
|
370
392
|
attrs: {
|
|
371
393
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -381,22 +403,26 @@ const makeChatsSocket = (config) => {
|
|
|
381
403
|
]
|
|
382
404
|
});
|
|
383
405
|
// extract from binary node
|
|
384
|
-
const decoded =
|
|
406
|
+
const decoded = yield (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
385
407
|
for (const key in decoded) {
|
|
386
408
|
const name = key;
|
|
387
409
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
388
410
|
try {
|
|
389
411
|
if (snapshot) {
|
|
390
|
-
const { state: newState, mutationMap } =
|
|
412
|
+
const { state: newState, mutationMap } = yield (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
391
413
|
states[name] = newState;
|
|
392
414
|
Object.assign(globalMutationMap, mutationMap);
|
|
393
415
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
394
|
-
|
|
416
|
+
yield authState.keys.set({ 'app-state-sync-version': {
|
|
417
|
+
[name]: newState
|
|
418
|
+
} });
|
|
395
419
|
}
|
|
396
420
|
// only process if there are syncd patches
|
|
397
421
|
if (patches.length) {
|
|
398
|
-
const { state: newState, mutationMap } =
|
|
399
|
-
|
|
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': {
|
|
424
|
+
[name]: newState
|
|
425
|
+
} });
|
|
400
426
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
401
427
|
initialVersionMap[name] = newState.version;
|
|
402
428
|
Object.assign(globalMutationMap, mutationMap);
|
|
@@ -411,11 +437,13 @@ const makeChatsSocket = (config) => {
|
|
|
411
437
|
catch (error) {
|
|
412
438
|
// if retry attempts overshoot
|
|
413
439
|
// or key not found
|
|
414
|
-
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
415
|
-
|
|
416
|
-
|
|
440
|
+
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
441
|
+
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
442
|
+
error.name === 'TypeError';
|
|
417
443
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
418
|
-
|
|
444
|
+
yield authState.keys.set({ 'app-state-sync-version': {
|
|
445
|
+
[name]: null
|
|
446
|
+
} });
|
|
419
447
|
// increment number of retries
|
|
420
448
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
421
449
|
if (isIrrecoverableError) {
|
|
@@ -425,24 +453,25 @@ const makeChatsSocket = (config) => {
|
|
|
425
453
|
}
|
|
426
454
|
}
|
|
427
455
|
}
|
|
428
|
-
});
|
|
456
|
+
}));
|
|
429
457
|
const { onMutation } = newAppStateChunkHandler(isInitialSync);
|
|
430
458
|
for (const key in globalMutationMap) {
|
|
431
459
|
onMutation(globalMutationMap[key]);
|
|
432
460
|
}
|
|
433
|
-
});
|
|
461
|
+
}));
|
|
434
462
|
/**
|
|
435
463
|
* fetch the profile picture of a user/group
|
|
436
464
|
* type = "preview" for a low res picture
|
|
437
465
|
* type = "image for the high res picture"
|
|
438
466
|
*/
|
|
439
|
-
const profilePictureUrl =
|
|
467
|
+
const profilePictureUrl = (jid_1, ...args_1) => __awaiter(void 0, [jid_1, ...args_1], void 0, function* (jid, type = 'preview', timeoutMs) {
|
|
440
468
|
var _a;
|
|
441
469
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
442
|
-
const result =
|
|
470
|
+
const result = yield query({
|
|
443
471
|
tag: 'iq',
|
|
444
472
|
attrs: {
|
|
445
|
-
|
|
473
|
+
target: jid,
|
|
474
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
446
475
|
type: 'get',
|
|
447
476
|
xmlns: 'w:profile:picture'
|
|
448
477
|
},
|
|
@@ -452,8 +481,8 @@ const makeChatsSocket = (config) => {
|
|
|
452
481
|
}, timeoutMs);
|
|
453
482
|
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
454
483
|
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
455
|
-
};
|
|
456
|
-
const sendPresenceUpdate =
|
|
484
|
+
});
|
|
485
|
+
const sendPresenceUpdate = (type, toJid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
457
486
|
const me = authState.creds.me;
|
|
458
487
|
if (type === 'available' || type === 'unavailable') {
|
|
459
488
|
if (!me.name) {
|
|
@@ -461,7 +490,7 @@ const makeChatsSocket = (config) => {
|
|
|
461
490
|
return;
|
|
462
491
|
}
|
|
463
492
|
ev.emit('connection.update', { isOnline: type === 'available' });
|
|
464
|
-
|
|
493
|
+
yield sendNode({
|
|
465
494
|
tag: 'presence',
|
|
466
495
|
attrs: {
|
|
467
496
|
name: me.name,
|
|
@@ -470,7 +499,7 @@ const makeChatsSocket = (config) => {
|
|
|
470
499
|
});
|
|
471
500
|
}
|
|
472
501
|
else {
|
|
473
|
-
|
|
502
|
+
yield sendNode({
|
|
474
503
|
tag: 'chatstate',
|
|
475
504
|
attrs: {
|
|
476
505
|
from: me.id,
|
|
@@ -484,7 +513,7 @@ const makeChatsSocket = (config) => {
|
|
|
484
513
|
]
|
|
485
514
|
});
|
|
486
515
|
}
|
|
487
|
-
};
|
|
516
|
+
});
|
|
488
517
|
/**
|
|
489
518
|
* @param toJid the jid to subscribe to
|
|
490
519
|
* @param tcToken token for subscription, use if present
|
|
@@ -496,22 +525,22 @@ const makeChatsSocket = (config) => {
|
|
|
496
525
|
id: generateMessageTag(),
|
|
497
526
|
type: 'subscribe'
|
|
498
527
|
},
|
|
499
|
-
content: tcToken
|
|
500
|
-
|
|
528
|
+
content: tcToken ?
|
|
529
|
+
[
|
|
501
530
|
{
|
|
502
531
|
tag: 'tctoken',
|
|
503
532
|
attrs: {},
|
|
504
533
|
content: tcToken
|
|
505
534
|
}
|
|
506
|
-
]
|
|
507
|
-
|
|
535
|
+
] :
|
|
536
|
+
undefined
|
|
508
537
|
}));
|
|
509
538
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
510
539
|
var _a;
|
|
511
540
|
let presence;
|
|
512
541
|
const jid = attrs.from;
|
|
513
542
|
const participant = attrs.participant || attrs.from;
|
|
514
|
-
if (shouldIgnoreJid(jid)) {
|
|
543
|
+
if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
|
|
515
544
|
return;
|
|
516
545
|
}
|
|
517
546
|
if (tag === 'presence') {
|
|
@@ -535,10 +564,12 @@ const makeChatsSocket = (config) => {
|
|
|
535
564
|
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
536
565
|
}
|
|
537
566
|
if (presence) {
|
|
538
|
-
ev.emit('presence.update', { id: jid, presences: {
|
|
567
|
+
ev.emit('presence.update', { id: jid, presences: {
|
|
568
|
+
[participant]: presence
|
|
569
|
+
} });
|
|
539
570
|
}
|
|
540
571
|
};
|
|
541
|
-
const appPatch =
|
|
572
|
+
const appPatch = (patchCreate) => __awaiter(void 0, void 0, void 0, function* () {
|
|
542
573
|
const name = patchCreate.type;
|
|
543
574
|
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
544
575
|
if (!myAppStateKeyId) {
|
|
@@ -546,13 +577,13 @@ const makeChatsSocket = (config) => {
|
|
|
546
577
|
}
|
|
547
578
|
let initial;
|
|
548
579
|
let encodeResult;
|
|
549
|
-
|
|
550
|
-
|
|
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* () {
|
|
551
582
|
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
552
|
-
|
|
553
|
-
const { [name]: currentSyncVersion } =
|
|
583
|
+
yield resyncAppState([name], false);
|
|
584
|
+
const { [name]: currentSyncVersion } = yield authState.keys.get('app-state-sync-version', [name]);
|
|
554
585
|
initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
|
|
555
|
-
encodeResult =
|
|
586
|
+
encodeResult = yield (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
556
587
|
const { patch, state } = encodeResult;
|
|
557
588
|
const node = {
|
|
558
589
|
tag: 'iq',
|
|
@@ -585,42 +616,24 @@ const makeChatsSocket = (config) => {
|
|
|
585
616
|
}
|
|
586
617
|
]
|
|
587
618
|
};
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
619
|
+
yield query(node);
|
|
620
|
+
yield authState.keys.set({ 'app-state-sync-version': {
|
|
621
|
+
[name]: state
|
|
622
|
+
} });
|
|
623
|
+
}));
|
|
624
|
+
}));
|
|
592
625
|
if (config.emitOwnEvents) {
|
|
593
626
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
594
|
-
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);
|
|
595
628
|
for (const key in mutationMap) {
|
|
596
629
|
onMutation(mutationMap[key]);
|
|
597
630
|
}
|
|
598
631
|
}
|
|
599
|
-
};
|
|
600
|
-
/** sending abt props may fix QR scan fail if server expects */
|
|
601
|
-
const fetchAbt = async () => {
|
|
602
|
-
const abtNode = await query({
|
|
603
|
-
tag: 'iq',
|
|
604
|
-
attrs: {
|
|
605
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
606
|
-
xmlns: 'abt',
|
|
607
|
-
type: 'get',
|
|
608
|
-
},
|
|
609
|
-
content: [
|
|
610
|
-
{ tag: 'props', attrs: { protocol: '1' } }
|
|
611
|
-
]
|
|
612
|
-
});
|
|
613
|
-
const propsNode = (0, WABinary_1.getBinaryNodeChild)(abtNode, 'props');
|
|
614
|
-
let props = {};
|
|
615
|
-
if (propsNode) {
|
|
616
|
-
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
617
|
-
}
|
|
618
|
-
logger.debug('fetched abt');
|
|
619
|
-
return props;
|
|
620
|
-
};
|
|
632
|
+
});
|
|
621
633
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
622
|
-
const fetchProps =
|
|
623
|
-
|
|
634
|
+
const fetchProps = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
635
|
+
var _a, _b;
|
|
636
|
+
const resultNode = yield query({
|
|
624
637
|
tag: 'iq',
|
|
625
638
|
attrs: {
|
|
626
639
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -628,22 +641,30 @@ const makeChatsSocket = (config) => {
|
|
|
628
641
|
type: 'get',
|
|
629
642
|
},
|
|
630
643
|
content: [
|
|
631
|
-
{
|
|
644
|
+
{
|
|
645
|
+
tag: 'props',
|
|
646
|
+
attrs: {
|
|
647
|
+
protocol: '2',
|
|
648
|
+
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
649
|
+
}
|
|
650
|
+
}
|
|
632
651
|
]
|
|
633
652
|
});
|
|
634
653
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
635
654
|
let props = {};
|
|
636
655
|
if (propsNode) {
|
|
656
|
+
authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
|
|
657
|
+
ev.emit('creds.update', authState.creds);
|
|
637
658
|
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
638
659
|
}
|
|
639
660
|
logger.debug('fetched props');
|
|
640
661
|
return props;
|
|
641
|
-
};
|
|
662
|
+
});
|
|
642
663
|
/**
|
|
643
664
|
* modify a chat -- mark unread, read etc.
|
|
644
665
|
* lastMessages must be sorted in reverse chronologically
|
|
645
666
|
* requires the last messages till the last message received; required for archive & unread
|
|
646
|
-
|
|
667
|
+
*/
|
|
647
668
|
const chatModify = (mod, jid) => {
|
|
648
669
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
649
670
|
return appPatch(patch);
|
|
@@ -705,15 +726,14 @@ const makeChatsSocket = (config) => {
|
|
|
705
726
|
* queries need to be fired on connection open
|
|
706
727
|
* help ensure parity with WA Web
|
|
707
728
|
* */
|
|
708
|
-
const executeInitQueries =
|
|
709
|
-
|
|
710
|
-
fetchAbt(),
|
|
729
|
+
const executeInitQueries = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
730
|
+
yield Promise.all([
|
|
711
731
|
fetchProps(),
|
|
712
732
|
fetchBlocklist(),
|
|
713
733
|
fetchPrivacySettings(),
|
|
714
734
|
]);
|
|
715
|
-
};
|
|
716
|
-
const upsertMessage = ev.createBufferedFunction(
|
|
735
|
+
});
|
|
736
|
+
const upsertMessage = ev.createBufferedFunction((msg, type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
717
737
|
var _a, _b, _c;
|
|
718
738
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
719
739
|
if (!!msg.pushName) {
|
|
@@ -724,26 +744,26 @@ const makeChatsSocket = (config) => {
|
|
|
724
744
|
}
|
|
725
745
|
// update our pushname too
|
|
726
746
|
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
727
|
-
ev.emit('creds.update', { me: {
|
|
747
|
+
ev.emit('creds.update', { me: Object.assign(Object.assign({}, authState.creds.me), { name: msg.pushName }) });
|
|
728
748
|
}
|
|
729
749
|
}
|
|
730
750
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
731
|
-
const shouldProcessHistoryMsg = historyMsg
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
751
|
+
const shouldProcessHistoryMsg = historyMsg ?
|
|
752
|
+
(shouldSyncHistoryMessage(historyMsg) &&
|
|
753
|
+
Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
|
|
754
|
+
false;
|
|
735
755
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
736
756
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
737
757
|
pendingAppStateSync = true;
|
|
738
758
|
}
|
|
739
|
-
|
|
740
|
-
(
|
|
741
|
-
if (historyMsg
|
|
742
|
-
|
|
759
|
+
yield Promise.all([
|
|
760
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
761
|
+
if (historyMsg &&
|
|
762
|
+
authState.creds.myAppStateKeyId) {
|
|
743
763
|
pendingAppStateSync = false;
|
|
744
|
-
|
|
764
|
+
yield doAppStateSync();
|
|
745
765
|
}
|
|
746
|
-
})(),
|
|
766
|
+
}))(),
|
|
747
767
|
(0, process_message_1.default)(msg, {
|
|
748
768
|
shouldProcessHistoryMsg,
|
|
749
769
|
ev,
|
|
@@ -754,27 +774,29 @@ const makeChatsSocket = (config) => {
|
|
|
754
774
|
getMessage: config.getMessage,
|
|
755
775
|
})
|
|
756
776
|
]);
|
|
757
|
-
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
758
|
-
|
|
759
|
-
|
|
777
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
|
|
778
|
+
pendingAppStateSync) {
|
|
779
|
+
yield doAppStateSync();
|
|
760
780
|
pendingAppStateSync = false;
|
|
761
781
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
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
|
+
}
|
|
771
793
|
}
|
|
772
|
-
}
|
|
794
|
+
});
|
|
773
795
|
}
|
|
774
|
-
});
|
|
796
|
+
}));
|
|
775
797
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
776
798
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
777
|
-
ws.on('CB:ib,,dirty',
|
|
799
|
+
ws.on('CB:ib,,dirty', (node) => __awaiter(void 0, void 0, void 0, function* () {
|
|
778
800
|
const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
|
|
779
801
|
const type = attrs.type;
|
|
780
802
|
switch (type) {
|
|
@@ -782,7 +804,7 @@ const makeChatsSocket = (config) => {
|
|
|
782
804
|
if (attrs.timestamp) {
|
|
783
805
|
let { lastAccountSyncTimestamp } = authState.creds;
|
|
784
806
|
if (lastAccountSyncTimestamp) {
|
|
785
|
-
|
|
807
|
+
yield cleanDirtyBits('account_sync', lastAccountSyncTimestamp);
|
|
786
808
|
}
|
|
787
809
|
lastAccountSyncTimestamp = +attrs.timestamp;
|
|
788
810
|
ev.emit('creds.update', { lastAccountSyncTimestamp });
|
|
@@ -795,7 +817,7 @@ const makeChatsSocket = (config) => {
|
|
|
795
817
|
logger.info({ node }, 'received unknown sync');
|
|
796
818
|
break;
|
|
797
819
|
}
|
|
798
|
-
});
|
|
820
|
+
}));
|
|
799
821
|
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
800
822
|
var _a;
|
|
801
823
|
if (connection === 'open') {
|
|
@@ -816,9 +838,7 @@ const makeChatsSocket = (config) => {
|
|
|
816
838
|
}
|
|
817
839
|
}
|
|
818
840
|
});
|
|
819
|
-
return {
|
|
820
|
-
...sock,
|
|
821
|
-
processingMutex,
|
|
841
|
+
return Object.assign(Object.assign({}, sock), { processingMutex,
|
|
822
842
|
fetchPrivacySettings,
|
|
823
843
|
upsertMessage,
|
|
824
844
|
appPatch,
|
|
@@ -848,7 +868,6 @@ const makeChatsSocket = (config) => {
|
|
|
848
868
|
removeChatLabel,
|
|
849
869
|
addMessageLabel,
|
|
850
870
|
removeMessageLabel,
|
|
851
|
-
star
|
|
852
|
-
};
|
|
871
|
+
star });
|
|
853
872
|
};
|
|
854
873
|
exports.makeChatsSocket = makeChatsSocket;
|