whalibmob 5.5.71 → 5.5.72

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/Client.js CHANGED
@@ -11,6 +11,11 @@ const { checkIfRegistered, checkNumberStatus, requestSmsCode, verifyCode, assert
11
11
  const { getDeviceConfig } = require('./DeviceConfig');
12
12
  const { createNewStore, saveStore, loadStore, toSixParts, fromSixParts } = require('./Store');
13
13
  const { BinaryNode } = require('./BinaryNode');
14
+
15
+ // How many times a message may be re-sent in answer to retry receipts before
16
+ // the client stops. Each resend can itself draw retries, so this is what keeps
17
+ // an undecryptable message from turning into a flood.
18
+ const MAX_RETRY_RESENDS = 2;
14
19
  const { NodeCache } = require('@cacheable/node-cache');
15
20
 
16
21
  // Group metadata cache lifetime — matches DeviceManager's device cache.
@@ -877,6 +882,23 @@ class WhalibmobClient extends EventEmitter {
877
882
  return;
878
883
  }
879
884
 
885
+ // Consume the entry before doing anything else. Every device that failed to
886
+ // decrypt sends its own retry receipt for the same message, and a group
887
+ // resend already re-addresses all of them — without this, each receipt
888
+ // started its own resend.
889
+ this._sentMsgCache.delete(msgId);
890
+
891
+ // Bound the chain. A resend that still cannot be decrypted draws fresh
892
+ // retry receipts of its own, so an unbounded handler answers each one with
893
+ // another send and floods the chat. Give up after a few rounds and leave
894
+ // the message undelivered rather than keep spamming.
895
+ const depth = (cached.retryDepth || 0) + 1;
896
+ if (depth > MAX_RETRY_RESENDS) {
897
+ _whaDbg('[DBG] RETRY_RECV msgId=' + msgId + ' — giving up after ' +
898
+ cached.retryDepth + ' resends\n');
899
+ return;
900
+ }
901
+
880
902
  const fromStr = attrs.from ? String(attrs.from) : '';
881
903
  const isGroup = fromStr.endsWith('@g.us');
882
904
 
@@ -912,13 +934,18 @@ class WhalibmobClient extends EventEmitter {
912
934
  // SenderKey distribution, which only _sendGroupMessage builds. Drop the
913
935
  // "already distributed" record first, or the resend would carry the same
914
936
  // bare skmsg the recipient just told us it could not read.
915
- const resendId = generateMessageId();
937
+ // Carry the round count into the resend so its own retry receipts continue
938
+ // the same chain instead of restarting it at zero.
939
+ const opts = Object.assign({}, cached.options, { _retryDepth: depth });
940
+
916
941
  if (cached.isGroup) {
942
+ const resendId = generateMessageId();
917
943
  if (this._signal && this._signal.senderKeyStore) {
918
944
  this._signal.senderKeyStore.invalidateSKDM(cached.toJid);
919
945
  }
946
+ _whaDbg('[DBG] RETRY_RESEND group round=' + depth + ' newId=' + resendId + '\n');
920
947
  this._sender._sendGroupMessage(
921
- cached.toJid, resendId, cached.plaintext, cached.mediaType, cached.options
948
+ cached.toJid, resendId, cached.plaintext, cached.mediaType, opts
922
949
  )
923
950
  .then(r => _whaDbg('[DBG] RETRY_RESEND group ok id=' + (r && r.id) + '\n'))
924
951
  .catch(e => _whaDbg('[DBG] RETRY_RESEND_ERR: ' + e.message));
@@ -926,7 +953,7 @@ class WhalibmobClient extends EventEmitter {
926
953
  }
927
954
 
928
955
  this._sender._sendDMMessage(
929
- cached.toJid, cached.msgId, cached.plaintext, cached.mediaType, cached.options
956
+ cached.toJid, cached.msgId, cached.plaintext, cached.mediaType, opts
930
957
  )
931
958
  .then(r => _whaDbg('[DBG] RETRY_RESEND ok id=' + r.id + '\n'))
932
959
  .catch(e => _whaDbg('[DBG] RETRY_RESEND_ERR: ' + e.message));
@@ -772,7 +772,8 @@ class MessageSender {
772
772
  // Cache plaintext so Client can re-send with fresh session on recipient retry
773
773
  if (this._client._sentMsgCache) {
774
774
  this._client._sentMsgCache.set(msgId, {
775
- plaintext, toJid, msgId, mediaType, options, recipientPhone
775
+ plaintext, toJid, msgId, mediaType, options, recipientPhone,
776
+ retryDepth: options._retryDepth || 0
776
777
  });
777
778
  // Keep cache bounded — evict oldest entries beyond 200
778
779
  if (this._client._sentMsgCache.size > 200) {
@@ -980,7 +981,8 @@ class MessageSender {
980
981
  // then silently never arrived.
981
982
  if (this._client._sentMsgCache) {
982
983
  this._client._sentMsgCache.set(msgId, {
983
- plaintext, toJid: groupJid, msgId, mediaType, options, isGroup: true
984
+ plaintext, toJid: groupJid, msgId, mediaType, options, isGroup: true,
985
+ retryDepth: options._retryDepth || 0
984
986
  });
985
987
  if (this._client._sentMsgCache.size > 200) {
986
988
  const firstKey = this._client._sentMsgCache.keys().next().value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whalibmob",
3
- "version": "5.5.71",
3
+ "version": "5.5.72",
4
4
  "description": "WhatsApp library for interaction with WhatsApp Mobile API no web",
5
5
  "author": "Kunboruto50",
6
6
  "main": "index.js",