@arcaelas/whatsapp 6.1.1 → 6.1.3

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.
@@ -575,15 +575,36 @@ class WhatsApp {
575
575
  * @internal
576
576
  */
577
577
  async #persist_contact(raw) {
578
- const existing = await this.engine.get(`/contact/${raw.id}`);
579
- await this.engine.set(`/contact/${raw.id}`, (0, store_1.serialize)(raw));
580
- if (raw.lid) {
581
- await this.engine.set(`/lid/${raw.lid}`, (0, store_1.serialize)(raw.id));
578
+ const current = (0, store_1.deserialize)(await this.engine.get(`/contact/${raw.id}`));
579
+ // Los upserts del re-sync llegan con los campos vacíos: sin fusionar borran el nombre
580
+ // que ya se conocía y el chat pasa a mostrar el número pelado.
581
+ // Re-sync upserts arrive with empty fields: without merging they wipe the name already
582
+ // known and the chat falls back to showing the bare number.
583
+ const doc = current
584
+ ? {
585
+ id: raw.id,
586
+ lid: raw.lid ?? current.lid,
587
+ name: raw.name ?? current.name,
588
+ notify: raw.notify ?? current.notify,
589
+ verified_name: raw.verified_name ?? current.verified_name,
590
+ img_url: raw.img_url ?? current.img_url,
591
+ status: raw.status ?? current.status,
592
+ }
593
+ : raw;
594
+ await this.engine.set(`/contact/${raw.id}`, (0, store_1.serialize)(doc));
595
+ if (doc.lid) {
596
+ await this.engine.set(`/lid/${doc.lid}`, (0, store_1.serialize)(doc.id));
582
597
  }
583
- if (existing === null) {
584
- const person = new this.Contact(raw);
585
- const cached_chat = (0, store_1.deserialize)(await this.engine.get(`/chat/${raw.id}`));
586
- this.emit('contact:created', person, new this.Chat(cached_chat ?? { id: raw.id, name: person.name }), this);
598
+ // Una ficha que existía vacía y ahora tiene nombre es un cambio que el consumidor
599
+ // necesita: sin avisar, quien memorice el contacto sigue mostrando el número.
600
+ // A card that existed empty and now has a name is a change the consumer needs: without
601
+ // notifying, whoever memoized the contact keeps showing the bare number.
602
+ const changed = current && ['lid', 'name', 'notify', 'verified_name', 'img_url', 'status'].some((key) => current[key] !== doc[key]);
603
+ if (!current || changed) {
604
+ const person = new this.Contact(doc);
605
+ const cached_chat = (0, store_1.deserialize)(await this.engine.get(`/chat/${doc.id}`));
606
+ const chat = new this.Chat(cached_chat ?? { id: doc.id, name: person.name });
607
+ this.emit(current ? 'contact:updated' : 'contact:created', person, chat, this);
587
608
  }
588
609
  }
589
610
  /** @internal */
@@ -611,6 +632,7 @@ class WhatsApp {
611
632
  const patch = {
612
633
  ...(c.notify && { notify: c.notify }),
613
634
  ...(c.name && { name: c.name }),
635
+ ...(c.verifiedName && { verified_name: c.verifiedName }),
614
636
  ...(c.imgUrl && { img_url: c.imgUrl }),
615
637
  ...(c.status && { status: c.status }),
616
638
  ...(c.lid && { lid: c.lid }),
@@ -967,16 +989,25 @@ class WhatsApp {
967
989
  if (!existing_doc && !doc.me) {
968
990
  const push_name = msg.pushName ?? null;
969
991
  const is_group = cid.endsWith('@g.us');
970
- if (doc.author && !(await this.engine.get(`/contact/${doc.author}`))) {
971
- await this.#persist_contact({
972
- id: doc.author,
973
- lid: msg.key.remoteJid?.endsWith('@lid') ? msg.key.remoteJid : null,
974
- name: null,
975
- notify: push_name,
976
- verified_name: msg.verifiedBizName ?? null,
977
- img_url: null,
978
- status: null,
979
- });
992
+ // El contacto se completa cuando no existe y también cuando existe sin ningún
993
+ // nombre: el mensaje trae el pushName y el nombre del negocio verificado, que
994
+ // es lo único que queda si un re-sync anterior dejó la ficha en blanco.
995
+ // The contact is filled in when missing and also when it exists with no name at
996
+ // all: the message carries the pushName and the verified business name, the only
997
+ // thing left when an earlier re-sync blanked the card.
998
+ if (doc.author) {
999
+ const known = (0, store_1.deserialize)(await this.engine.get(`/contact/${doc.author}`));
1000
+ if (!known || !(known.name ?? known.notify ?? known.verified_name)) {
1001
+ await this.#persist_contact({
1002
+ id: doc.author,
1003
+ lid: msg.key.remoteJid?.endsWith('@lid') ? msg.key.remoteJid : null,
1004
+ name: null,
1005
+ notify: push_name,
1006
+ verified_name: msg.verifiedBizName ?? null,
1007
+ img_url: null,
1008
+ status: null,
1009
+ });
1010
+ }
980
1011
  }
981
1012
  if (!(await this.engine.get(`/chat/${cid}`))) {
982
1013
  const chat_raw = {
@@ -536,15 +536,36 @@ export class WhatsApp {
536
536
  * @internal
537
537
  */
538
538
  async #persist_contact(raw) {
539
- const existing = await this.engine.get(`/contact/${raw.id}`);
540
- await this.engine.set(`/contact/${raw.id}`, serialize(raw));
541
- if (raw.lid) {
542
- await this.engine.set(`/lid/${raw.lid}`, serialize(raw.id));
539
+ const current = deserialize(await this.engine.get(`/contact/${raw.id}`));
540
+ // Los upserts del re-sync llegan con los campos vacíos: sin fusionar borran el nombre
541
+ // que ya se conocía y el chat pasa a mostrar el número pelado.
542
+ // Re-sync upserts arrive with empty fields: without merging they wipe the name already
543
+ // known and the chat falls back to showing the bare number.
544
+ const doc = current
545
+ ? {
546
+ id: raw.id,
547
+ lid: raw.lid ?? current.lid,
548
+ name: raw.name ?? current.name,
549
+ notify: raw.notify ?? current.notify,
550
+ verified_name: raw.verified_name ?? current.verified_name,
551
+ img_url: raw.img_url ?? current.img_url,
552
+ status: raw.status ?? current.status,
553
+ }
554
+ : raw;
555
+ await this.engine.set(`/contact/${raw.id}`, serialize(doc));
556
+ if (doc.lid) {
557
+ await this.engine.set(`/lid/${doc.lid}`, serialize(doc.id));
543
558
  }
544
- if (existing === null) {
545
- const person = new this.Contact(raw);
546
- const cached_chat = deserialize(await this.engine.get(`/chat/${raw.id}`));
547
- this.emit('contact:created', person, new this.Chat(cached_chat ?? { id: raw.id, name: person.name }), this);
559
+ // Una ficha que existía vacía y ahora tiene nombre es un cambio que el consumidor
560
+ // necesita: sin avisar, quien memorice el contacto sigue mostrando el número.
561
+ // A card that existed empty and now has a name is a change the consumer needs: without
562
+ // notifying, whoever memoized the contact keeps showing the bare number.
563
+ const changed = current && ['lid', 'name', 'notify', 'verified_name', 'img_url', 'status'].some((key) => current[key] !== doc[key]);
564
+ if (!current || changed) {
565
+ const person = new this.Contact(doc);
566
+ const cached_chat = deserialize(await this.engine.get(`/chat/${doc.id}`));
567
+ const chat = new this.Chat(cached_chat ?? { id: doc.id, name: person.name });
568
+ this.emit(current ? 'contact:updated' : 'contact:created', person, chat, this);
548
569
  }
549
570
  }
550
571
  /** @internal */
@@ -572,6 +593,7 @@ export class WhatsApp {
572
593
  const patch = {
573
594
  ...(c.notify && { notify: c.notify }),
574
595
  ...(c.name && { name: c.name }),
596
+ ...(c.verifiedName && { verified_name: c.verifiedName }),
575
597
  ...(c.imgUrl && { img_url: c.imgUrl }),
576
598
  ...(c.status && { status: c.status }),
577
599
  ...(c.lid && { lid: c.lid }),
@@ -928,16 +950,25 @@ export class WhatsApp {
928
950
  if (!existing_doc && !doc.me) {
929
951
  const push_name = msg.pushName ?? null;
930
952
  const is_group = cid.endsWith('@g.us');
931
- if (doc.author && !(await this.engine.get(`/contact/${doc.author}`))) {
932
- await this.#persist_contact({
933
- id: doc.author,
934
- lid: msg.key.remoteJid?.endsWith('@lid') ? msg.key.remoteJid : null,
935
- name: null,
936
- notify: push_name,
937
- verified_name: msg.verifiedBizName ?? null,
938
- img_url: null,
939
- status: null,
940
- });
953
+ // El contacto se completa cuando no existe y también cuando existe sin ningún
954
+ // nombre: el mensaje trae el pushName y el nombre del negocio verificado, que
955
+ // es lo único que queda si un re-sync anterior dejó la ficha en blanco.
956
+ // The contact is filled in when missing and also when it exists with no name at
957
+ // all: the message carries the pushName and the verified business name, the only
958
+ // thing left when an earlier re-sync blanked the card.
959
+ if (doc.author) {
960
+ const known = deserialize(await this.engine.get(`/contact/${doc.author}`));
961
+ if (!known || !(known.name ?? known.notify ?? known.verified_name)) {
962
+ await this.#persist_contact({
963
+ id: doc.author,
964
+ lid: msg.key.remoteJid?.endsWith('@lid') ? msg.key.remoteJid : null,
965
+ name: null,
966
+ notify: push_name,
967
+ verified_name: msg.verifiedBizName ?? null,
968
+ img_url: null,
969
+ status: null,
970
+ });
971
+ }
941
972
  }
942
973
  if (!(await this.engine.get(`/chat/${cid}`))) {
943
974
  const chat_raw = {
package/package.json CHANGED
@@ -72,7 +72,7 @@
72
72
  "release": "npm publish --access public"
73
73
  },
74
74
  "types": "./build/esm/index.d.ts",
75
- "version": "6.1.1",
75
+ "version": "6.1.3",
76
76
  "engines": {
77
77
  "node": ">=20"
78
78
  },