whalibmob 5.5.89 → 5.5.90

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.
Files changed (3) hide show
  1. package/README.md +3 -0
  2. package/lib/Client.js +54 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1495,6 +1495,9 @@ await client.changeGroupPicture('120363000000000000@g.us', fs.readFileSync('./gr
1495
1495
  const blocked = await client.blockContact('919634847671@s.whatsapp.net')
1496
1496
  await client.unblockContact('919634847671@s.whatsapp.net')
1497
1497
 
1498
+ // the block list is addressed by LID; a phone number is resolved to one first,
1499
+ // looking it up if it is not already known
1500
+
1498
1501
  // blocking done from the phone arrives as an event
1499
1502
  client.on('blocklist', ({ changes }) => console.log(changes))
1500
1503
  ```
package/lib/Client.js CHANGED
@@ -3509,27 +3509,71 @@ class WhalibmobClient extends EventEmitter {
3509
3509
  return this._updateBlocklist(jid, 'unblock');
3510
3510
  }
3511
3511
 
3512
- // The one IQ behind both, as whatsmeow's UpdateBlocklist sends it:
3512
+ // Work out the LID a block list item has to be addressed with, and the phone
3513
+ // JID that goes beside it.
3514
+ //
3515
+ // The server only accepts LID-addressed items on a LID account: a phone JID
3516
+ // comes back as <error code="400" text="bad-request" addressing_mode="lid"/>,
3517
+ // the attribute being the server saying which addressing it wanted. When the
3518
+ // mapping is not known yet a contact usync fetches it.
3519
+ async _resolveBlockTarget(jid) {
3520
+ const norm = toNonAdJid(makeJid(jid));
3521
+ const user = norm.split('@')[0];
3522
+
3523
+ if (norm.endsWith('@lid')) {
3524
+ const pn = this._lidToPn.get(user);
3525
+ return { lid: norm, pn: pn ? pn + '@s.whatsapp.net' : null };
3526
+ }
3527
+
3528
+ let lidUser = this._pnToLid.get(user);
3529
+ if (!lidUser && this._devMgr) {
3530
+ _whaDbg('[DBG] BLOCK_LID_LOOKUP ' + user);
3531
+ try { await this._devMgr._doContactUsync([user]); } catch (_) {}
3532
+ lidUser = this._pnToLid.get(user);
3533
+ }
3534
+ return { lid: lidUser ? lidUser + '@lid' : null, pn: norm };
3535
+ }
3536
+
3537
+ // The one IQ behind both:
3513
3538
  //
3514
3539
  // <iq xmlns="blocklist" type="set" to="s.whatsapp.net">
3515
- // <item jid="<JID>" action="block|unblock"/>
3540
+ // <item action="block" jid="<LID>" pn_jid="<phone JID>"/>
3516
3541
  // </iq>
3517
3542
  //
3518
- // Three things were wrong with the pair this replaces. The jid went out as a
3519
- // raw string rather than a binary JID. It was not reduced to its bare user
3520
- // first, so blocking a contact you happened to name with a device suffix sent
3521
- // the server a device JID it has nothing to block. And the reply was thrown
3522
- // away without being looked at — including a type="error" reply — so a block
3523
- // the server refused came back looking exactly like one that worked.
3543
+ // The item is addressed by LID, and a block carries the phone number beside
3544
+ // it; an unblock carries only the LID. That is the shape Baileys'
3545
+ // updateBlockStatus builds, and the one this server accepts — whatsmeow's
3546
+ // UpdateBlocklist still sends the plain JID it was handed, which is what this
3547
+ // used to do and what the server answered with 400 bad-request.
3548
+ //
3549
+ // Three other things were wrong with the pair this replaces. The jid went out
3550
+ // as a raw string rather than a binary JID. It was not reduced to its bare
3551
+ // user first, so naming a contact with a device suffix sent a device JID
3552
+ // there is nothing to block. And the reply was thrown away without being
3553
+ // looked at, so a refusal came back looking exactly like a success.
3524
3554
  async _updateBlocklist(jid, action) {
3525
- const target = toNonAdJid(makeJid(jid));
3555
+ const { lid, pn } = await this._resolveBlockTarget(jid);
3556
+ if (!lid) {
3557
+ throw new Error(action + 'Contact: could not resolve a LID for ' + jid +
3558
+ ' — the server only accepts LID-addressed block list items. ' +
3559
+ 'Check the number is on WhatsApp.');
3560
+ }
3561
+ const attrs = { action, jid: jidStrToObj(lid) };
3562
+ if (action === 'block') {
3563
+ if (!pn) {
3564
+ throw new Error('blockContact: no phone number known for ' + lid +
3565
+ ' — a block has to carry pn_jid beside the LID.');
3566
+ }
3567
+ attrs.pn_jid = jidStrToObj(pn);
3568
+ }
3569
+
3526
3570
  const node = new BinaryNode('iq', {
3527
3571
  id: this._genMsgId(),
3528
3572
  xmlns: 'blocklist',
3529
3573
  to: 's.whatsapp.net',
3530
3574
  type: 'set'
3531
3575
  }, [
3532
- new BinaryNode('item', { jid: jidStrToObj(target), action }, null)
3576
+ new BinaryNode('item', attrs, null)
3533
3577
  ]);
3534
3578
 
3535
3579
  const resp = await this._sendIq(node);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whalibmob",
3
- "version": "5.5.89",
3
+ "version": "5.5.90",
4
4
  "description": "WhatsApp library for interaction with WhatsApp Mobile API no web",
5
5
  "author": "Kunboruto50",
6
6
  "main": "index.js",