@arcaelas/whatsapp 6.1.1 → 6.1.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.
@@ -575,15 +575,30 @@ 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
+ if (!current) {
599
+ const person = new this.Contact(doc);
600
+ const cached_chat = (0, store_1.deserialize)(await this.engine.get(`/chat/${doc.id}`));
601
+ this.emit('contact:created', person, new this.Chat(cached_chat ?? { id: doc.id, name: person.name }), this);
587
602
  }
588
603
  }
589
604
  /** @internal */
@@ -611,6 +626,7 @@ class WhatsApp {
611
626
  const patch = {
612
627
  ...(c.notify && { notify: c.notify }),
613
628
  ...(c.name && { name: c.name }),
629
+ ...(c.verifiedName && { verified_name: c.verifiedName }),
614
630
  ...(c.imgUrl && { img_url: c.imgUrl }),
615
631
  ...(c.status && { status: c.status }),
616
632
  ...(c.lid && { lid: c.lid }),
@@ -967,16 +983,25 @@ class WhatsApp {
967
983
  if (!existing_doc && !doc.me) {
968
984
  const push_name = msg.pushName ?? null;
969
985
  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
- });
986
+ // El contacto se completa cuando no existe y también cuando existe sin ningún
987
+ // nombre: el mensaje trae el pushName y el nombre del negocio verificado, que
988
+ // es lo único que queda si un re-sync anterior dejó la ficha en blanco.
989
+ // The contact is filled in when missing and also when it exists with no name at
990
+ // all: the message carries the pushName and the verified business name, the only
991
+ // thing left when an earlier re-sync blanked the card.
992
+ if (doc.author) {
993
+ const known = (0, store_1.deserialize)(await this.engine.get(`/contact/${doc.author}`));
994
+ if (!known || !(known.name ?? known.notify ?? known.verified_name)) {
995
+ await this.#persist_contact({
996
+ id: doc.author,
997
+ lid: msg.key.remoteJid?.endsWith('@lid') ? msg.key.remoteJid : null,
998
+ name: null,
999
+ notify: push_name,
1000
+ verified_name: msg.verifiedBizName ?? null,
1001
+ img_url: null,
1002
+ status: null,
1003
+ });
1004
+ }
980
1005
  }
981
1006
  if (!(await this.engine.get(`/chat/${cid}`))) {
982
1007
  const chat_raw = {
@@ -536,15 +536,30 @@ 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
+ if (!current) {
560
+ const person = new this.Contact(doc);
561
+ const cached_chat = deserialize(await this.engine.get(`/chat/${doc.id}`));
562
+ this.emit('contact:created', person, new this.Chat(cached_chat ?? { id: doc.id, name: person.name }), this);
548
563
  }
549
564
  }
550
565
  /** @internal */
@@ -572,6 +587,7 @@ export class WhatsApp {
572
587
  const patch = {
573
588
  ...(c.notify && { notify: c.notify }),
574
589
  ...(c.name && { name: c.name }),
590
+ ...(c.verifiedName && { verified_name: c.verifiedName }),
575
591
  ...(c.imgUrl && { img_url: c.imgUrl }),
576
592
  ...(c.status && { status: c.status }),
577
593
  ...(c.lid && { lid: c.lid }),
@@ -928,16 +944,25 @@ export class WhatsApp {
928
944
  if (!existing_doc && !doc.me) {
929
945
  const push_name = msg.pushName ?? null;
930
946
  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
- });
947
+ // El contacto se completa cuando no existe y también cuando existe sin ningún
948
+ // nombre: el mensaje trae el pushName y el nombre del negocio verificado, que
949
+ // es lo único que queda si un re-sync anterior dejó la ficha en blanco.
950
+ // The contact is filled in when missing and also when it exists with no name at
951
+ // all: the message carries the pushName and the verified business name, the only
952
+ // thing left when an earlier re-sync blanked the card.
953
+ if (doc.author) {
954
+ const known = deserialize(await this.engine.get(`/contact/${doc.author}`));
955
+ if (!known || !(known.name ?? known.notify ?? known.verified_name)) {
956
+ await this.#persist_contact({
957
+ id: doc.author,
958
+ lid: msg.key.remoteJid?.endsWith('@lid') ? msg.key.remoteJid : null,
959
+ name: null,
960
+ notify: push_name,
961
+ verified_name: msg.verifiedBizName ?? null,
962
+ img_url: null,
963
+ status: null,
964
+ });
965
+ }
941
966
  }
942
967
  if (!(await this.engine.get(`/chat/${cid}`))) {
943
968
  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.2",
76
76
  "engines": {
77
77
  "node": ">=20"
78
78
  },