@rizzxdc/baileys 8.0.10 → 8.1.0
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 +4 -2
- package/README.md +107 -245
- package/WAProto/index.d.ts +15795 -0
- package/WAProto/index.js +25587 -4867
- package/lib/Defaults/index.d.ts +147 -0
- package/lib/Defaults/index.js +134 -104
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -11
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +5 -8
- package/lib/Signal/Group/group_cipher.d.ts +11 -0
- package/lib/Signal/Group/group_cipher.js +72 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +11 -13
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +11 -14
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +23 -26
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +61 -64
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +39 -44
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +35 -38
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +76 -79
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -26
- package/lib/Signal/libsignal.d.ts +55 -0
- package/lib/Signal/libsignal.js +414 -308
- package/lib/Signal/lid-mapping.d.ts +21 -0
- package/lib/Signal/lid-mapping.js +270 -149
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -4
- package/lib/Socket/Client/types.d.ts +6 -0
- package/lib/Socket/Client/types.js +8 -11
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +51 -50
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +357 -355
- package/lib/Socket/chats.d.ts +137 -0
- package/lib/Socket/chats.js +1195 -867
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +416 -398
- package/lib/Socket/dugong.js +8 -1
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +336 -301
- package/lib/Socket/index.d.ts +530 -0
- package/lib/Socket/index.js +8 -13
- package/lib/Socket/messages-recv.d.ts +334 -0
- package/lib/Socket/messages-recv.js +1729 -1121
- package/lib/Socket/messages-send.d.ts +330 -0
- package/lib/Socket/messages-send.js +684 -462
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +36 -40
- package/lib/Socket/newsletter.d.ts +284 -0
- package/lib/Socket/newsletter.js +247 -237
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +968 -790
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -6
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +414 -284
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +75 -76
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +21 -23
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.js +0 -2
- package/lib/Types/Bussines.d.ts +2 -0
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.d.ts +2 -0
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +5 -7
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.js +1 -3
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.d.ts +3 -0
- package/lib/Types/Label.js +21 -22
- package/lib/Types/LabelAssociation.d.ts +3 -0
- package/lib/Types/LabelAssociation.js +3 -4
- package/lib/Types/Message.d.ts +12 -0
- package/lib/Types/Message.js +11 -6
- package/lib/Types/Mex.d.ts +3 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +2 -0
- package/lib/Types/Product.js +0 -2
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +2 -0
- package/lib/Types/Signal.js +1 -3
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/Socket.js +1 -4
- package/lib/Types/State.d.ts +6 -0
- package/lib/Types/State.js +52 -8
- package/lib/Types/USync.d.ts +2 -0
- package/lib/Types/USync.js +1 -3
- package/lib/Types/index.d.ts +14 -0
- package/lib/Types/index.js +22 -25
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +285 -203
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +21 -19
- package/lib/Utils/business.d.ts +50 -0
- package/lib/Utils/business.js +206 -209
- package/lib/Utils/chat-utils.d.ts +409 -0
- package/lib/Utils/chat-utils.js +825 -706
- package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +88 -101
- package/lib/Utils/decode-wa-message.d.ts +84 -0
- package/lib/Utils/decode-wa-message.js +287 -238
- package/lib/Utils/event-buffer.d.ts +13 -0
- package/lib/Utils/event-buffer.js +602 -509
- package/lib/Utils/generics.d.ts +64 -0
- package/lib/Utils/generics.js +334 -295
- package/lib/Utils/history.d.ts +76 -0
- package/lib/Utils/history.js +125 -79
- package/lib/Utils/identity-change-handler.d.ts +14 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.js +25 -21
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -70
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +1 -4
- package/lib/Utils/lt-hash.d.ts +7 -0
- package/lib/Utils/lt-hash.js +7 -45
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +27 -31
- package/lib/Utils/message-retry-manager.d.ts +80 -0
- package/lib/Utils/message-retry-manager.js +165 -14
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +768 -572
- package/lib/Utils/messages.d.ts +46 -0
- package/lib/Utils/messages.js +1082 -130
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +191 -135
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.d.ts +26 -0
- package/lib/Utils/pre-key-manager.js +96 -76
- package/lib/Utils/process-message.d.ts +84 -0
- package/lib/Utils/process-message.js +718 -311
- package/lib/Utils/reporting-utils.d.ts +13 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.js +257 -0
- package/lib/Utils/signal.d.ts +83 -0
- package/lib/Utils/signal.js +174 -135
- package/lib/Utils/stanza-ack.d.ts +17 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +3 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +30 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -95
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +182 -180
- package/lib/WABinary/constants.d.ts +62 -0
- package/lib/WABinary/constants.js +1455 -1292
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +249 -228
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +207 -206
- package/lib/WABinary/generic-utils.d.ts +77 -0
- package/lib/WABinary/generic-utils.js +135 -99
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +5 -7
- package/lib/WABinary/jid-utils.d.ts +29 -0
- package/lib/WABinary/jid-utils.js +80 -78
- package/lib/WABinary/types.d.ts +2 -0
- package/lib/WABinary/types.js +1 -3
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +7 -9
- package/lib/WAM/constants.d.ts +34927 -0
- package/lib/WAM/constants.js +22847 -22848
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +129 -134
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +5 -6
- package/lib/WAUSync/USyncQuery.d.ts +21 -0
- package/lib/WAUSync/USyncQuery.js +92 -85
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +28 -22
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -5
- package/lib/index.d.ts +12 -0
- package/lib/index.js +31 -19
- package/package.json +12 -6
- package/lib/Types/Newsletter.js +0 -33
|
@@ -1,413 +1,431 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { generateMessageID, generateMessageIDV2, unixTimestampSeconds } from
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import logger from "../Utils/logger.js";
|
|
8
|
-
//=======================================================//
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { WAMessageStubType } from '../Types/index.js';
|
|
3
|
+
import { generateMessageID, generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
|
|
4
|
+
import logger from '../Utils/logger.js';
|
|
5
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
|
+
import { makeBusinessSocket } from './business.js';
|
|
9
7
|
export const makeCommunitiesSocket = (config) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
const communityMetadata = async (jid) => {
|
|
22
|
-
const result = await communityQuery(jid, "get", [{ tag: "query", attrs: { request: "interactive" } }]);
|
|
23
|
-
return extractCommunityMetadata(result);
|
|
24
|
-
};
|
|
25
|
-
const communityFetchAllParticipating = async () => {
|
|
26
|
-
const result = await query({
|
|
27
|
-
tag: "iq",
|
|
28
|
-
attrs: {
|
|
29
|
-
to: "@g.us",
|
|
30
|
-
xmlns: "w:g2",
|
|
31
|
-
type: "get"
|
|
32
|
-
},
|
|
33
|
-
content: [
|
|
34
|
-
{
|
|
35
|
-
tag: "participating",
|
|
36
|
-
attrs: {},
|
|
37
|
-
content: [
|
|
38
|
-
{ tag: "participants", attrs: {} },
|
|
39
|
-
{ tag: "description", attrs: {} }
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
]
|
|
8
|
+
const sock = makeBusinessSocket(config);
|
|
9
|
+
const { authState, ev, query, upsertMessage } = sock;
|
|
10
|
+
const communityQuery = async (jid, type, content) => query({
|
|
11
|
+
tag: 'iq',
|
|
12
|
+
attrs: {
|
|
13
|
+
type,
|
|
14
|
+
xmlns: 'w:g2',
|
|
15
|
+
to: jid
|
|
16
|
+
},
|
|
17
|
+
content
|
|
43
18
|
});
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
sock.ev.emit("groups.update", Object.values(data));
|
|
58
|
-
return data;
|
|
59
|
-
};
|
|
60
|
-
async function parseGroupResult(node) {
|
|
61
|
-
logger.info({ node }, "parseGroupResult");
|
|
62
|
-
const groupNode = getBinaryNodeChild(node, "group");
|
|
63
|
-
if (groupNode) {
|
|
64
|
-
try {
|
|
65
|
-
logger.info({ groupNode }, "groupNode");
|
|
66
|
-
const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
67
|
-
return metadata ? metadata : Optional.empty();
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error("Error parsing group metadata:", error);
|
|
71
|
-
return Optional.empty();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return Optional.empty();
|
|
75
|
-
}
|
|
76
|
-
const Optional = {
|
|
77
|
-
empty: () => null,
|
|
78
|
-
of: (value) => (value !== null ? { value } : null)
|
|
79
|
-
};
|
|
80
|
-
sock.ws.on("CB:ib,,dirty", async (node) => {
|
|
81
|
-
const { attrs } = getBinaryNodeChild(node, "dirty");
|
|
82
|
-
if (attrs.type !== "communities") {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
await communityFetchAllParticipating();
|
|
86
|
-
await sock.cleanDirtyBits("groups");
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
...sock,
|
|
90
|
-
communityMetadata,
|
|
91
|
-
communityCreate: async (subject, body) => {
|
|
92
|
-
const descriptionId = generateMessageID().substring(0, 12);
|
|
93
|
-
const result = await communityQuery("@g.us", "set", [
|
|
94
|
-
{
|
|
95
|
-
tag: "create",
|
|
96
|
-
attrs: { subject },
|
|
97
|
-
content: [
|
|
98
|
-
{
|
|
99
|
-
tag: "description",
|
|
100
|
-
attrs: { id: descriptionId },
|
|
101
|
-
content: [
|
|
19
|
+
const communityMetadata = async (jid) => {
|
|
20
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
21
|
+
return extractCommunityMetadata(result);
|
|
22
|
+
};
|
|
23
|
+
const communityFetchAllParticipating = async () => {
|
|
24
|
+
const result = await query({
|
|
25
|
+
tag: 'iq',
|
|
26
|
+
attrs: {
|
|
27
|
+
to: '@g.us',
|
|
28
|
+
xmlns: 'w:g2',
|
|
29
|
+
type: 'get'
|
|
30
|
+
},
|
|
31
|
+
content: [
|
|
102
32
|
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
33
|
+
tag: 'participating',
|
|
34
|
+
attrs: {},
|
|
35
|
+
content: [
|
|
36
|
+
{ tag: 'participants', attrs: {} },
|
|
37
|
+
{ tag: 'description', attrs: {} }
|
|
38
|
+
]
|
|
106
39
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
const data = {};
|
|
43
|
+
const communitiesChild = getBinaryNodeChild(result, 'communities');
|
|
44
|
+
if (communitiesChild) {
|
|
45
|
+
const communities = getBinaryNodeChildren(communitiesChild, 'community');
|
|
46
|
+
for (const communityNode of communities) {
|
|
47
|
+
const meta = extractCommunityMetadata({
|
|
48
|
+
tag: 'result',
|
|
49
|
+
attrs: {},
|
|
50
|
+
content: [communityNode]
|
|
51
|
+
});
|
|
52
|
+
data[meta.id] = meta;
|
|
120
53
|
}
|
|
121
|
-
]
|
|
122
|
-
}
|
|
123
|
-
]);
|
|
124
|
-
return await parseGroupResult(result);
|
|
125
|
-
},
|
|
126
|
-
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
127
|
-
const key = generateMessageIDV2();
|
|
128
|
-
const result = await communityQuery("@g.us", "set", [
|
|
129
|
-
{
|
|
130
|
-
tag: "create",
|
|
131
|
-
attrs: {
|
|
132
|
-
subject,
|
|
133
|
-
key
|
|
134
|
-
},
|
|
135
|
-
content: [
|
|
136
|
-
...participants.map(jid => ({
|
|
137
|
-
tag: "participant",
|
|
138
|
-
attrs: { jid }
|
|
139
|
-
})),
|
|
140
|
-
{ tag: "linked_parent", attrs: { jid: parentCommunityJid } }
|
|
141
|
-
]
|
|
142
|
-
}
|
|
143
|
-
]);
|
|
144
|
-
return await parseGroupResult(result);
|
|
145
|
-
},
|
|
146
|
-
communityLeave: async (id) => {
|
|
147
|
-
await communityQuery("@g.us", "set", [
|
|
148
|
-
{
|
|
149
|
-
tag: "leave",
|
|
150
|
-
attrs: {},
|
|
151
|
-
content: [{ tag: "community", attrs: { id } }]
|
|
152
54
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
165
|
-
await communityQuery(parentCommunityJid, "set", [
|
|
166
|
-
{
|
|
167
|
-
tag: "links",
|
|
168
|
-
attrs: {},
|
|
169
|
-
content: [
|
|
170
|
-
{
|
|
171
|
-
tag: "link",
|
|
172
|
-
attrs: { link_type: "sub_group" },
|
|
173
|
-
content: [{ tag: "group", attrs: { jid: groupJid } }]
|
|
55
|
+
sock.ev.emit('groups.update', Object.values(data));
|
|
56
|
+
return data;
|
|
57
|
+
};
|
|
58
|
+
async function parseGroupResult(node) {
|
|
59
|
+
logger.info({ node }, 'parseGroupResult');
|
|
60
|
+
const groupNode = getBinaryNodeChild(node, 'group');
|
|
61
|
+
if (groupNode) {
|
|
62
|
+
try {
|
|
63
|
+
logger.info({ groupNode }, 'groupNode');
|
|
64
|
+
const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
65
|
+
return metadata ? metadata : Optional.empty();
|
|
174
66
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
},
|
|
179
|
-
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
180
|
-
await communityQuery(parentCommunityJid, "set", [
|
|
181
|
-
{
|
|
182
|
-
tag: "unlink",
|
|
183
|
-
attrs: { unlink_type: "sub_group" },
|
|
184
|
-
content: [{ tag: "group", attrs: { jid: groupJid } }]
|
|
185
|
-
}
|
|
186
|
-
]);
|
|
187
|
-
},
|
|
188
|
-
communityFetchLinkedGroups: async (jid) => {
|
|
189
|
-
let communityJid = jid;
|
|
190
|
-
let isCommunity = false;
|
|
191
|
-
const metadata = await sock.groupMetadata(jid);
|
|
192
|
-
if (metadata.linkedParent) {
|
|
193
|
-
communityJid = metadata.linkedParent;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
isCommunity = true;
|
|
197
|
-
}
|
|
198
|
-
const result = await communityQuery(communityJid, "get", [{ tag: "sub_groups", attrs: {} }]);
|
|
199
|
-
const linkedGroupsData = [];
|
|
200
|
-
const subGroupsNode = getBinaryNodeChild(result, "sub_groups");
|
|
201
|
-
if (subGroupsNode) {
|
|
202
|
-
const groupNodes = getBinaryNodeChildren(subGroupsNode, "group");
|
|
203
|
-
for (const groupNode of groupNodes) {
|
|
204
|
-
linkedGroupsData.push({
|
|
205
|
-
id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, "g.us") : undefined,
|
|
206
|
-
subject: groupNode.attrs.subject || "",
|
|
207
|
-
creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
|
|
208
|
-
owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
|
|
209
|
-
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
communityJid,
|
|
215
|
-
isCommunity,
|
|
216
|
-
linkedGroups: linkedGroupsData
|
|
217
|
-
};
|
|
218
|
-
},
|
|
219
|
-
communityRequestParticipantsList: async (jid) => {
|
|
220
|
-
const result = await communityQuery(jid, "get", [
|
|
221
|
-
{
|
|
222
|
-
tag: "membership_approval_requests",
|
|
223
|
-
attrs: {}
|
|
224
|
-
}
|
|
225
|
-
]);
|
|
226
|
-
const node = getBinaryNodeChild(result, "membership_approval_requests");
|
|
227
|
-
const participants = getBinaryNodeChildren(node, "membership_approval_request");
|
|
228
|
-
return participants.map(v => v.attrs);
|
|
229
|
-
},
|
|
230
|
-
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
231
|
-
const result = await communityQuery(jid, "set", [
|
|
232
|
-
{
|
|
233
|
-
tag: "membership_requests_action",
|
|
234
|
-
attrs: {},
|
|
235
|
-
content: [
|
|
236
|
-
{
|
|
237
|
-
tag: action,
|
|
238
|
-
attrs: {},
|
|
239
|
-
content: participants.map(jid => ({
|
|
240
|
-
tag: "participant",
|
|
241
|
-
attrs: { jid }
|
|
242
|
-
}))
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('Error parsing group metadata:', error);
|
|
69
|
+
return Optional.empty();
|
|
243
70
|
}
|
|
244
|
-
]
|
|
245
|
-
}
|
|
246
|
-
]);
|
|
247
|
-
const node = getBinaryNodeChild(result, "membership_requests_action");
|
|
248
|
-
const nodeAction = getBinaryNodeChild(node, action);
|
|
249
|
-
const participantsAffected = getBinaryNodeChildren(nodeAction, "participant");
|
|
250
|
-
return participantsAffected.map(p => {
|
|
251
|
-
return { status: p.attrs.error || "200", jid: p.attrs.jid };
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
|
-
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
255
|
-
const result = await communityQuery(jid, "set", [
|
|
256
|
-
{
|
|
257
|
-
tag: action,
|
|
258
|
-
attrs: {},
|
|
259
|
-
content: participants.map(jid => ({
|
|
260
|
-
tag: "participant",
|
|
261
|
-
attrs: { jid }
|
|
262
|
-
}))
|
|
263
|
-
}
|
|
264
|
-
]);
|
|
265
|
-
const node = getBinaryNodeChild(result, action);
|
|
266
|
-
const participantsAffected = getBinaryNodeChildren(node, "participant");
|
|
267
|
-
return participantsAffected.map(p => {
|
|
268
|
-
return { status: p.attrs.error || "200", jid: p.attrs.jid, content: p };
|
|
269
|
-
});
|
|
270
|
-
},
|
|
271
|
-
communityUpdateDescription: async (jid, description) => {
|
|
272
|
-
const metadata = await communityMetadata(jid);
|
|
273
|
-
const prev = metadata.descId ?? null;
|
|
274
|
-
await communityQuery(jid, "set", [
|
|
275
|
-
{
|
|
276
|
-
tag: "description",
|
|
277
|
-
attrs: {
|
|
278
|
-
...(description ? { id: generateMessageID() } : { delete: "true" }),
|
|
279
|
-
...(prev ? { prev } : {})
|
|
280
|
-
},
|
|
281
|
-
content: description ? [{ tag: "body", attrs: {}, content: Buffer.from(description, "utf-8") }] : undefined
|
|
282
71
|
}
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return inviteNode?.attrs.code;
|
|
294
|
-
},
|
|
295
|
-
communityAcceptInvite: async (code) => {
|
|
296
|
-
const results = await communityQuery("@g.us", "set", [{ tag: "invite", attrs: { code } }]);
|
|
297
|
-
const result = getBinaryNodeChild(results, "community");
|
|
298
|
-
return result?.attrs.jid;
|
|
299
|
-
},
|
|
300
|
-
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
301
|
-
const result = await communityQuery(communityJid, "set", [
|
|
302
|
-
{ tag: "revoke", attrs: {}, content: [{ tag: "participant", attrs: { jid: invitedJid } }] }
|
|
303
|
-
]);
|
|
304
|
-
return !!result;
|
|
305
|
-
},
|
|
306
|
-
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
307
|
-
key = typeof key === "string" ? { remoteJid: key } : key;
|
|
308
|
-
const results = await communityQuery(inviteMessage.groupJid, "set", [
|
|
309
|
-
{
|
|
310
|
-
tag: "accept",
|
|
311
|
-
attrs: {
|
|
312
|
-
code: inviteMessage.inviteCode,
|
|
313
|
-
expiration: inviteMessage.inviteExpiration.toString(),
|
|
314
|
-
admin: key.remoteJid
|
|
315
|
-
}
|
|
72
|
+
return Optional.empty();
|
|
73
|
+
}
|
|
74
|
+
const Optional = {
|
|
75
|
+
empty: () => null,
|
|
76
|
+
of: (value) => (value !== null ? { value } : null)
|
|
77
|
+
};
|
|
78
|
+
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
79
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
80
|
+
if (attrs.type !== 'communities') {
|
|
81
|
+
return;
|
|
316
82
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
83
|
+
await communityFetchAllParticipating();
|
|
84
|
+
await sock.cleanDirtyBits('groups');
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
...sock,
|
|
88
|
+
communityQuery,
|
|
89
|
+
communityMetadata,
|
|
90
|
+
communityCreate: async (subject, body) => {
|
|
91
|
+
const descriptionId = generateMessageID().substring(0, 12);
|
|
92
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
93
|
+
{
|
|
94
|
+
tag: 'create',
|
|
95
|
+
attrs: { subject },
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
tag: 'description',
|
|
99
|
+
attrs: { id: descriptionId },
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
tag: 'body',
|
|
103
|
+
attrs: {},
|
|
104
|
+
content: Buffer.from(body || '', 'utf-8')
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
tag: 'parent',
|
|
110
|
+
attrs: { default_membership_approval_mode: 'request_required' }
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
tag: 'allow_non_admin_sub_group_creation',
|
|
114
|
+
attrs: {}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
tag: 'create_general_chat',
|
|
118
|
+
attrs: {}
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
]);
|
|
123
|
+
return await parseGroupResult(result);
|
|
124
|
+
},
|
|
125
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
126
|
+
const key = generateMessageIDV2();
|
|
127
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
128
|
+
{
|
|
129
|
+
tag: 'create',
|
|
130
|
+
attrs: {
|
|
131
|
+
subject,
|
|
132
|
+
key
|
|
133
|
+
},
|
|
134
|
+
content: [
|
|
135
|
+
...participants.map(jid => ({
|
|
136
|
+
tag: 'participant',
|
|
137
|
+
attrs: { jid }
|
|
138
|
+
})),
|
|
139
|
+
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
]);
|
|
143
|
+
return await parseGroupResult(result);
|
|
144
|
+
},
|
|
145
|
+
communityLeave: async (id) => {
|
|
146
|
+
await communityQuery('@g.us', 'set', [
|
|
147
|
+
{
|
|
148
|
+
tag: 'leave',
|
|
149
|
+
attrs: {},
|
|
150
|
+
content: [{ tag: 'community', attrs: { id } }]
|
|
151
|
+
}
|
|
152
|
+
]);
|
|
153
|
+
},
|
|
154
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
155
|
+
await communityQuery(jid, 'set', [
|
|
156
|
+
{
|
|
157
|
+
tag: 'subject',
|
|
158
|
+
attrs: {},
|
|
159
|
+
content: Buffer.from(subject, 'utf-8')
|
|
160
|
+
}
|
|
161
|
+
]);
|
|
162
|
+
},
|
|
163
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
164
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
165
|
+
{
|
|
166
|
+
tag: 'links',
|
|
167
|
+
attrs: {},
|
|
168
|
+
content: [
|
|
169
|
+
{
|
|
170
|
+
tag: 'link',
|
|
171
|
+
attrs: { link_type: 'sub_group' },
|
|
172
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
]);
|
|
177
|
+
},
|
|
178
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
179
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
180
|
+
{
|
|
181
|
+
tag: 'unlink',
|
|
182
|
+
attrs: { unlink_type: 'sub_group' },
|
|
183
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
184
|
+
}
|
|
185
|
+
]);
|
|
186
|
+
},
|
|
187
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
188
|
+
let communityJid = jid;
|
|
189
|
+
let isCommunity = false;
|
|
190
|
+
// Try to determine if it is a subgroup or a community
|
|
191
|
+
const metadata = await sock.groupMetadata(jid);
|
|
192
|
+
if (metadata.linkedParent) {
|
|
193
|
+
// It is a subgroup, get the community jid
|
|
194
|
+
communityJid = metadata.linkedParent;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// It is a community
|
|
198
|
+
isCommunity = true;
|
|
199
|
+
}
|
|
200
|
+
// Fetch all subgroups of the community
|
|
201
|
+
const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
|
|
202
|
+
const linkedGroupsData = [];
|
|
203
|
+
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups');
|
|
204
|
+
if (subGroupsNode) {
|
|
205
|
+
const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group');
|
|
206
|
+
for (const groupNode of groupNodes) {
|
|
207
|
+
linkedGroupsData.push({
|
|
208
|
+
id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
|
|
209
|
+
subject: groupNode.attrs.subject || '',
|
|
210
|
+
creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
|
|
211
|
+
owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
|
|
212
|
+
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
|
|
213
|
+
});
|
|
214
|
+
}
|
|
329
215
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
remoteJid: inviteMessage.groupJid,
|
|
336
|
-
id: generateMessageIDV2(sock.user?.id),
|
|
337
|
-
fromMe: false,
|
|
338
|
-
participant: key.remoteJid
|
|
216
|
+
return {
|
|
217
|
+
communityJid,
|
|
218
|
+
isCommunity,
|
|
219
|
+
linkedGroups: linkedGroupsData
|
|
220
|
+
};
|
|
339
221
|
},
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
222
|
+
communityRequestParticipantsList: async (jid) => {
|
|
223
|
+
const result = await communityQuery(jid, 'get', [
|
|
224
|
+
{
|
|
225
|
+
tag: 'membership_approval_requests',
|
|
226
|
+
attrs: {}
|
|
227
|
+
}
|
|
228
|
+
]);
|
|
229
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
230
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
231
|
+
return participants.map(v => v.attrs);
|
|
232
|
+
},
|
|
233
|
+
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
234
|
+
const result = await communityQuery(jid, 'set', [
|
|
235
|
+
{
|
|
236
|
+
tag: 'membership_requests_action',
|
|
237
|
+
attrs: {},
|
|
238
|
+
content: [
|
|
239
|
+
{
|
|
240
|
+
tag: action,
|
|
241
|
+
attrs: {},
|
|
242
|
+
content: participants.map(jid => ({
|
|
243
|
+
tag: 'participant',
|
|
244
|
+
attrs: { jid }
|
|
245
|
+
}))
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
]);
|
|
250
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
251
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
252
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
253
|
+
return participantsAffected.map(p => {
|
|
254
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
258
|
+
const result = await communityQuery(jid, 'set', [
|
|
259
|
+
{
|
|
260
|
+
tag: action,
|
|
261
|
+
attrs: action === 'remove' ? { linked_groups: 'true' } : {},
|
|
262
|
+
content: participants.map(jid => ({
|
|
263
|
+
tag: 'participant',
|
|
264
|
+
attrs: { jid }
|
|
265
|
+
}))
|
|
266
|
+
}
|
|
267
|
+
]);
|
|
268
|
+
const node = getBinaryNodeChild(result, action);
|
|
269
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
270
|
+
return participantsAffected.map(p => {
|
|
271
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
272
|
+
});
|
|
273
|
+
},
|
|
274
|
+
communityUpdateDescription: async (jid, description) => {
|
|
275
|
+
const metadata = await communityMetadata(jid);
|
|
276
|
+
const prev = metadata.descId ?? null;
|
|
277
|
+
await communityQuery(jid, 'set', [
|
|
278
|
+
{
|
|
279
|
+
tag: 'description',
|
|
280
|
+
attrs: {
|
|
281
|
+
...(description ? { id: generateMessageID() } : { delete: 'true' }),
|
|
282
|
+
...(prev ? { prev } : {})
|
|
283
|
+
},
|
|
284
|
+
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
285
|
+
}
|
|
286
|
+
]);
|
|
287
|
+
},
|
|
288
|
+
communityInviteCode: async (jid) => {
|
|
289
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
290
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
291
|
+
return inviteNode?.attrs.code;
|
|
292
|
+
},
|
|
293
|
+
communityRevokeInvite: async (jid) => {
|
|
294
|
+
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
295
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
296
|
+
return inviteNode?.attrs.code;
|
|
297
|
+
},
|
|
298
|
+
communityAcceptInvite: async (code) => {
|
|
299
|
+
const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
300
|
+
const result = getBinaryNodeChild(results, 'community');
|
|
301
|
+
return result?.attrs.jid;
|
|
302
|
+
},
|
|
303
|
+
/**
|
|
304
|
+
* revoke a v4 invite for someone
|
|
305
|
+
* @param communityJid community jid
|
|
306
|
+
* @param invitedJid jid of person you invited
|
|
307
|
+
* @returns true if successful
|
|
308
|
+
*/
|
|
309
|
+
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
310
|
+
const result = await communityQuery(communityJid, 'set', [
|
|
311
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
312
|
+
]);
|
|
313
|
+
return !!result;
|
|
314
|
+
},
|
|
315
|
+
/**
|
|
316
|
+
* accept a CommunityInviteMessage
|
|
317
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
318
|
+
* @param inviteMessage the message to accept
|
|
319
|
+
*/
|
|
320
|
+
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
321
|
+
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
322
|
+
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
323
|
+
{
|
|
324
|
+
tag: 'accept',
|
|
325
|
+
attrs: {
|
|
326
|
+
code: inviteMessage.inviteCode,
|
|
327
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
328
|
+
admin: key.remoteJid
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
]);
|
|
332
|
+
// if we have the full message key
|
|
333
|
+
// update the invite message to be expired
|
|
334
|
+
if (key.id) {
|
|
335
|
+
// create new invite message that is expired
|
|
336
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
337
|
+
inviteMessage.inviteExpiration = 0;
|
|
338
|
+
inviteMessage.inviteCode = '';
|
|
339
|
+
ev.emit('messages.update', [
|
|
340
|
+
{
|
|
341
|
+
key,
|
|
342
|
+
update: {
|
|
343
|
+
message: {
|
|
344
|
+
groupInviteMessage: inviteMessage
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
]);
|
|
349
|
+
}
|
|
350
|
+
// generate the community add message
|
|
351
|
+
await upsertMessage({
|
|
352
|
+
key: {
|
|
353
|
+
remoteJid: inviteMessage.groupJid,
|
|
354
|
+
id: generateMessageIDV2(sock.user?.id),
|
|
355
|
+
fromMe: false,
|
|
356
|
+
participant: key.remoteJid // TODO: investigate if this makes any sense at all
|
|
357
|
+
},
|
|
358
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
359
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
360
|
+
participant: key.remoteJid,
|
|
361
|
+
messageTimestamp: unixTimestampSeconds()
|
|
362
|
+
}, 'notify');
|
|
363
|
+
return results.attrs.from;
|
|
364
|
+
}),
|
|
365
|
+
communityGetInviteInfo: async (code) => {
|
|
366
|
+
const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
367
|
+
return extractCommunityMetadata(results);
|
|
368
|
+
},
|
|
369
|
+
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
370
|
+
const content = ephemeralExpiration
|
|
371
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
372
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
373
|
+
await communityQuery(jid, 'set', [content]);
|
|
374
|
+
},
|
|
375
|
+
communitySettingUpdate: async (jid, setting) => {
|
|
376
|
+
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
377
|
+
},
|
|
378
|
+
communityMemberAddMode: async (jid, mode) => {
|
|
379
|
+
await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
380
|
+
},
|
|
381
|
+
communityJoinApprovalMode: async (jid, mode) => {
|
|
382
|
+
await communityQuery(jid, 'set', [
|
|
383
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
|
|
384
|
+
]);
|
|
385
|
+
},
|
|
386
|
+
communityFetchAllParticipating
|
|
387
|
+
};
|
|
370
388
|
};
|
|
371
389
|
export const extractCommunityMetadata = (result) => {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
390
|
+
const community = getBinaryNodeChild(result, 'community');
|
|
391
|
+
const descChild = getBinaryNodeChild(community, 'description');
|
|
392
|
+
let desc;
|
|
393
|
+
let descId;
|
|
394
|
+
if (descChild) {
|
|
395
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
396
|
+
descId = descChild.attrs.id;
|
|
397
|
+
}
|
|
398
|
+
const communityId = community.attrs.id?.includes('@')
|
|
399
|
+
? community.attrs.id
|
|
400
|
+
: jidEncode(community.attrs.id || '', 'g.us');
|
|
401
|
+
const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration;
|
|
402
|
+
const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
|
|
403
|
+
const metadata = {
|
|
404
|
+
id: communityId,
|
|
405
|
+
subject: community.attrs.subject || '',
|
|
406
|
+
subjectOwner: community.attrs.s_o,
|
|
407
|
+
subjectTime: Number(community.attrs.s_t || 0),
|
|
408
|
+
size: getBinaryNodeChildren(community, 'participant').length,
|
|
409
|
+
creation: Number(community.attrs.creation || 0),
|
|
410
|
+
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
411
|
+
desc,
|
|
412
|
+
descId,
|
|
413
|
+
linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
|
|
414
|
+
restrict: !!getBinaryNodeChild(community, 'locked'),
|
|
415
|
+
announce: !!getBinaryNodeChild(community, 'announcement'),
|
|
416
|
+
isCommunity: !!getBinaryNodeChild(community, 'parent'),
|
|
417
|
+
isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_community'),
|
|
418
|
+
joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
|
|
419
|
+
memberAddMode,
|
|
420
|
+
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
|
|
421
|
+
return {
|
|
422
|
+
// TODO: IMPLEMENT THE PN/LID FIELDS HERE!!
|
|
423
|
+
id: attrs.jid,
|
|
424
|
+
admin: (attrs.type || null)
|
|
425
|
+
};
|
|
426
|
+
}),
|
|
427
|
+
ephemeralDuration: eph ? +eph : undefined,
|
|
428
|
+
addressingMode: getBinaryNodeChildString(community, 'addressing_mode')
|
|
429
|
+
};
|
|
430
|
+
return metadata;
|
|
412
431
|
};
|
|
413
|
-
//=======================================================//
|