@queenanya/baileys 6.9.0 → 6.9.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.
@@ -48,7 +48,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
48
48
  ];
49
49
  exports.DEFAULT_CONNECTION_CONFIG = {
50
50
  version: baileys_version_json_1.version,
51
- browser: Utils_1.Browsers.ubuntu('Firefox'),
51
+ browser: Utils_1.Browsers.ubuntu("Firefox"),
52
52
  waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
53
53
  connectTimeoutMs: 20000,
54
54
  keepAliveIntervalMs: 30000,
@@ -597,29 +597,9 @@ const makeChatsSocket = (config) => {
597
597
  }
598
598
  }
599
599
  };
600
- /** sending abt props may fix QR scan fail if server expects */
601
- const fetchAbt = async () => {
602
- const abtNode = await query({
603
- tag: 'iq',
604
- attrs: {
605
- to: WABinary_1.S_WHATSAPP_NET,
606
- xmlns: 'abt',
607
- type: 'get',
608
- },
609
- content: [
610
- { tag: 'props', attrs: { protocol: '1' } }
611
- ]
612
- });
613
- const propsNode = (0, WABinary_1.getBinaryNodeChild)(abtNode, 'props');
614
- let props = {};
615
- if (propsNode) {
616
- props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
617
- }
618
- logger.debug('fetched abt');
619
- return props;
620
- };
621
600
  /** sending non-abt props may fix QR scan fail if server expects */
622
601
  const fetchProps = async () => {
602
+ var _a, _b;
623
603
  const resultNode = await query({
624
604
  tag: 'iq',
625
605
  attrs: {
@@ -628,12 +608,17 @@ const makeChatsSocket = (config) => {
628
608
  type: 'get',
629
609
  },
630
610
  content: [
631
- { tag: 'props', attrs: {} }
611
+ { tag: 'props', attrs: {
612
+ protocol: '2',
613
+ hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ""
614
+ } }
632
615
  ]
633
616
  });
634
617
  const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
635
618
  let props = {};
636
619
  if (propsNode) {
620
+ authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
621
+ ev.emit('creds.update', authState.creds);
637
622
  props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
638
623
  }
639
624
  logger.debug('fetched props');
@@ -707,7 +692,6 @@ const makeChatsSocket = (config) => {
707
692
  * */
708
693
  const executeInitQueries = async () => {
709
694
  await Promise.all([
710
- fetchAbt(),
711
695
  fetchProps(),
712
696
  fetchBlocklist(),
713
697
  fetchPrivacySettings(),
@@ -17,10 +17,10 @@ export declare const waLabelAssociationKey: Comparable<LabelAssociation, string>
17
17
  export type BaileysInMemoryStoreConfig = {
18
18
  chatKey?: Comparable<Chat, string>;
19
19
  labelAssociationKey?: Comparable<LabelAssociation, string>;
20
- logger?: Logger;
20
+ logger: Logger;
21
21
  socket?: WASocket;
22
22
  };
23
- declare const _default: ({ logger: _logger, chatKey, labelAssociationKey, socket }: BaileysInMemoryStoreConfig) => {
23
+ declare const _default: ({ logger, chatKey, labelAssociationKey, socket }: BaileysInMemoryStoreConfig) => {
24
24
  chats: KeyedDB<Chat, string>;
25
25
  contacts: {
26
26
  [_: string]: Contact;
@@ -60,11 +60,11 @@ const predefinedLabels = Object.freeze({
60
60
  deleted: false
61
61
  }
62
62
  });
63
- exports.default = ({ logger: _logger, chatKey, labelAssociationKey, socket }) => {
63
+ exports.default = ({ logger, chatKey, labelAssociationKey, socket }) => {
64
64
  // const logger = _logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
65
65
  chatKey = chatKey || (0, exports.waChatKey)(true);
66
66
  labelAssociationKey = labelAssociationKey || exports.waLabelAssociationKey;
67
- const logger = _logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
67
+ logger = logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
68
68
  const KeyedDB = require('@adiwajshing/keyed-db').default;
69
69
  const chats = new KeyedDB(chatKey, c => c.id);
70
70
  const messages = {};
@@ -130,31 +130,31 @@ exports.default = ({ logger: _logger, chatKey, labelAssociationKey, socket }) =>
130
130
  contactsUpsert(contacts);
131
131
  });
132
132
  ev.on('contacts.update', async (updates) => {
133
+ var _a;
133
134
  for (const update of updates) {
134
135
  let contact;
135
136
  if (contacts[update.id]) {
136
137
  contact = contacts[update.id];
137
138
  }
138
139
  else {
139
- const contactHashes = await Promise.all(Object.keys(contacts).map(async (a) => {
140
- return (await (0, Utils_1.md5)(Buffer.from(a + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3);
140
+ const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
141
+ const { user } = (0, WABinary_1.jidDecode)(contactId);
142
+ return [contactId, (await (0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
141
143
  }));
142
- contact = contacts[contactHashes.find(a => a === update.id) || ''];
144
+ contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
143
145
  }
144
- if (update.imgUrl === 'changed' || update.imgUrl === 'removed') {
145
- if (contact) {
146
- if (update.imgUrl === 'changed') {
147
- contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
148
- }
149
- else {
150
- delete contact.imgUrl;
151
- }
146
+ if (contact) {
147
+ if (update.imgUrl === 'changed') {
148
+ contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
152
149
  }
153
- else {
154
- return logger.debug({ update }, 'got update for non-existant contact');
150
+ else if (update.imgUrl === 'removed') {
151
+ delete contact.imgUrl;
155
152
  }
156
153
  }
157
- Object.assign(contacts[update.id], contact);
154
+ else {
155
+ return logger.debug({ update }, 'got update for non-existant contact');
156
+ }
157
+ Object.assign(contacts[contact.id], contact);
158
158
  }
159
159
  });
160
160
  ev.on('chats.upsert', newChats => {
@@ -64,6 +64,7 @@ export type AuthenticationCreds = SignalCreds & {
64
64
  backupToken: Buffer;
65
65
  registration: RegistrationOptions;
66
66
  pairingCode: string | undefined;
67
+ lastPropHash: string | undefined;
67
68
  };
68
69
  export type SignalDataTypeMap = {
69
70
  'pre-key': KeyPair;
@@ -208,6 +208,8 @@ export type MiscMessageGenerationOptions = MinimalRelayOptions & {
208
208
  backgroundColor?: string;
209
209
  /** font type for status */
210
210
  font?: number;
211
+ /** if it is broadcast */
212
+ broadcast?: boolean;
211
213
  };
212
214
  export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
213
215
  userJid: string;
@@ -199,6 +199,7 @@ const initAuthCreds = () => {
199
199
  backupToken: (0, crypto_1.randomBytes)(20),
200
200
  registration: {},
201
201
  pairingCode: undefined,
202
+ lastPropHash: undefined,
202
203
  };
203
204
  };
204
205
  exports.initAuthCreds = initAuthCreds;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "6.9.0",
3
+ "version": "6.9.2",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",