@hansaka02/baileys 7.3.2 → 7.3.4

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 (202) hide show
  1. package/README.md +247 -203
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +62 -0
  4. package/lib/Defaults/history.js +17 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +4 -4
  13. package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -7
  16. package/lib/Signal/Group/sender-key-state.js +4 -4
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +45 -69
  19. package/lib/Signal/lid-mapping.js +15 -11
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +16 -14
  22. package/lib/Socket/business.js +41 -32
  23. package/lib/Socket/chats.js +123 -98
  24. package/lib/Socket/community.js +50 -40
  25. package/lib/Socket/groups.js +59 -47
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +219 -172
  28. package/lib/Socket/messages-send.js +187 -143
  29. package/lib/Socket/newsletter.js +61 -47
  30. package/lib/Socket/socket.js +133 -90
  31. package/lib/Socket/usync.js +6 -6
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/State.js +4 -4
  39. package/lib/Types/index.js +28 -12
  40. package/lib/Utils/auth-utils.js +28 -26
  41. package/lib/Utils/baileys-event-stream.js +68 -69
  42. package/lib/Utils/business.js +63 -53
  43. package/lib/Utils/chat-utils.js +81 -71
  44. package/lib/Utils/crypto.js +25 -45
  45. package/lib/Utils/decode-wa-message.js +319 -311
  46. package/lib/Utils/event-buffer.js +21 -22
  47. package/lib/Utils/generics.js +65 -82
  48. package/lib/Utils/history.js +21 -21
  49. package/lib/Utils/index.js +27 -13
  50. package/lib/Utils/link-preview.js +7 -30
  51. package/lib/Utils/logger.js +5 -5
  52. package/lib/Utils/lt-hash.js +3 -3
  53. package/lib/Utils/message-retry-manager.js +4 -4
  54. package/lib/Utils/messages-media.js +104 -109
  55. package/lib/Utils/messages.js +203 -171
  56. package/lib/Utils/noise-handler.js +28 -19
  57. package/lib/Utils/process-message.js +111 -96
  58. package/lib/Utils/signal.js +36 -25
  59. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  60. package/lib/Utils/validate-connection.js +52 -45
  61. package/lib/WABinary/decode.js +6 -32
  62. package/lib/WABinary/encode.js +3 -29
  63. package/lib/WABinary/generic-utils.js +4 -4
  64. package/lib/WABinary/index.js +27 -11
  65. package/lib/WAM/encode.js +16 -8
  66. package/lib/WAM/index.js +27 -11
  67. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  68. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  69. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  70. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  71. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  72. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  73. package/lib/WAUSync/Protocols/index.js +27 -11
  74. package/lib/WAUSync/USyncQuery.js +17 -10
  75. package/lib/WAUSync/index.js +27 -11
  76. package/lib/index.js +60 -31
  77. package/package.json +8 -14
  78. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  79. package/WAProto/Adv/Adv.d.ts +0 -643
  80. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  81. package/WAProto/Cert/Cert.d.ts +0 -613
  82. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  83. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  84. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  85. package/WAProto/E2E/E2E.d.ts +0 -41724
  86. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  87. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  88. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  89. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  90. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  91. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  92. package/WAProto/Protocol/Protocol.d.ts +0 -270
  93. package/WAProto/Reporting/Reporting.d.ts +0 -371
  94. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  95. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  96. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  97. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  98. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  99. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  100. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  101. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  102. package/WAProto/Web/Web.d.ts +0 -46383
  103. package/WAProto/index.d.ts +0 -55
  104. package/lib/Defaults/index.d.ts +0 -77
  105. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  106. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  107. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  108. package/lib/Signal/Group/index.d.ts +0 -11
  109. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  110. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  112. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  113. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  114. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  115. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  116. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  117. package/lib/Signal/libsignal.d.ts +0 -8
  118. package/lib/Signal/lid-mapping.d.ts +0 -28
  119. package/lib/Socket/Client/index.d.ts +0 -2
  120. package/lib/Socket/Client/types.d.ts +0 -16
  121. package/lib/Socket/Client/websocket.d.ts +0 -13
  122. package/lib/Socket/business.d.ts +0 -187
  123. package/lib/Socket/chats.d.ts +0 -97
  124. package/lib/Socket/community.d.ts +0 -129
  125. package/lib/Socket/groups.d.ts +0 -129
  126. package/lib/Socket/index.d.ts +0 -191
  127. package/lib/Socket/messages-recv.d.ts +0 -174
  128. package/lib/Socket/messages-send.d.ts +0 -165
  129. package/lib/Socket/newsletter.d.ts +0 -145
  130. package/lib/Socket/socket.d.ts +0 -45
  131. package/lib/Socket/usync.d.ts +0 -37
  132. package/lib/Store/index.d.ts +0 -4
  133. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  134. package/lib/Store/make-in-memory-store.d.ts +0 -123
  135. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  136. package/lib/Store/object-repository.d.ts +0 -10
  137. package/lib/Types/Auth.d.ts +0 -121
  138. package/lib/Types/Bussiness.d.ts +0 -28
  139. package/lib/Types/Call.d.ts +0 -14
  140. package/lib/Types/Chat.d.ts +0 -143
  141. package/lib/Types/Contact.d.ts +0 -23
  142. package/lib/Types/Events.d.ts +0 -226
  143. package/lib/Types/GroupMetadata.d.ts +0 -66
  144. package/lib/Types/Label.d.ts +0 -48
  145. package/lib/Types/LabelAssociation.d.ts +0 -35
  146. package/lib/Types/Message.d.ts +0 -484
  147. package/lib/Types/MexUpdates.d.ts +0 -9
  148. package/lib/Types/Newsletter.d.ts +0 -109
  149. package/lib/Types/Product.d.ts +0 -92
  150. package/lib/Types/Signal.d.ts +0 -98
  151. package/lib/Types/Socket.d.ts +0 -141
  152. package/lib/Types/State.d.ts +0 -41
  153. package/lib/Types/USync.d.ts +0 -26
  154. package/lib/Types/index.d.ts +0 -80
  155. package/lib/Utils/auth-utils.d.ts +0 -21
  156. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  157. package/lib/Utils/business.d.ts +0 -29
  158. package/lib/Utils/chat-utils.d.ts +0 -82
  159. package/lib/Utils/crypto.d.ts +0 -56
  160. package/lib/Utils/decode-wa-message.d.ts +0 -53
  161. package/lib/Utils/event-buffer.d.ts +0 -39
  162. package/lib/Utils/generics.d.ts +0 -117
  163. package/lib/Utils/history.d.ts +0 -23
  164. package/lib/Utils/index.d.ts +0 -20
  165. package/lib/Utils/link-preview.d.ts +0 -23
  166. package/lib/Utils/logger.d.ts +0 -13
  167. package/lib/Utils/lt-hash.d.ts +0 -14
  168. package/lib/Utils/make-mutex.d.ts +0 -9
  169. package/lib/Utils/message-retry-manager.d.ts +0 -88
  170. package/lib/Utils/messages-media.d.ts +0 -135
  171. package/lib/Utils/messages.d.ts +0 -105
  172. package/lib/Utils/noise-handler.d.ts +0 -20
  173. package/lib/Utils/process-message.d.ts +0 -49
  174. package/lib/Utils/signal.d.ts +0 -42
  175. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  176. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  177. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  178. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  179. package/lib/Utils/use-single-file-auth-state.js +0 -80
  180. package/lib/Utils/validate-connection.d.ts +0 -13
  181. package/lib/WABinary/constants.d.ts +0 -30
  182. package/lib/WABinary/decode.d.ts +0 -9
  183. package/lib/WABinary/encode.d.ts +0 -3
  184. package/lib/WABinary/generic-utils.d.ts +0 -28
  185. package/lib/WABinary/index.d.ts +0 -5
  186. package/lib/WABinary/jid-utils.d.ts +0 -58
  187. package/lib/WABinary/types.d.ts +0 -22
  188. package/lib/WAM/BinaryInfo.d.ts +0 -16
  189. package/lib/WAM/constants.d.ts +0 -47
  190. package/lib/WAM/encode.d.ts +0 -3
  191. package/lib/WAM/index.d.ts +0 -3
  192. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  193. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  194. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  195. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  196. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  197. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  198. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  199. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  200. package/lib/WAUSync/USyncUser.d.ts +0 -12
  201. package/lib/WAUSync/index.d.ts +0 -3
  202. package/lib/index.d.ts +0 -13
@@ -1,14 +1,24 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
3
4
 
4
- const WAProto_1 = require("../../WAProto")
5
- const Types_1 = require("../Types")
6
- const Utils_1 = require("../Utils")
7
- const WABinary_1 = require("../WABinary")
8
- const business_1 = require("./business")
5
+ const { proto } = require("../../WAProto")
6
+ const { WAMessageStubType } = require("../Types")
7
+ const {
8
+ generateMessageID,
9
+ unixTimestampSeconds
10
+ } = require("../Utils")
11
+ const {
12
+ getBinaryNodeChild,
13
+ getBinaryNodeChildren,
14
+ getBinaryNodeChildString,
15
+ jidEncode,
16
+ jidNormalizedUser
17
+ } = require("../WABinary")
18
+ const { makeBusinessSocket } = require("./business")
9
19
 
10
20
  const makeCommunitiesSocket = (config) => {
11
- const suki = business_1.makeBusinessSocket(config)
21
+ const suki = makeBusinessSocket(config)
12
22
  const { authState, ev, query, groupMetadata, upsertMessage } = suki
13
23
 
14
24
  const communityQuery = async (jid, type, content) => (query({
@@ -47,10 +57,10 @@ const makeCommunitiesSocket = (config) => {
47
57
  })
48
58
 
49
59
  const data = {}
50
- const communitiesChild = WABinary_1.getBinaryNodeChild(result, 'communities')
60
+ const communitiesChild = getBinaryNodeChild(result, 'communities')
51
61
 
52
62
  if (communitiesChild) {
53
- const communities = WABinary_1.getBinaryNodeChildren(communitiesChild, 'community')
63
+ const communities = getBinaryNodeChildren(communitiesChild, 'community')
54
64
  for (const communityNode of communities) {
55
65
  const meta = extractCommunityMetadata({
56
66
  tag: 'result',
@@ -66,7 +76,7 @@ const makeCommunitiesSocket = (config) => {
66
76
  }
67
77
 
68
78
  suki.ws.on('CB:ib,,dirty', async (node) => {
69
- const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
79
+ const { attrs } = getBinaryNodeChild(node, 'dirty')
70
80
 
71
81
  if (attrs.type !== 'communities') {
72
82
  return
@@ -81,7 +91,7 @@ const makeCommunitiesSocket = (config) => {
81
91
  communityQuery,
82
92
  communityMetadata,
83
93
  communityCreate: async (subject, body) => {
84
- const descriptionId = Utils_1.generateMessageID().substring(0, 12)
94
+ const descriptionId = generateMessageID().substring(0, 12)
85
95
 
86
96
  const result = await communityQuery('@g.us', 'set', [
87
97
  {
@@ -145,8 +155,8 @@ const makeCommunitiesSocket = (config) => {
145
155
  }
146
156
  ])
147
157
 
148
- const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests')
149
- const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request')
158
+ const node = getBinaryNodeChild(result, 'membership_approval_requests')
159
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request')
150
160
 
151
161
  return participants.map(v => v.attrs)
152
162
  },
@@ -166,9 +176,9 @@ const makeCommunitiesSocket = (config) => {
166
176
  ]
167
177
  }])
168
178
 
169
- const node = WABinary_1.getBinaryNodeChild(result, 'membership_requests_action')
170
- const nodeAction = WABinary_1.getBinaryNodeChild(node, action)
171
- const participantsAffected = WABinary_1.getBinaryNodeChildren(nodeAction, 'participant')
179
+ const node = getBinaryNodeChild(result, 'membership_requests_action')
180
+ const nodeAction = getBinaryNodeChild(node, action)
181
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant')
172
182
 
173
183
  return participantsAffected.map(p => {
174
184
  return { status: p.attrs.error || '200', jid: p.attrs.jid }
@@ -185,8 +195,8 @@ const makeCommunitiesSocket = (config) => {
185
195
  }))
186
196
  }
187
197
  ])
188
- const node = WABinary_1.getBinaryNodeChild(result, action)
189
- const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant')
198
+ const node = getBinaryNodeChild(result, action)
199
+ const participantsAffected = getBinaryNodeChildren(node, 'participant')
190
200
 
191
201
  return participantsAffected.map(p => {
192
202
  return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
@@ -200,7 +210,7 @@ const makeCommunitiesSocket = (config) => {
200
210
  {
201
211
  tag: 'description',
202
212
  attrs: {
203
- ...(description ? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
213
+ ...(description ? { id: generateMessageID() } : { delete: 'true' }),
204
214
  ...(prev ? { prev } : {})
205
215
  },
206
216
  content: description ? [
@@ -211,19 +221,19 @@ const makeCommunitiesSocket = (config) => {
211
221
  },
212
222
  communityInviteCode: async (jid) => {
213
223
  const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
214
- const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
224
+ const inviteNode = getBinaryNodeChild(result, 'invite')
215
225
 
216
226
  return inviteNode?.attrs?.code
217
227
  },
218
228
  communityRevokeInvite: async (jid) => {
219
229
  const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
220
- const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
230
+ const inviteNode = getBinaryNodeChild(result, 'invite')
221
231
 
222
232
  return inviteNode?.attrs?.code
223
233
  },
224
234
  communityAcceptInvite: async (code) => {
225
235
  const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
226
- const result = WABinary_1.getBinaryNodeChild(results, 'community')
236
+ const result = getBinaryNodeChild(results, 'community')
227
237
 
228
238
  return result?.attrs?.jid
229
239
  },
@@ -258,7 +268,7 @@ const makeCommunitiesSocket = (config) => {
258
268
  // update the invite message to be expired
259
269
  if (key.id) {
260
270
  // create new invite message that is expired
261
- inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
271
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage)
262
272
  inviteMessage.inviteExpiration = 0
263
273
  inviteMessage.inviteCode = ''
264
274
  ev.emit('messages.update', [
@@ -277,16 +287,16 @@ const makeCommunitiesSocket = (config) => {
277
287
  await upsertMessage({
278
288
  key: {
279
289
  remoteJid: inviteMessage.groupJid,
280
- id: Utils_1.generateMessageID(authState.creds.me?.id),
290
+ id: generateMessageID(authState.creds.me?.id),
281
291
  fromMe: false,
282
292
  participant: key.remoteJid,
283
293
  },
284
- messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
294
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
285
295
  messageStubParameters: [
286
296
  authState.creds.me.id
287
297
  ],
288
298
  participant: key.remoteJid,
289
- messageTimestamp: Utils_1.unixTimestampSeconds()
299
+ messageTimestamp: unixTimestampSeconds()
290
300
  }, 'notify')
291
301
 
292
302
  return results.attrs.from
@@ -316,21 +326,21 @@ const makeCommunitiesSocket = (config) => {
316
326
  }
317
327
 
318
328
  const extractCommunityMetadata = (result) => {
319
- const community = WABinary_1.getBinaryNodeChild(result, 'group')
320
- const descChild = WABinary_1.getBinaryNodeChild(community, 'description')
329
+ const community = getBinaryNodeChild(result, 'group')
330
+ const descChild = getBinaryNodeChild(community, 'description')
321
331
 
322
332
  let desc
323
333
  let descId
324
334
 
325
335
  if (descChild) {
326
- desc = WABinary_1.getBinaryNodeChildString(descChild, 'body')
336
+ desc = getBinaryNodeChildString(descChild, 'body')
327
337
  descId = descChild.attrs.id
328
338
  }
329
339
 
330
340
  const mode = community.attrs.addressing_mode
331
- const communityId = community.attrs.id.includes('@') ? community.attrs.id : WABinary_1.jidEncode(community.attrs.id, 'g.us')
332
- const eph = WABinary_1.getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration
333
- const memberAddMode = WABinary_1.getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add'
341
+ const communityId = community.attrs.id.includes('@') ? community.attrs.id : jidEncode(community.attrs.id, 'g.us')
342
+ const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration
343
+ const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add'
334
344
 
335
345
  const metadata = {
336
346
  id: communityId,
@@ -338,19 +348,19 @@ const extractCommunityMetadata = (result) => {
338
348
  subject: community.attrs.subject,
339
349
  subjectOwner: mode === 'lid' ? community.attrs.s_o_pn : community.attrs.s_o,
340
350
  subjectTime: +community.attrs.s_t,
341
- size: community.attrs?.size ? +community.attrs.size : WABinary_1.getBinaryNodeChildren(community, 'participant').length,
351
+ size: community.attrs?.size ? +community.attrs.size : getBinaryNodeChildren(community, 'participant').length,
342
352
  creation: +community.attrs.creation,
343
- owner: community.attrs.creator ? WABinary_1.jidNormalizedUser(mode === 'lid' ? community.attrs.creator_pn : community.attrs.creator) : undefined,
353
+ owner: community.attrs.creator ? jidNormalizedUser(mode === 'lid' ? community.attrs.creator_pn : community.attrs.creator) : undefined,
344
354
  desc,
345
355
  descId,
346
- linkedParent: WABinary_1.getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
347
- restrict: !!WABinary_1.getBinaryNodeChild(community, 'locked'),
348
- announce: !!WABinary_1.getBinaryNodeChild(community, 'announcement'),
349
- isCommunity: !!WABinary_1.getBinaryNodeChild(community, 'parent'),
350
- isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(community, 'default_sub_group'),
351
- joinApprovalMode: !!WABinary_1.getBinaryNodeChild(community, 'membership_approval_mode'),
356
+ linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
357
+ restrict: !!getBinaryNodeChild(community, 'locked'),
358
+ announce: !!getBinaryNodeChild(community, 'announcement'),
359
+ isCommunity: !!getBinaryNodeChild(community, 'parent'),
360
+ isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_group'),
361
+ joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
352
362
  memberAddMode,
353
- participants: WABinary_1.getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
363
+ participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
354
364
  return {
355
365
  id: mode === 'lid' ? community.phone_number : attrs.jid,
356
366
  lid: mode === 'lid' ? community.jid : attrs.lid,
@@ -1,14 +1,26 @@
1
1
  "use strict"
2
2
  Object.defineProperty(exports, "__esModule", { value: true })
3
3
 
4
- const WAProto_1 = require("../../WAProto")
5
- const Types_1 = require("../Types")
6
- const Utils_1 = require("../Utils")
7
- const WABinary_1 = require("../WABinary")
8
- const chats_1 = require("./chats")
4
+ const { proto } = require("../../WAProto")
5
+ const {
6
+ WAMessageStubType,
7
+ WAMessageAddressingMode
8
+ } = require("../Types")
9
+ const {
10
+ generateMessageID,
11
+ unixTimestampSeconds
12
+ } = require("../Utils")
13
+ const {
14
+ getBinaryNodeChild,
15
+ getBinaryNodeChildren,
16
+ getBinaryNodeChildString,
17
+ jidEncode,
18
+ jidNormalizedUser
19
+ } = require("../WABinary")
20
+ const { makeChatsSocket } = require("./chats")
9
21
 
10
22
  const makeGroupsSocket = (config) => {
11
- const suki = chats_1.makeChatsSocket(config)
23
+ const suki = makeChatsSocket(config)
12
24
  const { authState, ev, query, upsertMessage } = suki
13
25
 
14
26
  const groupQuery = async (jid, type, content) => (query({
@@ -47,10 +59,10 @@ const makeGroupsSocket = (config) => {
47
59
  })
48
60
 
49
61
  const data = {}
50
- const groupsChild = WABinary_1.getBinaryNodeChild(result, 'groups')
62
+ const groupsChild = getBinaryNodeChild(result, 'groups')
51
63
 
52
64
  if (groupsChild) {
53
- const groups = WABinary_1.getBinaryNodeChildren(groupsChild, 'group')
65
+ const groups = getBinaryNodeChildren(groupsChild, 'group')
54
66
  for (const groupNode of groups) {
55
67
  const meta = extractGroupMetadata({
56
68
  tag: 'result',
@@ -66,7 +78,7 @@ const makeGroupsSocket = (config) => {
66
78
  }
67
79
 
68
80
  suki.ws.on('CB:ib,,dirty', async (node) => {
69
- const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
81
+ const { attrs } = getBinaryNodeChild(node, 'dirty')
70
82
  if (attrs.type !== 'groups') {
71
83
  return
72
84
  }
@@ -80,7 +92,7 @@ const makeGroupsSocket = (config) => {
80
92
  groupQuery,
81
93
  groupMetadata,
82
94
  groupCreate: async (subject, participants) => {
83
- const key = Utils_1.generateMessageID()
95
+ const key = generateMessageID()
84
96
 
85
97
  const result = await groupQuery('@g.us', 'set', [
86
98
  {
@@ -126,8 +138,8 @@ const makeGroupsSocket = (config) => {
126
138
  }
127
139
  ])
128
140
 
129
- const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests')
130
- const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request')
141
+ const node = getBinaryNodeChild(result, 'membership_approval_requests')
142
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request')
131
143
 
132
144
  return participants.map(v => v.attrs)
133
145
  },
@@ -147,9 +159,9 @@ const makeGroupsSocket = (config) => {
147
159
  ]
148
160
  }])
149
161
 
150
- const node = WABinary_1.getBinaryNodeChild(result, 'membership_requests_action')
151
- const nodeAction = WABinary_1.getBinaryNodeChild(node, action)
152
- const participantsAffected = WABinary_1.getBinaryNodeChildren(nodeAction, 'participant')
162
+ const node = getBinaryNodeChild(result, 'membership_requests_action')
163
+ const nodeAction = getBinaryNodeChild(node, action)
164
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant')
153
165
 
154
166
  return participantsAffected.map(p => {
155
167
  return { status: p.attrs.error || '200', jid: p.attrs.jid }
@@ -166,8 +178,8 @@ const makeGroupsSocket = (config) => {
166
178
  }))
167
179
  }
168
180
  ])
169
- const node = WABinary_1.getBinaryNodeChild(result, action)
170
- const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant')
181
+ const node = getBinaryNodeChild(result, action)
182
+ const participantsAffected = getBinaryNodeChildren(node, 'participant')
171
183
 
172
184
  return participantsAffected.map(p => {
173
185
  return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
@@ -181,7 +193,7 @@ const makeGroupsSocket = (config) => {
181
193
  {
182
194
  tag: 'description',
183
195
  attrs: {
184
- ...(description ? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
196
+ ...(description ? { id: generateMessageID() } : { delete: 'true' }),
185
197
  ...(prev ? { prev } : {})
186
198
  },
187
199
  content: description ? [
@@ -192,19 +204,19 @@ const makeGroupsSocket = (config) => {
192
204
  },
193
205
  groupInviteCode: async (jid) => {
194
206
  const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
195
- const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
207
+ const inviteNode = getBinaryNodeChild(result, 'invite')
196
208
 
197
209
  return inviteNode?.attrs?.code
198
210
  },
199
211
  groupRevokeInvite: async (jid) => {
200
212
  const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
201
- const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
213
+ const inviteNode = getBinaryNodeChild(result, 'invite')
202
214
 
203
215
  return inviteNode?.attrs?.code
204
216
  },
205
217
  groupAcceptInvite: async (code) => {
206
218
  const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
207
- const result = WABinary_1.getBinaryNodeChild(results, 'group')
219
+ const result = getBinaryNodeChild(results, 'group')
208
220
 
209
221
  return result?.attrs?.jid
210
222
  },
@@ -239,7 +251,7 @@ const makeGroupsSocket = (config) => {
239
251
  // update the invite message to be expired
240
252
  if (key.id) {
241
253
  // create new invite message that is expired
242
- inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
254
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage)
243
255
  inviteMessage.inviteExpiration = 0
244
256
  inviteMessage.inviteCode = ''
245
257
  ev.emit('messages.update', [
@@ -258,16 +270,16 @@ const makeGroupsSocket = (config) => {
258
270
  await upsertMessage({
259
271
  key: {
260
272
  remoteJid: inviteMessage.groupJid,
261
- id: Utils_1.generateMessageID(authState.creds.me?.id),
273
+ id: generateMessageID(authState.creds.me?.id),
262
274
  fromMe: false,
263
275
  participant: key.remoteJid,
264
276
  },
265
- messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
277
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
266
278
  messageStubParameters: [
267
279
  authState.creds.me.id
268
280
  ],
269
281
  participant: key.remoteJid,
270
- messageTimestamp: Utils_1.unixTimestampSeconds()
282
+ messageTimestamp: unixTimestampSeconds()
271
283
  }, 'notify')
272
284
 
273
285
  return results.attrs.from
@@ -297,9 +309,9 @@ const makeGroupsSocket = (config) => {
297
309
  }
298
310
 
299
311
  const extractGroupMetadata = (result) => {
300
- const group = WABinary_1.getBinaryNodeChild(result, 'group')
301
- const descChild = WABinary_1.getBinaryNodeChild(group, 'description')
302
- const mode = group.attrs.addressing_mode === 'lid' ? Types_1.WAMessageAddressingMode.LID : Types_1.WAMessageAddressingMode.PN
312
+ const group = getBinaryNodeChild(result, 'group')
313
+ const descChild = getBinaryNodeChild(group, 'description')
314
+ const mode = group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN
303
315
 
304
316
  let desc
305
317
  let descId
@@ -307,43 +319,43 @@ const extractGroupMetadata = (result) => {
307
319
  let descOwnerLid
308
320
 
309
321
  if (descChild) {
310
- desc = WABinary_1.getBinaryNodeChildString(descChild, 'body')
322
+ desc = getBinaryNodeChildString(descChild, 'body')
311
323
  descId = descChild.attrs.id
312
- descOwner = mode === Types_1.WAMessageAddressingMode.LID ? WABinary_1.jidNormalizedUser(descChild.attrs.participant_pn) : WABinary_1.jidNormalizedUser(descChild.attrs.participant)
313
- descOwnerLid = mode === Types_1.WAMessageAddressingMode.LID ? WABinary_1.jidNormalizedUser(descChild.attrs.participant) : undefined
324
+ descOwner = mode === WAMessageAddressingMode.LID ? jidNormalizedUser(descChild.attrs.participant_pn) : jidNormalizedUser(descChild.attrs.participant)
325
+ descOwnerLid = mode === WAMessageAddressingMode.LID ? jidNormalizedUser(descChild.attrs.participant) : undefined
314
326
  }
315
327
 
316
- const groupId = group.attrs.id.includes('@') ? group.attrs.id : WABinary_1.jidEncode(group.attrs.id, 'g.us')
317
- const eph = WABinary_1.getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
318
- const memberAddMode = WABinary_1.getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
328
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us')
329
+ const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
330
+ const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
319
331
 
320
332
  const metadata = {
321
333
  id: groupId,
322
334
  addressingMode: mode,
323
335
  subject: group.attrs.subject,
324
- subjectOwner: mode === Types_1.WAMessageAddressingMode.LID ? group.attrs.s_o_pn : group.attrs.s_o,
336
+ subjectOwner: mode === WAMessageAddressingMode.LID ? group.attrs.s_o_pn : group.attrs.s_o,
325
337
  subjectOwnerLid: group.attrs.s_o,
326
338
  subjectTime: +group.attrs.s_t,
327
- size: group.attrs?.size ? +group.attrs.size : WABinary_1.getBinaryNodeChildren(group, 'participant').length,
339
+ size: group.attrs?.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
328
340
  creation: +group.attrs.creation,
329
- owner: group.attrs.creator ? WABinary_1.jidNormalizedUser(mode === Types_1.WAMessageAddressingMode.LID ? group.attrs.creator_pn : group.attrs.creator) : undefined,
330
- ownerLid: group.attrs.creator ? WABinary_1.jidNormalizedUser(group.attrs.creator) : undefined,
341
+ owner: group.attrs.creator ? jidNormalizedUser(mode === WAMessageAddressingMode.LID ? group.attrs.creator_pn : group.attrs.creator) : undefined,
342
+ ownerLid: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
331
343
  ownerCountry: group.attrs.creator_country_code,
332
344
  desc,
333
345
  descId,
334
346
  descOwner,
335
347
  descOwnerLid,
336
- linkedParent: WABinary_1.getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
337
- restrict: !!WABinary_1.getBinaryNodeChild(group, 'locked'),
338
- announce: !!WABinary_1.getBinaryNodeChild(group, 'announcement'),
339
- isCommunity: !!WABinary_1.getBinaryNodeChild(group, 'parent'),
340
- isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(group, 'default_sub_group'),
341
- joinApprovalMode: !!WABinary_1.getBinaryNodeChild(group, 'membership_approval_mode'),
348
+ linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
349
+ restrict: !!getBinaryNodeChild(group, 'locked'),
350
+ announce: !!getBinaryNodeChild(group, 'announcement'),
351
+ isCommunity: !!getBinaryNodeChild(group, 'parent'),
352
+ isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
353
+ joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
342
354
  memberAddMode,
343
- participants: WABinary_1.getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
355
+ participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
344
356
  return {
345
- id: mode === Types_1.WAMessageAddressingMode.LID ? attrs.phone_number : attrs.jid,
346
- lid: mode === Types_1.WAMessageAddressingMode.LID ? attrs.jid : attrs.lid,
357
+ id: mode === WAMessageAddressingMode.LID ? attrs.phone_number : attrs.jid,
358
+ lid: mode === WAMessageAddressingMode.LID ? attrs.jid : attrs.lid,
347
359
  admin: (attrs.type || null),
348
360
  }
349
361
  }),
@@ -2,13 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const Defaults_1 = require("../Defaults")
6
- const community_1 = require("./community")
5
+ const { DEFAULT_CONNECTION_CONFIG } = require("../Defaults/connection")
6
+ const { makeCommunitiesSocket } = require("./community")
7
7
 
8
8
  // export the last socket layer
9
9
  const makeWASocket = (config) => {
10
10
  const newConfig = {
11
- ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
11
+ ...DEFAULT_CONNECTION_CONFIG,
12
12
  ...config
13
13
  }
14
14
 
@@ -18,7 +18,7 @@ const makeWASocket = (config) => {
18
18
  newConfig.shouldSyncHistoryMessage = () => !!newConfig.syncFullHistory
19
19
  }
20
20
 
21
- return community_1.makeCommunitiesSocket(newConfig)
21
+ return makeCommunitiesSocket(newConfig)
22
22
  }
23
23
 
24
24
  exports.default = makeWASocket