whalibmob 5.40.45 → 5.40.46

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.
Files changed (2) hide show
  1. package/lib/Client.js +45 -21
  2. package/package.json +1 -1
package/lib/Client.js CHANGED
@@ -5,6 +5,25 @@ const { statusFrom } = require('./errors');
5
5
  const { dbg: _whaDbg, configureLogger: _whaConfigLogger } = require('./logger');
6
6
 
7
7
  const EventEmitter = require('events');
8
+
9
+ // _processNotification returns this when it already acked (primary pairing).
10
+ const NOTIFICATION_ACK_OWNED = Symbol('notification-ack-owned');
11
+
12
+ // Ack a notification. Every push needs one or the server closes the stream
13
+ // after ~5 min; echo participant/recipient like whatsmeow's sendAck.
14
+ function sendNotificationAck(client, attrs, type) {
15
+ if (!client._socket || !client._connected) return;
16
+ attrs = attrs || {};
17
+ const ack = {
18
+ id: attrs.id || '',
19
+ class: 'notification',
20
+ type: type || '',
21
+ to: attrs.from || 's.whatsapp.net'
22
+ };
23
+ if (attrs.participant) ack.participant = String(attrs.participant);
24
+ if (attrs.recipient) ack.recipient = String(attrs.recipient);
25
+ client._socket.sendNode(new BinaryNode('ack', ack, null));
26
+ }
8
27
  const path = require('path');
9
28
  const fs = require('fs');
10
29
  const crypto = require('crypto');
@@ -4100,6 +4119,14 @@ class WhalibmobClient extends EventEmitter {
4100
4119
  return;
4101
4120
  }
4102
4121
 
4122
+ if (childTag === 'ack') {
4123
+ // Server closed the stream on an unacked stanza; the child names which.
4124
+ const a = (child && child.attrs) || {};
4125
+ _whaDbg('[DBG] STREAM_ERROR ack — server closed the stream on an unacked stanza' +
4126
+ ' id=' + (a.id || '?') + ' class=' + (a.class || '?') + ' type=' + (a.type || '?') +
4127
+ ' from=' + (a.from || a.to || '?'));
4128
+ }
4129
+
4103
4130
  const reason = attrs.reason || conflictType || childTag || code || 'unknown';
4104
4131
  _whaDbg('[DBG] STREAM_ERROR code=' + code + ' child=' + childTag +
4105
4132
  ' conflict=' + conflictType + ' reason=' + reason);
@@ -5067,23 +5094,16 @@ class WhalibmobClient extends EventEmitter {
5067
5094
 
5068
5095
  _handleReceipt(node) {
5069
5096
  const attrs = node.attrs || {};
5097
+ // Ack first (a throwing listener below must not skip it). _sendStanzaAck
5098
+ // puts participant/recipient each on its own attribute; the old inline ack
5099
+ // put participant on `recipient`, so the server re-delivered it every login.
5100
+ this._sendStanzaAck(node);
5070
5101
  this.emit('receipt', {
5071
5102
  id: attrs.id ? String(attrs.id) : '',
5072
5103
  from: attrs.from ? String(attrs.from) : '',
5073
5104
  type: attrs.type ? String(attrs.type) : ''
5074
5105
  });
5075
5106
  this._captureReceipt(node);
5076
- // ACK the receipt back to server (include type so server clears from offline queue)
5077
- if (this._socket && this._connected) {
5078
- const ackAttrs = {
5079
- id: attrs.id || '',
5080
- class: 'receipt',
5081
- to: attrs.from || ''
5082
- };
5083
- if (attrs.type) ackAttrs.type = String(attrs.type);
5084
- if (attrs.participant) ackAttrs.recipient = String(attrs.participant);
5085
- this._socket.sendNode(new BinaryNode('ack', ackAttrs, null));
5086
- }
5087
5107
  // If the recipient couldn't decrypt our message, re-send with fresh Signal session
5088
5108
  if (String(attrs.type || '') === 'retry') {
5089
5109
  this._handleRetryFromRecipient(attrs);
@@ -5617,7 +5637,20 @@ class WhalibmobClient extends EventEmitter {
5617
5637
  });
5618
5638
  }
5619
5639
 
5640
+ // Ack on every exit path (early return or a throwing listener), like
5641
+ // whatsmeow's deferred maybeDeferredAck(). Primary pairing acks itself.
5620
5642
  _handleNotification(node) {
5643
+ const attrs = (node && node.attrs) || {};
5644
+ let ackOwnedElsewhere = false;
5645
+ try {
5646
+ ackOwnedElsewhere = WhalibmobClient.prototype._processNotification.call(this, node) ===
5647
+ NOTIFICATION_ACK_OWNED;
5648
+ } finally {
5649
+ if (!ackOwnedElsewhere) sendNotificationAck(this, attrs, attrs.type || '');
5650
+ }
5651
+ }
5652
+
5653
+ _processNotification(node) {
5621
5654
  const attrs = node.attrs || {};
5622
5655
  const type = attrs.type || '';
5623
5656
 
@@ -5702,7 +5735,7 @@ class WhalibmobClient extends EventEmitter {
5702
5735
  });
5703
5736
  }
5704
5737
  // Primary handler owns durability and the transport ACK.
5705
- return;
5738
+ return NOTIFICATION_ACK_OWNED;
5706
5739
  }
5707
5740
  }
5708
5741
 
@@ -5843,15 +5876,6 @@ class WhalibmobClient extends EventEmitter {
5843
5876
  this.emit('identity_change', { jid: fromJid, user: fromPhone });
5844
5877
  }
5845
5878
 
5846
- // Ack the notification
5847
- if (this._socket && this._connected) {
5848
- this._socket.sendNode(new BinaryNode('ack', {
5849
- id: attrs.id || '',
5850
- class: 'notification',
5851
- type: type,
5852
- to: attrs.from || 's.whatsapp.net'
5853
- }, null));
5854
- }
5855
5879
  }
5856
5880
 
5857
5881
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whalibmob",
3
- "version": "5.40.45",
3
+ "version": "5.40.46",
4
4
  "description": "Node.js library for WhatsApp — register a number over SMS, or link as a companion by QR. Signal E2E encryption, media, groups, channels.",
5
5
  "author": "Kunboruto20",
6
6
  "main": "index.js",