@hansaka02/baileys 7.3.2 → 7.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/lib/Defaults/baileys-version.json +2 -2
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +74 -0
  4. package/lib/Defaults/history.js +19 -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 +5 -18
  13. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -16
  16. package/lib/Signal/Group/sender-key-state.js +15 -61
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +237 -177
  19. package/lib/Signal/lid-mapping.js +128 -71
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +25 -16
  22. package/lib/Socket/business.js +46 -33
  23. package/lib/Socket/chats.js +286 -170
  24. package/lib/Socket/community.js +215 -77
  25. package/lib/Socket/groups.js +77 -61
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +629 -457
  28. package/lib/Socket/messages-send.js +645 -656
  29. package/lib/Socket/mex.js +61 -0
  30. package/lib/Socket/newsletter.js +166 -245
  31. package/lib/Socket/socket.js +396 -170
  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/Newsletter.js +32 -25
  39. package/lib/Types/State.js +4 -4
  40. package/lib/Types/index.js +28 -12
  41. package/lib/Utils/auth-utils.js +212 -375
  42. package/lib/Utils/baileys-event-stream.js +68 -69
  43. package/lib/Utils/browser-utils.js +43 -0
  44. package/lib/Utils/business.js +63 -53
  45. package/lib/Utils/chat-utils.js +241 -106
  46. package/lib/Utils/crypto.js +25 -45
  47. package/lib/Utils/decode-wa-message.js +361 -311
  48. package/lib/Utils/event-buffer.js +97 -42
  49. package/lib/Utils/generics.js +90 -207
  50. package/lib/Utils/history.js +29 -27
  51. package/lib/Utils/index.js +28 -14
  52. package/lib/Utils/link-preview.js +24 -62
  53. package/lib/Utils/logger.js +5 -5
  54. package/lib/Utils/lt-hash.js +29 -23
  55. package/lib/Utils/make-mutex.js +26 -28
  56. package/lib/Utils/message-retry-manager.js +55 -7
  57. package/lib/Utils/messages-media.js +434 -247
  58. package/lib/Utils/messages.js +963 -917
  59. package/lib/Utils/noise-handler.js +60 -20
  60. package/lib/Utils/pre-key-manager.js +126 -0
  61. package/lib/Utils/process-message.js +216 -141
  62. package/lib/Utils/signal.js +75 -37
  63. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  64. package/lib/Utils/validate-connection.js +96 -66
  65. package/lib/WABinary/constants.js +1268 -1268
  66. package/lib/WABinary/decode.js +62 -34
  67. package/lib/WABinary/encode.js +57 -36
  68. package/lib/WABinary/generic-utils.js +4 -4
  69. package/lib/WABinary/index.js +27 -11
  70. package/lib/WABinary/jid-utils.js +58 -11
  71. package/lib/WAM/constants.js +19064 -11563
  72. package/lib/WAM/encode.js +71 -14
  73. package/lib/WAM/index.js +27 -11
  74. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  75. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  76. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  77. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  78. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  79. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  80. package/lib/WAUSync/Protocols/index.js +27 -11
  81. package/lib/WAUSync/USyncQuery.js +51 -28
  82. package/lib/WAUSync/index.js +27 -11
  83. package/lib/index.js +60 -31
  84. package/package.json +12 -17
  85. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  86. package/WAProto/Adv/Adv.d.ts +0 -643
  87. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  88. package/WAProto/Cert/Cert.d.ts +0 -613
  89. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  90. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  91. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  92. package/WAProto/E2E/E2E.d.ts +0 -41724
  93. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  94. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  95. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  96. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  97. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  98. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  99. package/WAProto/Protocol/Protocol.d.ts +0 -270
  100. package/WAProto/Reporting/Reporting.d.ts +0 -371
  101. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  102. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  103. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  104. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  105. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  106. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  107. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  108. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  109. package/WAProto/Web/Web.d.ts +0 -46383
  110. package/WAProto/index.d.ts +0 -55
  111. package/lib/Defaults/index.d.ts +0 -77
  112. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  113. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  114. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  115. package/lib/Signal/Group/index.d.ts +0 -11
  116. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  117. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  118. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  119. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  120. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  121. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  122. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  123. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  124. package/lib/Signal/libsignal.d.ts +0 -8
  125. package/lib/Signal/lid-mapping.d.ts +0 -28
  126. package/lib/Socket/Client/index.d.ts +0 -2
  127. package/lib/Socket/Client/types.d.ts +0 -16
  128. package/lib/Socket/Client/websocket.d.ts +0 -13
  129. package/lib/Socket/business.d.ts +0 -187
  130. package/lib/Socket/chats.d.ts +0 -97
  131. package/lib/Socket/community.d.ts +0 -129
  132. package/lib/Socket/groups.d.ts +0 -129
  133. package/lib/Socket/index.d.ts +0 -191
  134. package/lib/Socket/messages-recv.d.ts +0 -174
  135. package/lib/Socket/messages-send.d.ts +0 -165
  136. package/lib/Socket/newsletter.d.ts +0 -145
  137. package/lib/Socket/socket.d.ts +0 -45
  138. package/lib/Socket/usync.d.ts +0 -37
  139. package/lib/Socket/usync.js +0 -83
  140. package/lib/Store/index.d.ts +0 -4
  141. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  142. package/lib/Store/make-in-memory-store.d.ts +0 -123
  143. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  144. package/lib/Store/object-repository.d.ts +0 -10
  145. package/lib/Types/Auth.d.ts +0 -121
  146. package/lib/Types/Bussiness.d.ts +0 -28
  147. package/lib/Types/Call.d.ts +0 -14
  148. package/lib/Types/Chat.d.ts +0 -143
  149. package/lib/Types/Contact.d.ts +0 -23
  150. package/lib/Types/Events.d.ts +0 -226
  151. package/lib/Types/GroupMetadata.d.ts +0 -66
  152. package/lib/Types/Label.d.ts +0 -48
  153. package/lib/Types/LabelAssociation.d.ts +0 -35
  154. package/lib/Types/Message.d.ts +0 -484
  155. package/lib/Types/MexUpdates.d.ts +0 -9
  156. package/lib/Types/Newsletter.d.ts +0 -109
  157. package/lib/Types/Product.d.ts +0 -92
  158. package/lib/Types/Signal.d.ts +0 -98
  159. package/lib/Types/Socket.d.ts +0 -141
  160. package/lib/Types/State.d.ts +0 -41
  161. package/lib/Types/USync.d.ts +0 -26
  162. package/lib/Types/index.d.ts +0 -80
  163. package/lib/Utils/auth-utils.d.ts +0 -21
  164. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  165. package/lib/Utils/business.d.ts +0 -29
  166. package/lib/Utils/chat-utils.d.ts +0 -82
  167. package/lib/Utils/crypto.d.ts +0 -56
  168. package/lib/Utils/decode-wa-message.d.ts +0 -53
  169. package/lib/Utils/event-buffer.d.ts +0 -39
  170. package/lib/Utils/generics.d.ts +0 -117
  171. package/lib/Utils/history.d.ts +0 -23
  172. package/lib/Utils/index.d.ts +0 -20
  173. package/lib/Utils/link-preview.d.ts +0 -23
  174. package/lib/Utils/logger.d.ts +0 -13
  175. package/lib/Utils/lt-hash.d.ts +0 -14
  176. package/lib/Utils/make-mutex.d.ts +0 -9
  177. package/lib/Utils/message-retry-manager.d.ts +0 -88
  178. package/lib/Utils/messages-media.d.ts +0 -135
  179. package/lib/Utils/messages.d.ts +0 -105
  180. package/lib/Utils/noise-handler.d.ts +0 -20
  181. package/lib/Utils/process-message.d.ts +0 -49
  182. package/lib/Utils/signal.d.ts +0 -42
  183. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  184. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  185. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  186. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  187. package/lib/Utils/use-single-file-auth-state.js +0 -80
  188. package/lib/Utils/validate-connection.d.ts +0 -13
  189. package/lib/WABinary/constants.d.ts +0 -30
  190. package/lib/WABinary/decode.d.ts +0 -9
  191. package/lib/WABinary/encode.d.ts +0 -3
  192. package/lib/WABinary/generic-utils.d.ts +0 -28
  193. package/lib/WABinary/index.d.ts +0 -5
  194. package/lib/WABinary/jid-utils.d.ts +0 -58
  195. package/lib/WABinary/types.d.ts +0 -22
  196. package/lib/WAM/BinaryInfo.d.ts +0 -16
  197. package/lib/WAM/constants.d.ts +0 -47
  198. package/lib/WAM/encode.d.ts +0 -3
  199. package/lib/WAM/index.d.ts +0 -3
  200. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  204. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  205. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  206. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  207. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  208. package/lib/WAUSync/USyncUser.d.ts +0 -12
  209. package/lib/WAUSync/index.d.ts +0 -3
  210. package/lib/index.d.ts +0 -13
@@ -1,15 +1,36 @@
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 { default: logger } = require("../Utils/logger")
7
+ const {
8
+ WAMessageStubType,
9
+ WAMessageAddressingMode
10
+ } = require("../Types")
11
+ const {
12
+ generateMessageID,
13
+ unixTimestampSeconds
14
+ } = require("../Utils")
15
+ const {
16
+ getBinaryNodeChild,
17
+ getBinaryNodeChildren,
18
+ getBinaryNodeChildString,
19
+ jidEncode,
20
+ jidNormalizedUser
21
+ } = require("../WABinary")
22
+ const { makeBusinessSocket } = require("./business")
9
23
 
10
24
  const makeCommunitiesSocket = (config) => {
11
- const suki = business_1.makeBusinessSocket(config)
12
- const { authState, ev, query, groupMetadata, upsertMessage } = suki
25
+ const suki = makeBusinessSocket(config)
26
+ const {
27
+ authState,
28
+ ev,
29
+ query,
30
+ groupMetadata,
31
+ upsertMessage,
32
+ cleanDirtyBits
33
+ } = suki
13
34
 
14
35
  const communityQuery = async (jid, type, content) => (query({
15
36
  tag: 'iq',
@@ -47,10 +68,10 @@ const makeCommunitiesSocket = (config) => {
47
68
  })
48
69
 
49
70
  const data = {}
50
- const communitiesChild = WABinary_1.getBinaryNodeChild(result, 'communities')
71
+ const communitiesChild = getBinaryNodeChild(result, 'communities')
51
72
 
52
73
  if (communitiesChild) {
53
- const communities = WABinary_1.getBinaryNodeChildren(communitiesChild, 'community')
74
+ const communities = getBinaryNodeChildren(communitiesChild, 'community')
54
75
  for (const communityNode of communities) {
55
76
  const meta = extractCommunityMetadata({
56
77
  tag: 'result',
@@ -65,15 +86,37 @@ const makeCommunitiesSocket = (config) => {
65
86
  return data
66
87
  }
67
88
 
89
+ async function parseGroupResult(node) {
90
+ logger.info({ node }, 'parseGroupResult')
91
+
92
+ const groupNode = getBinaryNodeChild(node, 'group')
93
+
94
+ if (groupNode) {
95
+ try {
96
+ logger.info({ groupNode }, 'groupNode')
97
+
98
+ const metadata = await groupMetadata(`${groupNode.attrs.id}@g.us`)
99
+
100
+ return metadata ? metadata : null
101
+ }
102
+ catch (error) {
103
+ logger.warn({ error }, 'Error parsing group metadata')
104
+ return null
105
+ }
106
+ }
107
+
108
+ return null
109
+ }
110
+
68
111
  suki.ws.on('CB:ib,,dirty', async (node) => {
69
- const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
112
+ const { attrs } = getBinaryNodeChild(node, 'dirty')
70
113
 
71
114
  if (attrs.type !== 'communities') {
72
115
  return
73
116
  }
74
117
 
75
118
  await communityFetchAllParticipating()
76
- await suki.cleanDirtyBits('groups')
119
+ await cleanDirtyBits('groups')
77
120
  })
78
121
 
79
122
  return {
@@ -81,7 +124,7 @@ const makeCommunitiesSocket = (config) => {
81
124
  communityQuery,
82
125
  communityMetadata,
83
126
  communityCreate: async (subject, body) => {
84
- const descriptionId = Utils_1.generateMessageID().substring(0, 12)
127
+ const descriptionId = generateMessageID().substring(0, 12)
85
128
 
86
129
  const result = await communityQuery('@g.us', 'set', [
87
130
  {
@@ -115,7 +158,28 @@ const makeCommunitiesSocket = (config) => {
115
158
  }
116
159
  ])
117
160
 
118
- return extractCommunityMetadata(result)
161
+ return await parseGroupResult(result)
162
+ },
163
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
164
+ const key = generateMessageID()
165
+ const result = await communityQuery('@g.us', 'set', [
166
+ {
167
+ tag: 'create',
168
+ attrs: {
169
+ subject,
170
+ key
171
+ },
172
+ content: [
173
+ ...participants.map(jid => ({
174
+ tag: 'participant',
175
+ attrs: { jid }
176
+ })),
177
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
178
+ ]
179
+ }
180
+ ])
181
+
182
+ return await parseGroupResult(result)
119
183
  },
120
184
  communityLeave: async (id) => {
121
185
  await communityQuery('@g.us', 'set', [
@@ -137,6 +201,72 @@ const makeCommunitiesSocket = (config) => {
137
201
  }
138
202
  ])
139
203
  },
204
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
205
+ await communityQuery(parentCommunityJid, 'set', [
206
+ {
207
+ tag: 'links',
208
+ attrs: {},
209
+ content: [
210
+ {
211
+ tag: 'link',
212
+ attrs: { link_type: 'sub_group' },
213
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
214
+ }
215
+ ]
216
+ }
217
+ ])
218
+ },
219
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
220
+ await communityQuery(parentCommunityJid, 'set', [
221
+ {
222
+ tag: 'unlink',
223
+ attrs: { unlink_type: 'sub_group' },
224
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
225
+ }
226
+ ])
227
+ },
228
+ communityFetchLinkedGroups: async (jid) => {
229
+ let communityJid = jid
230
+ let isCommunity = false
231
+
232
+ // Try to determine if it is a subgroup or a community
233
+ const metadata = await groupMetadata(jid)
234
+
235
+ if (metadata.linkedParent) {
236
+ // It is a subgroup, get the community jid
237
+ communityJid = metadata.linkedParent
238
+ }
239
+
240
+ else {
241
+ // It is a community
242
+ isCommunity = true
243
+ }
244
+
245
+ // Fetch all subgroups of the community
246
+ const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }])
247
+ const linkedGroupsData = []
248
+ const subGroupsNode = getBinaryNodeChild(result, 'sub_groups')
249
+
250
+ if (subGroupsNode) {
251
+ const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group')
252
+
253
+ for (const groupNode of groupNodes) {
254
+ linkedGroupsData.push({
255
+ id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
256
+ subject: groupNode.attrs.subject || '',
257
+ creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
258
+ owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
259
+ size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
260
+ })
261
+ }
262
+ }
263
+
264
+ return {
265
+ communityJid,
266
+ isCommunity,
267
+ linkedGroups: linkedGroupsData
268
+ }
269
+ },
140
270
  communityRequestParticipantsList: async (jid) => {
141
271
  const result = await communityQuery(jid, 'get', [
142
272
  {
@@ -145,13 +275,14 @@ const makeCommunitiesSocket = (config) => {
145
275
  }
146
276
  ])
147
277
 
148
- const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests')
149
- const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request')
278
+ const node = getBinaryNodeChild(result, 'membership_approval_requests')
279
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request')
150
280
 
151
281
  return participants.map(v => v.attrs)
152
282
  },
153
283
  communityRequestParticipantsUpdate: async (jid, participants, action) => {
154
- const result = await communityQuery(jid, 'set', [{
284
+ const result = await communityQuery(jid, 'set', [
285
+ {
155
286
  tag: 'membership_requests_action',
156
287
  attrs: {},
157
288
  content: [
@@ -164,11 +295,12 @@ const makeCommunitiesSocket = (config) => {
164
295
  }))
165
296
  }
166
297
  ]
167
- }])
168
-
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')
298
+ }
299
+ ])
300
+
301
+ const node = getBinaryNodeChild(result, 'membership_requests_action')
302
+ const nodeAction = getBinaryNodeChild(node, action)
303
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant')
172
304
 
173
305
  return participantsAffected.map(p => {
174
306
  return { status: p.attrs.error || '200', jid: p.attrs.jid }
@@ -178,15 +310,16 @@ const makeCommunitiesSocket = (config) => {
178
310
  const result = await communityQuery(jid, 'set', [
179
311
  {
180
312
  tag: action,
181
- attrs: {},
313
+ attrs: action === 'remove' ? { linked_groups: 'true' } : {},
182
314
  content: participants.map(jid => ({
183
315
  tag: 'participant',
184
316
  attrs: { jid }
185
317
  }))
186
318
  }
187
319
  ])
188
- const node = WABinary_1.getBinaryNodeChild(result, action)
189
- const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant')
320
+
321
+ const node = getBinaryNodeChild(result, action)
322
+ const participantsAffected = getBinaryNodeChildren(node, 'participant')
190
323
 
191
324
  return participantsAffected.map(p => {
192
325
  return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
@@ -194,38 +327,35 @@ const makeCommunitiesSocket = (config) => {
194
327
  },
195
328
  communityUpdateDescription: async (jid, description) => {
196
329
  const metadata = await communityMetadata(jid)
197
- const prev = metadata.descId ? metadata.descId : null
198
-
330
+ const prev = metadata.descId ?? null
199
331
  await communityQuery(jid, 'set', [
200
332
  {
201
333
  tag: 'description',
202
334
  attrs: {
203
- ...(description ? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
335
+ ...(description ? { id: generateMessageID() } : { delete: 'true' }),
204
336
  ...(prev ? { prev } : {})
205
337
  },
206
- content: description ? [
207
- { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
208
- ] : undefined
338
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
209
339
  }
210
340
  ])
211
341
  },
212
342
  communityInviteCode: async (jid) => {
213
343
  const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
214
- const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
344
+ const inviteNode = getBinaryNodeChild(result, 'invite')
215
345
 
216
- return inviteNode?.attrs?.code
346
+ return inviteNode?.attrs.code
217
347
  },
218
348
  communityRevokeInvite: async (jid) => {
219
349
  const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
220
- const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
350
+ const inviteNode = getBinaryNodeChild(result, 'invite')
221
351
 
222
- return inviteNode?.attrs?.code
352
+ return inviteNode?.attrs.code
223
353
  },
224
354
  communityAcceptInvite: async (code) => {
225
355
  const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
226
- const result = WABinary_1.getBinaryNodeChild(results, 'community')
356
+ const result = getBinaryNodeChild(results, 'community')
227
357
 
228
- return result?.attrs?.jid
358
+ return result?.attrs.jid
229
359
  },
230
360
  /**
231
361
  * revoke a v4 invite for someone
@@ -234,31 +364,36 @@ const makeCommunitiesSocket = (config) => {
234
364
  * @returns true if successful
235
365
  */
236
366
  communityRevokeInviteV4: async (communityJid, invitedJid) => {
237
- const result = await communityQuery(communityJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }])
367
+ const result = await communityQuery(communityJid, 'set', [
368
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
369
+ ])
238
370
 
239
371
  return !!result
240
372
  },
241
373
  /**
242
- * accept a GroupInviteMessage
374
+ * accept a CommunityInviteMessage
243
375
  * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
244
376
  * @param inviteMessage the message to accept
245
377
  */
246
378
  communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
247
379
  key = typeof key === 'string' ? { remoteJid: key } : key
248
- const results = await communityQuery(inviteMessage.groupJid, 'set', [{
380
+
381
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
382
+ {
249
383
  tag: 'accept',
250
384
  attrs: {
251
385
  code: inviteMessage.inviteCode,
252
386
  expiration: inviteMessage.inviteExpiration.toString(),
253
387
  admin: key.remoteJid
254
388
  }
255
- }])
256
-
389
+ }
390
+ ])
391
+
257
392
  // if we have the full message key
258
393
  // update the invite message to be expired
259
394
  if (key.id) {
260
395
  // create new invite message that is expired
261
- inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
396
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage)
262
397
  inviteMessage.inviteExpiration = 0
263
398
  inviteMessage.inviteCode = ''
264
399
  ev.emit('messages.update', [
@@ -273,33 +408,31 @@ const makeCommunitiesSocket = (config) => {
273
408
  ])
274
409
  }
275
410
 
276
- // generate the group add message
411
+ // generate the community add message
277
412
  await upsertMessage({
278
413
  key: {
279
414
  remoteJid: inviteMessage.groupJid,
280
- id: Utils_1.generateMessageID(authState.creds.me?.id),
415
+ id: generateMessageID(suki.user?.id),
281
416
  fromMe: false,
282
- participant: key.remoteJid,
417
+ participant: key.remoteJid // TODO: investigate if this makes any sense at all
283
418
  },
284
- messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
285
- messageStubParameters: [
286
- authState.creds.me.id
287
- ],
419
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
420
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
288
421
  participant: key.remoteJid,
289
- messageTimestamp: Utils_1.unixTimestampSeconds()
422
+ messageTimestamp: unixTimestampSeconds()
290
423
  }, 'notify')
291
424
 
292
425
  return results.attrs.from
293
426
  }),
294
427
  communityGetInviteInfo: async (code) => {
295
428
  const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
296
-
297
429
  return extractCommunityMetadata(results)
298
430
  },
299
431
  communityToggleEphemeral: async (jid, ephemeralExpiration) => {
300
- const content = ephemeralExpiration ?
301
- { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
302
- { tag: 'not_ephemeral', attrs: {} }
432
+ const content = ephemeralExpiration
433
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
434
+ : { tag: 'not_ephemeral', attrs: {} }
435
+
303
436
  await communityQuery(jid, 'set', [content])
304
437
  },
305
438
  communitySettingUpdate: async (jid, setting) => {
@@ -309,55 +442,60 @@ const makeCommunitiesSocket = (config) => {
309
442
  await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
310
443
  },
311
444
  communityJoinApprovalMode: async (jid, mode) => {
312
- await communityQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }])
445
+ await communityQuery(jid, 'set', [
446
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
447
+ ])
313
448
  },
314
449
  communityFetchAllParticipating
315
450
  }
316
451
  }
317
452
 
318
453
  const extractCommunityMetadata = (result) => {
319
- const community = WABinary_1.getBinaryNodeChild(result, 'group')
320
- const descChild = WABinary_1.getBinaryNodeChild(community, 'description')
454
+ const community = getBinaryNodeChild(result, 'group')
455
+ const descChild = getBinaryNodeChild(community, 'description')
321
456
 
322
457
  let desc
323
458
  let descId
324
459
 
325
460
  if (descChild) {
326
- desc = WABinary_1.getBinaryNodeChildString(descChild, 'body')
461
+ desc = getBinaryNodeChildString(descChild, 'body')
327
462
  descId = descChild.attrs.id
328
463
  }
329
464
 
330
465
  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'
466
+ const communityId = community.attrs.id.includes('@') ? community.attrs.id : jidEncode(community.attrs.id, 'g.us')
467
+ const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration
468
+ const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add'
334
469
 
335
470
  const metadata = {
336
471
  id: communityId,
337
- addressingMode: mode,
338
472
  subject: community.attrs.subject,
339
- subjectOwner: mode === 'lid' ? community.attrs.s_o_pn : community.attrs.s_o,
340
- subjectTime: +community.attrs.s_t,
341
- size: community.attrs?.size ? +community.attrs.size : WABinary_1.getBinaryNodeChildren(community, 'participant').length,
342
- creation: +community.attrs.creation,
343
- owner: community.attrs.creator ? WABinary_1.jidNormalizedUser(mode === 'lid' ? community.attrs.creator_pn : community.attrs.creator) : undefined,
473
+ subjectOwner: community.attrs.s_o,
474
+ subjectOwnerAlt: community.attrs?.s_o_pn ? community.attrs.s_o_pn : community.attrs.s_o,
475
+ subjectTime: Number(community.attrs.s_t || 0),
476
+ size: Number(community.attrs?.size ? community.attrs.size : getBinaryNodeChildren(community, 'participant').length),
477
+ creation: Number(community.attrs.creation || 0),
478
+ owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
479
+ ownerAlt: community.attrs.creator ? jidNormalizedUser(community.attrs?.creator_pn ? community.attrs.creator_pn : community.attrs.creator) : undefined,
480
+ ownerCountry: community.attrs.creator_country_code,
344
481
  desc,
345
482
  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'),
483
+ linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
484
+ restrict: !!getBinaryNodeChild(community, 'locked'),
485
+ announce: !!getBinaryNodeChild(community, 'announcement'),
486
+ isCommunity: !!getBinaryNodeChild(community, 'parent'),
487
+ isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_group'),
488
+ joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
352
489
  memberAddMode,
353
- participants: WABinary_1.getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
490
+ participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
354
491
  return {
355
- id: mode === 'lid' ? community.phone_number : attrs.jid,
356
- lid: mode === 'lid' ? community.jid : attrs.lid,
492
+ id: mode === WAMessageAddressingMode.LID ? community.phone_number : attrs.jid,
493
+ lid: mode === WAMessageAddressingMode.LID ? community.jid : attrs.lid,
357
494
  admin: (attrs.type || null),
358
495
  }
359
496
  }),
360
- ephemeralDuration: eph ? +eph : undefined,
497
+ ephemeralDuration: eph ? Number(ph) : undefined,
498
+ addressingMode: mode
361
499
  }
362
500
 
363
501
  return metadata