jagproject 26.3.23 → 26.3.26
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/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +73 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +64857 -145167
- package/engine-requirements.js +4 -7
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +49 -35
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/wileys-version.json +2 -2
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +5 -3
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +35 -46
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +21 -21
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +2 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +5 -10
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +8 -8
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +25 -37
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +358 -54
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +18 -30
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.js +160 -38
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +497 -314
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.js +438 -0
- package/lib/Socket/community.js +333 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +229 -91
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.js +1105 -501
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.js +1181 -501
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.js +227 -200
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +507 -206
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +17 -5
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +48 -89
- package/lib/Store/make-ordered-dictionary.js +1 -1
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +1 -3
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +1 -3
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.js +9 -5
- package/lib/Types/MexUpdates.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +36 -11
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +14 -14
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +222 -123
- package/lib/Utils/baileys-event-stream.js +60 -0
- package/lib/Utils/bridge-runtime.d.ts +1 -0
- package/lib/Utils/bridge-runtime.js +14 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +38 -29
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +54 -48
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +284 -189
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +16 -41
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +128 -48
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +124 -62
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +154 -138
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +77 -34
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +54 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +32 -19
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +12 -17
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +2 -43
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +21 -27
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +143 -45
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +429 -502
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +295 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.js +1025 -674
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +145 -91
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +112 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +316 -184
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +95 -0
- package/lib/Utils/rust-bridge-shim.d.ts +22 -0
- package/lib/Utils/rust-bridge-shim.js +70 -0
- package/lib/Utils/serial-task-queue.js +29 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +56 -39
- package/lib/Utils/streamToBuffer.js +17 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +20 -0
- package/lib/Utils/use-mongo-file-auth-state.js +71 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +11 -12
- package/lib/Utils/use-single-file-auth-state.js +73 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +59 -82
- package/lib/Utils/wileys-event-stream.js +1 -61
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +39 -4
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +17 -11
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +46 -18
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +9 -5
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +67 -37
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +34 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +19183 -11678
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +15 -17
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +6 -4
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +38 -30
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.d.ts +12 -0
- package/lib/index.js +3 -5
- package/package.json +7 -4
- package/LICENSE +0 -21
package/lib/Socket/groups.js
CHANGED
|
@@ -1,26 +1,116 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractGroupMetadata = exports.makeGroupsSocket = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
5
|
+
const index_js_2 = require("../Types/index.js");
|
|
6
|
+
const index_js_3 = require("../Utils/index.js");
|
|
7
|
+
const index_js_4 = require("../WABinary/index.js");
|
|
8
|
+
const chats_js_1 = require("./chats.js");
|
|
9
9
|
const makeGroupsSocket = (config) => {
|
|
10
|
-
const sock = (0,
|
|
10
|
+
const sock = (0, chats_js_1.makeChatsSocket)(config);
|
|
11
11
|
const { authState, ev, query, upsertMessage } = sock;
|
|
12
|
-
const
|
|
12
|
+
const { cachedGroupMetadata } = config;
|
|
13
|
+
// ── Built-in group metadata cache ─────────────────────────────────────────
|
|
14
|
+
const groupMetadataCache = new Map();
|
|
15
|
+
const GROUP_CACHE_TTL = (config.groupCacheTTL || 5) * 60 * 1000; // default 5 menit
|
|
16
|
+
const getCachedGroupMetadata = async (jid) => {
|
|
17
|
+
// 1. Cek user-provided cachedGroupMetadata (dari config makeWASocket)
|
|
18
|
+
if (cachedGroupMetadata) {
|
|
19
|
+
const cached = await cachedGroupMetadata(jid);
|
|
20
|
+
if (cached && Array.isArray(cached.participants))
|
|
21
|
+
return cached;
|
|
22
|
+
}
|
|
23
|
+
// 2. Cek internal Map cache
|
|
24
|
+
const entry = groupMetadataCache.get(jid);
|
|
25
|
+
if (entry && Date.now() - entry.ts < GROUP_CACHE_TTL) {
|
|
26
|
+
return entry.data;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
};
|
|
30
|
+
const setCachedGroupMetadata = (jid, data) => {
|
|
31
|
+
groupMetadataCache.set(jid, { data, ts: Date.now() });
|
|
32
|
+
};
|
|
33
|
+
// Update cache saat groups.update event
|
|
34
|
+
ev.on('groups.update', (updates) => {
|
|
35
|
+
for (const update of updates) {
|
|
36
|
+
const entry = groupMetadataCache.get(update.id);
|
|
37
|
+
if (entry) {
|
|
38
|
+
// Merge update ke cache yang ada
|
|
39
|
+
groupMetadataCache.set(update.id, {
|
|
40
|
+
data: { ...entry.data, ...update },
|
|
41
|
+
ts: entry.ts
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// Update cache saat participant berubah
|
|
47
|
+
// Debounce map to prevent duplicate refresh calls for same group
|
|
48
|
+
const _refreshDebounce = new Map();
|
|
49
|
+
const _refreshGroupMetadata = async (jid) => {
|
|
50
|
+
// Debounce: skip jika refresh sudah dijadwalkan dalam 2 detik terakhir
|
|
51
|
+
if (_refreshDebounce.has(jid))
|
|
52
|
+
return;
|
|
53
|
+
_refreshDebounce.set(jid, true);
|
|
54
|
+
setTimeout(() => _refreshDebounce.delete(jid), 2000);
|
|
55
|
+
try {
|
|
56
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
57
|
+
const meta = (0, exports.extractGroupMetadata)(result);
|
|
58
|
+
setCachedGroupMetadata(jid, meta);
|
|
59
|
+
// Emit groups.update agar subscriber luar (makeInMemoryStore dll) ikut terupdate
|
|
60
|
+
ev.emit('groups.update', [meta]);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
// Ignore jika gagal (bot mungkin sudah keluar dari grup)
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
ev.on('group-participants.update', ({ id, participants, action }) => {
|
|
67
|
+
const entry = groupMetadataCache.get(id);
|
|
68
|
+
if (entry && Array.isArray(entry.data?.participants)) {
|
|
69
|
+
// Fast-path: update cache lokal secara optimistis tanpa tunggu network
|
|
70
|
+
const meta = { ...entry.data, participants: [...entry.data.participants] };
|
|
71
|
+
if (action === 'add') {
|
|
72
|
+
const existing = new Set(meta.participants.map(p => p.id));
|
|
73
|
+
for (const jid of participants) {
|
|
74
|
+
if (!existing.has(jid))
|
|
75
|
+
meta.participants.push({ id: jid, admin: null });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (action === 'remove') {
|
|
79
|
+
meta.participants = meta.participants.filter(p => !participants.includes(p.id));
|
|
80
|
+
}
|
|
81
|
+
else if (action === 'promote') {
|
|
82
|
+
meta.participants = meta.participants.map(p => participants.includes(p.id) ? { ...p, admin: 'admin' } : p);
|
|
83
|
+
}
|
|
84
|
+
else if (action === 'demote') {
|
|
85
|
+
meta.participants = meta.participants.map(p => participants.includes(p.id) ? { ...p, admin: null } : p);
|
|
86
|
+
}
|
|
87
|
+
groupMetadataCache.set(id, { data: meta, ts: entry.ts });
|
|
88
|
+
}
|
|
89
|
+
// Auto-refresh dari network untuk semua aksi participant
|
|
90
|
+
// Ini memastikan data selalu akurat dari server WA
|
|
91
|
+
_refreshGroupMetadata(id);
|
|
92
|
+
});
|
|
93
|
+
// ── End group metadata cache ───────────────────────────────────────────────
|
|
94
|
+
const groupQuery = async (jid, type, content) => query({
|
|
13
95
|
tag: 'iq',
|
|
14
96
|
attrs: {
|
|
15
97
|
type,
|
|
16
98
|
xmlns: 'w:g2',
|
|
17
|
-
to: jid
|
|
99
|
+
to: jid
|
|
18
100
|
},
|
|
19
101
|
content
|
|
20
|
-
})
|
|
102
|
+
});
|
|
21
103
|
const groupMetadata = async (jid) => {
|
|
104
|
+
// Cek cache dulu sebelum hit network
|
|
105
|
+
const cached = await getCachedGroupMetadata(jid);
|
|
106
|
+
if (cached)
|
|
107
|
+
return cached;
|
|
108
|
+
// Fetch dari WA
|
|
22
109
|
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
23
|
-
|
|
110
|
+
const meta = (0, exports.extractGroupMetadata)(result);
|
|
111
|
+
// Simpan ke cache
|
|
112
|
+
setCachedGroupMetadata(jid, meta);
|
|
113
|
+
return meta;
|
|
24
114
|
};
|
|
25
115
|
const groupFetchAllParticipating = async () => {
|
|
26
116
|
const result = await query({
|
|
@@ -28,7 +118,7 @@ const makeGroupsSocket = (config) => {
|
|
|
28
118
|
attrs: {
|
|
29
119
|
to: '@g.us',
|
|
30
120
|
xmlns: 'w:g2',
|
|
31
|
-
type: 'get'
|
|
121
|
+
type: 'get'
|
|
32
122
|
},
|
|
33
123
|
content: [
|
|
34
124
|
{
|
|
@@ -42,9 +132,9 @@ const makeGroupsSocket = (config) => {
|
|
|
42
132
|
]
|
|
43
133
|
});
|
|
44
134
|
const data = {};
|
|
45
|
-
const groupsChild = (0,
|
|
135
|
+
const groupsChild = (0, index_js_4.getBinaryNodeChild)(result, 'groups');
|
|
46
136
|
if (groupsChild) {
|
|
47
|
-
const groups = (0,
|
|
137
|
+
const groups = (0, index_js_4.getBinaryNodeChildren)(groupsChild, 'group');
|
|
48
138
|
for (const groupNode of groups) {
|
|
49
139
|
const meta = (0, exports.extractGroupMetadata)({
|
|
50
140
|
tag: 'result',
|
|
@@ -54,11 +144,12 @@ const makeGroupsSocket = (config) => {
|
|
|
54
144
|
data[meta.id] = meta;
|
|
55
145
|
}
|
|
56
146
|
}
|
|
147
|
+
// TODO: properly parse LID / PN DATA
|
|
57
148
|
sock.ev.emit('groups.update', Object.values(data));
|
|
58
149
|
return data;
|
|
59
150
|
};
|
|
60
151
|
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
61
|
-
const { attrs } = (0,
|
|
152
|
+
const { attrs } = (0, index_js_4.getBinaryNodeChild)(node, 'dirty');
|
|
62
153
|
if (attrs.type !== 'groups') {
|
|
63
154
|
return;
|
|
64
155
|
}
|
|
@@ -67,10 +158,9 @@ const makeGroupsSocket = (config) => {
|
|
|
67
158
|
});
|
|
68
159
|
return {
|
|
69
160
|
...sock,
|
|
70
|
-
groupQuery,
|
|
71
161
|
groupMetadata,
|
|
72
162
|
groupCreate: async (subject, participants) => {
|
|
73
|
-
const key = (0,
|
|
163
|
+
const key = (0, index_js_3.generateMessageIDV2)();
|
|
74
164
|
const result = await groupQuery('@g.us', 'set', [
|
|
75
165
|
{
|
|
76
166
|
tag: 'create',
|
|
@@ -91,9 +181,7 @@ const makeGroupsSocket = (config) => {
|
|
|
91
181
|
{
|
|
92
182
|
tag: 'leave',
|
|
93
183
|
attrs: {},
|
|
94
|
-
content: [
|
|
95
|
-
{ tag: 'group', attrs: { id } }
|
|
96
|
-
]
|
|
184
|
+
content: [{ tag: 'group', attrs: { id } }]
|
|
97
185
|
}
|
|
98
186
|
]);
|
|
99
187
|
},
|
|
@@ -113,12 +201,13 @@ const makeGroupsSocket = (config) => {
|
|
|
113
201
|
attrs: {}
|
|
114
202
|
}
|
|
115
203
|
]);
|
|
116
|
-
const node = (0,
|
|
117
|
-
const participants = (0,
|
|
204
|
+
const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_approval_requests');
|
|
205
|
+
const participants = (0, index_js_4.getBinaryNodeChildren)(node, 'membership_approval_request');
|
|
118
206
|
return participants.map(v => v.attrs);
|
|
119
207
|
},
|
|
120
208
|
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
121
|
-
const result = await groupQuery(jid, 'set', [
|
|
209
|
+
const result = await groupQuery(jid, 'set', [
|
|
210
|
+
{
|
|
122
211
|
tag: 'membership_requests_action',
|
|
123
212
|
attrs: {},
|
|
124
213
|
content: [
|
|
@@ -131,10 +220,11 @@ const makeGroupsSocket = (config) => {
|
|
|
131
220
|
}))
|
|
132
221
|
}
|
|
133
222
|
]
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
const
|
|
223
|
+
}
|
|
224
|
+
]);
|
|
225
|
+
const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_requests_action');
|
|
226
|
+
const nodeAction = (0, index_js_4.getBinaryNodeChild)(node, action);
|
|
227
|
+
const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(nodeAction, 'participant');
|
|
138
228
|
return participantsAffected.map(p => {
|
|
139
229
|
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
140
230
|
});
|
|
@@ -150,43 +240,40 @@ const makeGroupsSocket = (config) => {
|
|
|
150
240
|
}))
|
|
151
241
|
}
|
|
152
242
|
]);
|
|
153
|
-
const node = (0,
|
|
154
|
-
const participantsAffected = (0,
|
|
243
|
+
const node = (0, index_js_4.getBinaryNodeChild)(result, action);
|
|
244
|
+
const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(node, 'participant');
|
|
155
245
|
return participantsAffected.map(p => {
|
|
156
246
|
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
157
247
|
});
|
|
158
248
|
},
|
|
159
249
|
groupUpdateDescription: async (jid, description) => {
|
|
160
|
-
var _a;
|
|
161
250
|
const metadata = await groupMetadata(jid);
|
|
162
|
-
const prev =
|
|
251
|
+
const prev = metadata.descId ?? null;
|
|
163
252
|
await groupQuery(jid, 'set', [
|
|
164
253
|
{
|
|
165
254
|
tag: 'description',
|
|
166
255
|
attrs: {
|
|
167
|
-
...(description ? { id: (0,
|
|
256
|
+
...(description ? { id: (0, index_js_3.generateMessageIDV2)() } : { delete: 'true' }),
|
|
168
257
|
...(prev ? { prev } : {})
|
|
169
258
|
},
|
|
170
|
-
content: description ? [
|
|
171
|
-
{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
|
|
172
|
-
] : undefined
|
|
259
|
+
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
173
260
|
}
|
|
174
261
|
]);
|
|
175
262
|
},
|
|
176
263
|
groupInviteCode: async (jid) => {
|
|
177
264
|
const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
178
|
-
const inviteNode = (0,
|
|
179
|
-
return inviteNode
|
|
265
|
+
const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
|
|
266
|
+
return inviteNode?.attrs.code;
|
|
180
267
|
},
|
|
181
268
|
groupRevokeInvite: async (jid) => {
|
|
182
269
|
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
183
|
-
const inviteNode = (0,
|
|
184
|
-
return inviteNode
|
|
270
|
+
const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
|
|
271
|
+
return inviteNode?.attrs.code;
|
|
185
272
|
},
|
|
186
273
|
groupAcceptInvite: async (code) => {
|
|
187
274
|
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
188
|
-
const result = (0,
|
|
189
|
-
return result
|
|
275
|
+
const result = (0, index_js_4.getBinaryNodeChild)(results, 'group');
|
|
276
|
+
return result?.attrs.jid;
|
|
190
277
|
},
|
|
191
278
|
/**
|
|
192
279
|
* revoke a v4 invite for someone
|
|
@@ -195,7 +282,9 @@ const makeGroupsSocket = (config) => {
|
|
|
195
282
|
* @returns true if successful
|
|
196
283
|
*/
|
|
197
284
|
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
198
|
-
const result = await groupQuery(groupJid, 'set', [
|
|
285
|
+
const result = await groupQuery(groupJid, 'set', [
|
|
286
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
287
|
+
]);
|
|
199
288
|
return !!result;
|
|
200
289
|
},
|
|
201
290
|
/**
|
|
@@ -204,21 +293,22 @@ const makeGroupsSocket = (config) => {
|
|
|
204
293
|
* @param inviteMessage the message to accept
|
|
205
294
|
*/
|
|
206
295
|
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
207
|
-
var _a;
|
|
208
296
|
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
209
|
-
const results = await groupQuery(inviteMessage.groupJid, 'set', [
|
|
297
|
+
const results = await groupQuery(inviteMessage.groupJid, 'set', [
|
|
298
|
+
{
|
|
210
299
|
tag: 'accept',
|
|
211
300
|
attrs: {
|
|
212
301
|
code: inviteMessage.inviteCode,
|
|
213
302
|
expiration: inviteMessage.inviteExpiration.toString(),
|
|
214
303
|
admin: key.remoteJid
|
|
215
304
|
}
|
|
216
|
-
}
|
|
305
|
+
}
|
|
306
|
+
]);
|
|
217
307
|
// if we have the full message key
|
|
218
308
|
// update the invite message to be expired
|
|
219
309
|
if (key.id) {
|
|
220
310
|
// create new invite message that is expired
|
|
221
|
-
inviteMessage =
|
|
311
|
+
inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
222
312
|
inviteMessage.inviteExpiration = 0;
|
|
223
313
|
inviteMessage.inviteCode = '';
|
|
224
314
|
ev.emit('messages.update', [
|
|
@@ -236,16 +326,14 @@ const makeGroupsSocket = (config) => {
|
|
|
236
326
|
await upsertMessage({
|
|
237
327
|
key: {
|
|
238
328
|
remoteJid: inviteMessage.groupJid,
|
|
239
|
-
id: (0,
|
|
329
|
+
id: (0, index_js_3.generateMessageIDV2)(sock.user?.id),
|
|
240
330
|
fromMe: false,
|
|
241
|
-
participant: key.remoteJid
|
|
331
|
+
participant: key.remoteJid
|
|
242
332
|
},
|
|
243
|
-
messageStubType:
|
|
244
|
-
messageStubParameters: [
|
|
245
|
-
authState.creds.me.id
|
|
246
|
-
],
|
|
333
|
+
messageStubType: index_js_2.WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
334
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
247
335
|
participant: key.remoteJid,
|
|
248
|
-
messageTimestamp: (0,
|
|
336
|
+
messageTimestamp: (0, index_js_3.unixTimestampSeconds)()
|
|
249
337
|
}, 'notify');
|
|
250
338
|
return results.attrs.from;
|
|
251
339
|
}),
|
|
@@ -254,9 +342,9 @@ const makeGroupsSocket = (config) => {
|
|
|
254
342
|
return (0, exports.extractGroupMetadata)(results);
|
|
255
343
|
},
|
|
256
344
|
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
257
|
-
const content = ephemeralExpiration
|
|
258
|
-
{ tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
259
|
-
{ tag: 'not_ephemeral', attrs: {} };
|
|
345
|
+
const content = ephemeralExpiration
|
|
346
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
347
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
260
348
|
await groupQuery(jid, 'set', [content]);
|
|
261
349
|
},
|
|
262
350
|
groupSettingUpdate: async (jid, setting) => {
|
|
@@ -266,63 +354,113 @@ const makeGroupsSocket = (config) => {
|
|
|
266
354
|
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
267
355
|
},
|
|
268
356
|
groupJoinApprovalMode: async (jid, mode) => {
|
|
269
|
-
await groupQuery(jid, 'set', [
|
|
357
|
+
await groupQuery(jid, 'set', [
|
|
358
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
|
|
359
|
+
]);
|
|
270
360
|
},
|
|
271
|
-
groupFetchAllParticipating
|
|
361
|
+
groupFetchAllParticipating,
|
|
362
|
+
/**
|
|
363
|
+
* Auto detect isAdmin & isBotAdmin dari groupMetadata
|
|
364
|
+
* @param {string} groupJid - JID grup
|
|
365
|
+
* @param {string} senderJid - JID pengirim pesan
|
|
366
|
+
* @returns {Promise<{isAdmin: boolean, isBotAdmin: boolean}>}
|
|
367
|
+
*/
|
|
368
|
+
getAdminStatus: async (groupJid, senderJid) => {
|
|
369
|
+
const normalizeJid = (jid) => {
|
|
370
|
+
if (!jid)
|
|
371
|
+
return null;
|
|
372
|
+
try {
|
|
373
|
+
return (0, index_js_4.jidNormalizedUser)(jid).split('@')[0];
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
return String(jid).split('@')[0];
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const botJid = sock.authState?.creds?.me?.id;
|
|
380
|
+
const meta = await sock.groupMetadata(groupJid).catch(() => null);
|
|
381
|
+
if (!meta || !Array.isArray(meta.participants)) {
|
|
382
|
+
return { isAdmin: false, isBotAdmin: false };
|
|
383
|
+
}
|
|
384
|
+
const senderNorm = normalizeJid(senderJid);
|
|
385
|
+
const botNorm = normalizeJid(botJid);
|
|
386
|
+
const isAdmin = meta.participants.some(p => {
|
|
387
|
+
const pid = normalizeJid(p.jid || p.id || p.lid);
|
|
388
|
+
return pid === senderNorm && (p.admin === 'admin' || p.admin === 'superadmin');
|
|
389
|
+
});
|
|
390
|
+
// Cek isBotAdmin: via participants
|
|
391
|
+
let isBotAdmin = meta.participants.some(p => {
|
|
392
|
+
const pid = normalizeJid(p.jid || p.id || p.lid);
|
|
393
|
+
return pid === botNorm && (p.admin === 'admin' || p.admin === 'superadmin');
|
|
394
|
+
});
|
|
395
|
+
// Fallback: cek via owner/subjectOwner
|
|
396
|
+
if (!isBotAdmin) {
|
|
397
|
+
const owners = [meta.owner, meta.subjectOwner, meta.ownerPn]
|
|
398
|
+
.filter(Boolean)
|
|
399
|
+
.map(normalizeJid);
|
|
400
|
+
if (owners.includes(botNorm))
|
|
401
|
+
isBotAdmin = true;
|
|
402
|
+
}
|
|
403
|
+
return { isAdmin, isBotAdmin };
|
|
404
|
+
}
|
|
272
405
|
};
|
|
273
406
|
};
|
|
274
407
|
exports.makeGroupsSocket = makeGroupsSocket;
|
|
275
408
|
const extractGroupMetadata = (result) => {
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
|
|
409
|
+
const group = (0, index_js_4.getBinaryNodeChild)(result, 'group');
|
|
410
|
+
const descChild = (0, index_js_4.getBinaryNodeChild)(group, 'description');
|
|
279
411
|
let desc;
|
|
280
412
|
let descId;
|
|
281
413
|
let descOwner;
|
|
282
|
-
let
|
|
414
|
+
let descOwnerPn;
|
|
283
415
|
let descTime;
|
|
284
416
|
if (descChild) {
|
|
285
|
-
desc = (0,
|
|
286
|
-
descOwner = (0,
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
417
|
+
desc = (0, index_js_4.getBinaryNodeChildString)(descChild, 'body');
|
|
418
|
+
descOwner = descChild.attrs.participant ? (0, index_js_4.jidNormalizedUser)(descChild.attrs.participant) : undefined;
|
|
419
|
+
descOwnerPn = descChild.attrs.participant_pn ? (0, index_js_4.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
|
|
420
|
+
descTime = +descChild.attrs.t;
|
|
290
421
|
descId = descChild.attrs.id;
|
|
291
|
-
descTime = descChild.attrs.t ? +descChild.attrs.t : undefined;
|
|
292
422
|
}
|
|
293
|
-
const
|
|
294
|
-
const
|
|
295
|
-
const
|
|
296
|
-
const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
|
|
423
|
+
const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, index_js_4.jidEncode)(group.attrs.id, 'g.us');
|
|
424
|
+
const eph = (0, index_js_4.getBinaryNodeChild)(group, 'ephemeral')?.attrs.expiration;
|
|
425
|
+
const memberAddMode = (0, index_js_4.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
|
|
297
426
|
const metadata = {
|
|
298
427
|
id: groupId,
|
|
299
|
-
|
|
428
|
+
notify: group.attrs.notify,
|
|
429
|
+
addressingMode: group.attrs.addressing_mode === 'lid' ? index_js_2.WAMessageAddressingMode.LID : index_js_2.WAMessageAddressingMode.PN,
|
|
300
430
|
subject: group.attrs.subject,
|
|
301
|
-
subjectOwner:
|
|
302
|
-
|
|
303
|
-
subjectTime:
|
|
304
|
-
size:
|
|
305
|
-
creation:
|
|
306
|
-
owner: (0,
|
|
307
|
-
|
|
431
|
+
subjectOwner: group.attrs.s_o,
|
|
432
|
+
subjectOwnerPn: group.attrs.s_o_pn,
|
|
433
|
+
subjectTime: +group.attrs.s_t,
|
|
434
|
+
size: group.attrs.size ? +group.attrs.size : (0, index_js_4.getBinaryNodeChildren)(group, 'participant').length,
|
|
435
|
+
creation: +group.attrs.creation,
|
|
436
|
+
owner: group.attrs.creator ? (0, index_js_4.jidNormalizedUser)(group.attrs.creator) : undefined,
|
|
437
|
+
ownerPn: group.attrs.creator_pn ? (0, index_js_4.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
|
|
438
|
+
owner_country_code: group.attrs.creator_country_code,
|
|
308
439
|
desc,
|
|
309
440
|
descId,
|
|
310
441
|
descOwner,
|
|
311
|
-
|
|
442
|
+
descOwnerPn,
|
|
312
443
|
descTime,
|
|
313
|
-
linkedParent: (
|
|
314
|
-
restrict: !!(0,
|
|
315
|
-
announce: !!(0,
|
|
316
|
-
isCommunity: !!(0,
|
|
317
|
-
isCommunityAnnounce: !!(0,
|
|
318
|
-
joinApprovalMode: !!(0,
|
|
444
|
+
linkedParent: (0, index_js_4.getBinaryNodeChild)(group, 'linked_parent')?.attrs.jid || undefined,
|
|
445
|
+
restrict: !!(0, index_js_4.getBinaryNodeChild)(group, 'locked'),
|
|
446
|
+
announce: !!(0, index_js_4.getBinaryNodeChild)(group, 'announcement'),
|
|
447
|
+
isCommunity: !!(0, index_js_4.getBinaryNodeChild)(group, 'parent'),
|
|
448
|
+
isCommunityAnnounce: !!(0, index_js_4.getBinaryNodeChild)(group, 'default_sub_group'),
|
|
449
|
+
joinApprovalMode: !!(0, index_js_4.getBinaryNodeChild)(group, 'membership_approval_mode'),
|
|
319
450
|
memberAddMode,
|
|
320
|
-
participants: (0,
|
|
451
|
+
participants: (0, index_js_4.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
|
|
452
|
+
const isLid = (0, index_js_4.isLidUser)(attrs.jid);
|
|
453
|
+
const pn = attrs.phone_number;
|
|
454
|
+
const hasPn = (0, index_js_4.isPnUser)(pn);
|
|
455
|
+
// Jika grup pakai LID addressing:
|
|
456
|
+
// - id → pakai phoneNumber (PN) agar bisa dicompare dengan m.sender
|
|
457
|
+
// - lid → simpan LID asli
|
|
458
|
+
// Jika grup pakai PN addressing: id tetap PN
|
|
321
459
|
return {
|
|
322
|
-
id: attrs.jid,
|
|
323
|
-
|
|
324
|
-
lid: attrs.
|
|
325
|
-
admin: (attrs.type || null)
|
|
460
|
+
id: isLid && hasPn ? pn : attrs.jid,
|
|
461
|
+
phoneNumber: isLid && hasPn ? pn : undefined,
|
|
462
|
+
lid: isLid ? attrs.jid : ((0, index_js_4.isPnUser)(attrs.jid) && (0, index_js_4.isLidUser)(attrs.lid) ? attrs.lid : undefined),
|
|
463
|
+
admin: (attrs.type || null)
|
|
326
464
|
};
|
|
327
465
|
}),
|
|
328
466
|
ephemeralDuration: eph ? +eph : undefined
|