@prototypevip/baileys 0.0.4 → 0.0.5

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.
@@ -199,6 +199,15 @@ export const makeChatsSocket = (config) => {
199
199
  }
200
200
  };
201
201
 
202
+ const getUsername = async (jid) => {
203
+ const usyncQuery = new USyncQuery()
204
+ .withUsernameProtocol()
205
+ .withContext("background");
206
+ usyncQuery.withUser(new USyncUser().withId(jid));
207
+ const result = await sock.executeUSyncQuery(usyncQuery);
208
+ return result?.list?.[0]?.username || null;
209
+ };
210
+
202
211
  const findUserId = async (pnLid) => {
203
212
  const cachedId = USER_ID_CACHE.get(pnLid);
204
213
  if (cachedId) {
@@ -212,6 +221,7 @@ export const makeChatsSocket = (config) => {
212
221
  )?.[0]?.lid;
213
222
  if (!userId.lid) {
214
223
  userId.lid = "id-not-found";
224
+ USER_ID_CACHE.set(pnLid, userId);
215
225
  return userId;
216
226
  }
217
227
  } else if (isLidUser(pnLid)) {
@@ -220,7 +230,18 @@ export const makeChatsSocket = (config) => {
220
230
  await signalRepository.lidMapping.getPNsForLIDs([pnLid])
221
231
  )?.[0]?.pn;
222
232
  if (!userId.phoneNumber) {
233
+ // ملحوظه: ده بيحصل عادي دلوقتي مع أي حساب حاطط "username" جديد بتاع
234
+ // واتساب، لأن رقمه بيبقى مش قابل للاكتشاف. من غير الكاش ده، كل رساله
235
+ // جايه من الحساب ده كانت بتعمل استعلام شبكه كامل تاني من الأول، وده
236
+ // اللي كان بيسبب التأخير/التعليق الملحوظ مع أي حد شايل يوزرنيم.
237
+ // كمان بنحاول نجيب اليوزرنيم نفسه عشان يتعرض بدل الرقم/الليد الخام.
223
238
  userId.phoneNumber = "id-not-found";
239
+ try {
240
+ userId.username = await getUsername(pnLid);
241
+ } catch {
242
+ userId.username = null;
243
+ }
244
+ USER_ID_CACHE.set(pnLid, userId);
224
245
  return userId;
225
246
  }
226
247
  } else {
@@ -1091,6 +1112,7 @@ export const makeChatsSocket = (config) => {
1091
1112
  fetchStatus: fetchStatus,
1092
1113
  fetchDisappearingDuration: fetchDisappearingDuration,
1093
1114
  findUserId: findUserId,
1115
+ getUsername: getUsername,
1094
1116
  updateProfilePicture: updateProfilePicture,
1095
1117
  removeProfilePicture: removeProfilePicture,
1096
1118
  updateProfileStatus: updateProfileStatus,
@@ -2,3 +2,4 @@ export * from "./USyncDeviceProtocol.js";
2
2
  export * from "./USyncContactProtocol.js";
3
3
  export * from "./USyncStatusProtocol.js";
4
4
  export * from "./USyncDisappearingModeProtocol.js";
5
+ export * from "./USyncUsernameProtocol.js";
@@ -6,6 +6,7 @@ import {
6
6
  USyncDeviceProtocol,
7
7
  USyncDisappearingModeProtocol,
8
8
  USyncStatusProtocol,
9
+ USyncUsernameProtocol,
9
10
  } from "./Protocols/index.js";
10
11
  import { USyncUser } from "./USyncUser.js";
11
12
  export class USyncQuery {
@@ -130,4 +131,8 @@ export class USyncQuery {
130
131
  this.protocols.push(new USyncLIDProtocol());
131
132
  return this;
132
133
  }
134
+ withUsernameProtocol() {
135
+ this.protocols.push(new USyncUsernameProtocol());
136
+ return this;
137
+ }
133
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prototypevip/baileys",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "A simple fork of Baileys for WhatsApp automation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",