gifted-baileys 1.5.4 → 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.
Files changed (250) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/WAProto.proto +88 -969
  3. package/WAProto/index.d.ts +1256 -13195
  4. package/WAProto/index.js +74730 -125106
  5. package/package.json +9 -27
  6. package/src/Defaults/baileys-version.json +3 -0
  7. package/{lib → src}/Defaults/index.js +14 -7
  8. package/src/Defaults/index.ts +131 -0
  9. package/src/Signal/libsignal.js +180 -0
  10. package/src/Signal/libsignal.ts +141 -0
  11. package/src/Socket/Client/abstract-socket-client.ts +19 -0
  12. package/{lib → src}/Socket/Client/index.js +3 -2
  13. package/src/Socket/Client/index.ts +3 -0
  14. package/src/Socket/Client/mobile-socket-client.js +78 -0
  15. package/src/Socket/Client/mobile-socket-client.ts +66 -0
  16. package/src/Socket/Client/web-socket-client.js +75 -0
  17. package/src/Socket/Client/web-socket-client.ts +57 -0
  18. package/{lib → src}/Socket/business.js +33 -28
  19. package/src/Socket/business.ts +281 -0
  20. package/{lib → src}/Socket/chats.js +176 -174
  21. package/src/Socket/chats.ts +1030 -0
  22. package/{lib → src}/Socket/groups.js +68 -80
  23. package/src/Socket/groups.ts +356 -0
  24. package/{lib → src}/Socket/index.js +1 -4
  25. package/src/Socket/index.ts +13 -0
  26. package/{lib → src}/Socket/messages-recv.js +211 -378
  27. package/src/Socket/messages-recv.ts +985 -0
  28. package/{lib → src}/Socket/messages-send.js +177 -452
  29. package/src/Socket/messages-send.ts +871 -0
  30. package/{lib → src}/Socket/newsletter.js +98 -107
  31. package/src/Socket/newsletter.ts +282 -0
  32. package/{lib → src}/Socket/registration.js +48 -56
  33. package/src/Socket/registration.ts +250 -0
  34. package/{lib → src}/Socket/socket.js +77 -77
  35. package/src/Socket/socket.ts +777 -0
  36. package/src/Store/index.ts +3 -0
  37. package/{lib → src}/Store/make-cache-manager-store.js +34 -25
  38. package/src/Store/make-cache-manager-store.ts +100 -0
  39. package/{lib → src}/Store/make-in-memory-store.js +32 -36
  40. package/src/Store/make-in-memory-store.ts +475 -0
  41. package/src/Store/make-ordered-dictionary.ts +86 -0
  42. package/{lib → src}/Store/object-repository.js +1 -1
  43. package/src/Store/object-repository.ts +32 -0
  44. package/src/Tests/test.app-state-sync.js +204 -0
  45. package/src/Tests/test.app-state-sync.ts +207 -0
  46. package/src/Tests/test.event-buffer.js +270 -0
  47. package/src/Tests/test.event-buffer.ts +319 -0
  48. package/src/Tests/test.key-store.js +76 -0
  49. package/src/Tests/test.key-store.ts +92 -0
  50. package/src/Tests/test.libsignal.js +141 -0
  51. package/src/Tests/test.libsignal.ts +186 -0
  52. package/src/Tests/test.media-download.js +93 -0
  53. package/src/Tests/test.media-download.ts +76 -0
  54. package/src/Tests/test.messages.js +33 -0
  55. package/src/Tests/test.messages.ts +37 -0
  56. package/src/Tests/utils.js +34 -0
  57. package/src/Tests/utils.ts +36 -0
  58. package/src/Types/Auth.ts +113 -0
  59. package/src/Types/Call.ts +15 -0
  60. package/src/Types/Chat.ts +106 -0
  61. package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
  62. package/src/Types/Events.ts +93 -0
  63. package/src/Types/GroupMetadata.ts +53 -0
  64. package/src/Types/Label.ts +36 -0
  65. package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
  66. package/src/Types/Message.ts +288 -0
  67. package/src/Types/Newsletter.ts +98 -0
  68. package/src/Types/Product.ts +85 -0
  69. package/src/Types/Signal.ts +68 -0
  70. package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -61
  71. package/src/Types/State.ts +29 -0
  72. package/src/Types/index.ts +59 -0
  73. package/{lib → src}/Utils/auth-utils.js +90 -73
  74. package/src/Utils/auth-utils.ts +222 -0
  75. package/src/Utils/baileys-event-stream.js +92 -0
  76. package/src/Utils/baileys-event-stream.ts +66 -0
  77. package/{lib → src}/Utils/business.js +43 -15
  78. package/src/Utils/business.ts +275 -0
  79. package/{lib → src}/Utils/chat-utils.js +94 -87
  80. package/src/Utils/chat-utils.ts +860 -0
  81. package/{lib → src}/Utils/crypto.js +2 -4
  82. package/src/Utils/crypto.ts +131 -0
  83. package/src/Utils/decode-wa-message.js +211 -0
  84. package/src/Utils/decode-wa-message.ts +228 -0
  85. package/{lib → src}/Utils/event-buffer.js +13 -4
  86. package/src/Utils/event-buffer.ts +613 -0
  87. package/{lib → src}/Utils/generics.js +86 -67
  88. package/src/Utils/generics.ts +434 -0
  89. package/{lib → src}/Utils/history.js +39 -13
  90. package/src/Utils/history.ts +112 -0
  91. package/src/Utils/index.ts +17 -0
  92. package/{lib → src}/Utils/link-preview.js +54 -17
  93. package/src/Utils/link-preview.ts +122 -0
  94. package/src/Utils/logger.ts +3 -0
  95. package/src/Utils/lt-hash.ts +61 -0
  96. package/{lib → src}/Utils/make-mutex.js +13 -4
  97. package/src/Utils/make-mutex.ts +44 -0
  98. package/{lib → src}/Utils/messages-media.js +255 -193
  99. package/src/Utils/messages-media.ts +847 -0
  100. package/{lib → src}/Utils/messages.js +118 -588
  101. package/src/Utils/messages.ts +956 -0
  102. package/src/Utils/noise-handler.ts +197 -0
  103. package/{lib → src}/Utils/process-message.js +30 -27
  104. package/src/Utils/process-message.ts +414 -0
  105. package/{lib → src}/Utils/signal.js +42 -25
  106. package/src/Utils/signal.ts +177 -0
  107. package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -27
  108. package/src/Utils/use-multi-file-auth-state.ts +90 -0
  109. package/{lib → src}/Utils/validate-connection.js +9 -40
  110. package/src/Utils/validate-connection.ts +238 -0
  111. package/src/WABinary/constants.ts +42 -0
  112. package/src/WABinary/decode.ts +265 -0
  113. package/{lib → src}/WABinary/encode.js +10 -16
  114. package/src/WABinary/encode.ts +236 -0
  115. package/src/WABinary/generic-utils.ts +121 -0
  116. package/src/WABinary/index.ts +5 -0
  117. package/src/WABinary/jid-utils.ts +68 -0
  118. package/src/WABinary/types.ts +17 -0
  119. package/src/WAM/BinaryInfo.ts +12 -0
  120. package/src/WAM/constants.ts +15382 -0
  121. package/src/WAM/encode.ts +174 -0
  122. package/src/WAM/index.ts +3 -0
  123. package/{lib → src}/index.js +0 -1
  124. package/src/index.ts +13 -0
  125. package/lib/Defaults/baileys-version.json +0 -3
  126. package/lib/Defaults/index.d.ts +0 -284
  127. package/lib/Signal/libsignal.d.ts +0 -3
  128. package/lib/Signal/libsignal.js +0 -161
  129. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  130. package/lib/Socket/Client/index.d.ts +0 -2
  131. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  132. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  133. package/lib/Socket/Client/types.d.ts +0 -17
  134. package/lib/Socket/Client/types.js +0 -13
  135. package/lib/Socket/Client/websocket.d.ts +0 -12
  136. package/lib/Socket/Client/websocket.js +0 -62
  137. package/lib/Socket/business.d.ts +0 -170
  138. package/lib/Socket/chats.d.ts +0 -81
  139. package/lib/Socket/groups.d.ts +0 -115
  140. package/lib/Socket/index.d.ts +0 -172
  141. package/lib/Socket/messages-recv.d.ts +0 -158
  142. package/lib/Socket/messages-send.d.ts +0 -155
  143. package/lib/Socket/newsletter.d.ts +0 -132
  144. package/lib/Socket/registration.d.ts +0 -264
  145. package/lib/Socket/socket.d.ts +0 -44
  146. package/lib/Socket/usync.d.ts +0 -37
  147. package/lib/Socket/usync.js +0 -70
  148. package/lib/Store/index.d.ts +0 -3
  149. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  150. package/lib/Store/make-in-memory-store.d.ts +0 -118
  151. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  152. package/lib/Store/object-repository.d.ts +0 -10
  153. package/lib/Types/Auth.d.ts +0 -109
  154. package/lib/Types/Call.d.ts +0 -13
  155. package/lib/Types/Chat.d.ts +0 -107
  156. package/lib/Types/Events.d.ts +0 -172
  157. package/lib/Types/GroupMetadata.d.ts +0 -56
  158. package/lib/Types/Label.d.ts +0 -46
  159. package/lib/Types/Message.d.ts +0 -433
  160. package/lib/Types/Newsletter.d.ts +0 -92
  161. package/lib/Types/Product.d.ts +0 -78
  162. package/lib/Types/Signal.d.ts +0 -57
  163. package/lib/Types/State.d.ts +0 -27
  164. package/lib/Types/USync.d.ts +0 -25
  165. package/lib/Types/USync.js +0 -2
  166. package/lib/Types/index.d.ts +0 -66
  167. package/lib/Utils/auth-utils.d.ts +0 -18
  168. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  169. package/lib/Utils/baileys-event-stream.js +0 -63
  170. package/lib/Utils/business.d.ts +0 -22
  171. package/lib/Utils/chat-utils.d.ts +0 -70
  172. package/lib/Utils/crypto.d.ts +0 -40
  173. package/lib/Utils/decode-wa-message.d.ts +0 -36
  174. package/lib/Utils/decode-wa-message.js +0 -226
  175. package/lib/Utils/event-buffer.d.ts +0 -35
  176. package/lib/Utils/generics.d.ts +0 -88
  177. package/lib/Utils/history.d.ts +0 -19
  178. package/lib/Utils/index.d.ts +0 -17
  179. package/lib/Utils/link-preview.d.ts +0 -21
  180. package/lib/Utils/logger.d.ts +0 -2
  181. package/lib/Utils/lt-hash.d.ts +0 -12
  182. package/lib/Utils/make-mutex.d.ts +0 -7
  183. package/lib/Utils/messages-media.d.ts +0 -113
  184. package/lib/Utils/messages.d.ts +0 -77
  185. package/lib/Utils/noise-handler.d.ts +0 -20
  186. package/lib/Utils/process-message.d.ts +0 -41
  187. package/lib/Utils/signal.d.ts +0 -33
  188. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  189. package/lib/Utils/validate-connection.d.ts +0 -11
  190. package/lib/WABinary/constants.d.ts +0 -27
  191. package/lib/WABinary/decode.d.ts +0 -6
  192. package/lib/WABinary/encode.d.ts +0 -2
  193. package/lib/WABinary/generic-utils.d.ts +0 -14
  194. package/lib/WABinary/index.d.ts +0 -5
  195. package/lib/WABinary/jid-utils.d.ts +0 -31
  196. package/lib/WABinary/types.d.ts +0 -18
  197. package/lib/WAM/BinaryInfo.d.ts +0 -8
  198. package/lib/WAM/constants.d.ts +0 -38
  199. package/lib/WAM/encode.d.ts +0 -2
  200. package/lib/WAM/index.d.ts +0 -3
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  202. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  203. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  204. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  205. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  206. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  207. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  208. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  209. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  210. package/lib/WAUSync/Protocols/index.js +0 -20
  211. package/lib/WAUSync/USyncQuery.d.ts +0 -26
  212. package/lib/WAUSync/USyncQuery.js +0 -79
  213. package/lib/WAUSync/USyncUser.d.ts +0 -10
  214. package/lib/WAUSync/USyncUser.js +0 -22
  215. package/lib/WAUSync/index.d.ts +0 -3
  216. package/lib/WAUSync/index.js +0 -19
  217. /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
  218. /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
  219. /package/{lib → src}/Store/index.js +0 -0
  220. /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
  221. /package/{lib → src}/Types/Auth.js +0 -0
  222. /package/{lib → src}/Types/Call.js +0 -0
  223. /package/{lib → src}/Types/Chat.js +0 -0
  224. /package/{lib → src}/Types/Contact.js +0 -0
  225. /package/{lib → src}/Types/Events.js +0 -0
  226. /package/{lib → src}/Types/GroupMetadata.js +0 -0
  227. /package/{lib → src}/Types/Label.js +0 -0
  228. /package/{lib → src}/Types/LabelAssociation.js +0 -0
  229. /package/{lib → src}/Types/Message.js +0 -0
  230. /package/{lib → src}/Types/Newsletter.js +0 -0
  231. /package/{lib → src}/Types/Product.js +0 -0
  232. /package/{lib → src}/Types/Signal.js +0 -0
  233. /package/{lib → src}/Types/Socket.js +0 -0
  234. /package/{lib → src}/Types/State.js +0 -0
  235. /package/{lib → src}/Types/index.js +0 -0
  236. /package/{lib → src}/Utils/index.js +0 -0
  237. /package/{lib → src}/Utils/logger.js +0 -0
  238. /package/{lib → src}/Utils/lt-hash.js +0 -0
  239. /package/{lib → src}/Utils/noise-handler.js +0 -0
  240. /package/{lib → src}/WABinary/constants.js +0 -0
  241. /package/{lib → src}/WABinary/decode.js +0 -0
  242. /package/{lib → src}/WABinary/generic-utils.js +0 -0
  243. /package/{lib → src}/WABinary/index.js +0 -0
  244. /package/{lib → src}/WABinary/jid-utils.js +0 -0
  245. /package/{lib → src}/WABinary/types.js +0 -0
  246. /package/{lib → src}/WAM/BinaryInfo.js +0 -0
  247. /package/{lib → src}/WAM/constants.js +0 -0
  248. /package/{lib → src}/WAM/encode.js +0 -0
  249. /package/{lib → src}/WAM/index.js +0 -0
  250. /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 WAUSync_1 = require("../WAUSync");
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, usync_1.makeUSyncSocket)(config);
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 = async (keyId) => {
29
- const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
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 = async (force = false) => {
39
+ });
40
+ const fetchPrivacySettings = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (force = false) {
33
41
  if (!privacySettings || force) {
34
- const { content } = await query({
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 = async (name, value) => {
51
- await query({
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 = async (value) => {
71
- await privacyQuery('last', value);
72
- };
73
- const updateOnlinePrivacy = async (value) => {
74
- await privacyQuery('online', value);
75
- };
76
- const updateProfilePicturePrivacy = async (value) => {
77
- await privacyQuery('profile', value);
78
- };
79
- const updateStatusPrivacy = async (value) => {
80
- await privacyQuery('status', value);
81
- };
82
- const updateReadReceiptsPrivacy = async (value) => {
83
- await privacyQuery('readreceipts', value);
84
- };
85
- const updateGroupsAddPrivacy = async (value) => {
86
- await privacyQuery('groupadd', value);
87
- };
88
- const updateDefaultDisappearingMode = async (duration) => {
89
- await query({
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 = async (userNodes, queryNode) => {
106
- const result = await query({
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 fetchUserLid = async (jid) => {
144
- const [result] = await interactiveQuery([
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: { jid }
148
- }
149
- ], {
150
- tag: 'lid',
151
- attrs: {}
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 lid = (0, WABinary_1.getBinaryNodeChild)(result, 'lid');
155
- return lid.attrs.val;
156
- }
157
- };
158
- const onWhatsApp = async (...jids) => {
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 = async (jid, content) => {
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 } = await (0, Utils_1.generateProfilePicture)(content);
202
- await query({
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 = async (jid) => {
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
- await query({
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 = async (status) => {
240
- await query({
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 = async (name) => {
257
- await chatModify({ pushNameSetting: name }, '');
258
- };
259
- const fetchBlocklist = async () => {
260
- const result = await query({
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 = async (jid, action) => {
273
- await query({
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 = async (jid) => {
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 = await query({
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 = async (type, fromTimestamp) => {
325
+ });
326
+ const cleanDirtyBits = (type, fromTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
337
327
  logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
338
- await sendNode({
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(async (collections, isInitialSync) => {
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
- await authState.keys.transaction(async () => {
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 = await authState.keys.get('app-state-sync-version', [name]);
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 = await query({
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 = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
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 } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
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
- await authState.keys.set({ 'app-state-sync-version': {
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 } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
436
- await authState.keys.set({ 'app-state-sync-version': {
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
- await authState.keys.set({ 'app-state-sync-version': {
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 sendPresenceUpdate = async (type, toJid) => {
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
- await sendNode({
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
- await sendNode({
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 = async (patchCreate) => {
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
- await processingMutex.mutex(async () => {
576
- await authState.keys.transaction(async () => {
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
- await resyncAppState([name], false);
579
- const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
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 = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
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
- await query(node);
615
- await authState.keys.set({ 'app-state-sync-version': {
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 } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger);
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 = async () => {
634
+ const fetchProps = () => __awaiter(void 0, void 0, void 0, function* () {
630
635
  var _a, _b;
631
- const resultNode = await query({
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 = async () => {
725
- await Promise.all([
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(async (msg, type) => {
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: { ...authState.creds.me, name: msg.pushName } });
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
- await Promise.all([
755
- (async () => {
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
- await doAppStateSync();
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
- await doAppStateSync();
779
+ yield doAppStateSync();
775
780
  pendingAppStateSync = false;
776
781
  }
777
- async function doAppStateSync() {
778
- if (!authState.creds.accountSyncCounter) {
779
- logger.info('doing initial app state sync');
780
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
781
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
782
- ev.emit('creds.update', { accountSyncCounter });
783
- if (needToFlushWithAppStateSync) {
784
- logger.debug('flushing with app state sync');
785
- ev.flush();
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', async (node) => {
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
- await cleanDirtyBits('account_sync', lastAccountSyncTimestamp);
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;