@vinzsocket/baileys 2.8.9 → 2.8.20

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 (83) hide show
  1. package/lib/Defaults/index.js +75 -73
  2. package/lib/Signal/Group/ciphertext-message.js +9 -9
  3. package/lib/Signal/Group/group-session-builder.js +21 -21
  4. package/lib/Signal/Group/group_cipher.js +79 -81
  5. package/lib/Signal/Group/index.js +2 -2
  6. package/lib/Signal/Group/keyhelper.js +9 -9
  7. package/lib/Signal/Group/queue-job.js +43 -46
  8. package/lib/Signal/Group/sender-chain-key.js +24 -25
  9. package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
  10. package/lib/Signal/Group/sender-key-message.js +55 -60
  11. package/lib/Signal/Group/sender-key-name.js +38 -39
  12. package/lib/Signal/Group/sender-key-record.js +39 -41
  13. package/lib/Signal/Group/sender-key-state.js +85 -89
  14. package/lib/Signal/Group/sender-message-key.js +22 -22
  15. package/lib/Signal/libsignal.js +387 -292
  16. package/lib/Signal/lid-mapping.js +98 -93
  17. package/lib/Socket/Client/types.js +6 -6
  18. package/lib/Socket/Client/websocket.js +44 -44
  19. package/lib/Socket/business.js +350 -365
  20. package/lib/Socket/chats.js +1019 -914
  21. package/lib/Socket/communities.js +454 -376
  22. package/lib/Socket/groups.js +378 -310
  23. package/lib/Socket/index.js +11 -11
  24. package/lib/Socket/messages-recv.js +1355 -1182
  25. package/lib/Socket/messages-send.js +1224 -1081
  26. package/lib/Socket/mex.js +40 -34
  27. package/lib/Socket/newsletter.js +212 -169
  28. package/lib/Socket/socket.js +896 -757
  29. package/lib/Store/index.js +1 -1
  30. package/lib/Store/make-cache-manager-store.js +75 -79
  31. package/lib/Store/make-in-memory-store.js +450 -389
  32. package/lib/Store/make-ordered-dictionary.js +73 -76
  33. package/lib/Store/object-repository.js +24 -22
  34. package/lib/Types/Chat.js +1 -7
  35. package/lib/Types/Label.js +20 -20
  36. package/lib/Types/LabelAssociation.js +2 -2
  37. package/lib/Types/Message.js +2 -2
  38. package/lib/Types/Newsletter.js +24 -24
  39. package/lib/Types/Socket.js +1 -1
  40. package/lib/Types/State.js +8 -8
  41. package/lib/Types/index.js +10 -10
  42. package/lib/Utils/auth-utils.js +408 -401
  43. package/lib/Utils/baileys-event-stream.js +44 -35
  44. package/lib/Utils/business.js +200 -197
  45. package/lib/Utils/chat-utils.js +775 -708
  46. package/lib/Utils/crypto.js +97 -85
  47. package/lib/Utils/decode-wa-message.js +240 -227
  48. package/lib/Utils/event-buffer.js +547 -518
  49. package/lib/Utils/extended-messages.js +250 -203
  50. package/lib/Utils/generics.js +300 -289
  51. package/lib/Utils/history.js +76 -69
  52. package/lib/Utils/lid-resolver.js +47 -42
  53. package/lib/Utils/link-preview.js +75 -65
  54. package/lib/Utils/logger.js +3 -1
  55. package/lib/Utils/lt-hash.js +38 -34
  56. package/lib/Utils/make-mutex.js +32 -34
  57. package/lib/Utils/mention.js +79 -86
  58. package/lib/Utils/message-retry-manager.js +148 -136
  59. package/lib/Utils/messages-media.js +652 -562
  60. package/lib/Utils/messages.js +753 -707
  61. package/lib/Utils/noise-handler.js +156 -135
  62. package/lib/Utils/process-message.js +404 -341
  63. package/lib/Utils/signal.js +180 -118
  64. package/lib/Utils/use-multi-file-auth-state.js +87 -91
  65. package/lib/Utils/validate-connection.js +167 -142
  66. package/lib/WABinary/constants.js +28 -1293
  67. package/lib/WABinary/decode.js +220 -218
  68. package/lib/WABinary/encode.js +199 -201
  69. package/lib/WABinary/generic-utils.js +80 -77
  70. package/lib/WABinary/jid-utils.js +41 -35
  71. package/lib/WAM/BinaryInfo.js +7 -7
  72. package/lib/WAM/constants.js +1 -15241
  73. package/lib/WAM/encode.js +124 -131
  74. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
  76. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
  77. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
  78. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
  81. package/lib/WAUSync/USyncQuery.js +82 -84
  82. package/lib/WAUSync/USyncUser.js +20 -20
  83. package/package.json +4 -1
@@ -4,324 +4,392 @@ import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
4
4
  import { feedGroupMetadata } from '../Utils/lid-resolver.js';
5
5
  import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
6
6
  import { makeChatsSocket } from './chats.js';
7
- export const makeGroupsSocket = (config) => {
8
- const sock = makeChatsSocket(config);
9
- const { authState, ev, query, upsertMessage } = sock;
10
- const groupQuery = async (jid, type, content) => query({
11
- tag: 'iq',
7
+ export const makeGroupsSocket = config => {
8
+ const sock = makeChatsSocket(config);
9
+ const {
10
+ authState,
11
+ ev,
12
+ query,
13
+ upsertMessage
14
+ } = sock;
15
+ const groupQuery = async (jid, type, content) => query({
16
+ tag: 'iq',
17
+ attrs: {
18
+ type,
19
+ xmlns: 'w:g2',
20
+ to: jid
21
+ },
22
+ content
23
+ });
24
+ const groupMetadata = async jid => {
25
+ const result = await groupQuery(jid, 'get', [{
26
+ tag: 'query',
27
+ attrs: {
28
+ request: 'interactive'
29
+ }
30
+ }]);
31
+ return extractGroupMetadata(result);
32
+ };
33
+ const groupFetchAllParticipating = async () => {
34
+ const result = await query({
35
+ tag: 'iq',
36
+ attrs: {
37
+ to: '@g.us',
38
+ xmlns: 'w:g2',
39
+ type: 'get'
40
+ },
41
+ content: [{
42
+ tag: 'participating',
43
+ attrs: {},
44
+ content: [{
45
+ tag: 'participants',
46
+ attrs: {}
47
+ }, {
48
+ tag: 'description',
49
+ attrs: {}
50
+ }]
51
+ }]
52
+ });
53
+ const data = {};
54
+ const groupsChild = getBinaryNodeChild(result, 'groups');
55
+ if (groupsChild) {
56
+ const groups = getBinaryNodeChildren(groupsChild, 'group');
57
+ for (const groupNode of groups) {
58
+ const meta = extractGroupMetadata({
59
+ tag: 'result',
60
+ attrs: {},
61
+ content: [groupNode]
62
+ });
63
+ data[meta.id] = meta;
64
+ }
65
+ }
66
+ sock.ev.emit('groups.update', Object.values(data));
67
+ return data;
68
+ };
69
+ sock.ws.on('CB:ib,,dirty', async node => {
70
+ const {
71
+ attrs
72
+ } = getBinaryNodeChild(node, 'dirty');
73
+ if (attrs.type !== 'groups') {
74
+ return;
75
+ }
76
+ await groupFetchAllParticipating();
77
+ await sock.cleanDirtyBits('groups');
78
+ });
79
+ return {
80
+ ...sock,
81
+ groupMetadata,
82
+ groupCreate: async (subject, participants) => {
83
+ const key = generateMessageIDV2();
84
+ const result = await groupQuery('@g.us', 'set', [{
85
+ tag: 'create',
12
86
  attrs: {
13
- type,
14
- xmlns: 'w:g2',
15
- to: jid
87
+ subject,
88
+ key
16
89
  },
17
- content
18
- });
19
- const groupMetadata = async (jid) => {
20
- const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
21
- return extractGroupMetadata(result);
22
- };
23
- const groupFetchAllParticipating = async () => {
24
- const result = await query({
25
- tag: 'iq',
90
+ content: participants.map(jid => ({
91
+ tag: 'participant',
92
+ attrs: {
93
+ jid
94
+ }
95
+ }))
96
+ }]);
97
+ return extractGroupMetadata(result);
98
+ },
99
+ groupLeave: async id => {
100
+ await groupQuery('@g.us', 'set', [{
101
+ tag: 'leave',
102
+ attrs: {},
103
+ content: [{
104
+ tag: 'group',
105
+ attrs: {
106
+ id
107
+ }
108
+ }]
109
+ }]);
110
+ },
111
+ groupUpdateSubject: async (jid, subject) => {
112
+ await groupQuery(jid, 'set', [{
113
+ tag: 'subject',
114
+ attrs: {},
115
+ content: Buffer.from(subject, 'utf-8')
116
+ }]);
117
+ },
118
+ groupRequestParticipantsList: async jid => {
119
+ const result = await groupQuery(jid, 'get', [{
120
+ tag: 'membership_approval_requests',
121
+ attrs: {}
122
+ }]);
123
+ const node = getBinaryNodeChild(result, 'membership_approval_requests');
124
+ const participants = getBinaryNodeChildren(node, 'membership_approval_request');
125
+ return participants.map(v => v.attrs);
126
+ },
127
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
128
+ const result = await groupQuery(jid, 'set', [{
129
+ tag: 'membership_requests_action',
130
+ attrs: {},
131
+ content: [{
132
+ tag: action,
133
+ attrs: {},
134
+ content: participants.map(jid => ({
135
+ tag: 'participant',
26
136
  attrs: {
27
- to: '@g.us',
28
- xmlns: 'w:g2',
29
- type: 'get'
30
- },
31
- content: [
32
- {
33
- tag: 'participating',
34
- attrs: {},
35
- content: [
36
- { tag: 'participants', attrs: {} },
37
- { tag: 'description', attrs: {} }
38
- ]
39
- }
40
- ]
41
- });
42
- const data = {};
43
- const groupsChild = getBinaryNodeChild(result, 'groups');
44
- if (groupsChild) {
45
- const groups = getBinaryNodeChildren(groupsChild, 'group');
46
- for (const groupNode of groups) {
47
- const meta = extractGroupMetadata({
48
- tag: 'result',
49
- attrs: {},
50
- content: [groupNode]
51
- });
52
- data[meta.id] = meta;
137
+ jid
53
138
  }
139
+ }))
140
+ }]
141
+ }]);
142
+ const node = getBinaryNodeChild(result, 'membership_requests_action');
143
+ const nodeAction = getBinaryNodeChild(node, action);
144
+ const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
145
+ return participantsAffected.map(p => {
146
+ return {
147
+ status: p.attrs.error || '200',
148
+ jid: p.attrs.jid
149
+ };
150
+ });
151
+ },
152
+ groupParticipantsUpdate: async (jid, participants, action) => {
153
+ const result = await groupQuery(jid, 'set', [{
154
+ tag: action,
155
+ attrs: {},
156
+ content: participants.map(jid => ({
157
+ tag: 'participant',
158
+ attrs: {
159
+ jid
160
+ }
161
+ }))
162
+ }]);
163
+ const node = getBinaryNodeChild(result, action);
164
+ const participantsAffected = getBinaryNodeChildren(node, 'participant');
165
+ return participantsAffected.map(p => {
166
+ return {
167
+ status: p.attrs.error || '200',
168
+ jid: p.attrs.jid,
169
+ content: p
170
+ };
171
+ });
172
+ },
173
+ groupUpdateDescription: async (jid, description) => {
174
+ const metadata = await groupMetadata(jid);
175
+ const prev = metadata.descId ?? null;
176
+ await groupQuery(jid, 'set', [{
177
+ tag: 'description',
178
+ attrs: {
179
+ ...(description ? {
180
+ id: generateMessageIDV2()
181
+ } : {
182
+ delete: 'true'
183
+ }),
184
+ ...(prev ? {
185
+ prev
186
+ } : {})
187
+ },
188
+ content: description ? [{
189
+ tag: 'body',
190
+ attrs: {},
191
+ content: Buffer.from(description, 'utf-8')
192
+ }] : undefined
193
+ }]);
194
+ },
195
+ groupInviteCode: async jid => {
196
+ const result = await groupQuery(jid, 'get', [{
197
+ tag: 'invite',
198
+ attrs: {}
199
+ }]);
200
+ const inviteNode = getBinaryNodeChild(result, 'invite');
201
+ return inviteNode?.attrs.code;
202
+ },
203
+ groupRevokeInvite: async jid => {
204
+ const result = await groupQuery(jid, 'set', [{
205
+ tag: 'invite',
206
+ attrs: {}
207
+ }]);
208
+ const inviteNode = getBinaryNodeChild(result, 'invite');
209
+ return inviteNode?.attrs.code;
210
+ },
211
+ groupAcceptInvite: async code => {
212
+ const results = await groupQuery('@g.us', 'set', [{
213
+ tag: 'invite',
214
+ attrs: {
215
+ code
54
216
  }
55
- sock.ev.emit('groups.update', Object.values(data));
56
- return data;
57
- };
58
- sock.ws.on('CB:ib,,dirty', async (node) => {
59
- const { attrs } = getBinaryNodeChild(node, 'dirty');
60
- if (attrs.type !== 'groups') {
61
- return;
217
+ }]);
218
+ const result = getBinaryNodeChild(results, 'group');
219
+ return result?.attrs.jid;
220
+ },
221
+ /**
222
+ * revoke a v4 invite for someone
223
+ * @param groupJid group jid
224
+ * @param invitedJid jid of person you invited
225
+ * @returns true if successful
226
+ */
227
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
228
+ const result = await groupQuery(groupJid, 'set', [{
229
+ tag: 'revoke',
230
+ attrs: {},
231
+ content: [{
232
+ tag: 'participant',
233
+ attrs: {
234
+ jid: invitedJid
235
+ }
236
+ }]
237
+ }]);
238
+ return !!result;
239
+ },
240
+ /**
241
+ * accept a GroupInviteMessage
242
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
243
+ * @param inviteMessage the message to accept
244
+ */
245
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
246
+ key = typeof key === 'string' ? {
247
+ remoteJid: key
248
+ } : key;
249
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [{
250
+ tag: 'accept',
251
+ attrs: {
252
+ code: inviteMessage.inviteCode,
253
+ expiration: inviteMessage.inviteExpiration.toString(),
254
+ admin: key.remoteJid
62
255
  }
63
- await groupFetchAllParticipating();
64
- await sock.cleanDirtyBits('groups');
65
- });
66
- return {
67
- ...sock,
68
- groupMetadata,
69
- groupCreate: async (subject, participants) => {
70
- const key = generateMessageIDV2();
71
- const result = await groupQuery('@g.us', 'set', [
72
- {
73
- tag: 'create',
74
- attrs: {
75
- subject,
76
- key
77
- },
78
- content: participants.map(jid => ({
79
- tag: 'participant',
80
- attrs: { jid }
81
- }))
82
- }
83
- ]);
84
- return extractGroupMetadata(result);
85
- },
86
- groupLeave: async (id) => {
87
- await groupQuery('@g.us', 'set', [
88
- {
89
- tag: 'leave',
90
- attrs: {},
91
- content: [{ tag: 'group', attrs: { id } }]
92
- }
93
- ]);
94
- },
95
- groupUpdateSubject: async (jid, subject) => {
96
- await groupQuery(jid, 'set', [
97
- {
98
- tag: 'subject',
99
- attrs: {},
100
- content: Buffer.from(subject, 'utf-8')
101
- }
102
- ]);
103
- },
104
- groupRequestParticipantsList: async (jid) => {
105
- const result = await groupQuery(jid, 'get', [
106
- {
107
- tag: 'membership_approval_requests',
108
- attrs: {}
109
- }
110
- ]);
111
- const node = getBinaryNodeChild(result, 'membership_approval_requests');
112
- const participants = getBinaryNodeChildren(node, 'membership_approval_request');
113
- return participants.map(v => v.attrs);
114
- },
115
- groupRequestParticipantsUpdate: async (jid, participants, action) => {
116
- const result = await groupQuery(jid, 'set', [
117
- {
118
- tag: 'membership_requests_action',
119
- attrs: {},
120
- content: [
121
- {
122
- tag: action,
123
- attrs: {},
124
- content: participants.map(jid => ({
125
- tag: 'participant',
126
- attrs: { jid }
127
- }))
128
- }
129
- ]
130
- }
131
- ]);
132
- const node = getBinaryNodeChild(result, 'membership_requests_action');
133
- const nodeAction = getBinaryNodeChild(node, action);
134
- const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
135
- return participantsAffected.map(p => {
136
- return { status: p.attrs.error || '200', jid: p.attrs.jid };
137
- });
138
- },
139
- groupParticipantsUpdate: async (jid, participants, action) => {
140
- const result = await groupQuery(jid, 'set', [
141
- {
142
- tag: action,
143
- attrs: {},
144
- content: participants.map(jid => ({
145
- tag: 'participant',
146
- attrs: { jid }
147
- }))
148
- }
149
- ]);
150
- const node = getBinaryNodeChild(result, action);
151
- const participantsAffected = getBinaryNodeChildren(node, 'participant');
152
- return participantsAffected.map(p => {
153
- return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
154
- });
155
- },
156
- groupUpdateDescription: async (jid, description) => {
157
- const metadata = await groupMetadata(jid);
158
- const prev = metadata.descId ?? null;
159
- await groupQuery(jid, 'set', [
160
- {
161
- tag: 'description',
162
- attrs: {
163
- ...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
164
- ...(prev ? { prev } : {})
165
- },
166
- content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
167
- }
168
- ]);
169
- },
170
- groupInviteCode: async (jid) => {
171
- const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
172
- const inviteNode = getBinaryNodeChild(result, 'invite');
173
- return inviteNode?.attrs.code;
174
- },
175
- groupRevokeInvite: async (jid) => {
176
- const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
177
- const inviteNode = getBinaryNodeChild(result, 'invite');
178
- return inviteNode?.attrs.code;
179
- },
180
- groupAcceptInvite: async (code) => {
181
- const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
182
- const result = getBinaryNodeChild(results, 'group');
183
- return result?.attrs.jid;
184
- },
185
- /**
186
- * revoke a v4 invite for someone
187
- * @param groupJid group jid
188
- * @param invitedJid jid of person you invited
189
- * @returns true if successful
190
- */
191
- groupRevokeInviteV4: async (groupJid, invitedJid) => {
192
- const result = await groupQuery(groupJid, 'set', [
193
- { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
194
- ]);
195
- return !!result;
196
- },
197
- /**
198
- * accept a GroupInviteMessage
199
- * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
200
- * @param inviteMessage the message to accept
201
- */
202
- groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
203
- key = typeof key === 'string' ? { remoteJid: key } : key;
204
- const results = await groupQuery(inviteMessage.groupJid, 'set', [
205
- {
206
- tag: 'accept',
207
- attrs: {
208
- code: inviteMessage.inviteCode,
209
- expiration: inviteMessage.inviteExpiration.toString(),
210
- admin: key.remoteJid
211
- }
212
- }
213
- ]);
214
- // if we have the full message key
215
- // update the invite message to be expired
216
- if (key.id) {
217
- // create new invite message that is expired
218
- inviteMessage = proto.Message.GroupInviteMessage.create(inviteMessage);
219
- inviteMessage.inviteExpiration = 0;
220
- inviteMessage.inviteCode = '';
221
- ev.emit('messages.update', [
222
- {
223
- key,
224
- update: {
225
- message: {
226
- groupInviteMessage: inviteMessage
227
- }
228
- }
229
- }
230
- ]);
256
+ }]);
257
+ // if we have the full message key
258
+ // update the invite message to be expired
259
+ if (key.id) {
260
+ // create new invite message that is expired
261
+ inviteMessage = proto.Message.GroupInviteMessage.create(inviteMessage);
262
+ inviteMessage.inviteExpiration = 0;
263
+ inviteMessage.inviteCode = '';
264
+ ev.emit('messages.update', [{
265
+ key,
266
+ update: {
267
+ message: {
268
+ groupInviteMessage: inviteMessage
231
269
  }
232
- // generate the group add message
233
- await upsertMessage({
234
- key: {
235
- remoteJid: inviteMessage.groupJid,
236
- id: generateMessageIDV2(sock.user?.id),
237
- fromMe: false,
238
- participant: key.remoteJid
239
- },
240
- messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
241
- messageStubParameters: [authState.creds.me.id],
242
- participant: key.remoteJid,
243
- messageTimestamp: unixTimestampSeconds()
244
- }, 'notify');
245
- return results.attrs.from;
246
- }),
247
- groupGetInviteInfo: async (code) => {
248
- const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
249
- return extractGroupMetadata(results);
250
- },
251
- groupToggleEphemeral: async (jid, ephemeralExpiration) => {
252
- const content = ephemeralExpiration
253
- ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
254
- : { tag: 'not_ephemeral', attrs: {} };
255
- await groupQuery(jid, 'set', [content]);
256
- },
257
- groupSettingUpdate: async (jid, setting) => {
258
- await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
270
+ }
271
+ }]);
272
+ }
273
+ // generate the group add message
274
+ await upsertMessage({
275
+ key: {
276
+ remoteJid: inviteMessage.groupJid,
277
+ id: generateMessageIDV2(sock.user?.id),
278
+ fromMe: false,
279
+ participant: key.remoteJid
259
280
  },
260
- groupMemberAddMode: async (jid, mode) => {
261
- await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
262
- },
263
- groupJoinApprovalMode: async (jid, mode) => {
264
- await groupQuery(jid, 'set', [
265
- { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
266
- ]);
267
- },
268
- groupFetchAllParticipating
269
- };
281
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
282
+ messageStubParameters: [authState.creds.me.id],
283
+ participant: key.remoteJid,
284
+ messageTimestamp: unixTimestampSeconds()
285
+ }, 'notify');
286
+ return results.attrs.from;
287
+ }),
288
+ groupGetInviteInfo: async code => {
289
+ const results = await groupQuery('@g.us', 'get', [{
290
+ tag: 'invite',
291
+ attrs: {
292
+ code
293
+ }
294
+ }]);
295
+ return extractGroupMetadata(results);
296
+ },
297
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
298
+ const content = ephemeralExpiration ? {
299
+ tag: 'ephemeral',
300
+ attrs: {
301
+ expiration: ephemeralExpiration.toString()
302
+ }
303
+ } : {
304
+ tag: 'not_ephemeral',
305
+ attrs: {}
306
+ };
307
+ await groupQuery(jid, 'set', [content]);
308
+ },
309
+ groupSettingUpdate: async (jid, setting) => {
310
+ await groupQuery(jid, 'set', [{
311
+ tag: setting,
312
+ attrs: {}
313
+ }]);
314
+ },
315
+ groupMemberAddMode: async (jid, mode) => {
316
+ await groupQuery(jid, 'set', [{
317
+ tag: 'member_add_mode',
318
+ attrs: {},
319
+ content: mode
320
+ }]);
321
+ },
322
+ groupJoinApprovalMode: async (jid, mode) => {
323
+ await groupQuery(jid, 'set', [{
324
+ tag: 'membership_approval_mode',
325
+ attrs: {},
326
+ content: [{
327
+ tag: 'group_join',
328
+ attrs: {
329
+ state: mode
330
+ }
331
+ }]
332
+ }]);
333
+ },
334
+ groupFetchAllParticipating
335
+ };
270
336
  };
271
- export const extractGroupMetadata = (result) => {
272
- const group = getBinaryNodeChild(result, 'group');
273
- const descChild = getBinaryNodeChild(group, 'description');
274
- let desc;
275
- let descId;
276
- let descOwner;
277
- let descOwnerPn;
278
- let descTime;
279
- if (descChild) {
280
- desc = getBinaryNodeChildString(descChild, 'body');
281
- descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
282
- descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
283
- descTime = +descChild.attrs.t;
284
- descId = descChild.attrs.id;
285
- }
286
- const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
287
- const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
288
- const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
289
- const metadata = {
290
- id: groupId,
291
- notify: group.attrs.notify,
292
- addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
293
- subject: group.attrs.subject,
294
- subjectOwner: group.attrs.s_o,
295
- subjectOwnerPn: group.attrs.s_o_pn,
296
- subjectTime: +group.attrs.s_t,
297
- size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
298
- creation: +group.attrs.creation,
299
- owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
300
- ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
301
- owner_country_code: group.attrs.creator_country_code,
302
- desc,
303
- descId,
304
- descOwner,
305
- descOwnerPn,
306
- descTime,
307
- linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
308
- restrict: !!getBinaryNodeChild(group, 'locked'),
309
- announce: !!getBinaryNodeChild(group, 'announcement'),
310
- isCommunity: !!getBinaryNodeChild(group, 'parent'),
311
- isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
312
- joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
313
- memberAddMode,
314
- participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
315
- return {
316
- id: attrs.jid,
317
- phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phoneNumber) ? attrs.phoneNumber : undefined,
318
- lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
319
- admin: (attrs.type || null)
320
- };
321
- }),
322
- ephemeralDuration: eph ? +eph : undefined
323
- };
324
- feedGroupMetadata(metadata);
325
- return metadata;
337
+ export const extractGroupMetadata = result => {
338
+ const group = getBinaryNodeChild(result, 'group');
339
+ const descChild = getBinaryNodeChild(group, 'description');
340
+ let desc;
341
+ let descId;
342
+ let descOwner;
343
+ let descOwnerPn;
344
+ let descTime;
345
+ if (descChild) {
346
+ desc = getBinaryNodeChildString(descChild, 'body');
347
+ descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
348
+ descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
349
+ descTime = +descChild.attrs.t;
350
+ descId = descChild.attrs.id;
351
+ }
352
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
353
+ const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
354
+ const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
355
+ const metadata = {
356
+ id: groupId,
357
+ notify: group.attrs.notify,
358
+ addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
359
+ subject: group.attrs.subject,
360
+ subjectOwner: group.attrs.s_o,
361
+ subjectOwnerPn: group.attrs.s_o_pn,
362
+ subjectTime: +group.attrs.s_t,
363
+ size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
364
+ creation: +group.attrs.creation,
365
+ owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
366
+ ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
367
+ owner_country_code: group.attrs.creator_country_code,
368
+ desc,
369
+ descId,
370
+ descOwner,
371
+ descOwnerPn,
372
+ descTime,
373
+ linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
374
+ restrict: !!getBinaryNodeChild(group, 'locked'),
375
+ announce: !!getBinaryNodeChild(group, 'announcement'),
376
+ isCommunity: !!getBinaryNodeChild(group, 'parent'),
377
+ isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
378
+ joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
379
+ memberAddMode,
380
+ participants: getBinaryNodeChildren(group, 'participant').map(({
381
+ attrs
382
+ }) => {
383
+ return {
384
+ id: attrs.jid,
385
+ phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phoneNumber) ? attrs.phoneNumber : undefined,
386
+ lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
387
+ admin: attrs.type || null
388
+ };
389
+ }),
390
+ ephemeralDuration: eph ? +eph : undefined
391
+ };
392
+ feedGroupMetadata(metadata);
393
+ return metadata;
326
394
  };
327
395
  //# sourceMappingURL=groups.js.map