@zervonexx/baileys 5.0.0 → 5.0.2
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/LICENSE +22 -22
- package/README.md +4124 -4112
- package/WAProto/WAProto.json +1 -0
- package/WAProto/WAProto.proto +7160 -0
- package/WAProto/WAProtoCompile.js +264 -322
- package/WAProto/index.js +55 -95
- package/lib/Builders/AIRich.js +673 -673
- package/lib/Builders/auto.js +49 -49
- package/lib/Builders/base.js +144 -144
- package/lib/Builders/builders.js +588 -588
- package/lib/Builders/index.js +3 -3
- package/lib/Defaults/index.js +249 -248
- package/lib/Signal/index.js +2 -2
- package/lib/Signal/libsignal.js +526 -526
- package/lib/Signal/lid-mapping.js +282 -282
- package/lib/Socket/Client/index.js +1 -1
- package/lib/Socket/Client/types.js +9 -9
- package/lib/Socket/Client/websocket.js +83 -83
- package/lib/Socket/business.js +151 -151
- package/lib/Socket/chats.js +854 -854
- package/lib/Socket/communities.js +146 -146
- package/lib/Socket/groups.js +293 -293
- package/lib/Socket/index.js +17 -14
- package/lib/Socket/messages-recv.js +993 -993
- package/lib/Socket/messages-send.js +722 -722
- package/lib/Socket/mex.js +33 -33
- package/lib/Socket/newsletter.js +783 -783
- package/lib/Socket/registration.js +154 -154
- package/lib/Socket/socket.js +797 -797
- package/lib/Socket/spam-report.js +143 -143
- package/lib/Socket/username.js +81 -81
- package/lib/Socket/zervonex-handler.js +57 -57
- package/lib/Store/index.js +6 -6
- package/lib/Store/make-cache-manager-store.js +80 -80
- package/lib/Store/make-in-memory-store.js +426 -426
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- package/lib/Store/reporting-info-store.js +37 -37
- package/lib/Types/Auth.js +1 -1
- package/lib/Types/Bussines.js +1 -1
- package/lib/Types/Call.js +1 -1
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Contact.js +1 -1
- package/lib/Types/Events.js +1 -1
- package/lib/Types/GroupMetadata.js +1 -1
- package/lib/Types/Label.js +24 -24
- package/lib/Types/LabelAssociation.js +6 -6
- package/lib/Types/Message.js +14 -14
- package/lib/Types/Newsletter.js +99 -99
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +14 -14
- package/lib/Types/State.js +26 -26
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +30 -30
- package/lib/Utils/auth-utils.js +159 -159
- package/lib/Utils/baileys-event-stream.js +32 -32
- package/lib/Utils/bot-capabilities.js +40 -40
- package/lib/Utils/bot-planning-replay.js +43 -43
- package/lib/Utils/browser-utils.js +29 -29
- package/lib/Utils/business.js +74 -74
- package/lib/Utils/chat-utils.js +316 -316
- package/lib/Utils/companion-reg-client-utils.js +19 -19
- package/lib/Utils/consumer-application.js +37 -37
- package/lib/Utils/crypto.js +52 -52
- package/lib/Utils/cstoken.js +14 -14
- package/lib/Utils/decode-wa-message.js +199 -199
- package/lib/Utils/event-buffer.js +272 -272
- package/lib/Utils/extras.js +186 -186
- package/lib/Utils/generics.js +195 -194
- package/lib/Utils/history.js +50 -50
- package/lib/Utils/identity-change-handler.js +18 -18
- package/lib/Utils/index.js +40 -40
- package/lib/Utils/link-preview.js +50 -50
- package/lib/Utils/logger.js +3 -2
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/make-mutex.js +15 -15
- package/lib/Utils/message-composer.js +61 -61
- package/lib/Utils/message-retry-manager.js +47 -47
- package/lib/Utils/messages-media.js +501 -501
- package/lib/Utils/messages.js +944 -942
- package/lib/Utils/meta-ai-msmsg.js +121 -121
- package/lib/Utils/meta-compositing.js +74 -74
- package/lib/Utils/modern-messages.js +234 -234
- package/lib/Utils/native-flow.js +80 -80
- package/lib/Utils/noise-handler.js +160 -160
- package/lib/Utils/pre-key-manager.js +75 -75
- package/lib/Utils/process-message.js +400 -400
- package/lib/Utils/reporting-utils.js +170 -170
- package/lib/Utils/signal.js +166 -166
- package/lib/Utils/spam-report-utils.js +165 -165
- package/lib/Utils/sync-action-utils.js +33 -33
- package/lib/Utils/tc-token-utils.js +153 -153
- package/lib/Utils/use-keyv-auth-state.js +199 -199
- package/lib/Utils/use-multi-file-auth-state.js +83 -83
- package/lib/Utils/validate-connection.js +171 -171
- package/lib/WABinary/constants.js +1320 -1320
- package/lib/WABinary/decode.js +151 -151
- package/lib/WABinary/encode.js +139 -139
- package/lib/WABinary/generic-utils.js +202 -202
- package/lib/WABinary/index.js +6 -6
- package/lib/WABinary/jid-utils.js +235 -235
- package/lib/WABinary/types.js +4 -4
- package/lib/WAM/BinaryInfo.js +9 -9
- package/lib/WAM/constants.js +22852 -22852
- package/lib/WAM/encode.js +149 -149
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +30 -30
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +15 -15
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +24 -24
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +21 -21
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +19 -19
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +19 -19
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +16 -16
- package/lib/WAUSync/Protocols/index.js +12 -12
- package/lib/WAUSync/USyncQuery.js +88 -88
- package/lib/WAUSync/USyncUser.js +20 -20
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +187 -192
- package/WAProto/fetcher.js +0 -68
- package/WAProto/parser.js +0 -334
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import { generateMessageID } from '../Utils/index.js'
|
|
2
|
-
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, jidEncode, jidNormalizedUser } from '../WABinary/index.js'
|
|
3
|
-
import { makeBusinessSocket } from './business.js'
|
|
4
|
-
|
|
5
|
-
const extractCommunityParticipants = (group) =>
|
|
6
|
-
getBinaryNodeChildren(group, 'participant').map(({ attrs }) => ({
|
|
7
|
-
id: attrs.jid,
|
|
8
|
-
admin: attrs.type || null
|
|
9
|
-
}))
|
|
10
|
-
|
|
11
|
-
export const extractCommunityMetadata = (result) => {
|
|
12
|
-
const community = getBinaryNodeChild(result, 'community') || getBinaryNodeChild(result, 'group')
|
|
13
|
-
if (!community) throw new Error('Community node not found in result')
|
|
14
|
-
const descChild = getBinaryNodeChild(community, 'description')
|
|
15
|
-
const communityId = community.attrs.id.includes('@') ? community.attrs.id : jidEncode(community.attrs.id, 'g.us')
|
|
16
|
-
return {
|
|
17
|
-
id: communityId,
|
|
18
|
-
subject: community.attrs.subject,
|
|
19
|
-
subjectTime: +community.attrs.s_t,
|
|
20
|
-
creation: +community.attrs.creation,
|
|
21
|
-
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
22
|
-
desc: descChild ? getBinaryNodeChildString(descChild, 'body') : undefined,
|
|
23
|
-
descId: descChild?.attrs.id,
|
|
24
|
-
participants: extractCommunityParticipants(community)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const makeCommunitiesSocket = (config) => {
|
|
29
|
-
const sock = makeBusinessSocket(config)
|
|
30
|
-
const { ev, query } = sock
|
|
31
|
-
|
|
32
|
-
const communityQuery = (jid, type, content) => query({ tag: 'iq', attrs: { type, xmlns: 'w:g2', to: jid }, content })
|
|
33
|
-
|
|
34
|
-
const communityMetadata = async (jid) => {
|
|
35
|
-
const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
|
|
36
|
-
return extractCommunityMetadata(result)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const communityFetchAllParticipating = async () => {
|
|
40
|
-
const result = await query({
|
|
41
|
-
tag: 'iq',
|
|
42
|
-
attrs: { to: '@g.us', xmlns: 'w:g2', type: 'get' },
|
|
43
|
-
content: [{ tag: 'participating', attrs: {}, content: [{ tag: 'participants', attrs: {} }, { tag: 'description', attrs: {} }] }]
|
|
44
|
-
})
|
|
45
|
-
const data = {}
|
|
46
|
-
const communitiesChild = getBinaryNodeChild(result, 'communities')
|
|
47
|
-
if (communitiesChild) {
|
|
48
|
-
for (const communityNode of getBinaryNodeChildren(communitiesChild, 'community')) {
|
|
49
|
-
const meta = extractCommunityMetadata({ tag: 'result', attrs: {}, content: [communityNode] })
|
|
50
|
-
data[meta.id] = meta
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
ev.emit('groups.update', Object.values(data))
|
|
54
|
-
return data
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
58
|
-
const { attrs } = getBinaryNodeChild(node, 'dirty')
|
|
59
|
-
if (attrs.type !== 'communities') return
|
|
60
|
-
await communityFetchAllParticipating()
|
|
61
|
-
await sock.cleanDirtyBits('groups')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
...sock,
|
|
66
|
-
communityMetadata,
|
|
67
|
-
communityCreate: async (subject, body) => {
|
|
68
|
-
const descriptionId = generateMessageID().substring(0, 12)
|
|
69
|
-
const result = await communityQuery('@g.us', 'set', [{
|
|
70
|
-
tag: 'create',
|
|
71
|
-
attrs: { subject },
|
|
72
|
-
content: [
|
|
73
|
-
{ tag: 'description', attrs: { id: descriptionId }, content: [{ tag: 'body', attrs: {}, content: Buffer.from(body || '', 'utf-8') }] },
|
|
74
|
-
{ tag: 'parent', attrs: { default_membership_approval_mode: 'request_required' } },
|
|
75
|
-
{ tag: 'allow_non_admin_sub_group_creation', attrs: {} },
|
|
76
|
-
{ tag: 'create_general_chat', attrs: {} }
|
|
77
|
-
]
|
|
78
|
-
}])
|
|
79
|
-
const groupNode = getBinaryNodeChild(result, 'group')
|
|
80
|
-
if (!groupNode) return null
|
|
81
|
-
try { return await sock.groupMetadata(`${groupNode.attrs.id}@g.us`) } catch { return null }
|
|
82
|
-
},
|
|
83
|
-
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
84
|
-
const key = generateMessageID()
|
|
85
|
-
const result = await communityQuery('@g.us', 'set', [{
|
|
86
|
-
tag: 'create',
|
|
87
|
-
attrs: { subject, key },
|
|
88
|
-
content: [
|
|
89
|
-
...participants.map(jid => ({ tag: 'participant', attrs: { jid } })),
|
|
90
|
-
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
91
|
-
]
|
|
92
|
-
}])
|
|
93
|
-
const groupNode = getBinaryNodeChild(result, 'group')
|
|
94
|
-
if (!groupNode) return null
|
|
95
|
-
try { return await sock.groupMetadata(`${groupNode.attrs.id}@g.us`) } catch { return null }
|
|
96
|
-
},
|
|
97
|
-
communityLeave: async (id) => {
|
|
98
|
-
await communityQuery('@g.us', 'set', [{ tag: 'leave', attrs: {}, content: [{ tag: 'community', attrs: { id } }] }])
|
|
99
|
-
},
|
|
100
|
-
communityUpdateSubject: async (jid, subject) => {
|
|
101
|
-
await communityQuery(jid, 'set', [{ tag: 'subject', attrs: {}, content: Buffer.from(subject, 'utf-8') }])
|
|
102
|
-
},
|
|
103
|
-
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
104
|
-
await communityQuery(parentCommunityJid, 'set', [{
|
|
105
|
-
tag: 'links',
|
|
106
|
-
attrs: {},
|
|
107
|
-
content: [{ tag: 'link', attrs: { link_type: 'sub_group' }, content: [{ tag: 'group', attrs: { jid: groupJid } }] }]
|
|
108
|
-
}])
|
|
109
|
-
},
|
|
110
|
-
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
111
|
-
await communityQuery(parentCommunityJid, 'set', [{ tag: 'unlink', attrs: { unlink_type: 'sub_group' }, content: [{ tag: 'group', attrs: { jid: groupJid } }] }])
|
|
112
|
-
},
|
|
113
|
-
communityFetchLinkedGroups: async (jid) => {
|
|
114
|
-
const metadata = await sock.groupMetadata(jid)
|
|
115
|
-
const communityJid = metadata.linkedParent || jid
|
|
116
|
-
const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }])
|
|
117
|
-
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups')
|
|
118
|
-
if (!subGroupsNode) return []
|
|
119
|
-
return getBinaryNodeChildren(subGroupsNode, 'group').map(g => ({
|
|
120
|
-
id: g.attrs.id.includes('@') ? g.attrs.id : jidEncode(g.attrs.id, 'g.us'),
|
|
121
|
-
subject: g.attrs.subject
|
|
122
|
-
}))
|
|
123
|
-
},
|
|
124
|
-
communityFetchAllParticipating,
|
|
125
|
-
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
126
|
-
const result = await communityQuery(jid, 'set', [{
|
|
127
|
-
tag: action,
|
|
128
|
-
attrs: {},
|
|
129
|
-
content: participants.map(jid => ({ tag: 'participant', attrs: { jid } }))
|
|
130
|
-
}])
|
|
131
|
-
const node = getBinaryNodeChild(result, action)
|
|
132
|
-
return getBinaryNodeChildren(node, 'participant').map(p => ({ status: p.attrs.error || '200', jid: p.attrs.jid }))
|
|
133
|
-
},
|
|
134
|
-
communityAcceptInvite: async (code) => {
|
|
135
|
-
const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
|
|
136
|
-
return getBinaryNodeChild(results, 'group')?.attrs.jid
|
|
137
|
-
},
|
|
138
|
-
communityInviteCode: async (jid) => {
|
|
139
|
-
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
|
|
140
|
-
return getBinaryNodeChild(result, 'invite')?.attrs.code
|
|
141
|
-
},
|
|
142
|
-
communityRevokeInvite: async (jid) => {
|
|
143
|
-
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
|
|
144
|
-
return getBinaryNodeChild(result, 'invite')?.attrs.code
|
|
145
|
-
}
|
|
146
|
-
}
|
|
1
|
+
import { generateMessageID } from '../Utils/index.js'
|
|
2
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, jidEncode, jidNormalizedUser } from '../WABinary/index.js'
|
|
3
|
+
import { makeBusinessSocket } from './business.js'
|
|
4
|
+
|
|
5
|
+
const extractCommunityParticipants = (group) =>
|
|
6
|
+
getBinaryNodeChildren(group, 'participant').map(({ attrs }) => ({
|
|
7
|
+
id: attrs.jid,
|
|
8
|
+
admin: attrs.type || null
|
|
9
|
+
}))
|
|
10
|
+
|
|
11
|
+
export const extractCommunityMetadata = (result) => {
|
|
12
|
+
const community = getBinaryNodeChild(result, 'community') || getBinaryNodeChild(result, 'group')
|
|
13
|
+
if (!community) throw new Error('Community node not found in result')
|
|
14
|
+
const descChild = getBinaryNodeChild(community, 'description')
|
|
15
|
+
const communityId = community.attrs.id.includes('@') ? community.attrs.id : jidEncode(community.attrs.id, 'g.us')
|
|
16
|
+
return {
|
|
17
|
+
id: communityId,
|
|
18
|
+
subject: community.attrs.subject,
|
|
19
|
+
subjectTime: +community.attrs.s_t,
|
|
20
|
+
creation: +community.attrs.creation,
|
|
21
|
+
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
22
|
+
desc: descChild ? getBinaryNodeChildString(descChild, 'body') : undefined,
|
|
23
|
+
descId: descChild?.attrs.id,
|
|
24
|
+
participants: extractCommunityParticipants(community)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const makeCommunitiesSocket = (config) => {
|
|
29
|
+
const sock = makeBusinessSocket(config)
|
|
30
|
+
const { ev, query } = sock
|
|
31
|
+
|
|
32
|
+
const communityQuery = (jid, type, content) => query({ tag: 'iq', attrs: { type, xmlns: 'w:g2', to: jid }, content })
|
|
33
|
+
|
|
34
|
+
const communityMetadata = async (jid) => {
|
|
35
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
|
|
36
|
+
return extractCommunityMetadata(result)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const communityFetchAllParticipating = async () => {
|
|
40
|
+
const result = await query({
|
|
41
|
+
tag: 'iq',
|
|
42
|
+
attrs: { to: '@g.us', xmlns: 'w:g2', type: 'get' },
|
|
43
|
+
content: [{ tag: 'participating', attrs: {}, content: [{ tag: 'participants', attrs: {} }, { tag: 'description', attrs: {} }] }]
|
|
44
|
+
})
|
|
45
|
+
const data = {}
|
|
46
|
+
const communitiesChild = getBinaryNodeChild(result, 'communities')
|
|
47
|
+
if (communitiesChild) {
|
|
48
|
+
for (const communityNode of getBinaryNodeChildren(communitiesChild, 'community')) {
|
|
49
|
+
const meta = extractCommunityMetadata({ tag: 'result', attrs: {}, content: [communityNode] })
|
|
50
|
+
data[meta.id] = meta
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
ev.emit('groups.update', Object.values(data))
|
|
54
|
+
return data
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
58
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty')
|
|
59
|
+
if (attrs.type !== 'communities') return
|
|
60
|
+
await communityFetchAllParticipating()
|
|
61
|
+
await sock.cleanDirtyBits('groups')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
...sock,
|
|
66
|
+
communityMetadata,
|
|
67
|
+
communityCreate: async (subject, body) => {
|
|
68
|
+
const descriptionId = generateMessageID().substring(0, 12)
|
|
69
|
+
const result = await communityQuery('@g.us', 'set', [{
|
|
70
|
+
tag: 'create',
|
|
71
|
+
attrs: { subject },
|
|
72
|
+
content: [
|
|
73
|
+
{ tag: 'description', attrs: { id: descriptionId }, content: [{ tag: 'body', attrs: {}, content: Buffer.from(body || '', 'utf-8') }] },
|
|
74
|
+
{ tag: 'parent', attrs: { default_membership_approval_mode: 'request_required' } },
|
|
75
|
+
{ tag: 'allow_non_admin_sub_group_creation', attrs: {} },
|
|
76
|
+
{ tag: 'create_general_chat', attrs: {} }
|
|
77
|
+
]
|
|
78
|
+
}])
|
|
79
|
+
const groupNode = getBinaryNodeChild(result, 'group')
|
|
80
|
+
if (!groupNode) return null
|
|
81
|
+
try { return await sock.groupMetadata(`${groupNode.attrs.id}@g.us`) } catch { return null }
|
|
82
|
+
},
|
|
83
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
84
|
+
const key = generateMessageID()
|
|
85
|
+
const result = await communityQuery('@g.us', 'set', [{
|
|
86
|
+
tag: 'create',
|
|
87
|
+
attrs: { subject, key },
|
|
88
|
+
content: [
|
|
89
|
+
...participants.map(jid => ({ tag: 'participant', attrs: { jid } })),
|
|
90
|
+
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
91
|
+
]
|
|
92
|
+
}])
|
|
93
|
+
const groupNode = getBinaryNodeChild(result, 'group')
|
|
94
|
+
if (!groupNode) return null
|
|
95
|
+
try { return await sock.groupMetadata(`${groupNode.attrs.id}@g.us`) } catch { return null }
|
|
96
|
+
},
|
|
97
|
+
communityLeave: async (id) => {
|
|
98
|
+
await communityQuery('@g.us', 'set', [{ tag: 'leave', attrs: {}, content: [{ tag: 'community', attrs: { id } }] }])
|
|
99
|
+
},
|
|
100
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
101
|
+
await communityQuery(jid, 'set', [{ tag: 'subject', attrs: {}, content: Buffer.from(subject, 'utf-8') }])
|
|
102
|
+
},
|
|
103
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
104
|
+
await communityQuery(parentCommunityJid, 'set', [{
|
|
105
|
+
tag: 'links',
|
|
106
|
+
attrs: {},
|
|
107
|
+
content: [{ tag: 'link', attrs: { link_type: 'sub_group' }, content: [{ tag: 'group', attrs: { jid: groupJid } }] }]
|
|
108
|
+
}])
|
|
109
|
+
},
|
|
110
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
111
|
+
await communityQuery(parentCommunityJid, 'set', [{ tag: 'unlink', attrs: { unlink_type: 'sub_group' }, content: [{ tag: 'group', attrs: { jid: groupJid } }] }])
|
|
112
|
+
},
|
|
113
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
114
|
+
const metadata = await sock.groupMetadata(jid)
|
|
115
|
+
const communityJid = metadata.linkedParent || jid
|
|
116
|
+
const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }])
|
|
117
|
+
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups')
|
|
118
|
+
if (!subGroupsNode) return []
|
|
119
|
+
return getBinaryNodeChildren(subGroupsNode, 'group').map(g => ({
|
|
120
|
+
id: g.attrs.id.includes('@') ? g.attrs.id : jidEncode(g.attrs.id, 'g.us'),
|
|
121
|
+
subject: g.attrs.subject
|
|
122
|
+
}))
|
|
123
|
+
},
|
|
124
|
+
communityFetchAllParticipating,
|
|
125
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
126
|
+
const result = await communityQuery(jid, 'set', [{
|
|
127
|
+
tag: action,
|
|
128
|
+
attrs: {},
|
|
129
|
+
content: participants.map(jid => ({ tag: 'participant', attrs: { jid } }))
|
|
130
|
+
}])
|
|
131
|
+
const node = getBinaryNodeChild(result, action)
|
|
132
|
+
return getBinaryNodeChildren(node, 'participant').map(p => ({ status: p.attrs.error || '200', jid: p.attrs.jid }))
|
|
133
|
+
},
|
|
134
|
+
communityAcceptInvite: async (code) => {
|
|
135
|
+
const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
|
|
136
|
+
return getBinaryNodeChild(results, 'group')?.attrs.jid
|
|
137
|
+
},
|
|
138
|
+
communityInviteCode: async (jid) => {
|
|
139
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
|
|
140
|
+
return getBinaryNodeChild(result, 'invite')?.attrs.code
|
|
141
|
+
},
|
|
142
|
+
communityRevokeInvite: async (jid) => {
|
|
143
|
+
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
|
|
144
|
+
return getBinaryNodeChild(result, 'invite')?.attrs.code
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
147
|
}
|