@neelegirl/baileys 1.5.3 → 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 (224) hide show
  1. package/README.md +16 -195
  2. package/index.js +38 -0
  3. package/package.json +16 -96
  4. package/LICENSE +0 -21
  5. package/WAProto/WAProto.proto +0 -5308
  6. package/WAProto/index.d.ts +0 -61295
  7. package/WAProto/index.js +0 -189754
  8. package/lib/Defaults/baileys-version.json +0 -3
  9. package/lib/Defaults/index.d.ts +0 -78
  10. package/lib/Defaults/index.js +0 -149
  11. package/lib/Defaults/phonenumber-mcc.json +0 -223
  12. package/lib/Signal/WASignalGroup/GroupProtocol.js +0 -1909
  13. package/lib/Signal/WASignalGroup/ciphertext-message.d.ts +0 -9
  14. package/lib/Signal/WASignalGroup/ciphertext-message.js +0 -19
  15. package/lib/Signal/WASignalGroup/ciphertext_message.js +0 -16
  16. package/lib/Signal/WASignalGroup/generate-proto.sh +0 -1
  17. package/lib/Signal/WASignalGroup/group-session-builder.d.ts +0 -17
  18. package/lib/Signal/WASignalGroup/group-session-builder.js +0 -72
  19. package/lib/Signal/WASignalGroup/group.proto +0 -42
  20. package/lib/Signal/WASignalGroup/group_cipher.d.ts +0 -19
  21. package/lib/Signal/WASignalGroup/group_cipher.js +0 -111
  22. package/lib/Signal/WASignalGroup/group_session_builder.js +0 -46
  23. package/lib/Signal/WASignalGroup/index.d.ts +0 -11
  24. package/lib/Signal/WASignalGroup/index.js +0 -61
  25. package/lib/Signal/WASignalGroup/keyhelper.d.ts +0 -16
  26. package/lib/Signal/WASignalGroup/keyhelper.js +0 -66
  27. package/lib/Signal/WASignalGroup/protobufs.js +0 -3
  28. package/lib/Signal/WASignalGroup/queue_job.js +0 -69
  29. package/lib/Signal/WASignalGroup/readme.md +0 -6
  30. package/lib/Signal/WASignalGroup/sender-chain-key.d.ts +0 -14
  31. package/lib/Signal/WASignalGroup/sender-chain-key.js +0 -47
  32. package/lib/Signal/WASignalGroup/sender-key-distribution-message.d.ts +0 -17
  33. package/lib/Signal/WASignalGroup/sender-key-distribution-message.js +0 -71
  34. package/lib/Signal/WASignalGroup/sender-key-message.d.ts +0 -19
  35. package/lib/Signal/WASignalGroup/sender-key-message.js +0 -73
  36. package/lib/Signal/WASignalGroup/sender-key-name.d.ts +0 -19
  37. package/lib/Signal/WASignalGroup/sender-key-name.js +0 -59
  38. package/lib/Signal/WASignalGroup/sender-key-record.d.ts +0 -32
  39. package/lib/Signal/WASignalGroup/sender-key-record.js +0 -58
  40. package/lib/Signal/WASignalGroup/sender-key-state.d.ts +0 -44
  41. package/lib/Signal/WASignalGroup/sender-key-state.js +0 -147
  42. package/lib/Signal/WASignalGroup/sender-message-key.d.ts +0 -11
  43. package/lib/Signal/WASignalGroup/sender-message-key.js +0 -33
  44. package/lib/Signal/WASignalGroup/sender_chain_key.js +0 -50
  45. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +0 -78
  46. package/lib/Signal/WASignalGroup/sender_key_message.js +0 -92
  47. package/lib/Signal/WASignalGroup/sender_key_name.js +0 -70
  48. package/lib/Signal/WASignalGroup/sender_key_record.js +0 -56
  49. package/lib/Signal/WASignalGroup/sender_key_state.js +0 -129
  50. package/lib/Signal/WASignalGroup/sender_message_key.js +0 -39
  51. package/lib/Signal/libsignal.d.ts +0 -8
  52. package/lib/Signal/libsignal.js +0 -391
  53. package/lib/Signal/lid-mapping.d.ts +0 -28
  54. package/lib/Signal/lid-mapping.js +0 -184
  55. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  56. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  57. package/lib/Socket/Client/index.d.ts +0 -2
  58. package/lib/Socket/Client/index.js +0 -22
  59. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  60. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  61. package/lib/Socket/Client/types.d.ts +0 -16
  62. package/lib/Socket/Client/types.js +0 -18
  63. package/lib/Socket/Client/websocket.d.ts +0 -13
  64. package/lib/Socket/Client/websocket.js +0 -62
  65. package/lib/Socket/business.d.ts +0 -187
  66. package/lib/Socket/business.js +0 -415
  67. package/lib/Socket/chats.d.ts +0 -97
  68. package/lib/Socket/chats.js +0 -1118
  69. package/lib/Socket/communities.d.ts +0 -223
  70. package/lib/Socket/communities.js +0 -433
  71. package/lib/Socket/groups.d.ts +0 -129
  72. package/lib/Socket/groups.js +0 -360
  73. package/lib/Socket/index.d.ts +0 -191
  74. package/lib/Socket/index.js +0 -24
  75. package/lib/Socket/messages-recv.d.ts +0 -174
  76. package/lib/Socket/messages-recv.js +0 -1506
  77. package/lib/Socket/messages-send.d.ts +0 -165
  78. package/lib/Socket/messages-send.js +0 -1785
  79. package/lib/Socket/mex.d.ts +0 -2
  80. package/lib/Socket/mex.js +0 -47
  81. package/lib/Socket/newsletter.d.ts +0 -145
  82. package/lib/Socket/newsletter.js +0 -295
  83. package/lib/Socket/socket.d.ts +0 -45
  84. package/lib/Socket/socket.js +0 -934
  85. package/lib/Socket/usync.d.ts +0 -37
  86. package/lib/Socket/usync.js +0 -83
  87. package/lib/Store/index.d.ts +0 -4
  88. package/lib/Store/index.js +0 -24
  89. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  90. package/lib/Store/make-cache-manager-store.js +0 -90
  91. package/lib/Store/make-in-memory-store.d.ts +0 -123
  92. package/lib/Store/make-in-memory-store.js +0 -429
  93. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  94. package/lib/Store/make-ordered-dictionary.js +0 -86
  95. package/lib/Store/object-repository.d.ts +0 -10
  96. package/lib/Store/object-repository.js +0 -31
  97. package/lib/Types/Auth.d.ts +0 -121
  98. package/lib/Types/Auth.js +0 -3
  99. package/lib/Types/Bussines.js +0 -3
  100. package/lib/Types/Bussiness.d.ts +0 -28
  101. package/lib/Types/Call.d.ts +0 -14
  102. package/lib/Types/Call.js +0 -3
  103. package/lib/Types/Chat.d.ts +0 -143
  104. package/lib/Types/Chat.js +0 -9
  105. package/lib/Types/Contact.d.ts +0 -23
  106. package/lib/Types/Contact.js +0 -3
  107. package/lib/Types/Events.d.ts +0 -226
  108. package/lib/Types/Events.js +0 -3
  109. package/lib/Types/GroupMetadata.d.ts +0 -66
  110. package/lib/Types/GroupMetadata.js +0 -3
  111. package/lib/Types/Label.d.ts +0 -48
  112. package/lib/Types/Label.js +0 -31
  113. package/lib/Types/LabelAssociation.d.ts +0 -35
  114. package/lib/Types/LabelAssociation.js +0 -13
  115. package/lib/Types/Message.d.ts +0 -484
  116. package/lib/Types/Message.js +0 -19
  117. package/lib/Types/MexUpdates.d.ts +0 -9
  118. package/lib/Types/MexUpdates.js +0 -18
  119. package/lib/Types/Newsletter.d.ts +0 -109
  120. package/lib/Types/Newsletter.js +0 -40
  121. package/lib/Types/Product.d.ts +0 -92
  122. package/lib/Types/Product.js +0 -3
  123. package/lib/Types/Signal.d.ts +0 -98
  124. package/lib/Types/Signal.js +0 -3
  125. package/lib/Types/Socket.d.ts +0 -141
  126. package/lib/Types/Socket.js +0 -3
  127. package/lib/Types/State.d.ts +0 -41
  128. package/lib/Types/State.js +0 -14
  129. package/lib/Types/USync.d.ts +0 -26
  130. package/lib/Types/USync.js +0 -3
  131. package/lib/Types/index.d.ts +0 -80
  132. package/lib/Types/index.js +0 -50
  133. package/lib/Utils/auth-utils.d.ts +0 -21
  134. package/lib/Utils/auth-utils.js +0 -528
  135. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  136. package/lib/Utils/baileys-event-stream.js +0 -70
  137. package/lib/Utils/business.d.ts +0 -29
  138. package/lib/Utils/business.js +0 -255
  139. package/lib/Utils/chat-utils.d.ts +0 -82
  140. package/lib/Utils/chat-utils.js +0 -809
  141. package/lib/Utils/crypto.d.ts +0 -56
  142. package/lib/Utils/crypto.js +0 -189
  143. package/lib/Utils/decode-wa-message.d.ts +0 -53
  144. package/lib/Utils/decode-wa-message.js +0 -323
  145. package/lib/Utils/event-buffer.d.ts +0 -39
  146. package/lib/Utils/event-buffer.js +0 -595
  147. package/lib/Utils/generics.d.ts +0 -131
  148. package/lib/Utils/generics.js +0 -630
  149. package/lib/Utils/history.d.ts +0 -23
  150. package/lib/Utils/history.js +0 -104
  151. package/lib/Utils/index.d.ts +0 -20
  152. package/lib/Utils/index.js +0 -40
  153. package/lib/Utils/link-preview.d.ts +0 -23
  154. package/lib/Utils/link-preview.js +0 -120
  155. package/lib/Utils/logger.d.ts +0 -13
  156. package/lib/Utils/logger.js +0 -7
  157. package/lib/Utils/lt-hash.d.ts +0 -14
  158. package/lib/Utils/lt-hash.js +0 -58
  159. package/lib/Utils/make-mutex.d.ts +0 -9
  160. package/lib/Utils/make-mutex.js +0 -49
  161. package/lib/Utils/message-retry-manager.d.ts +0 -88
  162. package/lib/Utils/message-retry-manager.js +0 -160
  163. package/lib/Utils/messages-media.d.ts +0 -135
  164. package/lib/Utils/messages-media.js +0 -869
  165. package/lib/Utils/messages.d.ts +0 -105
  166. package/lib/Utils/messages.js +0 -1745
  167. package/lib/Utils/noise-handler.d.ts +0 -21
  168. package/lib/Utils/noise-handler.js +0 -165
  169. package/lib/Utils/process-message.d.ts +0 -49
  170. package/lib/Utils/process-message.js +0 -427
  171. package/lib/Utils/signal.d.ts +0 -42
  172. package/lib/Utils/signal.js +0 -166
  173. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  174. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  175. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -18
  176. package/lib/Utils/use-multi-file-auth-state.js +0 -238
  177. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  178. package/lib/Utils/use-single-file-auth-state.js +0 -80
  179. package/lib/Utils/validate-connection.d.ts +0 -13
  180. package/lib/Utils/validate-connection.js +0 -220
  181. package/lib/WABinary/constants.d.ts +0 -30
  182. package/lib/WABinary/constants.js +0 -1316
  183. package/lib/WABinary/decode.d.ts +0 -9
  184. package/lib/WABinary/decode.js +0 -288
  185. package/lib/WABinary/encode.d.ts +0 -3
  186. package/lib/WABinary/encode.js +0 -265
  187. package/lib/WABinary/generic-utils.d.ts +0 -28
  188. package/lib/WABinary/generic-utils.js +0 -142
  189. package/lib/WABinary/index.d.ts +0 -5
  190. package/lib/WABinary/index.js +0 -25
  191. package/lib/WABinary/jid-utils.d.ts +0 -58
  192. package/lib/WABinary/jid-utils.js +0 -104
  193. package/lib/WABinary/types.d.ts +0 -22
  194. package/lib/WABinary/types.js +0 -3
  195. package/lib/WAM/BinaryInfo.d.ts +0 -16
  196. package/lib/WAM/BinaryInfo.js +0 -17
  197. package/lib/WAM/constants.d.ts +0 -47
  198. package/lib/WAM/constants.js +0 -15371
  199. package/lib/WAM/encode.d.ts +0 -3
  200. package/lib/WAM/encode.js +0 -164
  201. package/lib/WAM/index.d.ts +0 -3
  202. package/lib/WAM/index.js +0 -23
  203. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  204. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
  205. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  206. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -36
  207. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  208. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -62
  209. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  210. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -35
  211. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  212. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -38
  213. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  214. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -46
  215. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  216. package/lib/WAUSync/Protocols/index.js +0 -26
  217. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  218. package/lib/WAUSync/USyncQuery.js +0 -92
  219. package/lib/WAUSync/USyncUser.d.ts +0 -12
  220. package/lib/WAUSync/USyncUser.js +0 -30
  221. package/lib/WAUSync/index.d.ts +0 -3
  222. package/lib/WAUSync/index.js +0 -23
  223. package/lib/index.d.ts +0 -13
  224. package/lib/index.js +0 -33
@@ -1,1118 +0,0 @@
1
- "use strict"
2
-
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
- Object.defineProperty(exports, "__esModule", { value: true })
8
-
9
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"))
10
- const boom_1 = require("@hapi/boom")
11
- const WAProto_1 = require("../../WAProto")
12
- const Defaults_1 = require("../Defaults")
13
- const Types_1 = require("../Types")
14
- const Utils_1 = require("../Utils")
15
- const make_mutex_1 = require("../Utils/make-mutex")
16
- const WABinary_1 = require("../WABinary")
17
- const WAUSync_1 = require("../WAUSync")
18
- const socket_1 = require("./socket")
19
- const MAX_SYNC_ATTEMPTS = 2
20
-
21
- const makeChatsSocket = (config) => {
22
- const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config
23
- const baron = socket_1.makeSocket(config)
24
- const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, groupFetchAllParticipating } = baron
25
-
26
- let privacySettings
27
- let syncState = Types_1.SyncState.Connecting
28
-
29
- /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
30
- const processingMutex = make_mutex_1.makeMutex()
31
-
32
- // Timeout for AwaitingInitialSync State
33
- let awaitingSyncTimeout
34
-
35
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
36
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
37
- useClones: false
38
- })
39
-
40
- if (!config.placeholderResendCache) {
41
- config.placeholderResendCache = placeholderResendCache
42
- }
43
-
44
- /** helper function to fetch the given app state sync key */
45
- const getAppStateSyncKey = async (keyId) => {
46
- const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId])
47
- return key
48
- }
49
-
50
- const fetchPrivacySettings = async (force = false) => {
51
- if (!privacySettings || force) {
52
- const { content } = await query({
53
- tag: 'iq',
54
- attrs: {
55
- xmlns: 'privacy',
56
- to: WABinary_1.S_WHATSAPP_NET,
57
- type: 'get'
58
- },
59
- content: [
60
- { tag: 'privacy', attrs: {} }
61
- ]
62
- })
63
- privacySettings = WABinary_1.reduceBinaryNodeToDictionary(content?.[0], 'category')
64
- }
65
- return privacySettings
66
- }
67
-
68
- /** helper function to run a privacy IQ query */
69
- const privacyQuery = async (name, value) => {
70
- await query({
71
- tag: 'iq',
72
- attrs: {
73
- xmlns: 'privacy',
74
- to: WABinary_1.S_WHATSAPP_NET,
75
- type: 'set'
76
- },
77
- content: [{
78
- tag: 'privacy',
79
- attrs: {},
80
- content: [
81
- {
82
- tag: 'category',
83
- attrs: { name, value }
84
- }
85
- ]
86
- }]
87
- })
88
- }
89
-
90
- const updateMessagesPrivacy = async (value) => {
91
- await privacyQuery('messages', value)
92
- }
93
-
94
- const updateCallPrivacy = async (value) => {
95
- await privacyQuery('calladd', value)
96
- }
97
-
98
- const updateLastSeenPrivacy = async (value) => {
99
- await privacyQuery('last', value)
100
- }
101
-
102
- const updateOnlinePrivacy = async (value) => {
103
- await privacyQuery('online', value)
104
- }
105
-
106
- const updateProfilePicturePrivacy = async (value) => {
107
- await privacyQuery('profile', value)
108
- }
109
-
110
- const updateStatusPrivacy = async (value) => {
111
- await privacyQuery('status', value)
112
- }
113
-
114
- const updateReadReceiptsPrivacy = async (value) => {
115
- await privacyQuery('readreceipts', value)
116
- }
117
-
118
- const updateGroupsAddPrivacy = async (value) => {
119
- await privacyQuery('groupadd', value)
120
- }
121
-
122
- const updateDefaultDisappearingMode = async (duration) => {
123
- await query({
124
- tag: 'iq',
125
- attrs: {
126
- xmlns: 'disappearing_mode',
127
- to: WABinary_1.S_WHATSAPP_NET,
128
- type: 'set'
129
- },
130
- content: [{
131
- tag: 'disappearing_mode',
132
- attrs: {
133
- duration: duration.toString()
134
- }
135
- }]
136
- })
137
- }
138
-
139
- const getBotListV2 = async () => {
140
- const resp = await query({
141
- tag: 'iq',
142
- attrs: {
143
- xmlns: 'bot',
144
- to: WABinary_1.S_WHATSAPP_NET,
145
- type: 'get'
146
- },
147
- content: [{
148
- tag: 'bot',
149
- attrs: {
150
- v: '2'
151
- }
152
- }]
153
- })
154
-
155
- const botNode = WABinary_1.getBinaryNodeChild(resp, 'bot')
156
-
157
- const botList = []
158
-
159
- for(const section of WABinary_1.getBinaryNodeChildren(botNode, 'section')) {
160
- if(section.attrs.type === 'all') {
161
- for(const bot of WABinary_1.getBinaryNodeChildren(section, 'bot')) {
162
- botList.push({
163
- jid: bot.attrs.jid,
164
- personaId: bot.attrs['persona_id']
165
- })
166
- }
167
- }
168
- }
169
- return botList
170
- }
171
-
172
- const getLidUser = async (jid) => {
173
- if (!jid) {
174
- throw new boom_1.Boom('Please input a jid user')
175
- }
176
-
177
- if (!WABinary_1.isJidUser(jid)) {
178
- throw new boom_1.Boom('Invalid JID: Not a user JID!')
179
- }
180
-
181
- const targetJid = WABinary_1.jidNormalizedUser(jid)
182
-
183
- const usyncQuery = new WAUSync_1.USyncQuery()
184
- usyncQuery.protocols.push({
185
- name: 'lid',
186
- getQueryElement: () => ({
187
- tag: 'lid',
188
- attrs: {},
189
- content: undefined
190
- }),
191
- getUserElement: () => null,
192
- parser: (node) => node.attrs.val
193
- })
194
- usyncQuery.users.push({
195
- id: targetJid
196
- })
197
-
198
- const result = await baron.executeUSyncQuery(usyncQuery)
199
-
200
- if (result) {
201
- return result.list
202
- }
203
- }
204
-
205
- const fetchStatus = async (...jids) => {
206
- const usyncQuery = new WAUSync_1.USyncQuery().withStatusProtocol()
207
-
208
- for (const jid of jids) {
209
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid))
210
- }
211
-
212
- const result = await baron.executeUSyncQuery(usyncQuery)
213
-
214
- if (result) {
215
- return result.list
216
- }
217
- }
218
- const fetchDisappearingDuration = async (...jids) => {
219
- const usyncQuery = new WAUSync_1.USyncQuery().withDisappearingModeProtocol()
220
-
221
- for (const jid of jids) {
222
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid))
223
- }
224
-
225
- const result = await baron.executeUSyncQuery(usyncQuery)
226
- if (result) {
227
- return result.list
228
- }
229
- }
230
-
231
- /** update the profile picture for yourself or a group */
232
- const updateProfilePicture = async (jid, content) => {
233
- let targetJid
234
-
235
- if (!jid) {
236
- 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')
237
- }
238
-
239
- if (WABinary_1.jidNormalizedUser(jid) !== WABinary_1.jidNormalizedUser(authState.creds.me.id)) {
240
- targetJid = WABinary_1.jidNormalizedUser(jid) // in case it is someone other than us
241
- }
242
-
243
- const { img } = await Utils_1.generateProfilePicture(content)
244
-
245
- await query({
246
- tag: 'iq',
247
- attrs: {
248
- target: targetJid,
249
- to: WABinary_1.S_WHATSAPP_NET,
250
- type: 'set',
251
- xmlns: 'w:profile:picture'
252
- },
253
- content: [
254
- {
255
- tag: 'picture',
256
- attrs: { type: 'image' },
257
- content: img
258
- }
259
- ]
260
- })
261
- }
262
-
263
- /** remove the profile picture for yourself or a group */
264
- const removeProfilePicture = async (jid) => {
265
- let targetJid
266
-
267
- if (!jid) {
268
- 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')
269
- }
270
-
271
- if (WABinary_1.jidNormalizedUser(jid) !== WABinary_1.jidNormalizedUser(authState.creds.me.id)) {
272
- targetJid = WABinary_1.jidNormalizedUser(jid) // in case it is someone other than us
273
- }
274
-
275
- await query({
276
- tag: 'iq',
277
- attrs: {
278
- target: targetJid,
279
- to: WABinary_1.S_WHATSAPP_NET,
280
- type: 'set',
281
- xmlns: 'w:profile:picture'
282
- }
283
- })
284
- }
285
-
286
- /** update the profile status for yourself */
287
- const updateProfileStatus = async (status) => {
288
- await query({
289
- tag: 'iq',
290
- attrs: {
291
- to: WABinary_1.S_WHATSAPP_NET,
292
- type: 'set',
293
- xmlns: 'status'
294
- },
295
- content: [
296
- {
297
- tag: 'status',
298
- attrs: {},
299
- content: Buffer.from(status, 'utf-8')
300
- }
301
- ]
302
- })
303
- }
304
-
305
- const updateProfileName = async (name) => {
306
- await chatModify({ pushNameSetting: name }, '')
307
- }
308
-
309
- const fetchBlocklist = async () => {
310
- const result = await query({
311
- tag: 'iq',
312
- attrs: {
313
- xmlns: 'blocklist',
314
- to: WABinary_1.S_WHATSAPP_NET,
315
- type: 'get'
316
- }
317
- })
318
-
319
- const listNode = WABinary_1.getBinaryNodeChild(result, 'list')
320
-
321
- return WABinary_1.getBinaryNodeChildren(listNode, 'item').map((n) => n.attrs.jid)
322
- }
323
-
324
- const updateBlockStatus = async (jid, action) => {
325
- await query({
326
- tag: 'iq',
327
- attrs: {
328
- xmlns: 'blocklist',
329
- to: WABinary_1.S_WHATSAPP_NET,
330
- type: 'set'
331
- },
332
- content: [
333
- {
334
- tag: 'item',
335
- attrs: {
336
- action,
337
- jid
338
- }
339
- }
340
- ]
341
- })
342
- }
343
-
344
- const getBusinessProfile = async (jid) => {
345
- const results = await query({
346
- tag: 'iq',
347
- attrs: {
348
- to: 's.whatsapp.net',
349
- xmlns: 'w:biz',
350
- type: 'get'
351
- },
352
- content: [{
353
- tag: 'business_profile',
354
- attrs: { v: '244' },
355
- content: [{
356
- tag: 'profile',
357
- attrs: { jid }
358
- }]
359
- }]
360
- })
361
-
362
- const profileNode = WABinary_1.getBinaryNodeChild(results, 'business_profile')
363
-
364
- const profiles = WABinary_1.getBinaryNodeChild(profileNode, 'profile')
365
-
366
- if (profiles) {
367
- const address = WABinary_1.getBinaryNodeChild(profiles, 'address')
368
- const description = WABinary_1.getBinaryNodeChild(profiles, 'description')
369
- const website = WABinary_1.getBinaryNodeChild(profiles, 'website')
370
- const email = WABinary_1.getBinaryNodeChild(profiles, 'email')
371
- const category = WABinary_1.getBinaryNodeChild(WABinary_1.getBinaryNodeChild(profiles, 'categories'), 'category')
372
- const businessHours = WABinary_1.getBinaryNodeChild(profiles, 'business_hours')
373
- const businessHoursConfig = businessHours
374
- ? WABinary_1.getBinaryNodeChildren(businessHours, 'business_hours_config')
375
- : undefined
376
- const websiteStr = website?.content?.toString()
377
-
378
- return {
379
- wid: profiles?.attrs?.jid,
380
- address: address?.content?.toString(),
381
- description: description?.content?.toString() || '',
382
- website: websiteStr ? [websiteStr] : [],
383
- email: email?.content?.toString(),
384
- category: category?.content?.toString(),
385
- 'business_hours': {
386
- timezone: businessHours?.attrs?.timezone,
387
- 'business_config': businessHoursConfig?.map(({ attrs }) => attrs)
388
- }
389
- }
390
- }
391
- }
392
-
393
- const cleanDirtyBits = async (type, fromTimestamp) => {
394
- logger.info({ fromTimestamp }, 'clean dirty bits ' + type)
395
- await sendNode({
396
- tag: 'iq',
397
- attrs: {
398
- to: WABinary_1.S_WHATSAPP_NET,
399
- type: 'set',
400
- xmlns: 'urn:xmpp:whatsapp:dirty',
401
- id: generateMessageTag(),
402
- },
403
- content: [
404
- {
405
- tag: 'clean',
406
- attrs: {
407
- type,
408
- ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
409
- }
410
- }
411
- ]
412
- })
413
- }
414
-
415
- const newAppStateChunkHandler = (isInitialSync) => {
416
- return {
417
- onMutation(mutation) {
418
- Utils_1.processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger)
419
- }
420
- }
421
- }
422
-
423
- const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
424
- // we use this to determine which events to fire
425
- // otherwise when we resync from scratch -- all notifications will fire
426
- const initialVersionMap = {}
427
- const globalMutationMap = {}
428
- await authState.keys.transaction(async () => {
429
- const collectionsToHandle = new Set(collections)
430
- // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
431
- const attemptsMap = {}
432
- // keep executing till all collections are done
433
- // sometimes a single patch request will not return all the patches (God knows why)
434
- // so we fetch till they're all done (this is determined by the "has_more_patches" flag)
435
- while (collectionsToHandle.size) {
436
- const states = {}
437
- const nodes = []
438
-
439
- for (const name of collectionsToHandle) {
440
- const result = await authState.keys.get('app-state-sync-version', [name])
441
- let state = result[name]
442
- if (state) {
443
- if (typeof initialVersionMap[name] === 'undefined') {
444
- initialVersionMap[name] = state.version
445
- }
446
- }
447
- else {
448
- state = Utils_1.newLTHashState()
449
- }
450
- states[name] = state
451
- logger.info(`resyncing ${name} from v${state.version}`)
452
- nodes.push({
453
- tag: 'collection',
454
- attrs: {
455
- name,
456
- version: state.version.toString(),
457
- // return snapshot if being synced from scratch
458
- 'return_snapshot': (!state.version).toString()
459
- }
460
- })
461
- }
462
-
463
- const result = await query({
464
- tag: 'iq',
465
- attrs: {
466
- to: WABinary_1.S_WHATSAPP_NET,
467
- xmlns: 'w:sync:app:state',
468
- type: 'set'
469
- },
470
- content: [
471
- {
472
- tag: 'sync',
473
- attrs: {},
474
- content: nodes
475
- }
476
- ]
477
- })
478
-
479
- // extract from binary node
480
- const decoded = await Utils_1.extractSyncdPatches(result, config?.options)
481
-
482
- for (const key in decoded) {
483
- const name = key
484
- const { patches, hasMorePatches, snapshot } = decoded[name]
485
- try {
486
- if (snapshot) {
487
- const { state: newState, mutationMap } = await Utils_1.decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot)
488
- states[name] = newState
489
- Object.assign(globalMutationMap, mutationMap)
490
- logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`)
491
- await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
492
- }
493
-
494
- // only process if there are syncd patches
495
- if (patches.length) {
496
- const { state: newState, mutationMap } = await Utils_1.decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch)
497
- await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
498
- logger.info(`synced ${name} to v${newState.version}`)
499
- initialVersionMap[name] = newState.version
500
- Object.assign(globalMutationMap, mutationMap)
501
- }
502
-
503
- if (hasMorePatches) {
504
- logger.info(`${name} has more patches...`)
505
- }
506
- else { // collection is done with sync
507
- collectionsToHandle.delete(name)
508
- }
509
- }
510
- catch (error) {
511
- // if retry attempts overshoot
512
- // or key not found
513
- const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
514
- || error.output?.statusCode === 404
515
- || error.name === 'TypeError'
516
- logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`)
517
- await authState.keys.set({ 'app-state-sync-version': { [name]: null } })
518
- // increment number of retries
519
- attemptsMap[name] = (attemptsMap[name] || 0) + 1
520
-
521
- if (isIrrecoverableError) {
522
- // stop retrying
523
- collectionsToHandle.delete(name)
524
- }
525
- }
526
- }
527
- }
528
- }, authState?.creds?.me?.id || 'resync-app-state')
529
-
530
- const { onMutation } = newAppStateChunkHandler(isInitialSync)
531
-
532
- for (const key in globalMutationMap) {
533
- onMutation(globalMutationMap[key])
534
- }
535
- })
536
-
537
- // source: https://github.com/WhiskeySockets/Baileys/pull/1677
538
- const createCallLink = async (type, event, timeoutMs) => {
539
- type = type?.toLowerCase()
540
-
541
- if (!type || (type !== 'audio' && type !== 'video')) {
542
- throw new Error('Make sure the type is audio or video!')
543
- }
544
-
545
- const result = await query({
546
- tag: 'call',
547
- attrs: {
548
- id: generateMessageTag(),
549
- to: '@call'
550
- },
551
- content: [{
552
- tag: 'link_create',
553
- attrs: {
554
- media: type
555
- },
556
- content: event ? [{
557
- tag: 'event',
558
- attrs: {
559
- start_time: String(event)
560
- }
561
- }] : undefined
562
- }]
563
- }, timeoutMs)
564
-
565
- const child = WABinary_1.getBinaryNodeChild(result, 'link_create')
566
- const token = child?.attrs?.token
567
-
568
- return type === 'audio' ? Defaults_1.CALL_AUDIO_PREFIX + token : Defaults_1.CALL_VIDEO_PREFIX + token
569
- }
570
-
571
- const sendPresenceUpdate = async (type, toJid) => {
572
- const me = authState.creds.me
573
-
574
- if (type === 'available' || type === 'unavailable') {
575
- if (!me.name) {
576
- logger.warn('no name present, ignoring presence update request...')
577
- return
578
- }
579
-
580
- ev.emit('connection.update', { isOnline: type === 'available' })
581
- await sendNode({
582
- tag: 'presence',
583
- attrs: {
584
- name: me.name.replace(/@/g, ''),
585
- type
586
- }
587
- })
588
- }
589
- else {
590
- const { server } = WABinary_1.jidDecode(toJid)
591
-
592
- await sendNode({
593
- tag: 'chatstate',
594
- attrs: {
595
- from: server === 'lid' ? me.lid : me.id,
596
- to: toJid
597
- },
598
- content: [
599
- {
600
- tag: type === 'recording' ? 'composing' : type,
601
- attrs: type === 'recording' ? { media: 'audio' } : {}
602
- }
603
- ]
604
- })
605
- }
606
- }
607
-
608
- /**
609
- * @param toJid the jid to subscribe to
610
- * @param tcToken token for subscription, use if present
611
- */
612
- const presenceSubscribe = (toJid, tcToken) => (sendNode({
613
- tag: 'presence',
614
- attrs: {
615
- to: toJid,
616
- id: generateMessageTag(),
617
- type: 'subscribe'
618
- },
619
- content: tcToken
620
- ? [
621
- {
622
- tag: 'tctoken',
623
- attrs: {},
624
- content: tcToken
625
- }
626
- ]
627
- : undefined
628
- }))
629
-
630
- const handlePresenceUpdate = ({ tag, attrs, content }) => {
631
- let presence
632
- const jid = attrs.from
633
- const participant = attrs.participant || attrs.from
634
-
635
- if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
636
- return
637
- }
638
-
639
- if (tag === 'presence') {
640
- presence = {
641
- lastKnownPresence: attrs.type === 'unavailable' ? 'unavailable' : 'available',
642
- lastSeen: attrs.last && attrs.last !== 'deny' ? +attrs.last : undefined
643
- }
644
- }
645
-
646
- else if (Array.isArray(content)) {
647
- const [firstChild] = content
648
- let type = firstChild.tag
649
-
650
- if (type === 'paused') {
651
- type = 'available'
652
- }
653
-
654
- if (firstChild.attrs?.media === 'audio') {
655
- type = 'recording'
656
- }
657
-
658
- presence = { lastKnownPresence: type }
659
- }
660
-
661
- else {
662
- logger.error({ tag, attrs, content }, 'recv invalid presence node')
663
- }
664
-
665
- if (presence) {
666
- ev.emit('presence.update', { id: jid, presences: { [participant]: presence } })
667
- }
668
- }
669
-
670
- const appPatch = async (patchCreate) => {
671
- const name = patchCreate.type
672
- const myAppStateKeyId = authState.creds.myAppStateKeyId
673
-
674
- if (!myAppStateKeyId) {
675
- throw new boom_1.Boom('App state key not present!', { statusCode: 400 })
676
- }
677
-
678
- let initial
679
- let encodeResult
680
-
681
- await processingMutex.mutex(async () => {
682
- await authState.keys.transaction(async () => {
683
- logger.debug({ patch: patchCreate }, 'applying app patch')
684
- await resyncAppState([name], false)
685
- const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name])
686
- initial = currentSyncVersion || Utils_1.newLTHashState()
687
- encodeResult = await Utils_1.encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey)
688
- const { patch, state } = encodeResult
689
-
690
- const node = {
691
- tag: 'iq',
692
- attrs: {
693
- to: WABinary_1.S_WHATSAPP_NET,
694
- type: 'set',
695
- xmlns: 'w:sync:app:state'
696
- },
697
- content: [
698
- {
699
- tag: 'sync',
700
- attrs: {},
701
- content: [
702
- {
703
- tag: 'collection',
704
- attrs: {
705
- name,
706
- version: (state.version - 1).toString(),
707
- 'return_snapshot': 'false'
708
- },
709
- content: [
710
- {
711
- tag: 'patch',
712
- attrs: {},
713
- content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
714
- }
715
- ]
716
- }
717
- ]
718
- }
719
- ]
720
- }
721
- await query(node)
722
- await authState.keys.set({ 'app-state-sync-version': { [name]: state } })
723
- }, authState?.creds?.me?.id || 'app-patch')
724
- })
725
-
726
- if (config.emitOwnEvents) {
727
- const { onMutation } = newAppStateChunkHandler(false)
728
- const { mutationMap } = await Utils_1.decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger)
729
-
730
- for (const key in mutationMap) {
731
- onMutation(mutationMap[key])
732
- }
733
- }
734
- }
735
-
736
- /** sending non-abt props may fix QR scan fail if server expects */
737
- const fetchProps = async () => {
738
- const resultNode = await query({
739
- tag: 'iq',
740
- attrs: {
741
- to: WABinary_1.S_WHATSAPP_NET,
742
- xmlns: 'w',
743
- type: 'get',
744
- },
745
- content: [
746
- { tag: 'props', attrs: {
747
- protocol: '2',
748
- hash: authState?.creds?.lastPropHash || ''
749
- } }
750
- ]
751
- })
752
-
753
- const propsNode = WABinary_1.getBinaryNodeChild(resultNode, 'props')
754
- let props = {}
755
-
756
- if (propsNode) {
757
- if (propsNode.attrs?.hash) { // on some clients, the hash is returning as undefined
758
- authState.creds.lastPropHash = propsNode?.attrs?.hash
759
- ev.emit('creds.update', authState.creds)
760
- }
761
-
762
- props = WABinary_1.reduceBinaryNodeToDictionary(propsNode, 'prop')
763
- }
764
- logger.debug('fetched props')
765
- return props
766
- }
767
-
768
- /**
769
- * modify a chat -- mark unread, read etc.
770
- * lastMessages must be sorted in reverse chronologically
771
- * requires the last messages till the last message received required for archive & unread
772
- */
773
- const chatModify = (mod, jid) => {
774
- const patch = Utils_1.chatModificationToAppPatch(mod, jid)
775
- return appPatch(patch)
776
- }
777
-
778
- /**
779
- * Enable/Disable link preview privacy, not related to baileys link preview generation
780
- */
781
- const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
782
- return chatModify({
783
- disableLinkPreviews: {
784
- isPreviewsDisabled
785
- }
786
- }, '')
787
- }
788
-
789
- /**
790
- * Star or Unstar a message
791
- */
792
- const star = (jid, messages, star) => {
793
- return chatModify({
794
- star: {
795
- messages,
796
- star
797
- }
798
- }, jid)
799
- }
800
-
801
- /**
802
- * Add Or Edit Contact
803
- */
804
- const addOrEditContact = (jid, contact) => {
805
- return chatModify({
806
- contact
807
- }, jid)
808
- }
809
-
810
- /**
811
- * Remove Contact
812
- */
813
- const removeContact = (jid) => {
814
- return chatModify({
815
- contact: null
816
- }, jid)
817
- }
818
-
819
- /**
820
- * Adds label
821
- */
822
- const addLabel = (jid, labels) => {
823
- return chatModify({
824
- addLabel: {
825
- ...labels
826
- }
827
- }, jid)
828
- }
829
-
830
- /**
831
- * Adds label for the chats
832
- */
833
- const addChatLabel = (jid, labelId) => {
834
- return chatModify({
835
- addChatLabel: {
836
- labelId
837
- }
838
- }, jid)
839
- }
840
-
841
- /**
842
- * Removes label for the chat
843
- */
844
- const removeChatLabel = (jid, labelId) => {
845
- return chatModify({
846
- removeChatLabel: {
847
- labelId
848
- }
849
- }, jid)
850
- }
851
-
852
- /**
853
- * Adds label for the message
854
- */
855
- const addMessageLabel = (jid, messageId, labelId) => {
856
- return chatModify({
857
- addMessageLabel: {
858
- messageId,
859
- labelId
860
- }
861
- }, jid)
862
- }
863
-
864
- /**
865
- * Removes label for the message
866
- */
867
- const removeMessageLabel = (jid, messageId, labelId) => {
868
- return chatModify({
869
- removeMessageLabel: {
870
- messageId,
871
- labelId
872
- }
873
- }, jid)
874
- }
875
-
876
- /**
877
- * Removes Chats
878
- */
879
- const clearMessage = (jid, key, timeStamp) => {
880
- return chatModify({
881
- delete: true,
882
- lastMessages: [{
883
- key: key,
884
- messageTimestamp: timeStamp
885
- }],
886
- }, jid)
887
- }
888
-
889
- /**
890
- * Add or Edit Quick Reply
891
- */
892
- const addOrEditQuickReply = (quickReply) => {
893
- return chatModify({
894
- quickReply
895
- }, '')
896
- }
897
-
898
- /**
899
- * Remove Quick Reply
900
- */
901
- const removeQuickReply = (timestamp) => {
902
- return chatModify({
903
- quickReply: { timestamp, deleted: true }
904
- }, '')
905
- }
906
-
907
- /**
908
- * queries need to be fired on connection open
909
- * help ensure parity with WA Web
910
- * */
911
- const executeInitQueries = async () => {
912
- await Promise.all([
913
- fetchProps(),
914
- fetchBlocklist(),
915
- fetchPrivacySettings(),
916
- ])
917
- }
918
-
919
- const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
920
- ev.emit('messages.upsert', { messages: [msg], type })
921
- if (!!msg.pushName) {
922
- let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid)
923
- jid = WABinary_1.jidNormalizedUser(jid)
924
-
925
- if (!msg.key.fromMe) {
926
- ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }])
927
- }
928
-
929
- // update our pushname too
930
- if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
931
- ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } })
932
- }
933
- }
934
-
935
- const historyMsg = Utils_1.getHistoryMsg(msg.message)
936
- const shouldProcessHistoryMsg = historyMsg
937
- ? (shouldSyncHistoryMessage(historyMsg)
938
- && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
939
- : false
940
-
941
- if (historyMsg && syncState === Types_1.SyncState.AwaitingInitialSync) {
942
- if (awaitingSyncTimeout) {
943
- clearTimeout(awaitingSyncTimeout)
944
- awaitingSyncTimeout = undefined
945
- }
946
-
947
- if (shouldProcessHistoryMsg) {
948
- syncState = Types_1.SyncState.Syncing
949
- logger.info('Transitioned to Syncing state')
950
- // Let doAppStateSync handle the final flush after it`s done
951
- } else {
952
- syncState = Types_1.SyncState.Online
953
- logger.info('History sync skipped, transitioning to Online state and flushing buffer')
954
- ev.flush()
955
- }
956
- }
957
-
958
- const doAppStateSync = async () => {
959
- if (syncState === Types_1.SyncState.Syncing) {
960
- logger.info('Doing app state sync')
961
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true)
962
-
963
- // Sync is complete, go online and flush everything
964
- syncState = Types_1.SyncState.Online
965
- logger.info('App state sync complete, transitioning to Online state and flushing buffer')
966
- ev.flush()
967
-
968
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1
969
- ev.emit('creds.update', { accountSyncCounter })
970
- }
971
- }
972
-
973
- await Promise.all([
974
- (async () => {
975
- if (shouldProcessHistoryMsg) {
976
- await doAppStateSync()
977
- }
978
- })(),
979
- Utils_1.processMessage(msg, {
980
- signalRepository,
981
- shouldProcessHistoryMsg,
982
- placeholderResendCache,
983
- ev,
984
- creds: authState.creds,
985
- keyStore: authState.keys,
986
- logger,
987
- options: config.options,
988
- getMessage: config.getMessage,
989
- })
990
- ])
991
-
992
- if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === Types_1.SyncState.Syncing) {
993
- logger.info('App state sync key arrived, triggering app state sync')
994
- await doAppStateSync()
995
- }
996
- })
997
-
998
- ws.on('CB:presence', handlePresenceUpdate)
999
- ws.on('CB:chatstate', handlePresenceUpdate)
1000
- ws.on('CB:ib,,dirty', async (node) => {
1001
- const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
1002
- const type = attrs.type
1003
-
1004
- switch (type) {
1005
- case 'account_sync':
1006
- if (attrs.timestamp) {
1007
- let { lastAccountSyncTimestamp } = authState.creds
1008
- if (lastAccountSyncTimestamp) {
1009
- await cleanDirtyBits('account_sync', lastAccountSyncTimestamp)
1010
- }
1011
- lastAccountSyncTimestamp = +attrs.timestamp
1012
- ev.emit('creds.update', { lastAccountSyncTimestamp })
1013
- }
1014
- break
1015
- case 'groups':
1016
- await groupFetchAllParticipating()
1017
- await cleanDirtyBits('groups')
1018
- break
1019
- default:
1020
- logger.info({ node }, 'received unknown sync')
1021
- break
1022
- }
1023
- })
1024
-
1025
- ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
1026
- if (connection === 'open') {
1027
- if (fireInitQueries) {
1028
- executeInitQueries()
1029
- .catch(error => onUnexpectedError(error, 'init queries'))
1030
- }
1031
- sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
1032
- .catch(error => onUnexpectedError(error, 'presence update requests'))
1033
- }
1034
-
1035
- if (!receivedPendingNotifications || syncState !== Types_1.SyncState.Connecting) {
1036
- return
1037
- }
1038
-
1039
- syncState = Types_1.AwaitingInitialSync
1040
- logger.info('Connection is now AwaitingInitialSync, buffering events')
1041
- ev.buffer()
1042
-
1043
- const willSyncHistory = shouldSyncHistoryMessage(WAProto_1.proto.Message.HistorySyncNotification.fromObject({
1044
- syncType: WAProto_1.proto.HistorySync.HistorySyncType.RECENT
1045
- }))
1046
-
1047
- if (!willSyncHistory) {
1048
- logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.')
1049
- syncState = Types_1.SyncState.Online
1050
- setTimeout(() => ev.flush(), 0)
1051
- return
1052
- }
1053
-
1054
- logger.info('History sync is enabled, awaiting notification with a 20s timeout.')
1055
-
1056
- if (awaitingSyncTimeout) {
1057
- clearTimeout(awaitingSyncTimeout)
1058
- }
1059
-
1060
- awaitingSyncTimeout = setTimeout(() => {
1061
- if (syncState === Types_1.SyncState.AwaitingInitialSync) {
1062
- logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer')
1063
- syncState = Types_1.SyncState.Online
1064
- ev.flush()
1065
- }
1066
- }, 20_000)
1067
- })
1068
-
1069
- return {
1070
- ...baron,
1071
- star,
1072
- addOrEditContact,
1073
- removeContact,
1074
- processingMutex,
1075
- fetchPrivacySettings,
1076
- upsertMessage,
1077
- appPatch,
1078
- createCallLink,
1079
- sendPresenceUpdate,
1080
- presenceSubscribe,
1081
- getBotListV2,
1082
- getLidUser,
1083
- fetchBlocklist,
1084
- fetchStatus,
1085
- fetchDisappearingDuration,
1086
- updateProfilePicture,
1087
- removeProfilePicture,
1088
- updateProfileStatus,
1089
- updateProfileName,
1090
- updateBlockStatus,
1091
- updateCallPrivacy,
1092
- updateMessagesPrivacy,
1093
- updateLastSeenPrivacy,
1094
- updateOnlinePrivacy,
1095
- updateProfilePicturePrivacy,
1096
- updateStatusPrivacy,
1097
- updateReadReceiptsPrivacy,
1098
- updateGroupsAddPrivacy,
1099
- updateDefaultDisappearingMode,
1100
- updateDisableLinkPreviewsPrivacy,
1101
- getBusinessProfile,
1102
- resyncAppState,
1103
- chatModify,
1104
- cleanDirtyBits,
1105
- addLabel,
1106
- addChatLabel,
1107
- removeChatLabel,
1108
- addMessageLabel,
1109
- removeMessageLabel,
1110
- clearMessage,
1111
- addOrEditQuickReply,
1112
- removeQuickReply
1113
- }
1114
- }
1115
-
1116
- module.exports = {
1117
- makeChatsSocket
1118
- }