hridoy-ultimate 8.0.2 → 9.0.0

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 (281) hide show
  1. package/CHANGELOG.md +68 -40
  2. package/LICENSE +23 -0
  3. package/MERGE_REPORT.md +54 -0
  4. package/README.md +158 -113
  5. package/THIRD_PARTY_NOTICES.md +36 -0
  6. package/docs/TEST_RESULTS.md +68 -0
  7. package/docs/UPSTREAM_API_DOCS.md +2712 -0
  8. package/func/checkUpdate.js +6 -0
  9. package/func/logAdapter.js +33 -0
  10. package/func/logger.js +48 -0
  11. package/index.d.ts +812 -0
  12. package/index.js +30 -824
  13. package/module/config.js +46 -0
  14. package/module/login.js +136 -0
  15. package/module/loginHelper.js +1413 -0
  16. package/module/options.js +55 -0
  17. package/package.json +75 -22
  18. package/scripts/run-tests.js +19 -0
  19. package/scripts/syntax-check.js +22 -0
  20. package/src/{addExternalModule.js → api/action/addExternalModule.js} +8 -8
  21. package/src/{changeAvatar.js → api/action/changeAvatar.js} +32 -33
  22. package/src/{changeBio.js → api/action/changeBio.js} +19 -22
  23. package/src/api/action/dismissScrapingWarning.js +50 -0
  24. package/src/api/action/enableAutoSaveAppState.js +73 -0
  25. package/src/{getCurrentUserID.js → api/action/getCurrentUserID.js} +1 -1
  26. package/src/api/action/handleFriendRequest.js +57 -0
  27. package/src/api/action/logout.js +95 -0
  28. package/src/api/action/refreshFb_dtsg.js +47 -0
  29. package/src/{setPostReaction.js → api/action/setPostReaction.js} +23 -31
  30. package/src/{unfriend.js → api/action/unfriend.js} +14 -14
  31. package/src/api/http/httpGet.js +46 -0
  32. package/src/api/http/httpPost.js +52 -0
  33. package/src/api/http/postFormData.js +47 -0
  34. package/src/api/messaging/addUserToGroup.js +68 -0
  35. package/src/api/messaging/changeAdminStatus.js +126 -0
  36. package/src/{changeArchivedStatus.js → api/messaging/changeArchivedStatus.js} +15 -17
  37. package/src/{changeBlockedStatus.js → api/messaging/changeBlockedStatus.js} +13 -16
  38. package/src/api/messaging/changeGroupImage.js +91 -0
  39. package/src/api/messaging/changeNickname.js +70 -0
  40. package/src/api/messaging/changeThreadColor.js +79 -0
  41. package/src/api/messaging/changeThreadEmoji.js +111 -0
  42. package/src/{createNewGroup.js → api/messaging/createNewGroup.js} +24 -26
  43. package/src/api/messaging/createPoll.js +46 -0
  44. package/src/api/messaging/createThemeAI.js +98 -0
  45. package/src/api/messaging/deleteMessage.js +136 -0
  46. package/src/{deleteThread.js → api/messaging/deleteThread.js} +14 -16
  47. package/src/api/messaging/editMessage.js +105 -0
  48. package/src/api/messaging/forwardAttachment.js +57 -0
  49. package/src/api/messaging/forwardMessage.js +134 -0
  50. package/src/{getEmojiUrl.js → api/messaging/getEmojiUrl.js} +2 -2
  51. package/src/{getFriendsList.js → api/messaging/getFriendsList.js} +16 -19
  52. package/src/{getMessage.js → api/messaging/getMessage.js} +160 -180
  53. package/src/api/messaging/getThemePictures.js +62 -0
  54. package/src/api/messaging/handleMessageRequest.js +65 -0
  55. package/src/api/messaging/markAsDelivered.js +69 -0
  56. package/src/api/messaging/markAsRead.js +110 -0
  57. package/src/api/messaging/markAsReadAll.js +56 -0
  58. package/src/api/messaging/markAsSeen.js +68 -0
  59. package/src/api/messaging/muteThread.js +50 -0
  60. package/src/api/messaging/pinMessage.js +115 -0
  61. package/src/api/messaging/removeUserFromGroup.js +62 -0
  62. package/src/{resolvePhotoUrl.js → api/messaging/resolvePhotoUrl.js} +11 -15
  63. package/src/api/messaging/scheduler.js +264 -0
  64. package/src/{searchForThread.js → api/messaging/searchForThread.js} +12 -12
  65. package/src/api/messaging/sendBroadcast.js +93 -0
  66. package/src/api/messaging/sendMessage.js +269 -0
  67. package/src/api/messaging/sendTypingIndicator.js +90 -0
  68. package/src/api/messaging/sessionGuard.js +130 -0
  69. package/src/api/messaging/setMessageReaction.js +114 -0
  70. package/src/api/messaging/setTitle.js +124 -0
  71. package/src/api/messaging/shareContact.js +98 -0
  72. package/src/{threadColors.js → api/messaging/threadColors.js} +2 -5
  73. package/src/api/messaging/unsendMessage.js +105 -0
  74. package/src/api/messaging/uploadAttachment.js +493 -0
  75. package/src/api/socket/OldMessage.js +199 -0
  76. package/src/api/socket/core/connectMqtt.js +304 -0
  77. package/src/api/socket/core/emitAuth.js +95 -0
  78. package/src/api/socket/core/getSeqID.js +331 -0
  79. package/src/api/socket/core/getTaskResponseData.js +25 -0
  80. package/src/api/socket/core/lifecycle.js +117 -0
  81. package/src/api/socket/core/parseDelta.js +387 -0
  82. package/src/api/socket/detail/buildStream.js +215 -0
  83. package/src/api/socket/detail/constants.js +28 -0
  84. package/src/api/socket/e2ee/crypto.js +173 -0
  85. package/src/api/socket/e2ee/index.js +977 -0
  86. package/src/api/socket/e2ee/localMediaServer.js +59 -0
  87. package/src/api/socket/e2ee/mediaDecode.js +155 -0
  88. package/src/api/socket/e2ee/native/NOTICE.md +29 -0
  89. package/{lib → src/api/socket/e2ee/native/lib}/index.mjs +109 -66
  90. package/src/api/socket/e2ee/native/nativeMediaBridge.js +273 -0
  91. package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
  92. package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
  93. package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
  94. package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
  95. package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
  96. package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
  97. package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
  98. package/src/api/socket/e2ee/proto/proto-writer.ts +76 -0
  99. package/src/api/socket/e2ee/protocol.js +196 -0
  100. package/src/api/socket/e2ee/ratchet.js +219 -0
  101. package/src/api/socket/e2ee/store.js +182 -0
  102. package/src/api/socket/e2ee/vendor/fme/dist/index.cjs +6477 -0
  103. package/src/api/socket/e2ee/vendor/fme/proto/ArmadilloApplication.proto +281 -0
  104. package/src/api/socket/e2ee/vendor/fme/proto/ArmadilloICDC.proto +14 -0
  105. package/src/api/socket/e2ee/vendor/fme/proto/ConsumerApplication.proto +232 -0
  106. package/src/api/socket/e2ee/vendor/fme/proto/MessageApplication.proto +82 -0
  107. package/src/api/socket/e2ee/vendor/fme/proto/MessageTransport.proto +77 -0
  108. package/src/api/socket/e2ee/vendor/fme/proto/WACommon.proto +66 -0
  109. package/src/api/socket/e2ee/vendor/fme/proto/WAMediaTransport.proto +176 -0
  110. package/src/api/socket/listenE2EE.js +87 -0
  111. package/src/api/socket/listenMqtt.js +499 -0
  112. package/src/api/socket/middleware/index.js +216 -0
  113. package/src/api/socket/sendMessage.js +331 -0
  114. package/src/api/socket/sendMessageMqtt.js +69 -0
  115. package/src/{getThreadHistory.js → api/threads/getThreadHistory.js} +114 -132
  116. package/src/api/threads/getThreadInfo.js +329 -0
  117. package/src/api/threads/getThreadList.js +293 -0
  118. package/src/api/threads/getThreadPictures.js +78 -0
  119. package/src/{getUserID.js → api/users/getUserID.js} +22 -18
  120. package/src/api/users/getUserInfo.js +402 -0
  121. package/src/api/users/getUserInfoV2.js +134 -0
  122. package/src/app/MessengerBot.js +209 -0
  123. package/src/app/MessengerContext.js +32 -0
  124. package/src/app/createFcaClient.js +136 -0
  125. package/src/app/threadInfoRealtimeSync.js +284 -0
  126. package/src/core/sendReqMqtt.js +96 -0
  127. package/src/database/helpers.js +53 -0
  128. package/src/database/models/index.js +88 -0
  129. package/src/database/models/thread.js +50 -0
  130. package/src/database/models/user.js +46 -0
  131. package/src/database/threadData.js +94 -0
  132. package/src/database/userData.js +98 -0
  133. package/src/remote/remoteClient.js +123 -0
  134. package/src/utils/antiSuspension.js +219 -0
  135. package/src/utils/broadcast.js +51 -0
  136. package/src/utils/client.js +10 -0
  137. package/src/utils/constants.js +23 -0
  138. package/src/utils/cookies.js +85 -0
  139. package/src/utils/fingerprint.js +110 -0
  140. package/src/utils/format/attachment.js +357 -0
  141. package/src/utils/format/cookie.js +9 -0
  142. package/src/utils/format/date.js +50 -0
  143. package/src/utils/format/decode.js +44 -0
  144. package/src/utils/format/delta.js +195 -0
  145. package/src/utils/format/ids.js +64 -0
  146. package/src/utils/format/index.js +64 -0
  147. package/src/utils/format/message.js +88 -0
  148. package/src/utils/format/presence.js +132 -0
  149. package/src/utils/format/readTyp.js +44 -0
  150. package/src/utils/format/thread.js +42 -0
  151. package/src/utils/format/utils.js +141 -0
  152. package/src/utils/headers.js +125 -0
  153. package/src/utils/humanizer.js +256 -0
  154. package/src/utils/loginParser/autoLogin.js +125 -0
  155. package/src/utils/loginParser/extractDtsg.js +44 -0
  156. package/src/utils/loginParser/helpers.js +43 -0
  157. package/src/utils/loginParser/index.js +10 -0
  158. package/src/utils/loginParser/parseAndCheckLogin.js +241 -0
  159. package/src/utils/loginParser/textUtils.js +28 -0
  160. package/src/utils/nexca-logger.js +144 -0
  161. package/src/utils/nexca-utils.js +687 -0
  162. package/src/utils/request/client.js +26 -0
  163. package/src/utils/request/config.js +23 -0
  164. package/src/utils/request/defaults.js +46 -0
  165. package/src/utils/request/helpers.js +46 -0
  166. package/src/utils/request/index.js +17 -0
  167. package/src/utils/request/methods.js +163 -0
  168. package/src/utils/request/proxy.js +21 -0
  169. package/src/utils/request/retry.js +77 -0
  170. package/src/utils/request/sanitize.js +49 -0
  171. package/src/utils/typingIndicator.js +202 -0
  172. package/test/helpers/stub-modules.js +122 -0
  173. package/test/integration/logout.test.js +69 -0
  174. package/test/integration/mqtt-lifecycle.test.js +195 -0
  175. package/test/integration/package.test.js +116 -0
  176. package/test/integration/typing-wiring.test.js +71 -0
  177. package/test/unit/fingerprint.test.js +19 -0
  178. package/test/unit/humanizer.test.js +32 -0
  179. package/test/unit/lifecycle.test.js +92 -0
  180. package/test/unit/parsers.test.js +43 -0
  181. package/test/unit/typing.test.js +136 -0
  182. package/ANALYSIS.md +0 -31
  183. package/AUDIT_REPORT.md +0 -57
  184. package/advancedSystem.js +0 -95
  185. package/checkUpdate.js +0 -47
  186. package/config.json +0 -51
  187. package/e2ee.js +0 -738
  188. package/examples/basic-bot.js +0 -122
  189. package/examples/e2ee-bot.js +0 -141
  190. package/fca-config.example.json +0 -73
  191. package/scripts/check.js +0 -38
  192. package/src/OldMessage.js +0 -357
  193. package/src/addUserToGroup.js +0 -117
  194. package/src/changeAdminStatus.js +0 -105
  195. package/src/changeAvatarV2.js +0 -86
  196. package/src/changeAvt.js +0 -85
  197. package/src/changeBlockedStatusMqtt.js +0 -75
  198. package/src/changeCover.js +0 -73
  199. package/src/changeGroupImage.js +0 -137
  200. package/src/changeName.js +0 -79
  201. package/src/changeNickname.js +0 -61
  202. package/src/changeThreadColor.js +0 -67
  203. package/src/changeThreadEmoji.js +0 -57
  204. package/src/changeUsername.js +0 -59
  205. package/src/createCommentPost.js +0 -232
  206. package/src/createPoll.js +0 -73
  207. package/src/createPost.js +0 -276
  208. package/src/deleteMessage.js +0 -58
  209. package/src/editMessage.js +0 -76
  210. package/src/editMessageOld.js +0 -62
  211. package/src/follow.js +0 -74
  212. package/src/forwardAttachment.js +0 -62
  213. package/src/friendList.js +0 -104
  214. package/src/getAccess.js +0 -112
  215. package/src/getAvatarUser.js +0 -78
  216. package/src/getBotInitialData.js +0 -42
  217. package/src/getCtx.js +0 -5
  218. package/src/getOptions.js +0 -5
  219. package/src/getRegion.js +0 -7
  220. package/src/getThreadHistoryDeprecated.js +0 -71
  221. package/src/getThreadInfo.js +0 -232
  222. package/src/getThreadInfoDeprecated.js +0 -56
  223. package/src/getThreadList.js +0 -213
  224. package/src/getThreadListDeprecated.js +0 -46
  225. package/src/getThreadPictures.js +0 -59
  226. package/src/getThreadTheme.js +0 -81
  227. package/src/getUID.js +0 -119
  228. package/src/getUserInfo.js +0 -66
  229. package/src/handleFriendRequest.js +0 -46
  230. package/src/handleMessageRequest.js +0 -47
  231. package/src/httpGet.js +0 -49
  232. package/src/httpPost.js +0 -48
  233. package/src/httpPostFormData.js +0 -70
  234. package/src/listenMqtt.js +0 -1081
  235. package/src/listenNotification.js +0 -85
  236. package/src/logout.js +0 -18
  237. package/src/markAsDelivered.js +0 -47
  238. package/src/markAsRead.js +0 -72
  239. package/src/markAsReadAll.js +0 -40
  240. package/src/markAsSeen.js +0 -48
  241. package/src/metaTheme.js +0 -189
  242. package/src/muteThread.js +0 -45
  243. package/src/note.js +0 -228
  244. package/src/pinMessage.js +0 -54
  245. package/src/refreshFb_dtsg.js +0 -49
  246. package/src/removeSuspiciousAccount.js +0 -78
  247. package/src/removeUserFromGroup.js +0 -81
  248. package/src/reply.js +0 -442
  249. package/src/searchFriends.js +0 -140
  250. package/src/searchStickers.js +0 -53
  251. package/src/send.js +0 -46
  252. package/src/sendButtons.js +0 -163
  253. package/src/sendComment.js +0 -159
  254. package/src/sendFriendRequest.js +0 -112
  255. package/src/sendMessage.js +0 -441
  256. package/src/sendMessageMqtt.js +0 -323
  257. package/src/sendTypingIndicator.js +0 -68
  258. package/src/sendTypingIndicatorV2.js +0 -22
  259. package/src/setActiveStatus.js +0 -92
  260. package/src/setMessageReaction.js +0 -150
  261. package/src/setMessageReactionMqtt.js +0 -104
  262. package/src/setMessageReactionSafe.js +0 -44
  263. package/src/setProfileGuard.js +0 -44
  264. package/src/setProfileLock.js +0 -97
  265. package/src/setStoryReaction.js +0 -133
  266. package/src/setStorySeen.js +0 -108
  267. package/src/setThreadTheme.js +0 -102
  268. package/src/setTitle.js +0 -92
  269. package/src/shareContact.js +0 -110
  270. package/src/shareLink.js +0 -59
  271. package/src/stopListenMqtt.js +0 -60
  272. package/src/storyManager.js +0 -357
  273. package/src/suggestFriend.js +0 -132
  274. package/src/unsendMessage.js +0 -68
  275. package/src/uploadAttachment.js +0 -115
  276. package/test/fixes-1_2_4.test.js +0 -118
  277. package/test/mqtt-stop.test.js +0 -32
  278. package/test/reaction-mqtt.test.js +0 -57
  279. package/utils.js +0 -3056
  280. /package/{build → src/api/socket/e2ee/native/build}/messagix.dll +0 -0
  281. /package/{build → src/api/socket/e2ee/native/build}/messagix.so +0 -0
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
5
-
3
+ const log = require("../../../func/logAdapter");
4
+ const { formatID } = require("../../utils/format");
6
5
  function formatData(data) {
7
6
  return {
8
- userID: utils.formatID(data.uid.toString()),
7
+ userID: formatID(data.uid.toString()),
9
8
  photoUrl: data.photo,
10
9
  indexRank: data.index_rank,
11
10
  name: data.text,
@@ -17,41 +16,46 @@ function formatData(data) {
17
16
  };
18
17
  }
19
18
 
20
- module.exports = function (defaultFuncs, api, ctx) {
19
+ module.exports = function(defaultFuncs, api, ctx) {
21
20
  return function getUserID(name, callback) {
22
- var resolveFunc = function () { };
23
- var rejectFunc = function () { };
24
- var returnPromise = new Promise(function (resolve, reject) {
21
+ let resolveFunc = function() {};
22
+ let rejectFunc = function() {};
23
+ const returnPromise = new Promise(function(resolve, reject) {
25
24
  resolveFunc = resolve;
26
25
  rejectFunc = reject;
27
26
  });
28
27
 
29
28
  if (!callback) {
30
- callback = function (err, data) {
31
- if (err) return rejectFunc(err);
32
- resolveFunc(data);
29
+ callback = function(err, friendList) {
30
+ if (err) {
31
+ return rejectFunc(err);
32
+ }
33
+ resolveFunc(friendList);
33
34
  };
34
35
  }
35
36
 
36
- var form = {
37
+ const form = {
37
38
  value: name.toLowerCase(),
38
39
  viewer: ctx.userID,
39
40
  rsp: "search",
40
41
  context: "search",
41
42
  path: "/home.php",
42
- request_id: utils.getGUID()
43
+ request_id: ctx.clientId
43
44
  };
44
45
 
45
46
  defaultFuncs
46
47
  .get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
47
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
48
- .then(function (resData) {
49
- if (resData.error) throw resData;
48
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
49
+ .then(function(resData) {
50
+ if (resData.error) {
51
+ throw resData;
52
+ }
53
+
54
+ const data = resData.payload.entries;
50
55
 
51
- var data = resData.payload.entries;
52
56
  callback(null, data.map(formatData));
53
57
  })
54
- .catch(function (err) {
58
+ .catch(function(err) {
55
59
  log.error("getUserID", err);
56
60
  return callback(err);
57
61
  });
@@ -0,0 +1,402 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const log = require("../../../func/logAdapter");
6
+ const logger = require("../../../func/logger");
7
+ const { parseAndCheckLogin } = require("../../utils/client.js");
8
+
9
+ const DOC_PRIMARY = "5009315269112105";
10
+ const BATCH_PRIMARY = "MessengerParticipantsFetcher";
11
+ const DOC_V2 = "24418640587785718";
12
+ const FRIENDLY_V2 = "CometHovercardQueryRendererQuery";
13
+ const CALLER_V2 = "RelayModern";
14
+
15
+ function toJSONMaybe(s) {
16
+ if (!s) return null;
17
+ if (typeof s === "string") {
18
+ const t = s.trim().replace(/^for\s*\(\s*;\s*;\s*\)\s*;/, "");
19
+ try { return JSON.parse(t); } catch { return null; }
20
+ }
21
+ return s;
22
+ }
23
+
24
+ function usernameFromUrl(raw) {
25
+ if (!raw) return null;
26
+ try {
27
+ const u = new URL(raw);
28
+ if (/^www\.facebook\.com$/i.test(u.hostname)) {
29
+ const seg = u.pathname.replace(/^\//, "").replace(/\/$/, "");
30
+ if (seg && !/^profile\.php$/i.test(seg) && !seg.includes("/")) return seg;
31
+ }
32
+ } catch { }
33
+ return null;
34
+ }
35
+
36
+ function pickMeta(u) {
37
+ let friendshipStatus = null;
38
+ let gender = null;
39
+ let shortName = u?.short_name || null;
40
+ const pa = Array.isArray(u?.primaryActions) ? u.primaryActions : [];
41
+ const sa = Array.isArray(u?.secondaryActions) ? u.secondaryActions : [];
42
+ const aFriend = pa.find(x => x?.profile_action_type === "FRIEND");
43
+ if (aFriend?.client_handler?.profile_action?.restrictable_profile_owner) {
44
+ const p = aFriend.client_handler.profile_action.restrictable_profile_owner;
45
+ friendshipStatus = p?.friendship_status || null;
46
+ gender = p?.gender || gender;
47
+ shortName = p?.short_name || shortName;
48
+ }
49
+ if (!gender || !shortName) {
50
+ const aBlock = sa.find(x => x?.profile_action_type === "BLOCK");
51
+ const p2 = aBlock?.client_handler?.profile_action?.profile_owner;
52
+ if (p2) {
53
+ gender = p2.gender || gender;
54
+ shortName = p2.short_name || shortName;
55
+ }
56
+ }
57
+ return { friendshipStatus, gender, shortName };
58
+ }
59
+
60
+ function normalizeV2User(u) {
61
+ if (!u) return null;
62
+ const vanity = usernameFromUrl(u.profile_url || u.url);
63
+ const meta = pickMeta(u);
64
+ return {
65
+ id: u.id || null,
66
+ name: u.name || null,
67
+ firstName: meta.shortName || null,
68
+ vanity: vanity || u.username_for_profile || null,
69
+ thumbSrc: u.profile_picture?.uri || null,
70
+ profileUrl: u.profile_url || u.url || null,
71
+ gender: meta.gender || null,
72
+ type: "User",
73
+ isFriend: meta.friendshipStatus === "ARE_FRIENDS",
74
+ isMessengerUser: null,
75
+ isMessageBlockedByViewer: false,
76
+ workInfo: null,
77
+ messengerStatus: null
78
+ };
79
+ }
80
+
81
+ function normalizePrimaryActor(a) {
82
+ if (!a) return null;
83
+ return {
84
+ id: a.id || null,
85
+ name: a.name || null,
86
+ firstName: a.short_name || null,
87
+ vanity: a.username || null,
88
+ thumbSrc: a.big_image_src?.uri || null,
89
+ profileUrl: a.url || null,
90
+ gender: a.gender || null,
91
+ type: a.__typename || null,
92
+ isFriend: !!a.is_viewer_friend,
93
+ isMessengerUser: !!a.is_messenger_user,
94
+ isMessageBlockedByViewer: !!a.is_message_blocked_by_viewer,
95
+ workInfo: a.work_info || null,
96
+ messengerStatus: a.messenger_account_status_category || null
97
+ };
98
+ }
99
+
100
+ function mergeUserEntry(a, b) {
101
+ if (!a && !b) return null;
102
+ const x = a || {};
103
+ const y = b || {};
104
+ return {
105
+ id: x.id || y.id || null,
106
+ name: x.name || y.name || null,
107
+ firstName: x.firstName || y.firstName || null,
108
+ vanity: x.vanity || y.vanity || null,
109
+ thumbSrc: x.thumbSrc || y.thumbSrc || null,
110
+ profileUrl: x.profileUrl || y.profileUrl || null,
111
+ gender: x.gender || y.gender || null,
112
+ type: x.type || y.type || null,
113
+ isFriend: typeof x.isFriend === "boolean" ? x.isFriend : (typeof y.isFriend === "boolean" ? y.isFriend : false),
114
+ isMessengerUser: typeof x.isMessengerUser === "boolean" ? x.isMessengerUser : (typeof y.isMessengerUser === "boolean" ? y.isMessengerUser : null),
115
+ isMessageBlockedByViewer: typeof x.isMessageBlockedByViewer === "boolean" ? x.isMessageBlockedByViewer : (typeof y.isMessageBlockedByViewer === "boolean" ? y.isMessageBlockedByViewer : false),
116
+ workInfo: x.workInfo || y.workInfo || null,
117
+ messengerStatus: x.messengerStatus || y.messengerStatus || null
118
+ };
119
+ }
120
+
121
+ module.exports = function (defaultFuncs, api, ctx) {
122
+ // Read FastConfig-style anti-get-info flag from global config (if available)
123
+ const cfg = global.fca && global.fca.config;
124
+ const antiCfg = cfg && cfg.antiGetInfo;
125
+ const disableAntiUserInfo = !!(antiCfg && antiCfg.AntiGetUserInfo === true);
126
+
127
+ // Lightweight, Horizon-style implementation without database/queue
128
+ if (disableAntiUserInfo) {
129
+ function formatLegacyData(data) {
130
+ const retObj = {};
131
+ for (const prop in data) {
132
+ if (!Object.prototype.hasOwnProperty.call(data, prop)) continue;
133
+ const innerObj = data[prop] || {};
134
+ retObj[prop] = {
135
+ name: innerObj.name || null,
136
+ firstName: innerObj.firstName || null,
137
+ vanity: innerObj.vanity || null,
138
+ thumbSrc: innerObj.thumbSrc || null,
139
+ profileUrl: innerObj.uri || innerObj.profileUrl || null,
140
+ gender: innerObj.gender || null,
141
+ type: innerObj.type || null,
142
+ isFriend: !!innerObj.is_friend,
143
+ isBirthday: !!innerObj.is_birthday
144
+ };
145
+ }
146
+ return retObj;
147
+ }
148
+
149
+ return function getUserInfo(idsOrId, callback) {
150
+ let resolveFunc;
151
+ let rejectFunc;
152
+ const returnPromise = new Promise((resolve, reject) => {
153
+ resolveFunc = resolve;
154
+ rejectFunc = reject;
155
+ });
156
+
157
+ if (typeof callback !== "function") {
158
+ callback = (err, userInfo) => {
159
+ if (err) return rejectFunc(err);
160
+ resolveFunc(userInfo);
161
+ };
162
+ }
163
+
164
+ const ids = Array.isArray(idsOrId) ? idsOrId : [idsOrId];
165
+ const form = {};
166
+ ids.forEach((v, i) => {
167
+ form[`ids[${i}]`] = v;
168
+ });
169
+
170
+ defaultFuncs
171
+ .post("https://www.facebook.com/chat/user_info/", ctx.jar, form)
172
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
173
+ .then(resData => {
174
+ if (resData.error) throw resData;
175
+ const profiles = resData?.payload?.profiles || {};
176
+ return callback(null, formatLegacyData(profiles));
177
+ })
178
+ .catch(err => {
179
+ log.error(
180
+ "getUserInfo",
181
+ "Lỗi: getUserInfo Có Thể Do Bạn Spam Quá Nhiều !,Hãy Thử Lại !"
182
+ );
183
+ return callback(err);
184
+ });
185
+
186
+ return returnPromise;
187
+ };
188
+ }
189
+
190
+ const queue = [];
191
+ let isProcessingQueue = false;
192
+ const processingUsers = new Set();
193
+ const queuedUsers = new Set();
194
+ const cooldown = new Map();
195
+
196
+ const dbFiles = fs.readdirSync(path.join(__dirname, "../../database"))
197
+ .filter(f => path.extname(f) === ".js")
198
+ .reduce((acc, file) => {
199
+ const mod = require(path.join(__dirname, "../../database", file));
200
+ acc[path.basename(file, ".js")] = typeof mod === "function" ? mod(api) : mod;
201
+ return acc;
202
+ }, {});
203
+ const { userData } = dbFiles;
204
+ const { create, get, update, getAll } = userData;
205
+
206
+ async function fetchPrimary(ids) {
207
+ const form = {
208
+ queries: JSON.stringify({
209
+ o0: {
210
+ doc_id: DOC_PRIMARY,
211
+ query_params: { ids }
212
+ }
213
+ }),
214
+ batch_name: BATCH_PRIMARY
215
+ };
216
+ const resData = await defaultFuncs.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form).then(parseAndCheckLogin(ctx, defaultFuncs));
217
+ if (!resData || resData.length === 0) throw new Error("Empty response");
218
+ const first = resData[0];
219
+ if (!first || !first.o0) throw new Error("Invalid batch payload");
220
+ if (first.o0.errors && first.o0.errors.length) throw new Error(first.o0.errors[0].message || "GraphQL error");
221
+ const result = first.o0.data;
222
+ if (!result || !Array.isArray(result.messaging_actors)) return {};
223
+ const out = {};
224
+ for (const actor of result.messaging_actors) {
225
+ const n = normalizePrimaryActor(actor);
226
+ if (n?.id) out[n.id] = n;
227
+ }
228
+ return out;
229
+ }
230
+
231
+ async function fetchV2One(uid) {
232
+ const av = String(ctx?.userID || "");
233
+ const variablesObj = {
234
+ actionBarRenderLocation: "WWW_COMET_HOVERCARD",
235
+ context: "DEFAULT",
236
+ entityID: String(uid),
237
+ scale: 1,
238
+ __relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false
239
+ };
240
+ const form = {
241
+ av,
242
+ fb_api_caller_class: CALLER_V2,
243
+ fb_api_req_friendly_name: FRIENDLY_V2,
244
+ server_timestamps: true,
245
+ doc_id: DOC_V2,
246
+ variables: JSON.stringify(variablesObj)
247
+ };
248
+ const raw = await defaultFuncs.post("https://www.facebook.com/api/graphql/", null, form).then(parseAndCheckLogin(ctx, defaultFuncs));
249
+ const parsed = toJSONMaybe(raw) ?? raw;
250
+ const root = Array.isArray(parsed) ? parsed[0] : parsed;
251
+ const user = root?.data?.node?.comet_hovercard_renderer?.user || null;
252
+ const n = normalizeV2User(user);
253
+ return n && n.id ? { [n.id]: n } : {};
254
+ }
255
+
256
+ async function upsertUser(id, entry) {
257
+ try {
258
+ const existing = await get(id);
259
+ if (existing) {
260
+ await update(id, { data: entry });
261
+ } else {
262
+ await create(id, { data: entry });
263
+ }
264
+ } catch (e) {
265
+ logger(`user upsert ${id} error: ${e?.message || e}`, "warn");
266
+ }
267
+ }
268
+
269
+ async function fetchAndPersist(ids, creating = false) {
270
+ const result = {};
271
+ try {
272
+ const primary = await fetchPrimary(ids);
273
+ for (const id of ids) result[id] = primary[id] || null;
274
+ } catch (e) {
275
+ logger(`primary fetch error: ${e?.message || e}`, "warn");
276
+ }
277
+ if (creating) {
278
+ const needFallback = ids.filter(id => !result[id]);
279
+ if (needFallback.length) {
280
+ const tasks = needFallback.map(id => fetchV2One(id).catch(() => ({})));
281
+ const r = await Promise.allSettled(tasks);
282
+ for (let i = 0; i < needFallback.length; i++) {
283
+ const id = needFallback[i];
284
+ const ok = r[i].status === "fulfilled" ? r[i].value : {};
285
+ const n = ok[id] || null;
286
+ result[id] = n || null;
287
+ }
288
+ }
289
+ }
290
+ for (const id of ids) {
291
+ const merged = result[id] || null;
292
+ if (merged) await upsertUser(id, merged);
293
+ }
294
+ return result;
295
+ }
296
+
297
+ async function refreshAUser(id) {
298
+ try {
299
+ const out = await fetchAndPersist([id], false);
300
+ if (!out[id]) cooldown.set(id, Date.now() + 5 * 60 * 1000);
301
+ } catch (e) {
302
+ cooldown.set(id, Date.now() + 5 * 60 * 1000);
303
+ logger(`refresh user ${id} error: ${e?.message || e}`, "warn");
304
+ } finally {
305
+ queuedUsers.delete(id);
306
+ }
307
+ }
308
+
309
+ async function checkAndUpdateUsers() {
310
+ try {
311
+ const all = await getAll("userID");
312
+ const now = Date.now();
313
+ for (const row of all) {
314
+ const id = row.userID;
315
+ const cd = cooldown.get(id);
316
+ if (cd && now < cd) continue;
317
+ const lastUpdated = new Date(row.updatedAt).getTime();
318
+ if ((now - lastUpdated) / (1000 * 60) > 10 && !queuedUsers.has(id)) {
319
+ queuedUsers.add(id);
320
+ queue.push(() => refreshAUser(id));
321
+ }
322
+ }
323
+ } catch (e) {
324
+ logger(`checkAndUpdateUsers error: ${e?.message || e}`, "error");
325
+ }
326
+ }
327
+
328
+ async function processQueue() {
329
+ if (isProcessingQueue) return;
330
+ isProcessingQueue = true;
331
+ while (queue.length > 0) {
332
+ const task = queue.shift();
333
+ try {
334
+ await task();
335
+ } catch (e) {
336
+ logger(`user queue error: ${e?.message || e}`, "error");
337
+ }
338
+ }
339
+ isProcessingQueue = false;
340
+ }
341
+
342
+ // Store interval reference for cleanup
343
+ const updateInterval = setInterval(() => {
344
+ checkAndUpdateUsers();
345
+ processQueue();
346
+ }, 10000);
347
+
348
+ // Store interval in ctx for cleanup on logout/stop
349
+ if (!ctx._userInfoIntervals) {
350
+ ctx._userInfoIntervals = [];
351
+ }
352
+ ctx._userInfoIntervals.push(updateInterval);
353
+
354
+ return function getUserInfo(idsOrId, callback) {
355
+ let resolveFunc, rejectFunc;
356
+ const returnPromise = new Promise((resolve, reject) => { resolveFunc = resolve; rejectFunc = reject; });
357
+ if (typeof callback !== "function") {
358
+ callback = (err, data) => { if (err) return rejectFunc(err); resolveFunc(data); };
359
+ }
360
+ const ids = Array.isArray(idsOrId) ? idsOrId.map(v => String(v)) : [String(idsOrId)];
361
+ Promise.all(ids.map(id => get(id).catch(() => null))).then(async cachedRows => {
362
+ const ret = {};
363
+ const needCreate = [];
364
+ for (let i = 0; i < ids.length; i++) {
365
+ const id = ids[i];
366
+ const row = cachedRows[i];
367
+ if (row?.data && row.data.id) {
368
+ ret[id] = row.data;
369
+ } else {
370
+ needCreate.push(id);
371
+ }
372
+ }
373
+ if (needCreate.length) {
374
+ const fetched = await fetchAndPersist(needCreate, true);
375
+ for (const id of needCreate) ret[id] = fetched[id] || {
376
+ id,
377
+ name: null,
378
+ firstName: null,
379
+ vanity: null,
380
+ thumbSrc: null,
381
+ profileUrl: null,
382
+ gender: null,
383
+ type: null,
384
+ isFriend: false,
385
+ isMessengerUser: null,
386
+ isMessageBlockedByViewer: false,
387
+ workInfo: null,
388
+ messengerStatus: null
389
+ };
390
+ }
391
+ return callback(null, ret);
392
+ }).catch(err => {
393
+ // Horizon-style anti-get-info message to hint rate limiting / spam block
394
+ log.error(
395
+ "getUserInfo",
396
+ "Lỗi: getUserInfo Có Thể Do Bạn Spam Quá Nhiều !,Hãy Thử Lại !"
397
+ );
398
+ callback(err);
399
+ });
400
+ return returnPromise;
401
+ };
402
+ };
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ const { parseAndCheckLogin } = require("../../utils/client.js");
4
+ const logger = require("../../../func/logger");
5
+ const DEFAULT_DOC_ID = "24418640587785718";
6
+ const DEFAULT_FRIENDLY_NAME = "CometHovercardQueryRendererQuery";
7
+ const DEFAULT_CALLER_CLASS = "RelayModern";
8
+
9
+ function toJSONMaybe(s) {
10
+ if (!s) return null;
11
+ if (typeof s === "string") {
12
+ const t = s.trim().replace(/^for\s*\(\s*;\s*;\s*\)\s*;/, "");
13
+ try { return JSON.parse(t); } catch { return null; }
14
+ }
15
+ return s;
16
+ }
17
+
18
+ function usernameFromUrl(raw) {
19
+ if (!raw) return null;
20
+ try {
21
+ const u = new URL(raw);
22
+ if (/^www\.facebook\.com$/i.test(u.hostname)) {
23
+ const seg = u.pathname.replace(/^\//, "").replace(/\/$/, "");
24
+ if (seg && !/^profile\.php$/i.test(seg) && !seg.includes("/")) return seg;
25
+ }
26
+ } catch { }
27
+ return null;
28
+ }
29
+
30
+ function pickMeta(u) {
31
+ let friendshipStatus = null;
32
+ let gender = null;
33
+ let shortName = u?.short_name || null;
34
+ const pa = Array.isArray(u?.primaryActions) ? u.primaryActions : [];
35
+ const sa = Array.isArray(u?.secondaryActions) ? u.secondaryActions : [];
36
+ const aFriend = pa.find(x => x?.profile_action_type === "FRIEND");
37
+ if (aFriend?.client_handler?.profile_action?.restrictable_profile_owner) {
38
+ const p = aFriend.client_handler.profile_action.restrictable_profile_owner;
39
+ friendshipStatus = p?.friendship_status || null;
40
+ gender = p?.gender || gender;
41
+ shortName = p?.short_name || shortName;
42
+ }
43
+ if (!gender || !shortName) {
44
+ const aBlock = sa.find(x => x?.profile_action_type === "BLOCK");
45
+ const p2 = aBlock?.client_handler?.profile_action?.profile_owner;
46
+ if (p2) {
47
+ gender = p2.gender || gender;
48
+ shortName = p2.short_name || shortName;
49
+ }
50
+ }
51
+ return { friendshipStatus, gender, shortName };
52
+ }
53
+
54
+ function normalizeUser(u) {
55
+ if (!u) return null;
56
+ const vanity = usernameFromUrl(u.profile_url || u.url);
57
+ const meta = pickMeta(u);
58
+ return {
59
+ id: u.id || null,
60
+ name: u.name || null,
61
+ username: vanity || u.username_for_profile || null,
62
+ profileUrl: u.profile_url || u.url || null,
63
+ url: u.url || null,
64
+ isVerified: !!u.is_verified,
65
+ isMemorialized: !!u.is_visibly_memorialized,
66
+ avatar: u.profile_picture?.uri || null,
67
+ shortName: meta.shortName || null,
68
+ gender: meta.gender || null,
69
+ friendshipStatus: meta.friendshipStatus || null
70
+ };
71
+ }
72
+
73
+ function toRetObjEntry(nu) {
74
+ return {
75
+ name: nu?.name || null,
76
+ firstName: nu?.shortName || null,
77
+ vanity: nu?.username || null,
78
+ thumbSrc: nu?.avatar || null,
79
+ profileUrl: nu?.profileUrl || null,
80
+ gender: nu?.gender || null,
81
+ type: "User",
82
+ isFriend: nu?.friendshipStatus === "ARE_FRIENDS",
83
+ isMessengerUser: null,
84
+ isMessageBlockedByViewer: false,
85
+ workInfo: null,
86
+ messengerStatus: null
87
+ };
88
+ }
89
+
90
+ module.exports = function (defaultFuncs, api, ctx) {
91
+ async function fetchOne(uid) {
92
+ const av = String(ctx?.userID || "");
93
+ const variablesObj = {
94
+ actionBarRenderLocation: "WWW_COMET_HOVERCARD",
95
+ context: "DEFAULT",
96
+ entityID: String(uid),
97
+ scale: 1,
98
+ __relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false
99
+ };
100
+ const form = {
101
+ av,
102
+ fb_api_caller_class: DEFAULT_CALLER_CLASS,
103
+ fb_api_req_friendly_name: DEFAULT_FRIENDLY_NAME,
104
+ server_timestamps: true,
105
+ doc_id: DEFAULT_DOC_ID,
106
+ variables: JSON.stringify(variablesObj)
107
+ };
108
+ const raw = await defaultFuncs.post("https://www.facebook.com/api/graphql/", null, form).then(parseAndCheckLogin(ctx, defaultFuncs));
109
+ const parsed = toJSONMaybe(raw) ?? raw;
110
+ const root = Array.isArray(parsed) ? parsed[0] : parsed;
111
+ const user = root?.data?.node?.comet_hovercard_renderer?.user || null;
112
+ return normalizeUser(user);
113
+ }
114
+
115
+ return function getUserInfoV2(idOrList, callback) {
116
+ let resolveFunc, rejectFunc;
117
+ const returnPromise = new Promise((resolve, reject) => { resolveFunc = resolve; rejectFunc = reject; });
118
+ if (typeof callback !== "function") {
119
+ callback = (err, data) => { if (err) return rejectFunc(err); resolveFunc(data); };
120
+ }
121
+ const ids = Array.isArray(idOrList) ? idOrList.map(v => String(v)) : [String(idOrList)];
122
+ Promise.allSettled(ids.map(fetchOne))
123
+ .then(results => {
124
+ const retObj = {};
125
+ for (let i = 0; i < ids.length; i++) {
126
+ const nu = results[i].status === "fulfilled" ? results[i].value : null;
127
+ retObj[ids[i]] = toRetObjEntry(nu);
128
+ }
129
+ return callback(null, retObj);
130
+ })
131
+ .catch(err => { logger("getUserInfoV2" + err, "error"); callback(err); });
132
+ return returnPromise;
133
+ };
134
+ };