@realvare/based 2.7.54 → 2.7.55

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.
@@ -46,7 +46,7 @@ const makeMessagesRecvSocket = (config) => {
46
46
  tag: 'ack',
47
47
  attrs: {
48
48
  id: attrs.id,
49
- to: resolveJid(attrs.from),
49
+ to: attrs.from,
50
50
  class: tag
51
51
  }
52
52
  };
@@ -54,10 +54,10 @@ const makeMessagesRecvSocket = (config) => {
54
54
  stanza.attrs.error = errorCode.toString();
55
55
  }
56
56
  if (!!attrs.participant) {
57
- stanza.attrs.participant = resolveJid(attrs.participant);
57
+ stanza.attrs.participant = attrs.participant;
58
58
  }
59
59
  if (!!attrs.recipient) {
60
- stanza.attrs.recipient = resolveJid(attrs.recipient);
60
+ stanza.attrs.recipient = attrs.recipient;
61
61
  }
62
62
  if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
63
63
  stanza.attrs.type = attrs.type;
@@ -68,6 +68,7 @@ const makeMessagesRecvSocket = (config) => {
68
68
  logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
69
69
  await sendNode(stanza);
70
70
  };
71
+
71
72
  // Add withAck wrapper for guaranteed acknowledgments
72
73
  const withAck = (processFn) => async (node) => {
73
74
  try {
@@ -117,7 +118,7 @@ const makeMessagesRecvSocket = (config) => {
117
118
  const stanza = ({
118
119
  tag: 'call',
119
120
  attrs: {
120
- to: resolveJid(toJid),
121
+ to: toJid,
121
122
  },
122
123
  content: [{
123
124
  tag: 'offer',
@@ -140,13 +141,13 @@ const makeMessagesRecvSocket = (config) => {
140
141
  tag: 'call',
141
142
  attrs: {
142
143
  from: authState.creds.me.id,
143
- to: resolveJid(callFrom),
144
+ to: callFrom,
144
145
  },
145
146
  content: [{
146
147
  tag: 'reject',
147
148
  attrs: {
148
149
  'call-id': callId,
149
- 'call-creator': resolveJid(callFrom),
150
+ 'call-creator': callFrom,
150
151
  count: '0',
151
152
  },
152
153
  content: undefined,
@@ -180,7 +181,7 @@ const makeMessagesRecvSocket = (config) => {
180
181
  attrs: {
181
182
  id: msgId,
182
183
  type: 'retry',
183
- to: resolveJid(node.attrs.from)
184
+ to: node.attrs.from
184
185
  },
185
186
  content: [
186
187
  {
@@ -200,10 +201,10 @@ const makeMessagesRecvSocket = (config) => {
200
201
  ]
201
202
  };
202
203
  if (node.attrs.recipient) {
203
- receipt.attrs.recipient = resolveJid(node.attrs.recipient);
204
+ receipt.attrs.recipient = node.attrs.recipient;
204
205
  }
205
206
  if (node.attrs.participant) {
206
- receipt.attrs.participant = resolveJid(node.attrs.participant);
207
+ receipt.attrs.participant = node.attrs.participant;
207
208
  }
208
209
  if (retryCount > 1 || forceIncludeKeys) {
209
210
  const { update, preKeys } = await (0, Utils_1.getNextPreKeys)(authState, 1);
@@ -228,7 +229,7 @@ const makeMessagesRecvSocket = (config) => {
228
229
  });
229
230
  };
230
231
  const handleEncryptNotification = async (node) => {
231
- const from = resolveJid(node.attrs.from);
232
+ const from = node.attrs.from;
232
233
  if (from === WABinary_1.S_WHATSAPP_NET) {
233
234
  const countChild = (0, WABinary_1.getBinaryNodeChild)(node, 'count');
234
235
  const count = +countChild.attrs.value;
@@ -293,24 +294,22 @@ const makeMessagesRecvSocket = (config) => {
293
294
  msg.messageStubParameters = oldNumber || [];
294
295
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
295
296
  break;
296
- case 'add':
297
- case 'remove':
298
297
  case 'promote':
299
298
  case 'demote':
299
+ case 'remove':
300
+ case 'add':
300
301
  case 'leave':
301
- const stubTypes = {
302
- add: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
303
- remove: Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE,
304
- promote: Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE,
305
- demote: Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE,
306
- leave: Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE,
307
- };
308
- msg.messageStubType = stubTypes[child.tag];
309
- let affected = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
310
- if (affected.length === 0) {
311
- affected = [participant];
302
+ const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
303
+ msg.messageStubType = Types_1.WAMessageStubType[stubType];
304
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
305
+ if (participants.length === 1 &&
306
+ // if recv. "remove" message and sender removed themselves
307
+ // mark as left
308
+ (0, WABinary_1.areJidsSameUser)(participants[0], participant) &&
309
+ child.tag === 'remove') {
310
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
312
311
  }
313
- msg.messageStubParameters = affected;
312
+ msg.messageStubParameters = participants;
314
313
  break;
315
314
  case 'subject':
316
315
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
@@ -623,7 +622,7 @@ const makeMessagesRecvSocket = (config) => {
623
622
  // todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
624
623
  const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
625
624
  const remoteJid = key.remoteJid;
626
- const participant = resolveJid(key.participant || remoteJid);
625
+ const participant = key.participant || remoteJid;
627
626
  // if it's the primary jid sending the request
628
627
  // just re-send the message to everyone
629
628
  // prevents the first message decryption failure
@@ -658,7 +657,7 @@ const makeMessagesRecvSocket = (config) => {
658
657
  const { attrs, content } = node;
659
658
  const isLid = attrs.from.includes('lid');
660
659
  const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(resolveJid(attrs.participant) || resolveJid(attrs.from), isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
661
- const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? resolveJid(attrs.from) : resolveJid(attrs.recipient);
660
+ const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? resolveJid(attrs.from) : attrs.recipient;
662
661
  const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
663
662
  const key = {
664
663
  remoteJid,
@@ -719,14 +718,13 @@ const makeMessagesRecvSocket = (config) => {
719
718
  }
720
719
  if (attrs.type === 'retry') {
721
720
  // correctly set who is asking for the retry
722
- key.participant = key.participant || resolveJid(attrs.from);
721
+ key.participant = key.participant || attrs.from;
723
722
  const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
724
723
  if (willSendMessageAgain(ids[0], key.participant)) {
725
724
  if (key.fromMe) {
726
725
  try {
727
726
  logger.debug({ attrs, key }, 'recv retry request');
728
- sendMessagesAgain(key, ids, retryNode)
729
- .catch(error => logger.error({ key, ids, trace: error.stack }, 'error in sending message again'));
727
+ await sendMessagesAgain(key, ids, retryNode);
730
728
  }
731
729
  catch (error) {
732
730
  logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
@@ -782,7 +780,7 @@ const makeMessagesRecvSocket = (config) => {
782
780
  };
783
781
  const handleMessage = withAck(async (node) => {
784
782
  var _a, _b, _c;
785
- if (shouldIgnoreJid(resolveJid(node.attrs.from)) && node.attrs.from !== '@s.whatsapp.net') {
783
+ if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
786
784
  logger.debug({ key: node.attrs.key }, 'ignored message');
787
785
  return;
788
786
  }
@@ -850,7 +848,8 @@ const makeMessagesRecvSocket = (config) => {
850
848
  const metadata = await groupMetadata(msg.key.remoteJid);
851
849
  const sender = msg.message.extendedTextMessage.contextInfo.participant;
852
850
  const found = metadata.participants.find(p => p.id === sender);
853
- msg.message.extendedTextMessage.contextInfo.participant = (found === null || found === void 0 ? void 0 : found.jid) || (0, WABinary_1.lidToJid)(sender); }
851
+ msg.message.extendedTextMessage.contextInfo.participant = (found === null || found === void 0 ? void 0 : found.jid) || sender;
852
+ }
854
853
  }
855
854
  if (!(0, WABinary_1.isJidGroup)(msg.key.remoteJid) && (0, WABinary_1.isLidUser)(msg.key.remoteJid)) {
856
855
  msg.key.remoteJid = node.attrs.sender_pn || node.attrs.peer_recipient_pn;
@@ -926,15 +925,13 @@ const makeMessagesRecvSocket = (config) => {
926
925
  }],
927
926
  peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
928
927
  };
929
- const result = await Promise.race([
930
- sendPeerDataOperationMessage(pdoMessage),
931
- (0, Utils_1.delay)(15000).then(() => 'timeout')
932
- ]);
933
- if (result === 'timeout') {
934
- logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline');
935
- placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
936
- }
937
- return result;
928
+ setTimeout(() => {
929
+ if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
930
+ logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline');
931
+ placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
932
+ }
933
+ }, 15000);
934
+ return sendPeerDataOperationMessage(pdoMessage);
938
935
  };
939
936
  const handleCall = async (node) => {
940
937
  const { attrs } = node;
@@ -970,7 +967,7 @@ const makeMessagesRecvSocket = (config) => {
970
967
  await sendMessageAck(node);
971
968
  };
972
969
  const handleBadAck = async ({ attrs }) => {
973
- const key = { remoteJid: resolveJid(attrs.from), fromMe: true, id: attrs.id, 'server_id': attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
970
+ const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, 'server_id': attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
974
971
  // current hypothesis is that if pash is sent in the ack
975
972
  // it means -- the message hasn't reached all devices yet
976
973
  // we'll retry sending the message here
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realvare/based",
3
- "version": "2.7.54",
3
+ "version": "2.7.55",
4
4
  "description": "whatsapp api by sam",
5
5
  "keywords": [
6
6
  "baileys",