@whanext/core 0.19.9 → 0.19.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.19.11
4
+
5
+ - Direct `editedMessage` envelopes are now translated into `messageEdited` events instead of being emitted as ordinary messages.
6
+ - View-once detection now follows multi-device and transparent message wrappers before classifying received media.
7
+ - Added regression coverage for direct edit envelopes and device-sent view-once media.
8
+
9
+ ## 0.19.10
10
+
11
+ - Fixed restored sessions incorrectly waiting for a pairing challenge after the WhatsApp connection was already open.
12
+ - Pairing-code requests now stop immediately when an existing authenticated session reconnects.
13
+
3
14
  ## 0.19.9
4
15
 
5
16
  - Fixed live `message_addon` edits being discarded when Zapo reports the parent message timestamp instead of the mutation timestamp.
package/dist/index.js CHANGED
@@ -2434,7 +2434,8 @@ function isZapoViewOnceContent(input) {
2434
2434
  if (input.viewOnceMessage?.message || input.viewOnceMessageV2?.message || viewOnceV2ExtensionMessage(input)) {
2435
2435
  return true;
2436
2436
  }
2437
- return isZapoViewOnceContent(input.ephemeralMessage?.message);
2437
+ const nested = input.ephemeralMessage?.message ?? input.deviceSentMessage?.message ?? input.documentWithCaptionMessage?.message ?? editedWrapperMessage(input);
2438
+ return nested ? isZapoViewOnceContent(nested) : false;
2438
2439
  }
2439
2440
  function extractQuotedZapoMessage(input) {
2440
2441
  const event = input;
@@ -2837,7 +2838,7 @@ var ZapoProvider = class {
2837
2838
  );
2838
2839
  }
2839
2840
  const client = await this.#ensureClient();
2840
- if (client.getCredentials()?.meJid) {
2841
+ if (client.getCredentials()?.meJid || this.#connected) {
2841
2842
  return "";
2842
2843
  }
2843
2844
  if (!this.#connectPromise && !this.#connected) {
@@ -2851,6 +2852,9 @@ var ZapoProvider = class {
2851
2852
  "The WhatsApp pairing challenge was not received in time."
2852
2853
  );
2853
2854
  }
2855
+ if (!this.#pairingRequired || this.#connected || client.getCredentials()?.meJid) {
2856
+ return "";
2857
+ }
2854
2858
  return await client.auth.requestPairingCode(normalized);
2855
2859
  } catch (error) {
2856
2860
  if (error instanceof WhaNextError) throw error;
@@ -3114,6 +3118,18 @@ var ZapoProvider = class {
3114
3118
  });
3115
3119
  return;
3116
3120
  }
3121
+ const directEdit = this.#directEditedMessage(event.message);
3122
+ if (directEdit && event.key.id) {
3123
+ this.#enqueueProtocolEvent({
3124
+ ...event,
3125
+ protocolMessage: {
3126
+ type: proto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
3127
+ key: event.key,
3128
+ editedMessage: directEdit
3129
+ }
3130
+ });
3131
+ return;
3132
+ }
3117
3133
  this.#handleMessage(event);
3118
3134
  });
3119
3135
  client.on("message_send", (event) => {
@@ -3265,6 +3281,13 @@ var ZapoProvider = class {
3265
3281
  }
3266
3282
  return value;
3267
3283
  }
3284
+ #directEditedMessage(message) {
3285
+ if (!message) return void 0;
3286
+ const direct = message.editedMessage?.message;
3287
+ if (direct) return direct;
3288
+ const nested = message.ephemeralMessage?.message ?? message.deviceSentMessage?.message;
3289
+ return nested ? this.#directEditedMessage(nested) : void 0;
3290
+ }
3268
3291
  #protocolMessage(event) {
3269
3292
  if (event.protocolMessage) return event.protocolMessage;
3270
3293
  const content = unwrapZapoMessageContent(event.message);
@@ -3410,6 +3433,8 @@ var ZapoProvider = class {
3410
3433
  if (event.status === "open") {
3411
3434
  this.#connectPromise = void 0;
3412
3435
  this.#connected = true;
3436
+ this.#resolvePairingReady?.();
3437
+ this.#resolvePairingReady = void 0;
3413
3438
  this.#connectedAtSeconds = Math.floor(Date.now() / 1e3);
3414
3439
  this.#reconnectAttempt = 0;
3415
3440
  this.#closedNotified = false;