@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.
- package/README.md +247 -203
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +62 -0
- package/lib/Defaults/history.js +17 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +4 -4
- package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -7
- package/lib/Signal/Group/sender-key-state.js +4 -4
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +45 -69
- package/lib/Signal/lid-mapping.js +15 -11
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +16 -14
- package/lib/Socket/business.js +41 -32
- package/lib/Socket/chats.js +123 -98
- package/lib/Socket/community.js +50 -40
- package/lib/Socket/groups.js +59 -47
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +219 -172
- package/lib/Socket/messages-send.js +187 -143
- package/lib/Socket/newsletter.js +61 -47
- package/lib/Socket/socket.js +133 -90
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -5
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +28 -26
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +81 -71
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +319 -311
- package/lib/Utils/event-buffer.js +21 -22
- package/lib/Utils/generics.js +65 -82
- package/lib/Utils/history.js +21 -21
- package/lib/Utils/index.js +27 -13
- package/lib/Utils/link-preview.js +7 -30
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/messages-media.js +104 -109
- package/lib/Utils/messages.js +203 -171
- package/lib/Utils/noise-handler.js +28 -19
- package/lib/Utils/process-message.js +111 -96
- package/lib/Utils/signal.js +36 -25
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +52 -45
- package/lib/WABinary/decode.js +6 -32
- package/lib/WABinary/encode.js +3 -29
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WAM/encode.js +16 -8
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +17 -10
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +8 -14
- package/WAProto/AICommon/AICommon.d.ts +0 -11702
- package/WAProto/Adv/Adv.d.ts +0 -643
- package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
- package/WAProto/Cert/Cert.d.ts +0 -613
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
- package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
- package/WAProto/E2E/E2E.d.ts +0 -41724
- package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
- package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
- package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
- package/WAProto/Protocol/Protocol.d.ts +0 -270
- package/WAProto/Reporting/Reporting.d.ts +0 -371
- package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
- package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
- package/WAProto/UserPassword/UserPassword.d.ts +0 -363
- package/WAProto/VnameCert/VnameCert.d.ts +0 -821
- package/WAProto/Wa6/Wa6.d.ts +0 -2128
- package/WAProto/Web/Web.d.ts +0 -46383
- package/WAProto/index.d.ts +0 -55
- package/lib/Defaults/index.d.ts +0 -77
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts +0 -19
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -16
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -19
- package/lib/Signal/Group/sender-key-record.d.ts +0 -32
- package/lib/Signal/Group/sender-key-state.d.ts +0 -44
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -187
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/community.d.ts +0 -129
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -80
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/generics.d.ts +0 -117
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/signal.d.ts +0 -42
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -13
package/lib/Socket/community.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
"use strict"
|
|
2
|
+
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
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 =
|
|
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 =
|
|
60
|
+
const communitiesChild = getBinaryNodeChild(result, 'communities')
|
|
51
61
|
|
|
52
62
|
if (communitiesChild) {
|
|
53
|
-
const communities =
|
|
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 } =
|
|
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 =
|
|
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 =
|
|
149
|
-
const participants =
|
|
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 =
|
|
170
|
-
const nodeAction =
|
|
171
|
-
const participantsAffected =
|
|
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 =
|
|
189
|
-
const participantsAffected =
|
|
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:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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:
|
|
290
|
+
id: generateMessageID(authState.creds.me?.id),
|
|
281
291
|
fromMe: false,
|
|
282
292
|
participant: key.remoteJid,
|
|
283
293
|
},
|
|
284
|
-
messageStubType:
|
|
294
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
285
295
|
messageStubParameters: [
|
|
286
296
|
authState.creds.me.id
|
|
287
297
|
],
|
|
288
298
|
participant: key.remoteJid,
|
|
289
|
-
messageTimestamp:
|
|
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 =
|
|
320
|
-
const descChild =
|
|
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 =
|
|
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 :
|
|
332
|
-
const eph =
|
|
333
|
-
const memberAddMode =
|
|
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 :
|
|
351
|
+
size: community.attrs?.size ? +community.attrs.size : getBinaryNodeChildren(community, 'participant').length,
|
|
342
352
|
creation: +community.attrs.creation,
|
|
343
|
-
owner: community.attrs.creator ?
|
|
353
|
+
owner: community.attrs.creator ? jidNormalizedUser(mode === 'lid' ? community.attrs.creator_pn : community.attrs.creator) : undefined,
|
|
344
354
|
desc,
|
|
345
355
|
descId,
|
|
346
|
-
linkedParent:
|
|
347
|
-
restrict: !!
|
|
348
|
-
announce: !!
|
|
349
|
-
isCommunity: !!
|
|
350
|
-
isCommunityAnnounce: !!
|
|
351
|
-
joinApprovalMode: !!
|
|
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:
|
|
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,
|
package/lib/Socket/groups.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 =
|
|
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 =
|
|
62
|
+
const groupsChild = getBinaryNodeChild(result, 'groups')
|
|
51
63
|
|
|
52
64
|
if (groupsChild) {
|
|
53
|
-
const groups =
|
|
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 } =
|
|
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 =
|
|
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 =
|
|
130
|
-
const participants =
|
|
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 =
|
|
151
|
-
const nodeAction =
|
|
152
|
-
const participantsAffected =
|
|
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 =
|
|
170
|
-
const participantsAffected =
|
|
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:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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:
|
|
273
|
+
id: generateMessageID(authState.creds.me?.id),
|
|
262
274
|
fromMe: false,
|
|
263
275
|
participant: key.remoteJid,
|
|
264
276
|
},
|
|
265
|
-
messageStubType:
|
|
277
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
266
278
|
messageStubParameters: [
|
|
267
279
|
authState.creds.me.id
|
|
268
280
|
],
|
|
269
281
|
participant: key.remoteJid,
|
|
270
|
-
messageTimestamp:
|
|
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 =
|
|
301
|
-
const descChild =
|
|
302
|
-
const mode = group.attrs.addressing_mode === 'lid' ?
|
|
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 =
|
|
322
|
+
desc = getBinaryNodeChildString(descChild, 'body')
|
|
311
323
|
descId = descChild.attrs.id
|
|
312
|
-
descOwner = mode ===
|
|
313
|
-
descOwnerLid = mode ===
|
|
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 :
|
|
317
|
-
const eph =
|
|
318
|
-
const memberAddMode =
|
|
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 ===
|
|
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 :
|
|
339
|
+
size: group.attrs?.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
|
|
328
340
|
creation: +group.attrs.creation,
|
|
329
|
-
owner: group.attrs.creator ?
|
|
330
|
-
ownerLid: group.attrs.creator ?
|
|
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:
|
|
337
|
-
restrict: !!
|
|
338
|
-
announce: !!
|
|
339
|
-
isCommunity: !!
|
|
340
|
-
isCommunityAnnounce: !!
|
|
341
|
-
joinApprovalMode: !!
|
|
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:
|
|
355
|
+
participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
|
|
344
356
|
return {
|
|
345
|
-
id: mode ===
|
|
346
|
-
lid: mode ===
|
|
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
|
}),
|
package/lib/Socket/index.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
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
|
-
...
|
|
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
|
|
21
|
+
return makeCommunitiesSocket(newConfig)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
exports.default = makeWASocket
|