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,10 +1,8 @@
1
1
  "use strict";
2
2
 
3
- var log = require("npmlog");
4
-
5
- const utils = require("../utils");
6
- // @NethWs3Dev
7
-
3
+ const log = require("../../../func/logAdapter");
4
+ const { parseAndCheckLogin } = require("../../utils/client");
5
+ const { getAdminTextMessageType } = require("../../utils/format");
8
6
  function getExtension(original_extension, filename = "") {
9
7
  if (original_extension) {
10
8
  return original_extension;
@@ -27,7 +25,7 @@ function formatAttachmentsGraphQLResponse(attachment) {
27
25
  filename: attachment.filename,
28
26
  original_extension: getExtension(
29
27
  attachment.original_extension,
30
- attachment.filename,
28
+ attachment.filename
31
29
  ),
32
30
  thumbnailUrl: attachment.thumbnail.uri,
33
31
 
@@ -50,26 +48,9 @@ function formatAttachmentsGraphQLResponse(attachment) {
50
48
  ? {
51
49
  attributionAppID: attachment.attribution_app.id,
52
50
  name: attachment.attribution_app.name,
53
- logo: attachment.attribution_app.square_logo,
51
+ logo: attachment.attribution_app.square_logo
54
52
  }
55
- : null,
56
-
57
- // @TODO No idea what this is, should we expose it?
58
- // Ben - July 15th 2017
59
- // renderAsSticker: attachment.render_as_sticker,
60
-
61
- // This is _not_ the real URI, this is still just a large preview.
62
- // To get the URL we'll need to support a POST query to
63
- //
64
- // https://www.facebook.com/webgraphql/query/
65
- //
66
- // With the following query params:
67
- //
68
- // query_id:728987990612546
69
- // variables:{"id":"100009069356507","photoID":"10213724771692996"}
70
- // dpr:1
71
- //
72
- // No special form though.
53
+ : null
73
54
  };
74
55
  case "MessageAnimatedImage":
75
56
  return {
@@ -78,7 +59,7 @@ function formatAttachmentsGraphQLResponse(attachment) {
78
59
  filename: attachment.filename,
79
60
  original_extension: getExtension(
80
61
  attachment.original_extension,
81
- attachment.filename,
62
+ attachment.filename
82
63
  ),
83
64
 
84
65
  previewUrl: attachment.preview_image.uri,
@@ -103,9 +84,9 @@ function formatAttachmentsGraphQLResponse(attachment) {
103
84
  ? {
104
85
  attributionAppID: attachment.attribution_app.id,
105
86
  name: attachment.attribution_app.name,
106
- logo: attachment.attribution_app.square_logo,
87
+ logo: attachment.attribution_app.square_logo
107
88
  }
108
- : null,
89
+ : null
109
90
  };
110
91
  case "MessageVideo":
111
92
  return {
@@ -114,7 +95,7 @@ function formatAttachmentsGraphQLResponse(attachment) {
114
95
  filename: attachment.filename,
115
96
  original_extension: getExtension(
116
97
  attachment.original_extension,
117
- attachment.filename,
98
+ attachment.filename
118
99
  ),
119
100
  duration: attachment.playable_duration_in_ms,
120
101
 
@@ -128,7 +109,7 @@ function formatAttachmentsGraphQLResponse(attachment) {
128
109
  width: attachment.original_dimensions.x,
129
110
  height: attachment.original_dimensions.y,
130
111
 
131
- videoType: attachment.video_type.toLowerCase(),
112
+ videoType: attachment.video_type.toLowerCase()
132
113
  };
133
114
  case "MessageFile":
134
115
  return {
@@ -137,7 +118,7 @@ function formatAttachmentsGraphQLResponse(attachment) {
137
118
  filename: attachment.filename,
138
119
  original_extension: getExtension(
139
120
  attachment.original_extension,
140
- attachment.filename,
121
+ attachment.filename
141
122
  ),
142
123
 
143
124
  url: attachment.url,
@@ -146,7 +127,7 @@ function formatAttachmentsGraphQLResponse(attachment) {
146
127
 
147
128
  name: attachment.filename, // @Legacy
148
129
  mimeType: "", // @Legacy
149
- fileSize: -1, // @Legacy
130
+ fileSize: -1 // @Legacy
150
131
  };
151
132
  case "MessageAudio":
152
133
  return {
@@ -155,18 +136,18 @@ function formatAttachmentsGraphQLResponse(attachment) {
155
136
  filename: attachment.filename,
156
137
  original_extension: getExtension(
157
138
  attachment.original_extension,
158
- attachment.filename,
139
+ attachment.filename
159
140
  ),
160
141
 
161
142
  duration: attachment.playable_duration_in_ms,
162
143
  audioType: attachment.audio_type,
163
144
  url: attachment.playable_url,
164
145
 
165
- isVoiceMail: attachment.is_voicemail,
146
+ isVoiceMail: attachment.is_voicemail
166
147
  };
167
148
  default:
168
149
  return {
169
- error: "Don't know about attachment type " + attachment.__typename,
150
+ error: "Don't know about attachment type " + attachment.__typename
170
151
  };
171
152
  }
172
153
  }
@@ -191,32 +172,32 @@ function formatExtensibleAttachment(attachment) {
191
172
  attachment.story_attachment.media == null
192
173
  ? null
193
174
  : attachment.story_attachment.media.animated_image == null &&
194
- attachment.story_attachment.media.image == null
195
- ? null
196
- : (
197
- attachment.story_attachment.media.animated_image ||
198
- attachment.story_attachment.media.image
199
- ).uri,
175
+ attachment.story_attachment.media.image == null
176
+ ? null
177
+ : (
178
+ attachment.story_attachment.media.animated_image ||
179
+ attachment.story_attachment.media.image
180
+ ).uri,
200
181
  width:
201
182
  attachment.story_attachment.media == null
202
183
  ? null
203
184
  : attachment.story_attachment.media.animated_image == null &&
204
- attachment.story_attachment.media.image == null
205
- ? null
206
- : (
207
- attachment.story_attachment.media.animated_image ||
208
- attachment.story_attachment.media.image
209
- ).width,
185
+ attachment.story_attachment.media.image == null
186
+ ? null
187
+ : (
188
+ attachment.story_attachment.media.animated_image ||
189
+ attachment.story_attachment.media.image
190
+ ).width,
210
191
  height:
211
192
  attachment.story_attachment.media == null
212
193
  ? null
213
194
  : attachment.story_attachment.media.animated_image == null &&
214
- attachment.story_attachment.media.image == null
215
- ? null
216
- : (
217
- attachment.story_attachment.media.animated_image ||
218
- attachment.story_attachment.media.image
219
- ).height,
195
+ attachment.story_attachment.media.image == null
196
+ ? null
197
+ : (
198
+ attachment.story_attachment.media.animated_image ||
199
+ attachment.story_attachment.media.image
200
+ ).height,
220
201
  playable:
221
202
  attachment.story_attachment.media == null
222
203
  ? null
@@ -245,13 +226,14 @@ function formatExtensibleAttachment(attachment) {
245
226
  // width: "1280"
246
227
  // }
247
228
  //
248
- properties: attachment.story_attachment.properties.reduce(function (
229
+ properties: attachment.story_attachment.properties.reduce(function(
249
230
  obj,
250
- cur,
231
+ cur
251
232
  ) {
252
233
  obj[cur.key] = cur.value.text;
253
234
  return obj;
254
- }, {}),
235
+ },
236
+ {}),
255
237
 
256
238
  // Deprecated fields
257
239
  animatedImageSize: "", // @Legacy
@@ -262,32 +244,32 @@ function formatExtensibleAttachment(attachment) {
262
244
  attachment.story_attachment.media == null
263
245
  ? null
264
246
  : attachment.story_attachment.media.animated_image == null &&
265
- attachment.story_attachment.media.image == null
266
- ? null
267
- : (
268
- attachment.story_attachment.media.animated_image ||
269
- attachment.story_attachment.media.image
270
- ).uri, // @Legacy
247
+ attachment.story_attachment.media.image == null
248
+ ? null
249
+ : (
250
+ attachment.story_attachment.media.animated_image ||
251
+ attachment.story_attachment.media.image
252
+ ).uri, // @Legacy
271
253
  thumbnailWidth:
272
254
  attachment.story_attachment.media == null
273
255
  ? null
274
256
  : attachment.story_attachment.media.animated_image == null &&
275
- attachment.story_attachment.media.image == null
276
- ? null
277
- : (
278
- attachment.story_attachment.media.animated_image ||
279
- attachment.story_attachment.media.image
280
- ).width, // @Legacy
257
+ attachment.story_attachment.media.image == null
258
+ ? null
259
+ : (
260
+ attachment.story_attachment.media.animated_image ||
261
+ attachment.story_attachment.media.image
262
+ ).width, // @Legacy
281
263
  thumbnailHeight:
282
264
  attachment.story_attachment.media == null
283
265
  ? null
284
266
  : attachment.story_attachment.media.animated_image == null &&
285
- attachment.story_attachment.media.image == null
286
- ? null
287
- : (
288
- attachment.story_attachment.media.animated_image ||
289
- attachment.story_attachment.media.image
290
- ).height, // @Legacy
267
+ attachment.story_attachment.media.image == null
268
+ ? null
269
+ : (
270
+ attachment.story_attachment.media.animated_image ||
271
+ attachment.story_attachment.media.image
272
+ ).height // @Legacy
291
273
  };
292
274
  } else {
293
275
  return { error: "Don't know what to do with extensible_attachment." };
@@ -297,7 +279,7 @@ function formatExtensibleAttachment(attachment) {
297
279
  function formatReactionsGraphQL(reaction) {
298
280
  return {
299
281
  reaction: reaction.reaction,
300
- userID: reaction.user.id,
282
+ userID: reaction.user.id
301
283
  };
302
284
  }
303
285
 
@@ -309,16 +291,16 @@ function formatEventData(event) {
309
291
  switch (event.__typename) {
310
292
  case "ThemeColorExtensibleMessageAdminText":
311
293
  return {
312
- color: event.theme_color,
294
+ color: event.theme_color
313
295
  };
314
296
  case "ThreadNicknameExtensibleMessageAdminText":
315
297
  return {
316
298
  nickname: event.nickname,
317
- participantID: event.participant_id,
299
+ participantID: event.participant_id
318
300
  };
319
301
  case "ThreadIconExtensibleMessageAdminText":
320
302
  return {
321
- threadIcon: event.thread_icon,
303
+ threadIcon: event.thread_icon
322
304
  };
323
305
  case "InstantGameUpdateExtensibleMessageAdminText":
324
306
  return {
@@ -326,45 +308,45 @@ function formatEventData(event) {
326
308
  update_type: event.update_type,
327
309
  collapsed_text: event.collapsed_text,
328
310
  expanded_text: event.expanded_text,
329
- instant_game_update_data: event.instant_game_update_data,
311
+ instant_game_update_data: event.instant_game_update_data
330
312
  };
331
313
  case "GameScoreExtensibleMessageAdminText":
332
314
  return {
333
- game_type: event.game_type,
315
+ game_type: event.game_type
334
316
  };
335
317
  case "RtcCallLogExtensibleMessageAdminText":
336
318
  return {
337
319
  event: event.event,
338
320
  is_video_call: event.is_video_call,
339
- server_info_data: event.server_info_data,
321
+ server_info_data: event.server_info_data
340
322
  };
341
323
  case "GroupPollExtensibleMessageAdminText":
342
324
  return {
343
325
  event_type: event.event_type,
344
326
  total_count: event.total_count,
345
- question: event.question,
327
+ question: event.question
346
328
  };
347
329
  case "AcceptPendingThreadExtensibleMessageAdminText":
348
330
  return {
349
331
  accepter_id: event.accepter_id,
350
- requester_id: event.requester_id,
332
+ requester_id: event.requester_id
351
333
  };
352
334
  case "ConfirmFriendRequestExtensibleMessageAdminText":
353
335
  return {
354
336
  friend_request_recipient: event.friend_request_recipient,
355
- friend_request_sender: event.friend_request_sender,
337
+ friend_request_sender: event.friend_request_sender
356
338
  };
357
339
  case "AddContactExtensibleMessageAdminText":
358
340
  return {
359
341
  contact_added_id: event.contact_added_id,
360
- contact_adder_id: event.contact_adder_id,
342
+ contact_adder_id: event.contact_adder_id
361
343
  };
362
344
  case "AdExtensibleMessageAdminText":
363
345
  return {
364
346
  ad_client_token: event.ad_client_token,
365
347
  ad_id: event.ad_id,
366
348
  ad_preferences_link: event.ad_preferences_link,
367
- ad_properties: event.ad_properties,
349
+ ad_properties: event.ad_properties
368
350
  };
369
351
  // never data
370
352
  case "ParticipantJoinedGroupCallExtensibleMessageAdminText":
@@ -380,7 +362,7 @@ function formatEventData(event) {
380
362
  return {};
381
363
  default:
382
364
  return {
383
- error: "Don't know what to with event data type " + event.__typename,
365
+ error: "Don't know what to with event data type " + event.__typename
384
366
  };
385
367
  }
386
368
  }
@@ -391,7 +373,7 @@ function formatMessagesGraphQLResponse(data) {
391
373
  ? messageThread.thread_key.thread_fbid
392
374
  : messageThread.thread_key.other_user_id;
393
375
 
394
- const messages = messageThread.messages.nodes.map(function (d) {
376
+ const messages = messageThread.messages.nodes.map(function(d) {
395
377
  switch (d.__typename) {
396
378
  case "UserMessage":
397
379
  // Give priority to stickers. They're seen as normal messages but we've
@@ -420,17 +402,17 @@ function formatMessagesGraphQLResponse(data) {
420
402
 
421
403
  stickerID: d.sticker.id, // @Legacy
422
404
  spriteURI: d.sticker.sprite_image, // @Legacy
423
- spriteURI2x: d.sticker.sprite_image_2x, // @Legacy
424
- },
405
+ spriteURI2x: d.sticker.sprite_image_2x // @Legacy
406
+ }
425
407
  ];
426
408
  }
427
409
 
428
410
  var mentionsObj = {};
429
411
  if (d.message !== null) {
430
- d.message.ranges.forEach((e) => {
412
+ d.message.ranges.forEach(e => {
431
413
  mentionsObj[e.entity.id] = d.message.text.substr(
432
414
  e.offset,
433
- e.length,
415
+ e.length
434
416
  );
435
417
  });
436
418
  }
@@ -440,10 +422,10 @@ function formatMessagesGraphQLResponse(data) {
440
422
  attachments: maybeStickerAttachment
441
423
  ? maybeStickerAttachment
442
424
  : d.blob_attachments && d.blob_attachments.length > 0
443
- ? d.blob_attachments.map(formatAttachmentsGraphQLResponse)
444
- : d.extensible_attachment
445
- ? [formatExtensibleAttachment(d.extensible_attachment)]
446
- : [],
425
+ ? d.blob_attachments.map(formatAttachmentsGraphQLResponse)
426
+ : d.extensible_attachment
427
+ ? [formatExtensibleAttachment(d.extensible_attachment)]
428
+ : [],
447
429
  body: d.message !== null ? d.message.text : "",
448
430
  isGroup: messageThread.thread_type === "GROUP",
449
431
  messageID: d.message_id,
@@ -459,7 +441,7 @@ function formatMessagesGraphQLResponse(data) {
459
441
  ? d.message_reactions.map(formatReactionsGraphQL)
460
442
  : null,
461
443
  isSponsored: d.is_sponsored,
462
- snippet: d.snippet,
444
+ snippet: d.snippet
463
445
  };
464
446
  case "ThreadNameMessage":
465
447
  return {
@@ -472,13 +454,13 @@ function formatMessagesGraphQLResponse(data) {
472
454
  eventType: "change_thread_name",
473
455
  snippet: d.snippet,
474
456
  eventData: {
475
- threadName: d.thread_name,
457
+ threadName: d.thread_name
476
458
  },
477
459
 
478
460
  // @Legacy
479
461
  author: d.message_sender.id,
480
462
  logMessageType: "log:thread-name",
481
- logMessageData: { name: d.thread_name },
463
+ logMessageData: { name: d.thread_name }
482
464
  };
483
465
  case "ThreadImageMessage":
484
466
  return {
@@ -499,8 +481,8 @@ function formatMessagesGraphQLResponse(data) {
499
481
  attachmentID: d.image_with_metadata.legacy_attachment_id,
500
482
  width: d.image_with_metadata.original_dimensions.x,
501
483
  height: d.image_with_metadata.original_dimensions.y,
502
- url: d.image_with_metadata.preview.uri,
503
- },
484
+ url: d.image_with_metadata.preview.uri
485
+ }
504
486
  },
505
487
 
506
488
  // @Legacy
@@ -508,8 +490,8 @@ function formatMessagesGraphQLResponse(data) {
508
490
  logMessageData: {
509
491
  thread_icon: d.image_with_metadata
510
492
  ? d.image_with_metadata.preview.uri
511
- : null,
512
- },
493
+ : null
494
+ }
513
495
  };
514
496
  case "ParticipantLeftMessage":
515
497
  return {
@@ -523,18 +505,18 @@ function formatMessagesGraphQLResponse(data) {
523
505
  snippet: d.snippet,
524
506
  eventData: {
525
507
  // Array of IDs.
526
- participantsRemoved: d.participants_removed.map(function (p) {
508
+ participantsRemoved: d.participants_removed.map(function(p) {
527
509
  return p.id;
528
- }),
510
+ })
529
511
  },
530
512
 
531
513
  // @Legacy
532
514
  logMessageType: "log:unsubscribe",
533
515
  logMessageData: {
534
- leftParticipantFbId: d.participants_removed.map(function (p) {
516
+ leftParticipantFbId: d.participants_removed.map(function(p) {
535
517
  return p.id;
536
- }),
537
- },
518
+ })
519
+ }
538
520
  };
539
521
  case "ParticipantsAddedMessage":
540
522
  return {
@@ -548,18 +530,18 @@ function formatMessagesGraphQLResponse(data) {
548
530
  snippet: d.snippet,
549
531
  eventData: {
550
532
  // Array of IDs.
551
- participantsAdded: d.participants_added.map(function (p) {
533
+ participantsAdded: d.participants_added.map(function(p) {
552
534
  return p.id;
553
- }),
535
+ })
554
536
  },
555
537
 
556
538
  // @Legacy
557
539
  logMessageType: "log:subscribe",
558
540
  logMessageData: {
559
- addedParticipants: d.participants_added.map(function (p) {
541
+ addedParticipants: d.participants_added.map(function(p) {
560
542
  return p.id;
561
- }),
562
- },
543
+ })
544
+ }
563
545
  };
564
546
  case "VideoCallMessage":
565
547
  return {
@@ -573,7 +555,7 @@ function formatMessagesGraphQLResponse(data) {
573
555
  snippet: d.snippet,
574
556
 
575
557
  // @Legacy
576
- logMessageType: "other",
558
+ logMessageType: "other"
577
559
  };
578
560
  case "VoiceCallMessage":
579
561
  return {
@@ -587,7 +569,7 @@ function formatMessagesGraphQLResponse(data) {
587
569
  snippet: d.snippet,
588
570
 
589
571
  // @Legacy
590
- logMessageType: "other",
572
+ logMessageType: "other"
591
573
  };
592
574
  case "GenericAdminTextMessage":
593
575
  return {
@@ -602,10 +584,10 @@ function formatMessagesGraphQLResponse(data) {
602
584
  eventData: formatEventData(d.extensible_message_admin_text),
603
585
 
604
586
  // @Legacy
605
- logMessageType: utils.getAdminTextMessageType(
606
- d.extensible_message_admin_text_type,
587
+ logMessageType: getAdminTextMessageType(
588
+ d.extensible_message_admin_text_type
607
589
  ),
608
- logMessageData: d.extensible_message_admin_text, // Maybe different?
590
+ logMessageData: d.extensible_message_admin_text // Maybe different?
609
591
  };
610
592
  default:
611
593
  return { error: "Don't know about message type " + d.__typename };
@@ -614,22 +596,22 @@ function formatMessagesGraphQLResponse(data) {
614
596
  return messages;
615
597
  }
616
598
 
617
- module.exports = function (defaultFuncs, api, ctx) {
599
+ module.exports = function(defaultFuncs, api, ctx) {
618
600
  return function getThreadHistoryGraphQL(
619
601
  threadID,
620
602
  amount,
621
603
  timestamp,
622
- callback,
604
+ callback
623
605
  ) {
624
- let resolveFunc = function () {};
625
- let rejectFunc = function () {};
626
- const returnPromise = new Promise(function (resolve, reject) {
606
+ let resolveFunc = function() {};
607
+ let rejectFunc = function() {};
608
+ const returnPromise = new Promise(function(resolve, reject) {
627
609
  resolveFunc = resolve;
628
610
  rejectFunc = reject;
629
611
  });
630
612
 
631
613
  if (!callback) {
632
- callback = function (err, data) {
614
+ callback = function(err, data) {
633
615
  if (err) {
634
616
  return rejectFunc(err);
635
617
  }
@@ -640,7 +622,7 @@ module.exports = function (defaultFuncs, api, ctx) {
640
622
  // `queries` has to be a string. I couldn't tell from the dev console. This
641
623
  // took me a really long time to figure out. I deserve a cookie for this.
642
624
  const form = {
643
- av: ctx.globalOptions.pageID,
625
+ av: ctx.userID,
644
626
  queries: JSON.stringify({
645
627
  o0: {
646
628
  // This doc_id was valid on February 2nd 2017.
@@ -650,16 +632,16 @@ module.exports = function (defaultFuncs, api, ctx) {
650
632
  message_limit: amount,
651
633
  load_messages: 1,
652
634
  load_read_receipts: false,
653
- before: timestamp,
654
- },
655
- },
656
- }),
635
+ before: timestamp
636
+ }
637
+ }
638
+ })
657
639
  };
658
640
 
659
641
  defaultFuncs
660
642
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
661
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
662
- .then(function (resData) {
643
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
644
+ .then(function(resData) {
663
645
  if (resData.error) {
664
646
  throw resData;
665
647
  }
@@ -672,7 +654,7 @@ module.exports = function (defaultFuncs, api, ctx) {
672
654
 
673
655
  callback(null, formatMessagesGraphQLResponse(resData[0]));
674
656
  })
675
- .catch(function (err) {
657
+ .catch(function(err) {
676
658
  log.error("getThreadHistoryGraphQL", err);
677
659
  return callback(err);
678
660
  });