@baileys-md/baileys 11.2.4 → 12.0.0

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 (74) hide show
  1. package/README.md +113 -2
  2. package/WAProto/GenerateStatics.sh +4 -0
  3. package/WAProto/WAProto.proto +4775 -0
  4. package/WAProto/index.js +14270 -302
  5. package/lib/Defaults/index.js +50 -54
  6. package/lib/Defaults/wileys-version.json +3 -0
  7. package/lib/Signal/Group/ciphertext-message.js +15 -0
  8. package/lib/Signal/Group/group-session-builder.js +64 -0
  9. package/lib/Signal/Group/group_cipher.js +96 -0
  10. package/lib/Signal/Group/index.js +57 -0
  11. package/lib/Signal/Group/keyhelper.js +55 -0
  12. package/lib/Signal/Group/queue-job.js +57 -0
  13. package/lib/Signal/Group/sender-chain-key.js +34 -0
  14. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  15. package/lib/Signal/Group/sender-key-message.js +69 -0
  16. package/lib/Signal/Group/sender-key-name.js +51 -0
  17. package/lib/Signal/Group/sender-key-record.js +53 -0
  18. package/lib/Signal/Group/sender-key-state.js +99 -0
  19. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
  20. package/lib/Signal/libsignal.js +33 -20
  21. package/lib/Socket/Client/index.js +2 -3
  22. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
  23. package/lib/Socket/chats.js +136 -92
  24. package/lib/Socket/groups.js +16 -11
  25. package/lib/Socket/index.js +2 -2
  26. package/lib/Socket/messages-recv.js +26 -15
  27. package/lib/Socket/messages-send.js +122 -86
  28. package/lib/Socket/newsletter.js +23 -21
  29. package/lib/Socket/socket.js +29 -15
  30. package/lib/Store/make-in-memory-store.js +23 -15
  31. package/lib/Utils/auth-utils.js +0 -7
  32. package/lib/Utils/browser-utils.js +35 -0
  33. package/lib/Utils/chat-utils.js +2 -2
  34. package/lib/Utils/crypto.js +71 -29
  35. package/lib/Utils/decode-wa-message.js +15 -7
  36. package/lib/Utils/event-buffer.js +6 -8
  37. package/lib/Utils/generics.js +38 -16
  38. package/lib/Utils/history.js +1 -1
  39. package/lib/Utils/index.js +3 -1
  40. package/lib/Utils/message-retry-manager.js +128 -0
  41. package/lib/Utils/messages-media.js +212 -57
  42. package/lib/Utils/messages.js +38 -7
  43. package/lib/Utils/noise-handler.js +5 -10
  44. package/lib/Utils/process-message.js +34 -2
  45. package/lib/Utils/signal.js +26 -16
  46. package/lib/Utils/validate-connection.js +88 -66
  47. package/lib/Utils/{baileys-event-stream.js → wileys-event-stream.js} +1 -1
  48. package/lib/WABinary/constants.js +1276 -13
  49. package/lib/WABinary/jid-utils.js +20 -4
  50. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  51. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  52. package/lib/index.js +17 -6
  53. package/package.json +22 -17
  54. package/WASignalGroup/GroupProtocol.js +0 -1697
  55. package/WASignalGroup/ciphertext_message.js +0 -16
  56. package/WASignalGroup/group_cipher.js +0 -120
  57. package/WASignalGroup/group_session_builder.js +0 -46
  58. package/WASignalGroup/index.js +0 -5
  59. package/WASignalGroup/keyhelper.js +0 -21
  60. package/WASignalGroup/protobufs.js +0 -3
  61. package/WASignalGroup/queue_job.js +0 -69
  62. package/WASignalGroup/sender_chain_key.js +0 -50
  63. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  64. package/WASignalGroup/sender_key_message.js +0 -92
  65. package/WASignalGroup/sender_key_name.js +0 -70
  66. package/WASignalGroup/sender_key_record.js +0 -56
  67. package/WASignalGroup/sender_key_state.js +0 -129
  68. package/lib/Defaults/baileys-version.json +0 -3
  69. package/lib/Defaults/phonenumber-mcc.json +0 -223
  70. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  71. package/lib/Socket/registration.js +0 -166
  72. package/lib/Store/make-cache-manager-store.js +0 -83
  73. package/lib/Store/make-mongo-store.js +0 -567
  74. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -10,30 +10,37 @@ const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
11
  const Types_1 = require("../Types");
12
12
  const Utils_1 = require("../Utils");
13
- const jimp_1 = require('jimp');
14
13
  const make_mutex_1 = require("../Utils/make-mutex");
15
14
  const process_message_1 = __importDefault(require("../Utils/process-message"));
16
15
  const WABinary_1 = require("../WABinary");
17
16
  const WAUSync_1 = require("../WAUSync");
18
17
  const usync_1 = require("./usync");
18
+ const jimp_1 = require('jimp');
19
+ const chalk = require('chalk');
19
20
  const MAX_SYNC_ATTEMPTS = 2;
21
+ const SyncState = {
22
+ Connecting: 'connecting',
23
+ AwaitingInitialSync: 'awaiting_initial_sync',
24
+ Syncing: 'syncing',
25
+ Online: 'online'
26
+ };
20
27
  const makeChatsSocket = (config) => {
21
28
  const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
22
29
  const sock = (0, usync_1.makeUSyncSocket)(config);
23
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
30
+ const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, } = sock;
24
31
  let privacySettings;
32
+ let syncState = SyncState.Connecting;
25
33
  let needToFlushWithAppStateSync = false;
26
34
  let pendingAppStateSync = false;
27
- /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
35
+ let awaitingSyncTimeout;
28
36
  const processingMutex = (0, make_mutex_1.makeMutex)();
29
37
  const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
30
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
38
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
31
39
  useClones: false
32
40
  });
33
41
  if (!config.placeholderResendCache) {
34
42
  config.placeholderResendCache = placeholderResendCache;
35
43
  }
36
- /** helper function to fetch the given app state sync key */
37
44
  const getAppStateSyncKey = async (keyId) => {
38
45
  const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
39
46
  return key;
@@ -55,7 +62,6 @@ const makeChatsSocket = (config) => {
55
62
  }
56
63
  return privacySettings;
57
64
  };
58
- /** helper function to run a privacy IQ query */
59
65
  const privacyQuery = async (name, value) => {
60
66
  await query({
61
67
  tag: 'iq',
@@ -100,6 +106,9 @@ const makeChatsSocket = (config) => {
100
106
  const updateGroupsAddPrivacy = async (value) => {
101
107
  await privacyQuery('groupadd', value);
102
108
  };
109
+ const updateDisableLinkPreviewsPrivacy = async (isPreviewsDisabled) => {
110
+ return chatModify({ disableLinkPreviews: { isPreviewsDisabled } }, '');
111
+ };
103
112
  const updateDefaultDisappearingMode = async (duration) => {
104
113
  await query({
105
114
  tag: 'iq',
@@ -180,7 +189,6 @@ const makeChatsSocket = (config) => {
180
189
  return result.list;
181
190
  }
182
191
  };
183
- /** update the profile picture for yourself or a group */
184
192
  const updateProfilePicture = async (jid, content) => {
185
193
  let targetJid;
186
194
  const generate_1 = async (media) => {
@@ -217,14 +225,13 @@ const makeChatsSocket = (config) => {
217
225
  }]
218
226
  });
219
227
  };
220
- /** remove the profile picture for yourself or a group */
221
228
  const removeProfilePicture = async (jid) => {
222
229
  let targetJid;
223
230
  if (!jid) {
224
231
  throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
225
232
  }
226
233
  if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
227
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
234
+ targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
228
235
  }
229
236
  await query({
230
237
  tag: 'iq',
@@ -236,7 +243,6 @@ const makeChatsSocket = (config) => {
236
243
  }
237
244
  });
238
245
  };
239
- /** update the profile status for yourself */
240
246
  const updateProfileStatus = async (status) => {
241
247
  await query({
242
248
  tag: 'iq',
@@ -363,18 +369,12 @@ const makeChatsSocket = (config) => {
363
369
  };
364
370
  };
365
371
  const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
366
- // we use this to determine which events to fire
367
- // otherwise when we resync from scratch -- all notifications will fire
368
372
  const initialVersionMap = {};
369
373
  const globalMutationMap = {};
370
374
  await authState.keys.transaction(async () => {
371
375
  var _a;
372
376
  const collectionsToHandle = new Set(collections);
373
- // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
374
377
  const attemptsMap = {};
375
- // keep executing till all collections are done
376
- // sometimes a single patch request will not return all the patches (God knows why)
377
- // so we fetch till they're all done (this is determined by the "has_more_patches" flag)
378
378
  while (collectionsToHandle.size) {
379
379
  const states = {};
380
380
  const nodes = [];
@@ -396,7 +396,6 @@ const makeChatsSocket = (config) => {
396
396
  attrs: {
397
397
  name,
398
398
  version: state.version.toString(),
399
- // return snapshot if being synced from scratch
400
399
  'return_snapshot': (!state.version).toString()
401
400
  }
402
401
  });
@@ -416,7 +415,6 @@ const makeChatsSocket = (config) => {
416
415
  }
417
416
  ]
418
417
  });
419
- // extract from binary node
420
418
  const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
421
419
  for (const key in decoded) {
422
420
  const name = key;
@@ -429,7 +427,6 @@ const makeChatsSocket = (config) => {
429
427
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
430
428
  await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
431
429
  }
432
- // only process if there are syncd patches
433
430
  if (patches.length) {
434
431
  const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
435
432
  await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
@@ -440,22 +437,18 @@ const makeChatsSocket = (config) => {
440
437
  if (hasMorePatches) {
441
438
  logger.info(`${name} has more patches...`);
442
439
  }
443
- else { // collection is done with sync
440
+ else {
444
441
  collectionsToHandle.delete(name);
445
442
  }
446
443
  }
447
444
  catch (error) {
448
- // if retry attempts overshoot
449
- // or key not found
450
445
  const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
451
446
  || ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
452
447
  || error.name === 'TypeError';
453
448
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
454
449
  await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
455
- // increment number of retries
456
450
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
457
451
  if (isIrrecoverableError) {
458
- // stop retrying
459
452
  collectionsToHandle.delete(name);
460
453
  }
461
454
  }
@@ -467,28 +460,56 @@ const makeChatsSocket = (config) => {
467
460
  onMutation(globalMutationMap[key]);
468
461
  }
469
462
  });
470
- /**
471
- * fetch the profile picture of a user/group
472
- * type = "preview" for a low res picture
473
- * type = "image for the high res picture"
474
- */
475
463
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
476
464
  var _a;
477
465
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
466
+ try {
467
+ const result = await query({
468
+ tag: 'iq',
469
+ attrs: {
470
+ target: jid,
471
+ to: WABinary_1.S_WHATSAPP_NET,
472
+ type: 'get',
473
+ xmlns: 'w:profile:picture'
474
+ },
475
+ content: [
476
+ { tag: 'picture', attrs: { type, query: 'url' } }
477
+ ]
478
+ }, timeoutMs);
479
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
480
+ return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
481
+ } catch (error) {
482
+ if (error.message?.includes('item-not-found') ||
483
+ error.output?.payload?.statusCode === 404 ||
484
+ error.statusCode === 404) {
485
+ logger.info(chalk.gray(`[INFO] Profile pic not found for ${jid}, using fallback`));
486
+ return {
487
+ eurl: undefined,
488
+ id: jid.split('@')[0],
489
+ status: null,
490
+ img: null
491
+ };
492
+ }
493
+ throw error;
494
+ }
495
+ };
496
+ const createCallLink = async (type, event, timeoutMs) => {
478
497
  const result = await query({
479
- tag: 'iq',
498
+ tag: 'call',
480
499
  attrs: {
481
- target: jid,
482
- to: WABinary_1.S_WHATSAPP_NET,
483
- type: 'get',
484
- xmlns: 'w:profile:picture'
500
+ id: generateMessageTag(),
501
+ to: '@call'
485
502
  },
486
503
  content: [
487
- { tag: 'picture', attrs: { type, query: 'url' } }
504
+ {
505
+ tag: 'link_create',
506
+ attrs: { media: type },
507
+ content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
508
+ }
488
509
  ]
489
510
  }, timeoutMs);
490
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
491
- return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
511
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'link_create');
512
+ return child?.attrs?.token;
492
513
  };
493
514
  const sendPresenceUpdate = async (type, toJid) => {
494
515
  const me = authState.creds.me;
@@ -501,16 +522,18 @@ const makeChatsSocket = (config) => {
501
522
  await sendNode({
502
523
  tag: 'presence',
503
524
  attrs: {
504
- name: me.name,
525
+ name: me.name.replace(/@/g, ''),
505
526
  type
506
527
  }
507
528
  });
508
529
  }
509
530
  else {
531
+ const { server } = (0, WABinary_1.jidDecode)(toJid);
532
+ const isLid = server === 'lid';
510
533
  await sendNode({
511
534
  tag: 'chatstate',
512
535
  attrs: {
513
- from: me.id,
536
+ from: isLid ? me.lid : me.id,
514
537
  to: toJid,
515
538
  },
516
539
  content: [
@@ -522,10 +545,6 @@ const makeChatsSocket = (config) => {
522
545
  });
523
546
  }
524
547
  };
525
- /**
526
- * @param toJid the jid to subscribe to
527
- * @param tcToken token for subscription, use if present
528
- */
529
548
  const presenceSubscribe = (toJid, tcToken) => (sendNode({
530
549
  tag: 'presence',
531
550
  attrs: {
@@ -634,7 +653,6 @@ const makeChatsSocket = (config) => {
634
653
  }
635
654
  }
636
655
  };
637
- /** sending non-abt props may fix QR scan fail if server expects */
638
656
  const fetchProps = async () => {
639
657
  var _a, _b, _c;
640
658
  const resultNode = await query({
@@ -654,7 +672,7 @@ const makeChatsSocket = (config) => {
654
672
  const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
655
673
  let props = {};
656
674
  if (propsNode) {
657
- if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
675
+ if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
658
676
  authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
659
677
  ev.emit('creds.update', authState.creds);
660
678
  }
@@ -663,18 +681,10 @@ const makeChatsSocket = (config) => {
663
681
  logger.debug('fetched props');
664
682
  return props;
665
683
  };
666
- /**
667
- * modify a chat -- mark unread, read etc.
668
- * lastMessages must be sorted in reverse chronologically
669
- * requires the last messages till the last message received; required for archive & unread
670
- */
671
684
  const chatModify = (mod, jid) => {
672
685
  const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
673
686
  return appPatch(patch);
674
687
  };
675
- /**
676
- * Star or Unstar a message
677
- */
678
688
  const star = (jid, messages, star) => {
679
689
  return chatModify({
680
690
  star: {
@@ -683,9 +693,15 @@ const makeChatsSocket = (config) => {
683
693
  }
684
694
  }, jid);
685
695
  };
686
- /**
687
- * Adds label for the chats
688
- */
696
+ const addOrEditContact = (jid, contact) => {
697
+ return chatModify({ contact }, jid);
698
+ };
699
+ const removeContact = (jid) => {
700
+ return chatModify({ contact: null }, jid);
701
+ };
702
+ const addLabel = (jid, labels) => {
703
+ return chatModify({ addLabel: { ...labels } }, jid);
704
+ };
689
705
  const addChatLabel = (jid, labelId) => {
690
706
  return chatModify({
691
707
  addChatLabel: {
@@ -693,9 +709,6 @@ const makeChatsSocket = (config) => {
693
709
  }
694
710
  }, jid);
695
711
  };
696
- /**
697
- * Removes label for the chat
698
- */
699
712
  const removeChatLabel = (jid, labelId) => {
700
713
  return chatModify({
701
714
  removeChatLabel: {
@@ -703,9 +716,6 @@ const makeChatsSocket = (config) => {
703
716
  }
704
717
  }, jid);
705
718
  };
706
- /**
707
- * Adds label for the message
708
- */
709
719
  const addMessageLabel = (jid, messageId, labelId) => {
710
720
  return chatModify({
711
721
  addMessageLabel: {
@@ -714,9 +724,6 @@ const makeChatsSocket = (config) => {
714
724
  }
715
725
  }, jid);
716
726
  };
717
- /**
718
- * Removes label for the message
719
- */
720
727
  const removeMessageLabel = (jid, messageId, labelId) => {
721
728
  return chatModify({
722
729
  removeMessageLabel: {
@@ -725,10 +732,6 @@ const makeChatsSocket = (config) => {
725
732
  }
726
733
  }, jid);
727
734
  };
728
- /**
729
- * queries need to be fired on connection open
730
- * help ensure parity with WA Web
731
- * */
732
735
  const executeInitQueries = async () => {
733
736
  await Promise.all([
734
737
  fetchProps(),
@@ -745,7 +748,6 @@ const makeChatsSocket = (config) => {
745
748
  if (!msg.key.fromMe) {
746
749
  ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
747
750
  }
748
- // update our pushname too
749
751
  if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
750
752
  ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
751
753
  }
@@ -755,6 +757,31 @@ const makeChatsSocket = (config) => {
755
757
  ? (shouldSyncHistoryMessage(historyMsg)
756
758
  && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
757
759
  : false;
760
+ if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
761
+ if (awaitingSyncTimeout) {
762
+ clearTimeout(awaitingSyncTimeout);
763
+ awaitingSyncTimeout = undefined;
764
+ }
765
+ if (shouldProcessHistoryMsg) {
766
+ syncState = SyncState.Syncing;
767
+ logger.info('Transitioned to Syncing state');
768
+ } else {
769
+ syncState = SyncState.Online;
770
+ logger.info('History sync skipped, transitioning to Online state and flushing buffer');
771
+ ev.flush();
772
+ }
773
+ }
774
+ const doAppStateSync = async () => {
775
+ if (syncState === SyncState.Syncing) {
776
+ logger.info('Doing app state sync');
777
+ await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
778
+ syncState = SyncState.Online;
779
+ logger.info('App state sync complete, transitioning to Online state and flushing buffer');
780
+ ev.flush();
781
+ const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
782
+ ev.emit('creds.update', { accountSyncCounter });
783
+ }
784
+ };
758
785
  if (historyMsg && !authState.creds.myAppStateKeyId) {
759
786
  logger.warn('skipping app state sync, as myAppStateKeyId is not set');
760
787
  pendingAppStateSync = true;
@@ -768,6 +795,7 @@ const makeChatsSocket = (config) => {
768
795
  }
769
796
  })(),
770
797
  (0, process_message_1.default)(msg, {
798
+ signalRepository,
771
799
  shouldProcessHistoryMsg,
772
800
  placeholderResendCache,
773
801
  ev,
@@ -783,18 +811,6 @@ const makeChatsSocket = (config) => {
783
811
  await doAppStateSync();
784
812
  pendingAppStateSync = false;
785
813
  }
786
- async function doAppStateSync() {
787
- if (!authState.creds.accountSyncCounter) {
788
- logger.info('doing initial app state sync');
789
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
790
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
791
- ev.emit('creds.update', { accountSyncCounter });
792
- if (needToFlushWithAppStateSync) {
793
- logger.debug('flushing with app state sync');
794
- ev.flush();
795
- }
796
- }
797
- }
798
814
  });
799
815
  ws.on('CB:presence', handlePresenceUpdate);
800
816
  ws.on('CB:chatstate', handlePresenceUpdate);
@@ -813,7 +829,6 @@ const makeChatsSocket = (config) => {
813
829
  }
814
830
  break;
815
831
  case 'groups':
816
- // handled in groups.ts
817
832
  break;
818
833
  default:
819
834
  logger.info({ node }, 'received unknown sync');
@@ -830,18 +845,43 @@ const makeChatsSocket = (config) => {
830
845
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
831
846
  .catch(error => onUnexpectedError(error, 'presence update requests'));
832
847
  }
833
- if (receivedPendingNotifications) {
834
- // if we don't have the app state key
835
- // we keep buffering events until we finally have
836
- // the key and can sync the messages
837
- if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
838
- ev.buffer();
839
- needToFlushWithAppStateSync = true;
840
- }
848
+ if (receivedPendingNotifications &&
849
+ !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
850
+ ev.buffer();
851
+ needToFlushWithAppStateSync = true;
852
+ }
853
+ if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
854
+ return;
841
855
  }
856
+ syncState = SyncState.AwaitingInitialSync;
857
+ logger.info('Connection is now AwaitingInitialSync, buffering events');
858
+ ev.buffer();
859
+ const willSyncHistory = shouldSyncHistoryMessage(
860
+ WAProto_1.proto.Message.HistorySyncNotification.create({
861
+ syncType: WAProto_1.proto.HistorySync.HistorySyncType.RECENT
862
+ })
863
+ );
864
+ if (!willSyncHistory) {
865
+ logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
866
+ syncState = SyncState.Online;
867
+ setTimeout(() => ev.flush(), 0);
868
+ return;
869
+ }
870
+ logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
871
+ if (awaitingSyncTimeout) {
872
+ clearTimeout(awaitingSyncTimeout);
873
+ }
874
+ awaitingSyncTimeout = setTimeout(() => {
875
+ if (syncState === SyncState.AwaitingInitialSync) {
876
+ logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
877
+ syncState = SyncState.Online;
878
+ ev.flush();
879
+ }
880
+ }, 20000);
842
881
  });
843
882
  return {
844
883
  ...sock,
884
+ createCallLink,
845
885
  getBotListV2,
846
886
  processingMutex,
847
887
  fetchPrivacySettings,
@@ -859,6 +899,7 @@ const makeChatsSocket = (config) => {
859
899
  updateProfileStatus,
860
900
  updateProfileName,
861
901
  updateBlockStatus,
902
+ updateDisableLinkPreviewsPrivacy,
862
903
  updateCallPrivacy,
863
904
  updateMessagesPrivacy,
864
905
  updateLastSeenPrivacy,
@@ -872,6 +913,9 @@ const makeChatsSocket = (config) => {
872
913
  resyncAppState,
873
914
  chatModify,
874
915
  cleanDirtyBits,
916
+ addOrEditContact,
917
+ removeContact,
918
+ addLabel,
875
919
  addChatLabel,
876
920
  removeChatLabel,
877
921
  addMessageLabel,
@@ -879,4 +923,4 @@ const makeChatsSocket = (config) => {
879
923
  star
880
924
  };
881
925
  };
882
- exports.makeChatsSocket = makeChatsSocket;
926
+ exports.makeChatsSocket = makeChatsSocket;
@@ -67,6 +67,7 @@ const makeGroupsSocket = (config) => {
67
67
  });
68
68
  return {
69
69
  ...sock,
70
+ groupQuery,
70
71
  groupMetadata,
71
72
  groupCreate: async (subject, participants) => {
72
73
  const key = (0, Utils_1.generateMessageIDV2)();
@@ -278,14 +279,16 @@ const extractGroupMetadata = (result) => {
278
279
  let desc;
279
280
  let descId;
280
281
  let descOwner;
281
- let descOwnerPhoneNumber;
282
+ let descOwnerLid;
282
283
  let descTime;
283
284
  if (descChild) {
284
285
  desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
285
- descOwner = descChild.attrs.participant;
286
- descOwnerPhoneNumber = descChild.attrs.participant_pn;
286
+ descOwner = (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn || descChild.attrs.participant);
287
+ if (group.attrs.addressing_mode === 'lid') {
288
+ descOwnerLid = (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant);
289
+ }
287
290
  descId = descChild.attrs.id;
288
- descTime = +descChild.attrs.t;
291
+ descTime = descChild.attrs.t ? +descChild.attrs.t : undefined;
289
292
  }
290
293
  const groupSize = group.attrs.size ? Number(group.attrs.size) : undefined;
291
294
  const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
@@ -295,16 +298,17 @@ const extractGroupMetadata = (result) => {
295
298
  id: groupId,
296
299
  addressingMode: group.attrs.addressing_mode,
297
300
  subject: group.attrs.subject,
298
- subjectOwner: group.attrs.s_o,
299
- subjectOwnerPhoneNumber: group.attrs.s_o_pn,
300
- subjectTime: +group.attrs.s_t,
301
+ subjectOwner: (0, WABinary_1.jidNormalizedUser)(group.attrs.s_o_pn || group.attrs.s_o),
302
+ ...(group.attrs.addressing_mode === 'lid' ? { subjectOwnerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.s_o) } : {}),
303
+ subjectTime: group.attrs.s_t ? +group.attrs.s_t : undefined,
301
304
  size: groupSize || (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
302
- creation: +group.attrs.creation,
303
- owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
305
+ creation: group.attrs.creation ? +group.attrs.creation : undefined,
306
+ owner: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn || group.attrs.creator),
307
+ ...(group.attrs.addressing_mode === 'lid' ? { ownerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) } : {}),
304
308
  desc,
305
309
  descId,
306
310
  descOwner,
307
- descOwnerPhoneNumber,
311
+ descOwnerLid,
308
312
  descTime,
309
313
  linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
310
314
  restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
@@ -316,7 +320,8 @@ const extractGroupMetadata = (result) => {
316
320
  participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
317
321
  return {
318
322
  id: attrs.jid,
319
- phoneNumber: attrs.phone_number || attrs.jid,
323
+ jid: attrs.phone_number || attrs.jid,
324
+ lid: attrs.lid || attrs.jid,
320
325
  admin: (attrs.type || null),
321
326
  };
322
327
  }),
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Defaults_1 = require("../Defaults");
4
- const registration_1 = require("./registration");
4
+ const business_1 = require("./business");
5
5
  // export the last socket layer
6
- const makeWASocket = (config) => ((0, registration_1.makeRegistrationSocket)({
6
+ const makeWASocket = (config) => ((0, business_1.makeBusinessSocket)({
7
7
  ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
8
  ...config
9
9
  }));