dibosockets 1.0.3 → 1.0.4

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 (40) hide show
  1. package/WAProto/WAProto.proto +1013 -169
  2. package/lib/Api/Internet/growagarden.js +28 -0
  3. package/lib/Api/creator.json +13 -0
  4. package/lib/Api/downloader/tiktokdownload.js +132 -0
  5. package/lib/Api/index.js +38 -0
  6. package/lib/Api/nsfw/loli.js +79 -0
  7. package/lib/Api/stalker/githubstalk.js +46 -0
  8. package/lib/Api/stalker/stalkroblox.js +94 -0
  9. package/lib/Api/stalker/tiktokstalk.js +68 -0
  10. package/lib/Api/tools/ssweb.js +38 -0
  11. package/lib/Defaults/baileys-version.json +1 -1
  12. package/lib/Defaults/index.js +50 -34
  13. package/lib/Defaults/phonenumber_mcc.json +223 -0
  14. package/lib/Socket/RHandler.js +158 -240
  15. package/lib/Socket/business.js +8 -2
  16. package/lib/Socket/chats.js +371 -142
  17. package/lib/Socket/communities.js +441 -0
  18. package/lib/Socket/index.js +43 -10
  19. package/lib/Socket/messages-recv.js +15 -4
  20. package/lib/Socket/messages-send.js +13 -35
  21. package/lib/Socket/newsletter.js +107 -124
  22. package/lib/Socket/socket.js +35 -23
  23. package/lib/Store/make-in-memory-store.js +2 -2
  24. package/lib/Types/Newsletter.js +18 -38
  25. package/lib/Utils/async-iterable.js +41 -0
  26. package/lib/Utils/baileys-event-stream.js +1 -1
  27. package/lib/Utils/browser-utils.js +35 -0
  28. package/lib/Utils/event-buffer.js +2 -2
  29. package/lib/Utils/generics.js +4 -0
  30. package/lib/Utils/index.js +3 -3
  31. package/lib/Utils/message-retry-manager.js +128 -0
  32. package/lib/Utils/messages-media.js +88 -49
  33. package/lib/Utils/messages.js +91 -16
  34. package/lib/Utils/process-message.js +19 -0
  35. package/lib/Utils/resolveJid.js +52 -0
  36. package/lib/Utils/use-multi-file-auth-state.js +0 -3
  37. package/lib/Utils/validate-connection.js +77 -21
  38. package/lib/WABinary/jid-utils.js +3 -1
  39. package/lib/index.js +2 -1
  40. package/package.json +2 -2
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageRetryManager = void 0;
4
+
5
+ const lru_cache_1 = require("lru-cache");
6
+
7
+ const RECENT_MESSAGES_SIZE = 512;
8
+
9
+ const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000;
10
+
11
+ const PHONE_REQUEST_DELAY = 3000;
12
+
13
+ class MessageRetryManager {
14
+ constructor(logger, maxMsgRetryCount) {
15
+ this.logger = logger;
16
+ this.maxMsgRetryCount = maxMsgRetryCount;
17
+ this._recentMessagesMap = new lru_cache_1.LRUCache({
18
+ max: RECENT_MESSAGES_SIZE
19
+ });
20
+ this._sessionRecreateHistory = new lru_cache_1.LRUCache({
21
+ ttl: RECREATE_SESSION_TIMEOUT * 2,
22
+ ttlAutopurge: true
23
+ });
24
+ this._retryCounters = new lru_cache_1.LRUCache({
25
+ ttl: 15 * 60 * 1000,
26
+ ttlAutopurge: true,
27
+ updateAgeOnGet: true
28
+ });
29
+ this._pendingPhoneRequests = {};
30
+ this.statistics = {
31
+ totalRetries: 0,
32
+ successfulRetries: 0,
33
+ failedRetries: 0,
34
+ mediaRetries: 0,
35
+ sessionRecreations: 0,
36
+ phoneRequests: 0
37
+ };
38
+ this.maxMsgRetryCount = maxMsgRetryCount;
39
+ }
40
+ addRecentMessage(to, id, message) {
41
+ const key = { to, id };
42
+ const keyStr = this._keyToString(key);
43
+ this._recentMessagesMap.set(keyStr, {
44
+ message,
45
+ timestamp: Date.now()
46
+ });
47
+ this.logger.debug(`Added message to retry cache: ${to}/${id}`);
48
+ }
49
+ getRecentMessage(to, id) {
50
+ const key = { to, id };
51
+ const keyStr = this._keyToString(key);
52
+ return this._recentMessagesMap.get(keyStr);
53
+ }
54
+ shouldRecreateSession(jid, retryCount, hasSession) {
55
+ if (!hasSession) {
56
+ this._sessionRecreateHistory.set(jid, Date.now());
57
+ this.statistics.sessionRecreations++;
58
+ return {
59
+ reason: "we don't have a Signal session with them",
60
+ recreate: true
61
+ };
62
+ }
63
+ if (retryCount < 2) {
64
+ return { reason: '', recreate: false };
65
+ }
66
+ const now = Date.now();
67
+ const prevTime = this._sessionRecreateHistory.get(jid);
68
+ if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
69
+ this._sessionRecreateHistory.set(jid, now);
70
+ this.statistics.sessionRecreations++;
71
+ return {
72
+ reason: 'retry count > 1 and over an hour since last recreation',
73
+ recreate: true
74
+ };
75
+ }
76
+ return { reason: '', recreate: false };
77
+ }
78
+ incrementRetryCount(messageId) {
79
+ this._retryCounters.set(messageId, (this._retryCounters.get(messageId) || 0) + 1);
80
+ this.statistics.totalRetries++;
81
+ return this._retryCounters.get(messageId);
82
+ }
83
+ getRetryCount(messageId) {
84
+ return this._retryCounters.get(messageId) || 0;
85
+ }
86
+ hasExceededMaxRetries(messageId) {
87
+ return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
88
+ }
89
+ markRetrySuccess(messageId) {
90
+ this.statistics.successfulRetries++;
91
+ this._retryCounters.delete(messageId);
92
+ this._cancelPendingPhoneRequest(messageId);
93
+ }
94
+ markRetryFailed(messageId) {
95
+ this.statistics.failedRetries++;
96
+ this._retryCounters.delete(messageId);
97
+ }
98
+ schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
99
+ this._cancelPendingPhoneRequest(messageId);
100
+ this._pendingPhoneRequests[messageId] = setTimeout(() => {
101
+ delete this._pendingPhoneRequests[messageId];
102
+ this.statistics.phoneRequests++;
103
+ callback();
104
+ }, delay);
105
+ this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
106
+ }
107
+ cancelPendingPhoneRequest(messageId) {
108
+ const timeout = this._pendingPhoneRequests[messageId];
109
+ if (timeout) {
110
+ clearTimeout(timeout);
111
+ delete this._pendingPhoneRequests[messageId];
112
+ this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
113
+ }
114
+ }
115
+ _keyToString(key) {
116
+ return `${key.to}:${key.id}`;
117
+ }
118
+ _cancelPendingPhoneRequest(messageId) {
119
+ const timeout = this._pendingPhoneRequests[messageId];
120
+ if (timeout) {
121
+ clearTimeout(timeout);
122
+ delete this._pendingPhoneRequests[messageId];
123
+ this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
124
+ }
125
+ }
126
+ }
127
+
128
+ exports.MessageRetryManager = MessageRetryManager;
@@ -60,7 +60,6 @@ const WAProto_1 = require("../../WAProto");
60
60
  const Defaults_1 = require("../Defaults");
61
61
  const WABinary_1 = require("../WABinary");
62
62
  const crypto_1 = require("./crypto");
63
- const streamToBuffer = require("./streamToBuffer")
64
63
  const generics_1 = require("./generics");
65
64
  const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
66
65
  const getImageProcessingLibrary = async () => {
@@ -77,7 +76,7 @@ const getImageProcessingLibrary = async () => {
77
76
  if (sharp) {
78
77
  return { sharp };
79
78
  }
80
- const jimp = (_jimp === null || _jimp === void 0 ? void 0 : _jimp.default) || _jimp;
79
+ const jimp = (_jimp === null || _jimp === void 0 ? void 0 : _jimp.default) || _jimp;
81
80
  if (jimp) {
82
81
  return { jimp };
83
82
  }
@@ -88,6 +87,53 @@ const hkdfInfoKey = (type) => {
88
87
  return `WhatsApp ${hkdfInfo} Keys`;
89
88
  };
90
89
  exports.hkdfInfoKey = hkdfInfoKey;
90
+
91
+ const getRawMediaUploadData = async (media, mediaType, logger) => {
92
+
93
+ const { stream } = await exports.getStream(media);
94
+ logger === null || logger === void 0 ? void 0 : logger.debug('got stream for raw upload');
95
+ const hasher = Crypto.createHash('sha256');
96
+
97
+ // Generate file temp
98
+ const filePath = (0, path_1.join)((0, os_1.tmpdir)(), mediaType + (0, generics_1.generateMessageIDV2)());
99
+ const fileWriteStream = (0, fs_1.createWriteStream)(filePath);
100
+
101
+ let fileLength = 0;
102
+ try {
103
+ for await (const data of stream) {
104
+ fileLength += data.length;
105
+ hasher.update(data);
106
+ // Handle backpressure
107
+ if (!fileWriteStream.write(data)) {
108
+ await (0, events_1.once)(fileWriteStream, 'drain');
109
+ }
110
+ }
111
+ fileWriteStream.end();
112
+ await (0, events_1.once)(fileWriteStream, 'finish');
113
+ stream.destroy();
114
+
115
+ const fileSha256 = hasher.digest();
116
+ logger === null || logger === void 0 ? void 0 : logger.debug('hashed data for raw upload');
117
+
118
+ return {
119
+ filePath: filePath,
120
+ fileSha256,
121
+ fileLength
122
+ };
123
+ }
124
+ catch (error) {
125
+ fileWriteStream.destroy();
126
+ stream.destroy();
127
+ try {
128
+ await fs_1.promises.unlink(filePath);
129
+ }
130
+ catch (_a) {
131
+ // ignore
132
+ }
133
+ throw error;
134
+ }
135
+ };
136
+ exports.getRawMediaUploadData = getRawMediaUploadData;
91
137
  /** generates all the keys required to encrypt/decrypt & sign a media message */
92
138
  async function getMediaKeys(buffer, mediaType) {
93
139
  if (!buffer) {
@@ -365,59 +411,43 @@ async function getAudioDuration(buffer) {
365
411
  metadata = await musicMetadata.parseStream(buffer, undefined, options);
366
412
  }
367
413
  return metadata.format.duration;
368
- }
369
- const toBuffer = async (stream) => {
370
- const chunks = [];
371
- for await (const chunk of stream) {
372
- chunks.push(chunk);
373
- }
374
- stream.destroy();
375
- return Buffer.concat(chunks);
376
- };
377
- exports.toBuffer = toBuffer;
378
-
414
+ }
379
415
  async function getAudioWaveform(buffer, logger) {
380
416
  try {
381
- const { default: decoder } = await eval('import("audio-decode")')
382
- let audioData
383
-
417
+ const { default: decoder } = await eval('import(\'audio-decode\')');
418
+ let audioData;
384
419
  if (Buffer.isBuffer(buffer)) {
385
- audioData = buffer
386
- } else if (typeof buffer === 'string') {
387
- const rStream = fs_1.createReadStream(buffer)
388
- audioData = await streamToBuffer(rStream)
389
- } else {
390
- audioData = await streamToBuffer(buffer)
420
+ audioData = buffer;
391
421
  }
392
-
393
- const audioBuffer = await decoder(audioData)
394
- const rawData = audioBuffer.getChannelData(0)
395
- const samples = 64
396
- const blockSize = Math.floor(rawData.length / samples)
397
- const filteredData = []
398
-
399
- // === Versi TS style: ambil RATA-RATA amplitudo biar halus ===
422
+ else if (typeof buffer === 'string') {
423
+ const rStream = (0, fs_1.createReadStream)(buffer);
424
+ audioData = await (0, exports.toBuffer)(rStream);
425
+ }
426
+ else {
427
+ audioData = await (0, exports.toBuffer)(buffer);
428
+ }
429
+ const audioBuffer = await decoder(audioData);
430
+ const rawData = audioBuffer.getChannelData(0);
431
+ const samples = 64;
432
+ const blockSize = Math.floor(rawData.length / samples);
433
+ const filteredData = [];
400
434
  for (let i = 0; i < samples; i++) {
401
- let sum = 0
402
- const blockStart = blockSize * i
435
+ const blockStart = blockSize * i;
436
+ let sum = 0;
403
437
  for (let j = 0; j < blockSize; j++) {
404
- sum += Math.abs(rawData[blockStart + j] || 0)
438
+ sum = sum + Math.abs(rawData[blockStart + j]);
405
439
  }
406
- filteredData.push(sum / blockSize)
440
+ filteredData.push(sum / blockSize);
407
441
  }
408
-
409
- // Normalisasi
410
- const multiplier = Math.pow(Math.max(...filteredData) || 1, -1)
411
- const normalizedData = filteredData.map((n) => n * multiplier)
412
-
413
- // Hasil akhir: Uint8Array rentang 0–100
414
- return new Uint8Array(normalizedData.map((n) => Math.floor(100 * n)))
415
- } catch (e) {
416
- logger?.debug?.('⚠️ Failed to generate waveform: ' + e)
417
- return new Uint8Array(64).fill(0)
442
+ const multiplier = Math.pow(Math.max(...filteredData), -1);
443
+ const normalizedData = filteredData.map((n) => n * multiplier);
444
+ const waveform = new Uint8Array(normalizedData.map((n) => Math.floor(100 * n)));
445
+ return waveform;
446
+ }
447
+ catch (e) {
448
+ logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
418
449
  }
419
450
  }
420
-
421
451
  const toReadable = (buffer) => {
422
452
  const readable = new stream_1.Readable({ read: () => { } });
423
453
  readable.push(buffer);
@@ -425,6 +455,15 @@ const toReadable = (buffer) => {
425
455
  return readable;
426
456
  };
427
457
  exports.toReadable = toReadable;
458
+ const toBuffer = async (stream) => {
459
+ const chunks = [];
460
+ for await (const chunk of stream) {
461
+ chunks.push(chunk);
462
+ }
463
+ stream.destroy();
464
+ return Buffer.concat(chunks);
465
+ };
466
+ exports.toBuffer = toBuffer;
428
467
  const getStream = async (item, opts) => {
429
468
  if (Buffer.isBuffer(item)) {
430
469
  return { stream: (0, exports.toReadable)(item), type: 'buffer' };
@@ -534,7 +573,10 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
534
573
  }
535
574
  };
536
575
  exports.prepareStream = prepareStream;
537
- const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
576
+ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts, isNewsletter } = {}) => {
577
+ if (isNewsletter) {
578
+ throw new Error('encryptedStream must not be used for newsletter media');
579
+ }
538
580
  const { stream, type } = await (0, exports.getStream)(media, opts);
539
581
  logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
540
582
  const mediaKey = Crypto.randomBytes(32);
@@ -882,6 +924,3 @@ const MEDIA_RETRY_STATUS_MAP = {
882
924
  [WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
883
925
  [WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
884
926
  };
885
- function __importStar(arg0) {
886
- throw new Error('Function not implemented.');
887
- }
@@ -82,20 +82,20 @@ const prepareWAMessageMedia = async (message, options) => {
82
82
  media: message[mediaType]
83
83
  };
84
84
  delete uploadData[mediaType];
85
- // check if cacheable + generate cache key
85
+
86
+ // Check cache
86
87
  const cacheableKey = typeof uploadData.media === 'object' &&
87
88
  ('url' in uploadData.media) &&
88
89
  !!uploadData.media.url &&
89
- !!options.mediaCache && (
90
- // generate the key
91
- mediaType + ':' + uploadData.media.url.toString());
90
+ !!options.mediaCache && (mediaType + ':' + uploadData.media.url.toString());
91
+
92
92
  if (mediaType === 'document' && !uploadData.fileName) {
93
93
  uploadData.fileName = 'file';
94
94
  }
95
95
  if (!uploadData.mimetype) {
96
96
  uploadData.mimetype = MIMETYPE_MAP[mediaType];
97
97
  }
98
- // check for cache hit
98
+
99
99
  if (cacheableKey) {
100
100
  const mediaBuff = options.mediaCache.get(cacheableKey);
101
101
  if (mediaBuff) {
@@ -106,19 +106,85 @@ const prepareWAMessageMedia = async (message, options) => {
106
106
  return obj;
107
107
  }
108
108
  }
109
+
110
+ const isNewsletter = !!options.jid && (0, WABinary_1.isJidNewsletter)(options.jid);
111
+
112
+ if (isNewsletter && mediaType === 'audio') {
113
+ uploadData.mimetype = 'audio/mp4';
114
+ }
115
+
116
+ if (isNewsletter) {
117
+ logger === null || logger === void 0 ? void 0 : logger.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
118
+
119
+ const { filePath, fileSha256, fileLength } = await (0, messages_media_1.getRawMediaUploadData)(
120
+ uploadData.media,
121
+ options.mediaTypeOverride || mediaType,
122
+ logger
123
+ );
124
+
125
+ const fileSha256B64 = fileSha256.toString('base64');
126
+ const uploadInput = filePath;
127
+
128
+ const { mediaUrl, directPath } = await options.upload(uploadInput, {
129
+ fileEncSha256B64: fileSha256B64,
130
+ mediaType
131
+ });
132
+
133
+ await fs_1.promises.unlink(filePath);
134
+
135
+ const obj = Types_1.WAProto.Message.fromObject({
136
+ [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
137
+ url: mediaUrl,
138
+ directPath,
139
+ fileSha256,
140
+ fileLength,
141
+ ...uploadData,
142
+ media: undefined
143
+ })
144
+ });
145
+
146
+
147
+ if (uploadData.ptv && mediaType === 'video') {
148
+ obj.ptvMessage = obj.videoMessage;
149
+ delete obj.videoMessage;
150
+
151
+ delete obj.ptvMessage.jpegThumbnail;
152
+ delete obj.ptvMessage.seconds;
153
+ delete obj.ptvMessage.gifPlayback;
154
+ delete obj.ptvMessage.contextInfo;
155
+
156
+ obj.ptvMessage.ptv = true;
157
+ obj.ptvMessage.mimetype = 'video/mp4';
158
+ }
159
+
160
+
161
+ if (obj.stickerMessage) {
162
+ obj.stickerMessage.stickerSentTs = Date.now();
163
+ }
164
+
165
+ if (cacheableKey) {
166
+ logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
167
+ options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
168
+ }
169
+
170
+ return obj;
171
+ }
109
172
  const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
110
173
  const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
111
174
  (typeof uploadData['jpegThumbnail'] === 'undefined');
112
175
  const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
113
176
  const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
114
177
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
115
- const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
178
+
179
+ // Enkripsi standar
180
+ const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
116
181
  logger,
117
182
  saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
118
183
  opts: options.options
119
184
  });
120
- // url safe Base64 encode the SHA256 hash of the body
121
- const fileEncSha256B64 = (options.newsletter ? fileSha256 : fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
185
+
186
+ const fileEncSha256B64 = (fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
187
+
122
188
  const [{ mediaUrl, directPath, handle }] = await Promise.all([
123
189
  (async () => {
124
190
  const result = await options.upload(encWriteStream, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
@@ -171,6 +237,7 @@ const prepareWAMessageMedia = async (message, options) => {
171
237
  }
172
238
  }
173
239
  });
240
+
174
241
  const obj = Types_1.WAProto.Message.fromObject({
175
242
  [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
176
243
  url: handle ? undefined : mediaUrl,
@@ -184,10 +251,12 @@ const prepareWAMessageMedia = async (message, options) => {
184
251
  media: undefined
185
252
  })
186
253
  });
187
- if (uploadData.ptv) {
188
- obj.ptvMessage = obj.videoMessage;
189
- delete obj.videoMessage;
190
- }
254
+
255
+ if (uploadData.ptv && mediaType === 'video') {
256
+ obj.ptvMessage = obj.videoMessage;
257
+ delete obj.videoMessage;
258
+ }
259
+
191
260
  if (cacheableKey) {
192
261
  logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
193
262
  options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
@@ -195,6 +264,7 @@ const prepareWAMessageMedia = async (message, options) => {
195
264
  return obj;
196
265
  };
197
266
  exports.prepareWAMessageMedia = prepareWAMessageMedia;
267
+
198
268
  const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
199
269
  ephemeralExpiration = ephemeralExpiration || 0;
200
270
  const content = {
@@ -378,10 +448,6 @@ const generateWAMessageContent = async (message, options) => {
378
448
  break;
379
449
  }
380
450
  }
381
- else if ('ptv' in message && message.ptv) {
382
- const { videoMessage } = await (0, exports.prepareWAMessageMedia)({ video: message.video }, options);
383
- m.ptvMessage = videoMessage;
384
- }
385
451
  else if ('product' in message) {
386
452
  const { imageMessage } = await (0, exports.prepareWAMessageMedia)({ image: message.product.productImage }, options);
387
453
  m.productMessage = Types_1.WAProto.Message.ProductMessage.fromObject({
@@ -1028,3 +1094,12 @@ const assertMediaContent = (content) => {
1028
1094
  return mediaContent;
1029
1095
  };
1030
1096
  exports.assertMediaContent = assertMediaContent;
1097
+
1098
+ const getSenderLid = (message) => {
1099
+ const sender = message.key.participant || message.key.remoteJid;
1100
+ const user = (0, WABinary_1.jidDecode)(sender)?.user || '';
1101
+ const lid = (0, WABinary_1.jidEncode)(user, 'lid');
1102
+ console.log('sender lid:', lid);
1103
+ return { jid: sender, lid };
1104
+ };
1105
+ exports.getSenderLid = getSenderLid;
@@ -130,6 +130,25 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
130
130
  }
131
131
  }
132
132
  const content = (0, messages_1.normalizeMessageContent)(message.message);
133
+ const senderId = message.key.participant || message.key.remoteJid;
134
+ if ((0, WABinary_1.isLidUser)(senderId)) {
135
+ const jid = (0, WABinary_1.lidToJid)(senderId);
136
+ if (message.key.participant) {
137
+ message.key.participant = jid;
138
+ }
139
+ else {
140
+ message.key.remoteJid = jid;
141
+ }
142
+ }
143
+ const mJids = content && content.contextInfo && content.contextInfo.mentionedJid ? content.contextInfo.mentionedJid : [];
144
+ for (let i = 0; i < mJids.length; i++) {
145
+ if ((0, WABinary_1.isLidUser)(mJids[i])) {
146
+ mJids[i] = (0, WABinary_1.lidToJid)(mJids[i]);
147
+ }
148
+ }
149
+ if (content && content.contextInfo && content.contextInfo.participant && (0, WABinary_1.isLidUser)(content.contextInfo.participant)) {
150
+ content.contextInfo.participant = (0, WABinary_1.lidToJid)(content.contextInfo.participant);
151
+ }
133
152
  // unarchive chat if it's a real message, or someone reacted to our message
134
153
  // and we've the unarchive chats setting on
135
154
  if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe))
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.resolveJid = resolveJid;
5
+
6
+ /**
7
+ Resolve LID / raw id menjadi JID WhatsApp asli
8
+ @param {import('@rexxhayanasi/elaina-baileys').WASocket} conn
9
+ @param {any} m
10
+ @param {string|null} target
11
+ @returns {Promise<string|null>}
12
+ */
13
+
14
+ async function resolveJid(conn, m, target) {
15
+ let input =
16
+ target ||
17
+ (m.mentionedJid && m.mentionedJid[0]) ||
18
+ (m.quoted && m.quoted.sender) ||
19
+ m.sender;
20
+
21
+ if (!input) return null;
22
+
23
+
24
+ if (/@s.whatsapp.net$/.test(input))
25
+ return input;
26
+
27
+
28
+ if (!m.isGroup || !m.chat)
29
+ return null;
30
+
31
+ let meta;
32
+ try {
33
+ meta = await conn.groupMetadata(m.chat);
34
+ } catch {
35
+ return null;
36
+ }
37
+
38
+ if (!meta || !Array.isArray(meta.participants))
39
+ return null;
40
+
41
+ const participant = meta.participants.find(p =>
42
+ p.jid === input ||
43
+ p.id === input ||
44
+ p.lid === input ||
45
+ (typeof input === "string" && input.replace(/@lid$/, "") === p.lid?.replace(/@lid$/, ""))
46
+ );
47
+
48
+ if (participant && participant.jid)
49
+ return participant.jid;
50
+
51
+ return null;
52
+ }
@@ -8,9 +8,6 @@ const WAProto_1 = require("../../WAProto");
8
8
  const auth_utils_1 = require("./auth-utils");
9
9
  const generics_1 = require("./generics");
10
10
  // We need to lock files due to the fact that we are using async functions to read and write files
11
- // https://github.com/WhiskeySockets/Baileys/issues/794
12
- // https://github.com/nodejs/node/issues/26338
13
- // Use a Map to store mutexes for each file path
14
11
  const fileLocks = new Map();
15
12
  // Get or create a mutex for a specific file path
16
13
  const getFileLock = (path) => {