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
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+
3
+ var url = require("url");
4
+ const querystring = require("querystring");
5
+
6
+ function _formatAttachment(attachment1, attachment2) {
7
+ attachment2 = attachment2 || { id: "", image_data: {} };
8
+ attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
9
+ var blob = attachment1.blob_attachment;
10
+ var type =
11
+ blob && blob.__typename ? blob.__typename : attachment1.attach_type;
12
+ if (!type && attachment1.sticker_attachment) {
13
+ type = "StickerAttachment";
14
+ blob = attachment1.sticker_attachment;
15
+ } else if (!type && attachment1.extensible_attachment) {
16
+ if (
17
+ attachment1.extensible_attachment.story_attachment &&
18
+ attachment1.extensible_attachment.story_attachment.target &&
19
+ attachment1.extensible_attachment.story_attachment.target.__typename &&
20
+ attachment1.extensible_attachment.story_attachment.target.__typename ===
21
+ "MessageLocation"
22
+ )
23
+ type = "MessageLocation";
24
+ else type = "ExtensibleAttachment";
25
+
26
+ blob = attachment1.extensible_attachment;
27
+ }
28
+
29
+ if (blob && blob.real_metadata) {
30
+ const realMetadata = blob.real_metadata;
31
+ if (realMetadata.Src) {
32
+ attachment2.src = realMetadata.Src;
33
+ }
34
+ if (realMetadata.ThumbnailSrc) {
35
+ attachment2.thumbnailSrc = realMetadata.ThumbnailSrc;
36
+ }
37
+ }
38
+
39
+ switch (type) {
40
+ case "sticker":
41
+ return {
42
+ type: "sticker",
43
+ ID: attachment1.metadata.stickerID.toString(),
44
+ url: attachment1.url,
45
+ packID: attachment1.metadata.packID.toString(),
46
+ spriteUrl: attachment1.metadata.spriteURI,
47
+ spriteUrl2x: attachment1.metadata.spriteURI2x,
48
+ width: attachment1.metadata.width,
49
+ height: attachment1.metadata.height,
50
+ caption: attachment2.caption,
51
+ description: attachment2.description,
52
+ frameCount: attachment1.metadata.frameCount,
53
+ frameRate: attachment1.metadata.frameRate,
54
+ framesPerRow: attachment1.metadata.framesPerRow,
55
+ framesPerCol: attachment1.metadata.framesPerCol,
56
+ stickerID: attachment1.metadata.stickerID.toString(),
57
+ spriteURI: attachment1.metadata.spriteURI,
58
+ spriteURI2x: attachment1.metadata.spriteURI2x,
59
+ };
60
+ case "file":
61
+ return {
62
+ type: "file",
63
+ filename: attachment1.name,
64
+ ID: attachment2.id.toString(),
65
+ url: attachment1.url,
66
+ isMalicious: attachment2.is_malicious,
67
+ contentType: attachment2.mime_type,
68
+ name: attachment1.name,
69
+ mimeType: attachment2.mime_type,
70
+ fileSize: attachment2.file_size,
71
+ };
72
+ case "photo":
73
+ return {
74
+ type: "photo",
75
+ ID: attachment1.metadata.fbid.toString(),
76
+ filename: attachment1.fileName,
77
+ thumbnailUrl: attachment1.thumbnail_url,
78
+ previewUrl: attachment1.preview_url,
79
+ previewWidth: attachment1.preview_width,
80
+ previewHeight: attachment1.preview_height,
81
+ largePreviewUrl: attachment1.large_preview_url,
82
+ largePreviewWidth: attachment1.large_preview_width,
83
+ largePreviewHeight: attachment1.large_preview_height,
84
+ url: attachment1.metadata.url,
85
+ width: attachment1.metadata.dimensions.split(",")[0],
86
+ height: attachment1.metadata.dimensions.split(",")[1],
87
+ name: attachment1.fileName,
88
+ };
89
+ case "animated_image":
90
+ return {
91
+ type: "animated_image",
92
+ ID: attachment2.id.toString(),
93
+ filename: attachment2.filename,
94
+ previewUrl: attachment1.preview_url,
95
+ previewWidth: attachment1.preview_width,
96
+ previewHeight: attachment1.preview_height,
97
+ url: attachment2.image_data.url,
98
+ width: attachment2.image_data.width,
99
+ height: attachment2.image_data.height,
100
+ name: attachment1.name,
101
+ facebookUrl: attachment1.url,
102
+ thumbnailUrl: attachment1.thumbnail_url,
103
+ mimeType: attachment2.mime_type,
104
+ rawGifImage: attachment2.image_data.raw_gif_image,
105
+ rawWebpImage: attachment2.image_data.raw_webp_image,
106
+ animatedGifUrl: attachment2.image_data.animated_gif_url,
107
+ animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url,
108
+ animatedWebpUrl: attachment2.image_data.animated_webp_url,
109
+ animatedWebpPreviewUrl:
110
+ attachment2.image_data.animated_webp_preview_url,
111
+ };
112
+ case "share":
113
+ return {
114
+ type: "share",
115
+ ID: attachment1.share.share_id.toString(),
116
+ url: attachment2.href,
117
+ title: attachment1.share.title,
118
+ description: attachment1.share.description,
119
+ source: attachment1.share.source,
120
+ image: attachment1.share.media.image,
121
+ width: attachment1.share.media.image_size.width,
122
+ height: attachment1.share.media.image_size.height,
123
+ playable: attachment1.share.media.playable,
124
+ duration: attachment1.share.media.duration,
125
+ subattachments: attachment1.share.subattachments,
126
+ properties: {},
127
+ animatedImageSize: attachment1.share.media.animated_image_size,
128
+ facebookUrl: attachment1.share.uri,
129
+ target: attachment1.share.target,
130
+ styleList: attachment1.share.style_list,
131
+ };
132
+ case "video":
133
+ return {
134
+ type: "video",
135
+ ID: attachment1.metadata.fbid.toString(),
136
+ filename: attachment1.name,
137
+ previewUrl: attachment1.preview_url,
138
+ previewWidth: attachment1.preview_width,
139
+ previewHeight: attachment1.preview_height,
140
+ url: attachment1.url,
141
+ width: attachment1.metadata.dimensions.width,
142
+ height: attachment1.metadata.dimensions.height,
143
+ duration: attachment1.metadata.duration,
144
+ videoType: "unknown",
145
+ thumbnailUrl: attachment1.thumbnail_url,
146
+ };
147
+ case "error":
148
+ return {
149
+ type: "error",
150
+ attachment1: attachment1,
151
+ attachment2: attachment2,
152
+ };
153
+ case "MessageImage":
154
+ return {
155
+ type: "photo",
156
+ ID: blob.legacy_attachment_id,
157
+ filename: blob.filename,
158
+ thumbnailUrl: blob.thumbnail.uri,
159
+ previewUrl: blob.preview.uri,
160
+ previewWidth: blob.preview.width,
161
+ previewHeight: blob.preview.height,
162
+ largePreviewUrl: blob.large_preview.uri,
163
+ largePreviewWidth: blob.large_preview.width,
164
+ largePreviewHeight: blob.large_preview.height,
165
+ url: blob.large_preview.uri,
166
+ width: blob.original_dimensions.x,
167
+ height: blob.original_dimensions.y,
168
+ name: blob.filename,
169
+ };
170
+ case "MessageAnimatedImage":
171
+ return {
172
+ type: "animated_image",
173
+ ID: blob.legacy_attachment_id,
174
+ filename: blob.filename,
175
+ previewUrl: blob.preview_image.uri,
176
+ previewWidth: blob.preview_image.width,
177
+ previewHeight: blob.preview_image.height,
178
+ url: blob.animated_image.uri,
179
+ width: blob.animated_image.width,
180
+ height: blob.animated_image.height,
181
+ thumbnailUrl: blob.preview_image.uri,
182
+ name: blob.filename,
183
+ facebookUrl: blob.animated_image.uri,
184
+ rawGifImage: blob.animated_image.uri,
185
+ animatedGifUrl: blob.animated_image.uri,
186
+ animatedGifPreviewUrl: blob.preview_image.uri,
187
+ animatedWebpUrl: blob.animated_image.uri,
188
+ animatedWebpPreviewUrl: blob.preview_image.uri,
189
+ };
190
+ case "MessageVideo":
191
+ return {
192
+ type: "video",
193
+ filename: blob.filename,
194
+ ID: blob.legacy_attachment_id,
195
+ previewUrl: blob.large_image.uri,
196
+ previewWidth: blob.large_image.width,
197
+ previewHeight: blob.large_image.height,
198
+ url: blob.playable_url,
199
+ width: blob.original_dimensions.x,
200
+ height: blob.original_dimensions.y,
201
+ duration: blob.playable_duration_in_ms,
202
+ videoType: blob.video_type.toLowerCase(),
203
+ thumbnailUrl: blob.large_image.uri,
204
+ };
205
+ case "MessageAudio":
206
+ return {
207
+ type: "audio",
208
+ filename: blob.filename,
209
+ ID: blob.url_shimhash,
210
+ audioType: blob.audio_type,
211
+ duration: blob.playable_duration_in_ms,
212
+ url: blob.playable_url,
213
+ isVoiceMail: blob.is_voicemail,
214
+ };
215
+ case "StickerAttachment":
216
+ return {
217
+ type: "sticker",
218
+ ID: blob.id,
219
+ url: blob.url,
220
+ packID: blob.pack ? blob.pack.id : null,
221
+ spriteUrl: blob.sprite_image,
222
+ spriteUrl2x: blob.sprite_image_2x,
223
+ width: blob.width,
224
+ height: blob.height,
225
+ caption: blob.label,
226
+ description: blob.label,
227
+ frameCount: blob.frame_count,
228
+ frameRate: blob.frame_rate,
229
+ framesPerRow: blob.frames_per_row,
230
+ framesPerCol: blob.frames_per_column,
231
+ stickerID: blob.id,
232
+ spriteURI: blob.sprite_image,
233
+ spriteURI2x: blob.sprite_image_2x,
234
+ };
235
+ case "MessageLocation": {
236
+ var urlAttach = blob.story_attachment.url;
237
+ var mediaAttach = blob.story_attachment.media;
238
+ var u = querystring.parse(url.parse(urlAttach).query).u;
239
+ var where1 = querystring.parse(url.parse(u).query).where1;
240
+ var address = where1.split(", ");
241
+ var latitude;
242
+ var longitude;
243
+ try {
244
+ latitude = Number.parseFloat(address[0]);
245
+ longitude = Number.parseFloat(address[1]);
246
+ } catch (err) {}
247
+ var imageUrl;
248
+ var width;
249
+ var height;
250
+ if (mediaAttach && mediaAttach.image) {
251
+ imageUrl = mediaAttach.image.uri;
252
+ width = mediaAttach.image.width;
253
+ height = mediaAttach.image.height;
254
+ }
255
+ return {
256
+ type: "location",
257
+ ID: blob.legacy_attachment_id,
258
+ latitude: latitude,
259
+ longitude: longitude,
260
+ image: imageUrl,
261
+ width: width,
262
+ height: height,
263
+ url: u || urlAttach,
264
+ address: where1,
265
+ facebookUrl: blob.story_attachment.url,
266
+ target: blob.story_attachment.target,
267
+ styleList: blob.story_attachment.style_list,
268
+ };
269
+ }
270
+ case "ExtensibleAttachment":
271
+ return {
272
+ type: "share",
273
+ ID: blob.legacy_attachment_id,
274
+ url: blob.story_attachment.url,
275
+ title: blob.story_attachment.title_with_entities.text,
276
+ description:
277
+ blob.story_attachment.description &&
278
+ blob.story_attachment.description.text,
279
+ source: blob.story_attachment.source
280
+ ? blob.story_attachment.source.text
281
+ : null,
282
+ image:
283
+ blob.story_attachment.media &&
284
+ blob.story_attachment.media.image &&
285
+ blob.story_attachment.media.image.uri,
286
+ width:
287
+ blob.story_attachment.media &&
288
+ blob.story_attachment.media.image &&
289
+ blob.story_attachment.media.image.width,
290
+ height:
291
+ blob.story_attachment.media &&
292
+ blob.story_attachment.media.image &&
293
+ blob.story_attachment.media.image.height,
294
+ playable:
295
+ blob.story_attachment.media &&
296
+ blob.story_attachment.media.is_playable,
297
+ duration:
298
+ blob.story_attachment.media &&
299
+ blob.story_attachment.media.playable_duration_in_ms,
300
+ playableUrl:
301
+ blob.story_attachment.media == null
302
+ ? null
303
+ : blob.story_attachment.media.playable_url,
304
+ subattachments: blob.story_attachment.subattachments,
305
+ properties: blob.story_attachment.properties.reduce(function (obj, cur) {
306
+ obj[cur.key] = cur.value.text;
307
+ return obj;
308
+ }, {}),
309
+ facebookUrl: blob.story_attachment.url,
310
+ target: blob.story_attachment.target,
311
+ styleList: blob.story_attachment.style_list,
312
+ };
313
+ case "MessageFile":
314
+ return {
315
+ type: "file",
316
+ filename: blob.filename,
317
+ ID: blob.message_file_fbid,
318
+ url: blob.url,
319
+ isMalicious: blob.is_malicious,
320
+ contentType: blob.content_type,
321
+ name: blob.filename,
322
+ mimeType: "",
323
+ fileSize: -1,
324
+ };
325
+ default:
326
+ throw new Error(
327
+ "unrecognized attach_file of type " +
328
+ type +
329
+ "`" +
330
+ JSON.stringify(attachment1, null, 4) +
331
+ " attachment2: " +
332
+ JSON.stringify(attachment2, null, 4) +
333
+ "`",
334
+ );
335
+ }
336
+ }
337
+
338
+ function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
339
+ attachmentMap = shareMap || attachmentMap;
340
+ return attachments
341
+ ? attachments.map(function (att, idx) {
342
+ if (
343
+ !attachmentMap ||
344
+ !attachmentIds ||
345
+ !attachmentMap[attachmentIds[idx]]
346
+ ) {
347
+ return _formatAttachment(att);
348
+ }
349
+ return _formatAttachment(att, attachmentMap[attachmentIds[idx]]);
350
+ })
351
+ : [];
352
+ }
353
+
354
+ module.exports = {
355
+ _formatAttachment,
356
+ formatAttachment,
357
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ function formatCookie(arr, urlBase) {
4
+ return arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + urlBase + ".com";
5
+ }
6
+
7
+ module.exports = {
8
+ formatCookie,
9
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var NUM_TO_MONTH = [
4
+ "Jan",
5
+ "Feb",
6
+ "Mar",
7
+ "Apr",
8
+ "May",
9
+ "Jun",
10
+ "Jul",
11
+ "Aug",
12
+ "Sep",
13
+ "Oct",
14
+ "Nov",
15
+ "Dec",
16
+ ];
17
+ var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
18
+
19
+ function formatDate(date) {
20
+ var d = date.getUTCDate();
21
+ d = d >= 10 ? d : "0" + d;
22
+ var h = date.getUTCHours();
23
+ h = h >= 10 ? h : "0" + h;
24
+ var m = date.getUTCMinutes();
25
+ m = m >= 10 ? m : "0" + m;
26
+ var s = date.getUTCSeconds();
27
+ s = s >= 10 ? s : "0" + s;
28
+ return (
29
+ NUM_TO_DAY[date.getUTCDay()] +
30
+ ", " +
31
+ d +
32
+ " " +
33
+ NUM_TO_MONTH[date.getUTCMonth()] +
34
+ " " +
35
+ date.getUTCFullYear() +
36
+ " " +
37
+ h +
38
+ ":" +
39
+ m +
40
+ ":" +
41
+ s +
42
+ " GMT"
43
+ );
44
+ }
45
+
46
+ module.exports = {
47
+ NUM_TO_MONTH,
48
+ NUM_TO_DAY,
49
+ formatDate,
50
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ function decodeClientPayload(payload) {
4
+ function Utf8ArrayToStr(array) {
5
+ var out, i, len, c;
6
+ var char2, char3;
7
+ out = "";
8
+ len = array.length;
9
+ i = 0;
10
+ while (i < len) {
11
+ c = array[i++];
12
+ switch (c >> 4) {
13
+ case 0:
14
+ case 1:
15
+ case 2:
16
+ case 3:
17
+ case 4:
18
+ case 5:
19
+ case 6:
20
+ case 7:
21
+ out += String.fromCharCode(c);
22
+ break;
23
+ case 12:
24
+ case 13:
25
+ char2 = array[i++];
26
+ out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
27
+ break;
28
+ case 14:
29
+ char2 = array[i++];
30
+ char3 = array[i++];
31
+ out += String.fromCharCode(
32
+ ((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
33
+ );
34
+ break;
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+ return JSON.parse(Utf8ArrayToStr(payload));
40
+ }
41
+
42
+ module.exports = {
43
+ decodeClientPayload,
44
+ };
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+
3
+ const { formatID } = require("./utils");
4
+ const { _formatAttachment } = require("./attachment");
5
+
6
+ function getAdminTextMessageType(m) {
7
+ const type = m && (m.type || m);
8
+ switch (type) {
9
+ case "joinable_group_link_mode_change":
10
+ return "log:link-status";
11
+ case "magic_words":
12
+ return "log:magic-words";
13
+ case "change_thread_theme":
14
+ return "log:thread-color";
15
+ case "change_thread_icon":
16
+ case "change_thread_quick_reaction":
17
+ return "log:thread-icon";
18
+ case "change_thread_nickname":
19
+ return "log:user-nickname";
20
+ case "change_thread_admins":
21
+ return "log:thread-admins";
22
+ case "group_poll":
23
+ return "log:thread-poll";
24
+ case "change_thread_approval_mode":
25
+ return "log:thread-approval-mode";
26
+ case "messenger_call_log":
27
+ case "participant_joined_group_call":
28
+ case "rtc_call_log":
29
+ return "log:thread-call";
30
+ case "pin_messages_v2":
31
+ return "log:thread-pinned";
32
+ case "unpin_messages_v2":
33
+ return "log:unpin-message";
34
+ default:
35
+ return m && m.type != null ? m.type : type;
36
+ }
37
+ }
38
+
39
+ function formatDeltaEvent(m) {
40
+ var logMessageType;
41
+ var logMessageData;
42
+ switch (m.class) {
43
+ case "AdminTextMessage":
44
+ logMessageType = getAdminTextMessageType(m);
45
+ logMessageData = Object.assign({}, m.untypedData, { rawType: m.type });
46
+ break;
47
+ case "ThreadName":
48
+ logMessageType = "log:thread-name";
49
+ logMessageData = { name: m.name };
50
+ break;
51
+ case "ParticipantsAddedToGroupThread":
52
+ logMessageType = "log:subscribe";
53
+ logMessageData = { addedParticipants: m.addedParticipants };
54
+ break;
55
+ case "ParticipantLeftGroupThread":
56
+ logMessageType = "log:unsubscribe";
57
+ logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
58
+ break;
59
+ case "UserLocation": {
60
+ logMessageType = "log:user-location";
61
+ logMessageData = {
62
+ Image:
63
+ m.attachments[0].mercury.extensible_attachment.story_attachment.media
64
+ .image,
65
+ Location:
66
+ m.attachments[0].mercury.extensible_attachment.story_attachment.target
67
+ .location_title,
68
+ coordinates:
69
+ m.attachments[0].mercury.extensible_attachment.story_attachment.target
70
+ .coordinate,
71
+ url: m.attachments[0].mercury.extensible_attachment.story_attachment
72
+ .url,
73
+ };
74
+ }
75
+ case "ApprovalQueue":
76
+ logMessageType = "log:approval-queue";
77
+ logMessageData = {
78
+ approvalQueue: {
79
+ action: m.action,
80
+ recipientFbId: m.recipientFbId,
81
+ requestSource: m.requestSource,
82
+ ...m.messageMetadata,
83
+ },
84
+ };
85
+ }
86
+ return {
87
+ type: "event",
88
+ threadID: formatID(
89
+ (
90
+ m.messageMetadata.threadKey.threadFbId ||
91
+ m.messageMetadata.threadKey.otherUserFbId
92
+ ).toString(),
93
+ ),
94
+ logMessageType: logMessageType,
95
+ logMessageData: logMessageData,
96
+ logMessageBody: m.messageMetadata.adminText,
97
+ author: m.messageMetadata.actorFbId,
98
+ participantIDs: (m?.participants || []).map((e) => e.toString()),
99
+ };
100
+ }
101
+
102
+ function getMentionsFromDeltaMessage(m) {
103
+ var body = m.body || "";
104
+ var mentions = {};
105
+ var mdata = [];
106
+ if (m.data && m.data.prng) {
107
+ try {
108
+ mdata = JSON.parse(m.data.prng);
109
+ } catch (e) {
110
+ mdata = [];
111
+ }
112
+ }
113
+ if (mdata.length > 0) {
114
+ for (var i = 0; i < mdata.length; i++) {
115
+ var id = mdata[i].i;
116
+ var o = parseInt(mdata[i].o, 10) || 0;
117
+ var l = parseInt(mdata[i].l, 10) || 0;
118
+ mentions[String(id)] = body.substring(o, o + l);
119
+ }
120
+ return mentions;
121
+ }
122
+ var md = m.messageMetadata;
123
+ if (
124
+ md &&
125
+ md.data &&
126
+ md.data.data &&
127
+ md.data.data.Gb &&
128
+ md.data.data.Gb.asMap &&
129
+ md.data.data.Gb.asMap.data
130
+ ) {
131
+ var gbData = md.data.data.Gb.asMap.data;
132
+ for (var key in gbData) {
133
+ if (!Object.prototype.hasOwnProperty.call(gbData, key)) continue;
134
+ var entry = gbData[key];
135
+ if (entry && entry.asMap && entry.asMap.data) {
136
+ var d = entry.asMap.data;
137
+ var id = d.id && d.id.asLong ? String(d.id.asLong) : null;
138
+ var offset = parseInt(
139
+ d.offset && d.offset.asLong ? d.offset.asLong : 0,
140
+ 10,
141
+ );
142
+ var len = parseInt(
143
+ d.length && d.length.asLong ? d.length.asLong : 0,
144
+ 10,
145
+ );
146
+ if (id != null) {
147
+ mentions[id] = body.substring(offset, offset + len);
148
+ }
149
+ }
150
+ }
151
+ }
152
+ return mentions;
153
+ }
154
+
155
+ function formatDeltaMessage(m) {
156
+ var md = m.messageMetadata;
157
+ var body = m.body || "";
158
+ var mentions = getMentionsFromDeltaMessage(m);
159
+ var args = body === "" ? [] : body.trim().split(/\s+/);
160
+ return {
161
+ type: "message",
162
+ senderID: formatID(md.actorFbId.toString()),
163
+ threadID: formatID(
164
+ (md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString(),
165
+ ),
166
+ messageID: md.messageId,
167
+ args: args,
168
+ body: body,
169
+ attachments: (m.attachments || []).map((v) => _formatAttachment(v)),
170
+ mentions: mentions,
171
+ timestamp: md.timestamp,
172
+ isGroup: !!md.threadKey.threadFbId,
173
+ participantIDs: (m.participants || []).map((p) => formatID(p.toString())),
174
+ isUnread: md.isUnread !== undefined ? md.isUnread : false,
175
+ };
176
+ }
177
+
178
+ function formatDeltaReadReceipt(delta) {
179
+ return {
180
+ reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
181
+ time: delta.actionTimestampMs,
182
+ threadID: formatID(
183
+ (delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString(),
184
+ ),
185
+ type: "read_receipt",
186
+ };
187
+ }
188
+
189
+ module.exports = {
190
+ getAdminTextMessageType,
191
+ formatDeltaEvent,
192
+ formatDeltaMessage,
193
+ getMentionsFromDeltaMessage,
194
+ formatDeltaReadReceipt,
195
+ };