@badzz88/baileys 8.4.5 → 8.4.7
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/WAProto/WAProto.proto +671 -194
- package/WAProto/fix-imports.js +85 -86
- package/lib/Defaults/index.js +16 -23
- package/lib/Signal/libsignal.js +1 -2
- package/lib/Socket/luxu.js +5 -6
- package/lib/Socket/messages-send.js +37 -43
- package/lib/Socket/newsletter.js +1 -5
- package/lib/Socket/socket.js +42 -11
- package/lib/Socket/username.js +5 -5
- package/lib/Utils/browser-utils.js +1 -0
- package/lib/Utils/chat-utils.js +1 -2
- package/lib/Utils/generics.js +4 -4
- package/lib/Utils/process-message.js +1 -1
- package/lib/Utils/signal.js +1 -2
- package/lib/Utils/validate-connection.js +1 -2
- package/lib/{Signal/Group/Protocols.js → WAUSync/Protocols/USyncNewsletterProtocol.js} +5 -11
- package/lib/index.js +3 -4
- package/package.json +137 -132
- package/WAProto/fix-import.js +0 -38
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/community.js +0 -392
- package/lib/Socket/dugong.js +0 -637
- package/lib/Socket/registration.js +0 -167
- package/lib/Socket/usync.js +0 -69
- package/lib/Types/Newsletter.js +0 -38
- package/lib/Utils/baileys-event-stream.js +0 -63
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MobileSocketClient = void 0;
|
|
4
|
-
const net_1 = require("net");
|
|
5
|
-
const abstract_socket_client_1 = require("./abstract-socket-client");
|
|
6
|
-
class MobileSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.socket = null;
|
|
10
|
-
}
|
|
11
|
-
get isOpen() {
|
|
12
|
-
var _a;
|
|
13
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'open';
|
|
14
|
-
}
|
|
15
|
-
get isClosed() {
|
|
16
|
-
var _a;
|
|
17
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
|
18
|
-
}
|
|
19
|
-
get isClosing() {
|
|
20
|
-
var _a;
|
|
21
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
|
22
|
-
}
|
|
23
|
-
get isConnecting() {
|
|
24
|
-
var _a;
|
|
25
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'opening';
|
|
26
|
-
}
|
|
27
|
-
async connect() {
|
|
28
|
-
var _a;
|
|
29
|
-
if (this.socket) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (this.config.agent) {
|
|
33
|
-
throw new Error('There are not support for proxy agent for mobile connection');
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.socket = (0, net_1.connect)({
|
|
37
|
-
host: this.url.hostname,
|
|
38
|
-
port: Number(this.url.port) || 443
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
this.socket.setMaxListeners(0);
|
|
42
|
-
const events = ['close', 'connect', 'data', 'drain', 'end', 'error', 'lookup', 'ready', 'timeout'];
|
|
43
|
-
for (const event of events) {
|
|
44
|
-
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.on(event, (...args) => this.emit(event, ...args));
|
|
45
|
-
}
|
|
46
|
-
this.socket.on('data', (...args) => this.emit('message', ...args));
|
|
47
|
-
this.socket.on('ready', (...args) => this.emit('open', ...args));
|
|
48
|
-
}
|
|
49
|
-
async close() {
|
|
50
|
-
if (!this.socket) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
return new Promise(resolve => {
|
|
54
|
-
this.socket.end(resolve);
|
|
55
|
-
this.socket = null;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
send(str, cb) {
|
|
59
|
-
if (this.socket === null) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return this.socket.write(str, undefined, cb);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.MobileSocketClient = MobileSocketClient;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WebSocketClient = void 0;
|
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
|
-
const Defaults_1 = require("../../Defaults");
|
|
9
|
-
const abstract_socket_client_1 = require("./abstract-socket-client");
|
|
10
|
-
class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.socket = null;
|
|
14
|
-
}
|
|
15
|
-
get isOpen() {
|
|
16
|
-
var _a;
|
|
17
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
|
|
18
|
-
}
|
|
19
|
-
get isClosed() {
|
|
20
|
-
var _a;
|
|
21
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
|
|
22
|
-
}
|
|
23
|
-
get isClosing() {
|
|
24
|
-
var _a;
|
|
25
|
-
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
|
|
26
|
-
}
|
|
27
|
-
get isConnecting() {
|
|
28
|
-
var _a;
|
|
29
|
-
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
|
|
30
|
-
}
|
|
31
|
-
async connect() {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
if (this.socket) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
this.socket = new ws_1.default(this.url, {
|
|
37
|
-
origin: Defaults_1.DEFAULT_ORIGIN,
|
|
38
|
-
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
39
|
-
handshakeTimeout: this.config.connectTimeoutMs,
|
|
40
|
-
timeout: this.config.connectTimeoutMs,
|
|
41
|
-
agent: this.config.agent,
|
|
42
|
-
});
|
|
43
|
-
this.socket.setMaxListeners(0);
|
|
44
|
-
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
45
|
-
for (const event of events) {
|
|
46
|
-
(_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async close() {
|
|
50
|
-
if (!this.socket) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
this.socket.close();
|
|
54
|
-
this.socket = null;
|
|
55
|
-
}
|
|
56
|
-
send(str, cb) {
|
|
57
|
-
var _a;
|
|
58
|
-
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
|
|
59
|
-
return Boolean(this.socket);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.WebSocketClient = WebSocketClient;
|
package/lib/Socket/community.js
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeCommunitiesSocket = exports.extractCommunityMetadata = void 0;
|
|
4
|
-
const { proto } = require("../../WAProto");
|
|
5
|
-
const { WAMessageStubType, WAMessageAddressingMode } = require("../Types");
|
|
6
|
-
const { generateMessageID, unixTimestampSeconds } = require("../Utils");
|
|
7
|
-
const {
|
|
8
|
-
getBinaryNodeChild,
|
|
9
|
-
getBinaryNodeChildren,
|
|
10
|
-
getBinaryNodeChildString,
|
|
11
|
-
jidEncode,
|
|
12
|
-
jidNormalizedUser,
|
|
13
|
-
} = require("../WABinary");
|
|
14
|
-
const { makeBusinessSocket } = require("./business");
|
|
15
|
-
const makeCommunitiesSocket = (config) => {
|
|
16
|
-
const conn = makeBusinessSocket(config);
|
|
17
|
-
const { authState, ev, query, groupMetadata, upsertMessage, cleanDirtyBits } = conn;
|
|
18
|
-
const communityQuery = async (jid, type, content) => query({
|
|
19
|
-
tag: 'iq',
|
|
20
|
-
attrs: { type, xmlns: 'w:g2', to: jid },
|
|
21
|
-
content
|
|
22
|
-
});
|
|
23
|
-
const communityMetadata = async (jid) => {
|
|
24
|
-
const result = await communityQuery(jid, 'get', [
|
|
25
|
-
{ tag: 'query', attrs: { request: 'interactive' } }
|
|
26
|
-
]);
|
|
27
|
-
return extractCommunityMetadata(result);
|
|
28
|
-
};
|
|
29
|
-
const communityFetchAllParticipating = async () => {
|
|
30
|
-
const result = await query({
|
|
31
|
-
tag: 'iq',
|
|
32
|
-
attrs: { to: '@g.us', xmlns: 'w:g2', type: 'get' },
|
|
33
|
-
content: [
|
|
34
|
-
{
|
|
35
|
-
tag: 'participating',
|
|
36
|
-
attrs: {},
|
|
37
|
-
content: [
|
|
38
|
-
{ tag: 'participants', attrs: {} },
|
|
39
|
-
{ tag: 'description', attrs: {} }
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
});
|
|
44
|
-
const data = {};
|
|
45
|
-
const communitiesChild = getBinaryNodeChild(result, 'communities');
|
|
46
|
-
if (communitiesChild) {
|
|
47
|
-
const communities = getBinaryNodeChildren(communitiesChild, 'community');
|
|
48
|
-
for (const communityNode of communities) {
|
|
49
|
-
const meta = extractCommunityMetadata({
|
|
50
|
-
tag: 'result',
|
|
51
|
-
attrs: {},
|
|
52
|
-
content: [communityNode]
|
|
53
|
-
});
|
|
54
|
-
data[meta.id] = meta;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
conn.ev.emit('groups.update', Object.values(data));
|
|
58
|
-
return data;
|
|
59
|
-
};
|
|
60
|
-
async function parseGroupResult(node) {
|
|
61
|
-
var _a;
|
|
62
|
-
(_a = conn.logger) === null || _a === void 0 ? void 0 : _a.info({ node }, 'parseGroupResult');
|
|
63
|
-
const groupNode = getBinaryNodeChild(node, 'group');
|
|
64
|
-
if (groupNode) {
|
|
65
|
-
try {
|
|
66
|
-
const metadata = await groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
67
|
-
return metadata || null;
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
var _b;
|
|
71
|
-
(_b = conn.logger) === null || _b === void 0 ? void 0 : _b.warn({ error }, 'Error parsing group metadata');
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
conn.ws.on('CB:ib,,dirty', async (node) => {
|
|
78
|
-
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
79
|
-
if (attrs.type !== 'communities') {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
await communityFetchAllParticipating();
|
|
83
|
-
await cleanDirtyBits('groups');
|
|
84
|
-
});
|
|
85
|
-
return {
|
|
86
|
-
...conn,
|
|
87
|
-
communityQuery,
|
|
88
|
-
communityMetadata,
|
|
89
|
-
communityCreate: async (subject, body) => {
|
|
90
|
-
const descriptionId = generateMessageID().substring(0, 12);
|
|
91
|
-
const result = await communityQuery('@g.us', 'set', [
|
|
92
|
-
{
|
|
93
|
-
tag: 'create',
|
|
94
|
-
attrs: { subject },
|
|
95
|
-
content: [
|
|
96
|
-
{
|
|
97
|
-
tag: 'description',
|
|
98
|
-
attrs: { id: descriptionId },
|
|
99
|
-
content: [
|
|
100
|
-
{ tag: 'body', attrs: {}, content: Buffer.from(body || '', 'utf-8') }
|
|
101
|
-
]
|
|
102
|
-
},
|
|
103
|
-
{ tag: 'parent', attrs: { default_membership_approval_mode: 'request_required' } },
|
|
104
|
-
{ tag: 'allow_non_admin_sub_group_creation', attrs: {} },
|
|
105
|
-
{ tag: 'create_general_chat', attrs: {} }
|
|
106
|
-
]
|
|
107
|
-
}
|
|
108
|
-
]);
|
|
109
|
-
return await parseGroupResult(result);
|
|
110
|
-
},
|
|
111
|
-
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
112
|
-
const key = generateMessageID();
|
|
113
|
-
const result = await communityQuery('@g.us', 'set', [
|
|
114
|
-
{
|
|
115
|
-
tag: 'create',
|
|
116
|
-
attrs: { subject, key },
|
|
117
|
-
content: [
|
|
118
|
-
...participants.map((jid) => ({ tag: 'participant', attrs: { jid } })),
|
|
119
|
-
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
120
|
-
]
|
|
121
|
-
}
|
|
122
|
-
]);
|
|
123
|
-
return await parseGroupResult(result);
|
|
124
|
-
},
|
|
125
|
-
communityLeave: async (id) => {
|
|
126
|
-
await communityQuery('@g.us', 'set', [
|
|
127
|
-
{ tag: 'leave', attrs: {}, content: [{ tag: 'community', attrs: { id } }] }
|
|
128
|
-
]);
|
|
129
|
-
},
|
|
130
|
-
communityUpdateSubject: async (jid, subject) => {
|
|
131
|
-
await communityQuery(jid, 'set', [
|
|
132
|
-
{ tag: 'subject', attrs: {}, content: Buffer.from(subject, 'utf-8') }
|
|
133
|
-
]);
|
|
134
|
-
},
|
|
135
|
-
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
136
|
-
await communityQuery(parentCommunityJid, 'set', [
|
|
137
|
-
{
|
|
138
|
-
tag: 'links',
|
|
139
|
-
attrs: {},
|
|
140
|
-
content: [
|
|
141
|
-
{
|
|
142
|
-
tag: 'link',
|
|
143
|
-
attrs: { link_type: 'sub_group' },
|
|
144
|
-
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
145
|
-
}
|
|
146
|
-
]
|
|
147
|
-
}
|
|
148
|
-
]);
|
|
149
|
-
},
|
|
150
|
-
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
151
|
-
await communityQuery(parentCommunityJid, 'set', [
|
|
152
|
-
{
|
|
153
|
-
tag: 'unlink',
|
|
154
|
-
attrs: { unlink_type: 'sub_group' },
|
|
155
|
-
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
156
|
-
}
|
|
157
|
-
]);
|
|
158
|
-
},
|
|
159
|
-
communityFetchLinkedGroups: async (jid) => {
|
|
160
|
-
let communityJid = jid;
|
|
161
|
-
let isCommunity = false;
|
|
162
|
-
const metadata = await groupMetadata(jid);
|
|
163
|
-
if (metadata.linkedParent) {
|
|
164
|
-
communityJid = metadata.linkedParent;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
isCommunity = true;
|
|
168
|
-
}
|
|
169
|
-
const result = await communityQuery(communityJid, 'get', [
|
|
170
|
-
{ tag: 'sub_groups', attrs: {} }
|
|
171
|
-
]);
|
|
172
|
-
const linkedGroupsData = [];
|
|
173
|
-
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups');
|
|
174
|
-
if (subGroupsNode) {
|
|
175
|
-
const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group');
|
|
176
|
-
for (const groupNode of groupNodes) {
|
|
177
|
-
linkedGroupsData.push({
|
|
178
|
-
id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
|
|
179
|
-
subject: groupNode.attrs.subject || '',
|
|
180
|
-
creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
|
|
181
|
-
owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
|
|
182
|
-
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return { communityJid, isCommunity, linkedGroups: linkedGroupsData };
|
|
187
|
-
},
|
|
188
|
-
communityRequestParticipantsList: async (jid) => {
|
|
189
|
-
const result = await communityQuery(jid, 'get', [
|
|
190
|
-
{ tag: 'membership_approval_requests', attrs: {} }
|
|
191
|
-
]);
|
|
192
|
-
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
193
|
-
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
194
|
-
return participants.map((v) => v.attrs);
|
|
195
|
-
},
|
|
196
|
-
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
197
|
-
const result = await communityQuery(jid, 'set', [
|
|
198
|
-
{
|
|
199
|
-
tag: 'membership_requests_action',
|
|
200
|
-
attrs: {},
|
|
201
|
-
content: [
|
|
202
|
-
{
|
|
203
|
-
tag: action,
|
|
204
|
-
attrs: {},
|
|
205
|
-
content: participants.map((jid) => ({ tag: 'participant', attrs: { jid } }))
|
|
206
|
-
}
|
|
207
|
-
]
|
|
208
|
-
}
|
|
209
|
-
]);
|
|
210
|
-
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
211
|
-
const nodeAction = getBinaryNodeChild(node, action);
|
|
212
|
-
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
213
|
-
return participantsAffected.map((p) => ({ status: p.attrs.error || '200', jid: p.attrs.jid }));
|
|
214
|
-
},
|
|
215
|
-
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
216
|
-
const result = await communityQuery(jid, 'set', [
|
|
217
|
-
{
|
|
218
|
-
tag: action,
|
|
219
|
-
attrs: action === 'remove' ? { linked_groups: 'true' } : {},
|
|
220
|
-
content: participants.map((jid) => ({ tag: 'participant', attrs: { jid } }))
|
|
221
|
-
}
|
|
222
|
-
]);
|
|
223
|
-
const node = getBinaryNodeChild(result, action);
|
|
224
|
-
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
225
|
-
return participantsAffected.map((p) => ({ status: p.attrs.error || '200', jid: p.attrs.jid, content: p }));
|
|
226
|
-
},
|
|
227
|
-
communityUpdateDescription: async (jid, description) => {
|
|
228
|
-
var _a;
|
|
229
|
-
const metadata = await communityMetadata(jid);
|
|
230
|
-
const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
|
|
231
|
-
await communityQuery(jid, 'set', [
|
|
232
|
-
{
|
|
233
|
-
tag: 'description',
|
|
234
|
-
attrs: {
|
|
235
|
-
...(description ? { id: generateMessageID() } : { delete: 'true' }),
|
|
236
|
-
...(prev ? { prev } : {})
|
|
237
|
-
},
|
|
238
|
-
content: description
|
|
239
|
-
? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }]
|
|
240
|
-
: undefined
|
|
241
|
-
}
|
|
242
|
-
]);
|
|
243
|
-
},
|
|
244
|
-
communityInviteCode: async (jid) => {
|
|
245
|
-
var _a;
|
|
246
|
-
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
247
|
-
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
248
|
-
return (_a = inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs) === null || _a === void 0 ? void 0 : _a.code;
|
|
249
|
-
},
|
|
250
|
-
communityRevokeInvite: async (jid) => {
|
|
251
|
-
var _a;
|
|
252
|
-
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
253
|
-
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
254
|
-
return (_a = inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs) === null || _a === void 0 ? void 0 : _a.code;
|
|
255
|
-
},
|
|
256
|
-
communityAcceptInvite: async (code) => {
|
|
257
|
-
var _a;
|
|
258
|
-
const results = await communityQuery('@g.us', 'set', [
|
|
259
|
-
{ tag: 'invite', attrs: { code } }
|
|
260
|
-
]);
|
|
261
|
-
const result = getBinaryNodeChild(results, 'community');
|
|
262
|
-
return (_a = result === null || result === void 0 ? void 0 : result.attrs) === null || _a === void 0 ? void 0 : _a.jid;
|
|
263
|
-
},
|
|
264
|
-
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
265
|
-
const result = await communityQuery(communityJid, 'set', [
|
|
266
|
-
{
|
|
267
|
-
tag: 'revoke',
|
|
268
|
-
attrs: {},
|
|
269
|
-
content: [{ tag: 'participant', attrs: { jid: invitedJid } }]
|
|
270
|
-
}
|
|
271
|
-
]);
|
|
272
|
-
return !!result;
|
|
273
|
-
},
|
|
274
|
-
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
275
|
-
var _a;
|
|
276
|
-
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
277
|
-
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
278
|
-
{
|
|
279
|
-
tag: 'accept',
|
|
280
|
-
attrs: {
|
|
281
|
-
code: inviteMessage.inviteCode,
|
|
282
|
-
expiration: inviteMessage.inviteExpiration.toString(),
|
|
283
|
-
admin: key.remoteJid
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
]);
|
|
287
|
-
if (key.id) {
|
|
288
|
-
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
289
|
-
inviteMessage.inviteExpiration = 0;
|
|
290
|
-
inviteMessage.inviteCode = '';
|
|
291
|
-
ev.emit('messages.update', [
|
|
292
|
-
{ key, update: { message: { groupInviteMessage: inviteMessage } } }
|
|
293
|
-
]);
|
|
294
|
-
}
|
|
295
|
-
await upsertMessage({
|
|
296
|
-
key: {
|
|
297
|
-
remoteJid: inviteMessage.groupJid,
|
|
298
|
-
id: generateMessageID((_a = conn.user) === null || _a === void 0 ? void 0 : _a.id),
|
|
299
|
-
fromMe: false,
|
|
300
|
-
participant: key.remoteJid
|
|
301
|
-
},
|
|
302
|
-
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
303
|
-
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
304
|
-
participant: key.remoteJid,
|
|
305
|
-
messageTimestamp: unixTimestampSeconds()
|
|
306
|
-
}, 'notify');
|
|
307
|
-
return results.attrs.from;
|
|
308
|
-
}),
|
|
309
|
-
communityGetInviteInfo: async (code) => {
|
|
310
|
-
const results = await communityQuery('@g.us', 'get', [
|
|
311
|
-
{ tag: 'invite', attrs: { code } }
|
|
312
|
-
]);
|
|
313
|
-
return extractCommunityMetadata(results);
|
|
314
|
-
},
|
|
315
|
-
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
316
|
-
const content = ephemeralExpiration
|
|
317
|
-
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
318
|
-
: { tag: 'not_ephemeral', attrs: {} };
|
|
319
|
-
await communityQuery(jid, 'set', [content]);
|
|
320
|
-
},
|
|
321
|
-
communitySettingUpdate: async (jid, setting) => {
|
|
322
|
-
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
323
|
-
},
|
|
324
|
-
communityMemberAddMode: async (jid, mode) => {
|
|
325
|
-
await communityQuery(jid, 'set', [
|
|
326
|
-
{ tag: 'member_add_mode', attrs: {}, content: mode }
|
|
327
|
-
]);
|
|
328
|
-
},
|
|
329
|
-
communityJoinApprovalMode: async (jid, mode) => {
|
|
330
|
-
await communityQuery(jid, 'set', [
|
|
331
|
-
{
|
|
332
|
-
tag: 'membership_approval_mode',
|
|
333
|
-
attrs: {},
|
|
334
|
-
content: [{ tag: 'community_join', attrs: { state: mode } }]
|
|
335
|
-
}
|
|
336
|
-
]);
|
|
337
|
-
},
|
|
338
|
-
communityFetchAllParticipating
|
|
339
|
-
};
|
|
340
|
-
};
|
|
341
|
-
exports.makeCommunitiesSocket = makeCommunitiesSocket;
|
|
342
|
-
const extractCommunityMetadata = (result) => {
|
|
343
|
-
var _a, _b, _c, _d, _e;
|
|
344
|
-
const community = getBinaryNodeChild(result, 'group');
|
|
345
|
-
const descChild = getBinaryNodeChild(community, 'description');
|
|
346
|
-
let desc;
|
|
347
|
-
let descId;
|
|
348
|
-
if (descChild) {
|
|
349
|
-
desc = getBinaryNodeChildString(descChild, 'body');
|
|
350
|
-
descId = descChild.attrs.id;
|
|
351
|
-
}
|
|
352
|
-
const mode = community.attrs.addressing_mode;
|
|
353
|
-
const communityId = community.attrs.id.includes('@')
|
|
354
|
-
? community.attrs.id
|
|
355
|
-
: jidEncode(community.attrs.id, 'g.us');
|
|
356
|
-
const eph = (_a = getBinaryNodeChild(community, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
|
|
357
|
-
const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
|
|
358
|
-
const metadata = {
|
|
359
|
-
id: communityId,
|
|
360
|
-
subject: community.attrs.subject,
|
|
361
|
-
subjectOwner: community.attrs.s_o,
|
|
362
|
-
subjectOwnerAlt: ((_b = community.attrs) === null || _b === void 0 ? void 0 : _b.s_o_pn) ? community.attrs.s_o_pn : community.attrs.s_o,
|
|
363
|
-
subjectTime: Number(community.attrs.s_t || 0),
|
|
364
|
-
size: Number((_c = community.attrs) === null || _c === void 0 ? void 0 : _c.size
|
|
365
|
-
? community.attrs.size
|
|
366
|
-
: getBinaryNodeChildren(community, 'participant').length),
|
|
367
|
-
creation: Number(community.attrs.creation || 0),
|
|
368
|
-
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
369
|
-
ownerAlt: community.attrs.creator
|
|
370
|
-
? jidNormalizedUser(((_d = community.attrs) === null || _d === void 0 ? void 0 : _d.creator_pn) ? community.attrs.creator_pn : community.attrs.creator)
|
|
371
|
-
: undefined,
|
|
372
|
-
ownerCountry: community.attrs.creator_country_code,
|
|
373
|
-
desc,
|
|
374
|
-
descId,
|
|
375
|
-
linkedParent: ((_e = getBinaryNodeChild(community, 'linked_parent')) === null || _e === void 0 ? void 0 : _e.attrs.jid) || undefined,
|
|
376
|
-
restrict: !!getBinaryNodeChild(community, 'locked'),
|
|
377
|
-
announce: !!getBinaryNodeChild(community, 'announcement'),
|
|
378
|
-
isCommunity: !!getBinaryNodeChild(community, 'parent'),
|
|
379
|
-
isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_group'),
|
|
380
|
-
joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
|
|
381
|
-
memberAddMode,
|
|
382
|
-
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => ({
|
|
383
|
-
id: mode === WAMessageAddressingMode.LID ? community.attrs.phone_number : attrs.jid,
|
|
384
|
-
lid: mode === WAMessageAddressingMode.LID ? community.attrs.jid : attrs.lid,
|
|
385
|
-
admin: attrs.type || null
|
|
386
|
-
})),
|
|
387
|
-
ephemeralDuration: eph ? Number(eph) : undefined,
|
|
388
|
-
addressingMode: mode
|
|
389
|
-
};
|
|
390
|
-
return metadata;
|
|
391
|
-
};
|
|
392
|
-
exports.extractCommunityMetadata = extractCommunityMetadata;
|