amiudmodz 5.2.0 → 5.2.1

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.
@@ -57,7 +57,7 @@ exports.BufferJSON = {
57
57
  return value;
58
58
  }
59
59
  };
60
- const getKeyAuthor = (key, meId = 'me') => (((key === null || key === void 0 ? void 0 : key.fromMe) ? meId : (key === null || key === void 0 ? void 0 : key.participant) || (key === null || key === void 0 ? void 0 : key.remoteJid)) || '');
60
+ const getKeyAuthor = (key, meId = 'me') => key ? (key.fromMe ? meId : (key.participant || key.remoteJid || '')) : '';
61
61
  exports.getKeyAuthor = getKeyAuthor;
62
62
  const writeRandomPadMax16 = (msg) => {
63
63
  const pad = (0, crypto_1.randomBytes)(1);
@@ -99,7 +99,7 @@ exports.encodeBigEndian = encodeBigEndian;
99
99
  const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
100
100
  exports.toNumber = toNumber;
101
101
  /** unix timestamp of a date in seconds */
102
- const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
102
+ const unixTimestampSeconds = (date) => date ? Math.floor(date.getTime() / 1000) : Math.floor(Date.now() / 1000);
103
103
  exports.unixTimestampSeconds = unixTimestampSeconds;
104
104
  const debouncedTimeout = (intervalMs = 1000, task) => {
105
105
  let timeout;
@@ -10,28 +10,54 @@ const jidEncode = (user, server, device, agent) => {
10
10
  return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
11
11
  };
12
12
  exports.jidEncode = jidEncode;
13
+ const jidDecodeCache = new Map();
13
14
  const jidDecode = (jid) => {
14
- const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
15
+ if (typeof jid !== 'string') {
16
+ return undefined;
17
+ }
18
+ const cached = jidDecodeCache.get(jid);
19
+ if (cached !== undefined) {
20
+ return cached;
21
+ }
22
+ const sepIdx = jid.indexOf('@');
15
23
  if (sepIdx < 0) {
24
+ jidDecodeCache.set(jid, undefined);
16
25
  return undefined;
17
26
  }
18
27
  const server = jid.slice(sepIdx + 1);
19
28
  const userCombined = jid.slice(0, sepIdx);
20
- const [userAgent, device] = userCombined.split(':');
21
- const user = userAgent.split('_')[0];
22
- return {
29
+
30
+ let user = userCombined;
31
+ let device;
32
+ const colonIdx = userCombined.indexOf(':');
33
+ if (colonIdx >= 0) {
34
+ const userAgent = userCombined.slice(0, colonIdx);
35
+ device = userCombined.slice(colonIdx + 1);
36
+ const underscoreIdx = userAgent.indexOf('_');
37
+ user = underscoreIdx >= 0 ? userAgent.slice(0, underscoreIdx) : userAgent;
38
+ } else {
39
+ const underscoreIdx = userCombined.indexOf('_');
40
+ user = underscoreIdx >= 0 ? userCombined.slice(0, underscoreIdx) : userCombined;
41
+ }
42
+
43
+ const decoded = {
23
44
  server,
24
45
  user,
25
-
26
46
  domainType: (server === 'lid' || server === 'hosted.lid') ? 1 : 0,
27
47
  device: device ? +device : undefined
28
48
  };
49
+ jidDecodeCache.set(jid, decoded);
50
+ return decoded;
29
51
  };
30
52
  exports.jidDecode = jidDecode;
31
53
  /** is the jid a user */
32
54
  const areJidsSameUser = (jid1, jid2) => {
33
- var _a, _b;
34
- return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
55
+ if (jid1 === jid2) {
56
+ return true;
57
+ }
58
+ const decoded1 = jidDecode(jid1);
59
+ const decoded2 = jidDecode(jid2);
60
+ return (decoded1?.user === decoded2?.user);
35
61
  };
36
62
  exports.areJidsSameUser = areJidsSameUser;
37
63
  /** is the jid a user */
@@ -52,12 +78,23 @@ exports.isJidStatusBroadcast = isJidStatusBroadcast;
52
78
  /** is the jid the newsletter */
53
79
  const isJidNewsLetter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('newsletter'));
54
80
  exports.isJidNewsLetter = isJidNewsLetter;
81
+ const jidNormalizedUserCache = new Map();
55
82
  const jidNormalizedUser = (jid) => {
56
- const result = (0, exports.jidDecode)(jid);
83
+ if (typeof jid !== 'string') {
84
+ return '';
85
+ }
86
+ const cached = jidNormalizedUserCache.get(jid);
87
+ if (cached !== undefined) {
88
+ return cached;
89
+ }
90
+ const result = jidDecode(jid);
57
91
  if (!result) {
92
+ jidNormalizedUserCache.set(jid, '');
58
93
  return '';
59
94
  }
60
95
  const { user, server } = result;
61
- return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
96
+ const normalized = jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
97
+ jidNormalizedUserCache.set(jid, normalized);
98
+ return normalized;
62
99
  };
63
100
  exports.jidNormalizedUser = jidNormalizedUser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amiudmodz",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "WhatsApp Baileys mod Powered by UDMODZ",
5
5
  "keywords": [
6
6
  "whatsapp",