zapo-js 1.8.0 → 1.8.2

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.
@@ -24,6 +24,23 @@ interface WaIncomingMessageAckHandlerOptions {
24
24
  readonly emitUnhandledStanza?: (event: WaIncomingUnhandledStanzaEvent) => void;
25
25
  readonly emitDecryptedPayload?: (build: () => WaIncomingDecryptedPayloadEvent) => void;
26
26
  }
27
+ /**
28
+ * Resolves who authored a {@link proto.IWebMessageInfo}. The top-level
29
+ * `participant` wins over `key.participant` - history sync carries the group
30
+ * sender in the former and leaves the latter empty on a large share of records.
31
+ * A self-sent group/broadcast message with neither falls back to this account,
32
+ * preferring `originalSelfAuthorUserJidString` over `meJid` (the current account
33
+ * user JID) so a message authored under a previous identity keeps its author.
34
+ *
35
+ * The participant fields are read whatever the thread type is, matching how
36
+ * WhatsApp Web builds the author: only the self-sent fallback is gated on
37
+ * group/broadcast. A 1:1 record normally carries neither, so this returns
38
+ * `undefined` there and the caller supplies the thread JID instead.
39
+ *
40
+ * `threadJid` overrides `key.remoteJid` for carriers that know the thread out
41
+ * of band, such as a group history bundle whose records may omit it.
42
+ */
43
+ export declare function resolveWebMessageInfoAuthor(webMessageInfo: proto.IWebMessageInfo, meJid?: string | null, threadJid?: string): string | undefined;
27
44
  /**
28
45
  * Rebuilds a `message` event from a recovered {@link proto.IWebMessageInfo}
29
46
  * (placeholder resend). `meJid` is the current account user JID, used as the
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveWebMessageInfoAuthor = resolveWebMessageInfoAuthor;
3
4
  exports.buildRecoveredIncomingEvent = buildRecoveredIncomingEvent;
4
5
  exports.handleIncomingMessageAck = handleIncomingMessageAck;
5
6
  const context_info_1 = require("../context-info");
@@ -129,6 +130,32 @@ function buildIncomingEventRawNode(node) {
129
130
  content: children
130
131
  };
131
132
  }
133
+ /**
134
+ * Resolves who authored a {@link proto.IWebMessageInfo}. The top-level
135
+ * `participant` wins over `key.participant` - history sync carries the group
136
+ * sender in the former and leaves the latter empty on a large share of records.
137
+ * A self-sent group/broadcast message with neither falls back to this account,
138
+ * preferring `originalSelfAuthorUserJidString` over `meJid` (the current account
139
+ * user JID) so a message authored under a previous identity keeps its author.
140
+ *
141
+ * The participant fields are read whatever the thread type is, matching how
142
+ * WhatsApp Web builds the author: only the self-sent fallback is gated on
143
+ * group/broadcast. A 1:1 record normally carries neither, so this returns
144
+ * `undefined` there and the caller supplies the thread JID instead.
145
+ *
146
+ * `threadJid` overrides `key.remoteJid` for carriers that know the thread out
147
+ * of band, such as a group history bundle whose records may omit it.
148
+ */
149
+ function resolveWebMessageInfoAuthor(webMessageInfo, meJid, threadJid) {
150
+ const key = webMessageInfo.key ?? {};
151
+ const chatJid = threadJid ?? key.remoteJid ?? undefined;
152
+ const isGroupOrBroadcast = chatJid ? (0, jid_1.isGroupJid)(chatJid) || (0, jid_1.isBroadcastJid)(chatJid) : false;
153
+ const rawSelfAuthor = webMessageInfo.originalSelfAuthorUserJidString ?? meJid ?? undefined;
154
+ const selfAuthor = key.fromMe === true && isGroupOrBroadcast && rawSelfAuthor
155
+ ? (0, jid_1.toUserJid)(rawSelfAuthor)
156
+ : undefined;
157
+ return webMessageInfo.participant ?? key.participant ?? selfAuthor ?? undefined;
158
+ }
132
159
  /**
133
160
  * Rebuilds a `message` event from a recovered {@link proto.IWebMessageInfo}
134
161
  * (placeholder resend). `meJid` is the current account user JID, used as the
@@ -141,9 +168,7 @@ function buildRecoveredIncomingEvent(webMessageInfo, meJid) {
141
168
  const fromMe = key.fromMe === true;
142
169
  const isGroup = chatJid ? (0, jid_1.isGroupJid)(chatJid) : false;
143
170
  const isBroadcast = chatJid ? (0, jid_1.isBroadcastJid)(chatJid) : false;
144
- const rawSelfAuthor = webMessageInfo.originalSelfAuthorUserJidString ?? meJid ?? undefined;
145
- const selfAuthor = fromMe && (isGroup || isBroadcast) && rawSelfAuthor ? (0, jid_1.toUserJid)(rawSelfAuthor) : undefined;
146
- const participant = webMessageInfo.participant ?? key.participant ?? selfAuthor;
171
+ const participant = resolveWebMessageInfoAuthor(webMessageInfo, meJid);
147
172
  const pushName = webMessageInfo.pushName ?? undefined;
148
173
  const rawSender = fromMe ? undefined : isGroup || isBroadcast ? participant : chatJid;
149
174
  const sender = rawSender ? (0, jid_1.parseJidFull)(rawSender) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zapo-js",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "High-performance WhatsApp Web TypeScript library",
5
5
  "license": "MIT",
6
6
  "author": "vinikjkkj <contact@vinicius.email> (https://github.com/vinikjkkj)",