@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.
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +74 -0
- package/lib/Defaults/history.js +19 -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 +5 -18
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.js +15 -61
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +237 -177
- package/lib/Signal/lid-mapping.js +128 -71
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +25 -16
- package/lib/Socket/business.js +46 -33
- package/lib/Socket/chats.js +286 -170
- package/lib/Socket/community.js +215 -77
- package/lib/Socket/groups.js +77 -61
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +629 -457
- package/lib/Socket/messages-send.js +645 -656
- package/lib/Socket/mex.js +61 -0
- package/lib/Socket/newsletter.js +166 -245
- package/lib/Socket/socket.js +396 -170
- 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/Newsletter.js +32 -25
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +212 -375
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/browser-utils.js +43 -0
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +241 -106
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +361 -311
- package/lib/Utils/event-buffer.js +97 -42
- package/lib/Utils/generics.js +90 -207
- package/lib/Utils/history.js +29 -27
- package/lib/Utils/index.js +28 -14
- package/lib/Utils/link-preview.js +24 -62
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +29 -23
- package/lib/Utils/make-mutex.js +26 -28
- package/lib/Utils/message-retry-manager.js +55 -7
- package/lib/Utils/messages-media.js +434 -247
- package/lib/Utils/messages.js +963 -917
- package/lib/Utils/noise-handler.js +60 -20
- package/lib/Utils/pre-key-manager.js +126 -0
- package/lib/Utils/process-message.js +216 -141
- package/lib/Utils/signal.js +75 -37
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +96 -66
- package/lib/WABinary/constants.js +1268 -1268
- package/lib/WABinary/decode.js +62 -34
- package/lib/WABinary/encode.js +57 -36
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WABinary/jid-utils.js +58 -11
- package/lib/WAM/constants.js +19064 -11563
- package/lib/WAM/encode.js +71 -14
- 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 +51 -28
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +12 -17
- 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/Socket/usync.js +0 -83
- 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,15 +1,36 @@
|
|
|
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 { 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 =
|
|
12
|
-
const {
|
|
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 =
|
|
71
|
+
const communitiesChild = getBinaryNodeChild(result, 'communities')
|
|
51
72
|
|
|
52
73
|
if (communitiesChild) {
|
|
53
|
-
const communities =
|
|
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 } =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
149
|
-
const participants =
|
|
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
|
-
|
|
170
|
-
const
|
|
171
|
-
const
|
|
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
|
-
|
|
189
|
-
const
|
|
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
|
|
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:
|
|
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 =
|
|
344
|
+
const inviteNode = getBinaryNodeChild(result, 'invite')
|
|
215
345
|
|
|
216
|
-
return inviteNode?.attrs
|
|
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 =
|
|
350
|
+
const inviteNode = getBinaryNodeChild(result, 'invite')
|
|
221
351
|
|
|
222
|
-
return inviteNode?.attrs
|
|
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 =
|
|
356
|
+
const result = getBinaryNodeChild(results, 'community')
|
|
227
357
|
|
|
228
|
-
return result?.attrs
|
|
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', [
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
|
411
|
+
// generate the community add message
|
|
277
412
|
await upsertMessage({
|
|
278
413
|
key: {
|
|
279
414
|
remoteJid: inviteMessage.groupJid,
|
|
280
|
-
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:
|
|
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:
|
|
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', [
|
|
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 =
|
|
320
|
-
const descChild =
|
|
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 =
|
|
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 :
|
|
332
|
-
const eph =
|
|
333
|
-
const memberAddMode =
|
|
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:
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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:
|
|
347
|
-
restrict: !!
|
|
348
|
-
announce: !!
|
|
349
|
-
isCommunity: !!
|
|
350
|
-
isCommunityAnnounce: !!
|
|
351
|
-
joinApprovalMode: !!
|
|
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:
|
|
490
|
+
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
|
|
354
491
|
return {
|
|
355
|
-
id: mode ===
|
|
356
|
-
lid: mode ===
|
|
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 ?
|
|
497
|
+
ephemeralDuration: eph ? Number(ph) : undefined,
|
|
498
|
+
addressingMode: mode
|
|
361
499
|
}
|
|
362
500
|
|
|
363
501
|
return metadata
|