@xmanrui/dsh-im 2.1.0 → 2.2.1

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.
@@ -1,4 +1,4 @@
1
- import { createHash } from 'node:crypto';
1
+ import { createHash, randomBytes } from 'node:crypto';
2
2
 
3
3
  import {
4
4
  areJidsSameUser,
@@ -217,9 +217,9 @@ export function normalizeWhatsappMessage(message, accountJid, {
217
217
  const fromMe = message.key.fromMe === true;
218
218
  const selfChat = fromMe && !group
219
219
  && [remoteJid, alternateRemoteJid].some((jid) => jid && areJidsSameUser(jid, accountJid));
220
- if (fromMe && !selfChat) return null;
221
- const senderJid = selfChat ? accountJid : group ? message.key.participant : remoteJid;
222
- const senderAlternateJid = group ? message.key.participantAlt : alternateRemoteJid;
220
+ if (fromMe && !selfChat && !group) return null;
221
+ const senderJid = fromMe ? accountJid : group ? message.key.participant : remoteJid;
222
+ const senderAlternateJid = group && !fromMe ? message.key.participantAlt : alternateRemoteJid;
223
223
  if (typeof senderJid !== 'string' || !senderJid) return null;
224
224
  const viewOnce = hasViewOnceWrapper(message.message);
225
225
  const content = normalizeMessageContent(message.message);
@@ -241,7 +241,7 @@ export function normalizeWhatsappMessage(message, accountJid, {
241
241
  content: messageText(content),
242
242
  images: image ? [image] : [],
243
243
  files: file ? [file] : [],
244
- addressed: !group || mentioned || replyToSelf,
244
+ addressed: !group || fromMe || mentioned || replyToSelf,
245
245
  selfChat,
246
246
  replyTarget: { jid: remoteJid, quoted: message, selfChat },
247
247
  };
@@ -272,6 +272,14 @@ class RecentWhatsappOutboundIds {
272
272
  }
273
273
 
274
274
  remember(id) {
275
+ this.#store(id);
276
+ }
277
+
278
+ reserve(id) {
279
+ this.#store(id);
280
+ }
281
+
282
+ #store(id) {
275
283
  if (typeof id !== 'string' || !id) return;
276
284
  this.#purge();
277
285
  this.#ids.set(id, Date.now() + 5 * 60_000);
@@ -360,10 +368,23 @@ export class WhatsappBotClient {
360
368
  await this.#stopTyping(target.jid);
361
369
  const providerMessageIds = [];
362
370
  for (const [index, chunk] of splitMessageText(text, 4_000).entries()) {
371
+ const messageId = randomBytes(10).toString('hex').toUpperCase();
372
+ const options = {
373
+ ...(index === 0 && target.quoted ? { quoted: target.quoted } : {}),
374
+ messageId,
375
+ };
376
+ // Linked-account group messages are valid inbound prompts in open mode.
377
+ // Reserve our own id before dispatch so an early local echo cannot loop
378
+ // back through the bridge as another owner-authored group prompt.
379
+ if (typeof this.#outboundIds.reserve === 'function') {
380
+ this.#outboundIds.reserve(messageId);
381
+ } else {
382
+ this.#outboundIds.remember(messageId);
383
+ }
363
384
  const result = await this.#socket.sendMessage(
364
385
  target.jid,
365
386
  { text: chunk },
366
- index === 0 && target.quoted ? { quoted: target.quoted } : undefined,
387
+ options,
367
388
  );
368
389
  this.#outboundIds.remember(result?.key?.id);
369
390
  if (typeof result?.key?.id === 'string' && result.key.id) {