fca-smart-shankar 10.9.1 → 13.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 (169) hide show
  1. package/.replit +12 -3
  2. package/.upm/store.json +1 -1
  3. package/CHANGELOG.md +2 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +175 -30
  6. package/generated-icon.png +0 -0
  7. package/index.js +511 -414
  8. package/package.json +370 -85
  9. package/replit.nix +5 -0
  10. package/shankar-fca.json +4 -0
  11. package/src/addExternalModule.js +14 -5
  12. package/src/addUserToGroup.js +56 -20
  13. package/src/changeAdminStatus.js +44 -20
  14. package/src/changeArchivedStatus.js +25 -11
  15. package/src/changeAvatar.js +136 -0
  16. package/src/{changeAvt.js → changeAvatarV2.js} +3 -2
  17. package/src/changeBio.js +26 -15
  18. package/src/changeBlockedStatus.js +21 -8
  19. package/src/changeBlockedStatusMqtt.js +80 -0
  20. package/src/changeCover.js +73 -0
  21. package/src/changeGroupImage.js +53 -24
  22. package/src/changeName.js +79 -0
  23. package/src/changeNickname.js +27 -13
  24. package/src/changeThreadColor.js +22 -19
  25. package/src/changeThreadEmoji.js +24 -11
  26. package/src/changeUsername.js +59 -0
  27. package/src/createCommentPost.js +230 -0
  28. package/src/createNewGroup.js +38 -20
  29. package/src/createPoll.js +27 -16
  30. package/src/createPost.js +277 -0
  31. package/src/data/getThreadInfo.json +1 -0
  32. package/src/deleteMessage.js +24 -13
  33. package/src/deleteThread.js +25 -12
  34. package/src/editMessage.js +71 -53
  35. package/src/editMessageOld.js +67 -0
  36. package/src/follow.js +74 -0
  37. package/src/forwardAttachment.js +27 -15
  38. package/src/getAccess.js +112 -0
  39. package/src/getAvatarUser.js +78 -0
  40. package/src/getCurrentUserID.js +1 -1
  41. package/src/getEmojiUrl.js +10 -8
  42. package/src/getFriendsList.js +25 -15
  43. package/src/getMessage.js +813 -81
  44. package/src/getRegion.js +7 -0
  45. package/src/getThreadHistory.js +241 -98
  46. package/src/getThreadHistoryDeprecated.js +93 -0
  47. package/src/getThreadInfo.js +90 -287
  48. package/src/getThreadInfoDeprecated.js +80 -0
  49. package/src/getThreadList.js +214 -157
  50. package/src/getThreadListDeprecated.js +75 -0
  51. package/src/getThreadPictures.js +39 -19
  52. package/src/getUID.js +113 -50
  53. package/src/getUserID.js +18 -14
  54. package/src/getUserInfo.js +65 -71
  55. package/src/handleFriendRequest.js +24 -13
  56. package/src/handleMessageRequest.js +36 -20
  57. package/src/httpGet.js +34 -18
  58. package/src/httpPost.js +35 -18
  59. package/src/httpPostFormData.js +53 -24
  60. package/src/listenMqtt.js +680 -944
  61. package/src/listenNotification.js +85 -0
  62. package/src/logout.js +22 -15
  63. package/src/markAsDelivered.js +25 -15
  64. package/src/markAsRead.js +45 -27
  65. package/src/markAsReadAll.js +21 -14
  66. package/src/markAsSeen.js +28 -18
  67. package/src/muteThread.js +17 -12
  68. package/src/pinMessage.js +59 -0
  69. package/src/refreshFb_dtsg.js +89 -0
  70. package/src/removeUserFromGroup.js +47 -17
  71. package/src/resolvePhotoUrl.js +21 -13
  72. package/src/searchForThread.js +23 -13
  73. package/src/searchStickers.js +53 -0
  74. package/src/sendMessage.js +178 -117
  75. package/src/sendMessageMqtt.js +322 -0
  76. package/src/sendTypingIndicator.js +46 -16
  77. package/src/sendTypingIndicatorV2.js +28 -0
  78. package/src/setMessageReaction.js +33 -20
  79. package/src/setMessageReactionMqtt.js +62 -0
  80. package/src/setPostReaction.js +105 -95
  81. package/src/setProfileGuard.js +45 -0
  82. package/src/setStoryReaction.js +64 -0
  83. package/src/setTitle.js +34 -18
  84. package/src/shareContact.js +92 -37
  85. package/src/shareLink.js +5 -4
  86. package/src/stopListenMqtt.js +26 -0
  87. package/src/threadColors.js +110 -18
  88. package/src/unfriend.js +18 -9
  89. package/src/unsendMessage.js +31 -34
  90. package/src/uploadAttachment.js +94 -0
  91. package/test/data/shareAttach.js +1 -1
  92. package/test/test.js +1 -1
  93. package/utils.js +1393 -2918
  94. package/.cache/replit/env/latest +0 -56
  95. package/.cache/replit/env/latest.json +0 -1
  96. package/.cache/replit/modules/nodejs-14.res +0 -1
  97. package/.cache/replit/modules/replit.res +0 -1
  98. package/.cache/replit/modules/web.res +0 -1
  99. package/.cache/replit/modules.stamp +0 -0
  100. package/.cache/typescript/5.5/package.json +0 -1
  101. package/.config/configstore/update-notifier-npm.json +0 -4
  102. package/.gitattributes +0 -2
  103. package/Extra/Balancer.js +0 -49
  104. package/Extra/Bypass/956/index.js +0 -234
  105. package/Extra/Bypass/test/aaaa.json +0 -170
  106. package/Extra/Bypass/test/index.js +0 -188
  107. package/Extra/Database/index.js +0 -469
  108. package/Extra/ExtraAddons.js +0 -82
  109. package/Extra/ExtraFindUID.js +0 -62
  110. package/Extra/ExtraGetThread.js +0 -365
  111. package/Extra/ExtraScreenShot.js +0 -430
  112. package/Extra/ExtraUptimeRobot.js +0 -38
  113. package/Extra/Html/Classic/script.js +0 -119
  114. package/Extra/Html/Classic/style.css +0 -8
  115. package/Extra/Security/AES_256_GCM/index.js +0 -0
  116. package/Extra/Security/Base/Step_1.js +0 -6
  117. package/Extra/Security/Base/Step_2.js +0 -22
  118. package/Extra/Security/Base/Step_3.js +0 -22
  119. package/Extra/Security/Base/index.js +0 -191
  120. package/Extra/Security/Index.js +0 -5
  121. package/Extra/Security/Step_1.js +0 -6
  122. package/Extra/Security/Step_2.js +0 -22
  123. package/Extra/Security/Step_3.js +0 -22
  124. package/Extra/Src/Change_Environment.js +0 -24
  125. package/Extra/Src/Check_Update.js +0 -67
  126. package/Extra/Src/History.js +0 -115
  127. package/Extra/Src/Instant_Update.js +0 -65
  128. package/Extra/Src/Last-Run.js +0 -65
  129. package/Extra/Src/Premium.js +0 -81
  130. package/Extra/Src/Release_Memory.js +0 -160
  131. package/Extra/Src/Websocket.js +0 -213
  132. package/Extra/Src/image/checkmate.jpg +0 -0
  133. package/Extra/Src/test.js +0 -28
  134. package/Extra/Src/uuid.js +0 -137
  135. package/Func/AcceptAgreement.js +0 -31
  136. package/Func/ClearCache.js +0 -64
  137. package/Func/ReportV1.js +0 -54
  138. package/LICENSE +0 -678
  139. package/Language/index.json +0 -228
  140. package/Main.js +0 -1444
  141. package/SECURITY.md +0 -18
  142. package/broadcast.js +0 -44
  143. package/logger.js +0 -66
  144. package/src/Dev_Horizon_Data.js +0 -125
  145. package/src/Dev_getThreadInfoOLD.js +0 -422
  146. package/src/Dev_shareTest2.js +0 -68
  147. package/src/Dev_shareTest3.js +0 -71
  148. package/src/Premium.js +0 -25
  149. package/src/Screenshot.js +0 -83
  150. package/src/getAccessToken.js +0 -28
  151. package/src/getThreadInfoOLD.js +0 -422
  152. package/src/getThreadMain.js +0 -220
  153. package/src/getUserInfoMain.js +0 -65
  154. package/src/getUserInfoV2.js +0 -32
  155. package/src/getUserInfoV3.js +0 -63
  156. package/src/getUserInfoV4.js +0 -55
  157. package/src/getUserInfoV5.js +0 -61
  158. package/src/listenMqttV1.js +0 -846
  159. package/src/sendMqttMessage.js +0 -71
  160. package/src/unsendMqttMessage.js +0 -66
  161. package/test/Database_Test.js +0 -4
  162. package/test/Db2.js +0 -530
  163. package/test/Shankar_Database/A_README.md +0 -1
  164. package/test/Shankar_Database/Database.db +0 -0
  165. package/test/env/.env +0 -0
  166. package/test/example-db.db +0 -0
  167. package/test/memoryleak.js +0 -18
  168. package/test/testname.js +0 -1342
  169. package/test/testv2.js +0 -3
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ module.exports = function (defaultFuncs, api, ctx) {
4
+ return function getRegion() {
5
+ return ctx?.region;
6
+ };
7
+ };
@@ -1,7 +1,20 @@
1
1
  "use strict";
2
2
 
3
- var utils = require("../utils");
4
- var log = require("npmlog");
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ function getExtension(original_extension, filename = "") {
7
+ if (original_extension) {
8
+ return original_extension;
9
+ } else {
10
+ const extension = filename.split(".").pop();
11
+ if (extension === filename) {
12
+ return "";
13
+ } else {
14
+ return extension;
15
+ }
16
+ }
17
+ }
5
18
 
6
19
  function formatAttachmentsGraphQLResponse(attachment) {
7
20
  switch (attachment.__typename) {
@@ -10,6 +23,10 @@ function formatAttachmentsGraphQLResponse(attachment) {
10
23
  type: "photo",
11
24
  ID: attachment.legacy_attachment_id,
12
25
  filename: attachment.filename,
26
+ original_extension: getExtension(
27
+ attachment.original_extension,
28
+ attachment.filename,
29
+ ),
13
30
  thumbnailUrl: attachment.thumbnail.uri,
14
31
 
15
32
  previewUrl: attachment.preview.uri,
@@ -29,11 +46,11 @@ function formatAttachmentsGraphQLResponse(attachment) {
29
46
  // @Undocumented
30
47
  attributionApp: attachment.attribution_app
31
48
  ? {
32
- attributionAppID: attachment.attribution_app.id,
33
- name: attachment.attribution_app.name,
34
- logo: attachment.attribution_app.square_logo
35
- }
36
- : null
49
+ attributionAppID: attachment.attribution_app.id,
50
+ name: attachment.attribution_app.name,
51
+ logo: attachment.attribution_app.square_logo,
52
+ }
53
+ : null,
37
54
 
38
55
  // @TODO No idea what this is, should we expose it?
39
56
  // Ben - July 15th 2017
@@ -57,6 +74,10 @@ function formatAttachmentsGraphQLResponse(attachment) {
57
74
  type: "animated_image",
58
75
  ID: attachment.legacy_attachment_id,
59
76
  filename: attachment.filename,
77
+ original_extension: getExtension(
78
+ attachment.original_extension,
79
+ attachment.filename,
80
+ ),
60
81
 
61
82
  previewUrl: attachment.preview_image.uri,
62
83
  previewWidth: attachment.preview_image.width,
@@ -78,17 +99,22 @@ function formatAttachmentsGraphQLResponse(attachment) {
78
99
  // @Undocumented
79
100
  attributionApp: attachment.attribution_app
80
101
  ? {
81
- attributionAppID: attachment.attribution_app.id,
82
- name: attachment.attribution_app.name,
83
- logo: attachment.attribution_app.square_logo
84
- }
85
- : null
102
+ attributionAppID: attachment.attribution_app.id,
103
+ name: attachment.attribution_app.name,
104
+ logo: attachment.attribution_app.square_logo,
105
+ }
106
+ : null,
86
107
  };
87
108
  case "MessageVideo":
88
109
  return {
89
110
  type: "video",
90
- filename: attachment.filename,
91
111
  ID: attachment.legacy_attachment_id,
112
+ filename: attachment.filename,
113
+ original_extension: getExtension(
114
+ attachment.original_extension,
115
+ attachment.filename,
116
+ ),
117
+ duration: attachment.playable_duration_in_ms,
92
118
 
93
119
  thumbnailUrl: attachment.large_image.uri, // @Legacy
94
120
 
@@ -100,14 +126,17 @@ function formatAttachmentsGraphQLResponse(attachment) {
100
126
  width: attachment.original_dimensions.x,
101
127
  height: attachment.original_dimensions.y,
102
128
 
103
- duration: attachment.playable_duration_in_ms,
104
- videoType: attachment.video_type.toLowerCase()
129
+ videoType: attachment.video_type.toLowerCase(),
105
130
  };
106
131
  case "MessageFile":
107
132
  return {
108
133
  type: "file",
109
- filename: attachment.filename,
110
134
  ID: attachment.message_file_fbid,
135
+ filename: attachment.filename,
136
+ original_extension: getExtension(
137
+ attachment.original_extension,
138
+ attachment.filename,
139
+ ),
111
140
 
112
141
  url: attachment.url,
113
142
  isMalicious: attachment.is_malicious,
@@ -115,23 +144,27 @@ function formatAttachmentsGraphQLResponse(attachment) {
115
144
 
116
145
  name: attachment.filename, // @Legacy
117
146
  mimeType: "", // @Legacy
118
- fileSize: -1 // @Legacy
147
+ fileSize: -1, // @Legacy
119
148
  };
120
149
  case "MessageAudio":
121
150
  return {
122
151
  type: "audio",
123
- filename: attachment.filename,
124
152
  ID: attachment.url_shimhash, // Not fowardable
153
+ filename: attachment.filename,
154
+ original_extension: getExtension(
155
+ attachment.original_extension,
156
+ attachment.filename,
157
+ ),
125
158
 
126
- audioType: attachment.audio_type,
127
159
  duration: attachment.playable_duration_in_ms,
160
+ audioType: attachment.audio_type,
128
161
  url: attachment.playable_url,
129
162
 
130
- isVoiceMail: attachment.is_voicemail
163
+ isVoiceMail: attachment.is_voicemail,
131
164
  };
132
165
  default:
133
166
  return {
134
- error: "Don't know about attachment type " + attachment.__typename
167
+ error: "Don't know about attachment type " + attachment.__typename,
135
168
  };
136
169
  }
137
170
  }
@@ -144,15 +177,56 @@ function formatExtensibleAttachment(attachment) {
144
177
  url: attachment.story_attachment.url,
145
178
 
146
179
  title: attachment.story_attachment.title_with_entities.text,
147
- description: attachment.story_attachment.description && attachment.story_attachment.description.text,
148
- source: attachment.story_attachment.source == null ? null : attachment.story_attachment.source.text,
149
-
150
- image: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).uri,
151
- width: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).width,
152
- height: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).height,
153
- playable: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.is_playable,
154
- duration: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.playable_duration_in_ms,
155
- playableUrl: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.playable_url,
180
+ description:
181
+ attachment.story_attachment.description &&
182
+ attachment.story_attachment.description.text,
183
+ source:
184
+ attachment.story_attachment.source == null
185
+ ? null
186
+ : attachment.story_attachment.source.text,
187
+
188
+ image:
189
+ attachment.story_attachment.media == null
190
+ ? null
191
+ : attachment.story_attachment.media.animated_image == null &&
192
+ attachment.story_attachment.media.image == null
193
+ ? null
194
+ : (
195
+ attachment.story_attachment.media.animated_image ||
196
+ attachment.story_attachment.media.image
197
+ ).uri,
198
+ width:
199
+ attachment.story_attachment.media == null
200
+ ? null
201
+ : attachment.story_attachment.media.animated_image == null &&
202
+ attachment.story_attachment.media.image == null
203
+ ? null
204
+ : (
205
+ attachment.story_attachment.media.animated_image ||
206
+ attachment.story_attachment.media.image
207
+ ).width,
208
+ height:
209
+ attachment.story_attachment.media == null
210
+ ? null
211
+ : attachment.story_attachment.media.animated_image == null &&
212
+ attachment.story_attachment.media.image == null
213
+ ? null
214
+ : (
215
+ attachment.story_attachment.media.animated_image ||
216
+ attachment.story_attachment.media.image
217
+ ).height,
218
+ playable:
219
+ attachment.story_attachment.media == null
220
+ ? null
221
+ : attachment.story_attachment.media.is_playable,
222
+ duration:
223
+ attachment.story_attachment.media == null
224
+ ? null
225
+ : attachment.story_attachment.media.playable_duration_in_ms,
226
+ playableUrl:
227
+ attachment.story_attachment.media == null
228
+ ? null
229
+ : attachment.story_attachment.media.playable_url,
156
230
 
157
231
  subattachments: attachment.story_attachment.subattachments,
158
232
 
@@ -169,7 +243,10 @@ function formatExtensibleAttachment(attachment) {
169
243
  // width: "1280"
170
244
  // }
171
245
  //
172
- properties: attachment.story_attachment.properties.reduce(function (obj, cur) {
246
+ properties: attachment.story_attachment.properties.reduce(function (
247
+ obj,
248
+ cur,
249
+ ) {
173
250
  obj[cur.key] = cur.value.text;
174
251
  return obj;
175
252
  }, {}),
@@ -179,77 +256,113 @@ function formatExtensibleAttachment(attachment) {
179
256
  facebookUrl: "", // @Legacy
180
257
  styleList: "", // @Legacy
181
258
  target: "", // @Legacy
182
- thumbnailUrl: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).uri, // @Legacy
183
- thumbnailWidth: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).width, // @Legacy
184
- thumbnailHeight: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).height // @Legacy
259
+ thumbnailUrl:
260
+ attachment.story_attachment.media == null
261
+ ? null
262
+ : attachment.story_attachment.media.animated_image == null &&
263
+ attachment.story_attachment.media.image == null
264
+ ? null
265
+ : (
266
+ attachment.story_attachment.media.animated_image ||
267
+ attachment.story_attachment.media.image
268
+ ).uri, // @Legacy
269
+ thumbnailWidth:
270
+ attachment.story_attachment.media == null
271
+ ? null
272
+ : attachment.story_attachment.media.animated_image == null &&
273
+ attachment.story_attachment.media.image == null
274
+ ? null
275
+ : (
276
+ attachment.story_attachment.media.animated_image ||
277
+ attachment.story_attachment.media.image
278
+ ).width, // @Legacy
279
+ thumbnailHeight:
280
+ attachment.story_attachment.media == null
281
+ ? null
282
+ : attachment.story_attachment.media.animated_image == null &&
283
+ attachment.story_attachment.media.image == null
284
+ ? null
285
+ : (
286
+ attachment.story_attachment.media.animated_image ||
287
+ attachment.story_attachment.media.image
288
+ ).height, // @Legacy
185
289
  };
290
+ } else {
291
+ return { error: "Don't know what to do with extensible_attachment." };
186
292
  }
187
- else return { error: "Don't know what to do with extensible_attachment." };
188
293
  }
189
294
 
190
295
  function formatReactionsGraphQL(reaction) {
191
296
  return {
192
297
  reaction: reaction.reaction,
193
- userID: reaction.user.id
298
+ userID: reaction.user.id,
194
299
  };
195
300
  }
196
301
 
197
302
  function formatEventData(event) {
198
- if (event == null) return {};
303
+ if (event == null) {
304
+ return {};
305
+ }
199
306
 
200
307
  switch (event.__typename) {
201
308
  case "ThemeColorExtensibleMessageAdminText":
202
- return { color: event.theme_color };
309
+ return {
310
+ color: event.theme_color,
311
+ };
203
312
  case "ThreadNicknameExtensibleMessageAdminText":
204
313
  return {
205
314
  nickname: event.nickname,
206
- participantID: event.participant_id
315
+ participantID: event.participant_id,
207
316
  };
208
317
  case "ThreadIconExtensibleMessageAdminText":
209
- return { threadIcon: event.thread_icon };
318
+ return {
319
+ threadIcon: event.thread_icon,
320
+ };
210
321
  case "InstantGameUpdateExtensibleMessageAdminText":
211
322
  return {
212
- gameID: (event.game == null ? null : event.game.id),
323
+ gameID: event.game == null ? null : event.game.id,
213
324
  update_type: event.update_type,
214
325
  collapsed_text: event.collapsed_text,
215
326
  expanded_text: event.expanded_text,
216
- instant_game_update_data: event.instant_game_update_data
327
+ instant_game_update_data: event.instant_game_update_data,
217
328
  };
218
329
  case "GameScoreExtensibleMessageAdminText":
219
- return { game_type: event.game_type };
330
+ return {
331
+ game_type: event.game_type,
332
+ };
220
333
  case "RtcCallLogExtensibleMessageAdminText":
221
334
  return {
222
335
  event: event.event,
223
336
  is_video_call: event.is_video_call,
224
- server_info_data: event.server_info_data
337
+ server_info_data: event.server_info_data,
225
338
  };
226
339
  case "GroupPollExtensibleMessageAdminText":
227
340
  return {
228
341
  event_type: event.event_type,
229
342
  total_count: event.total_count,
230
- question: event.question
343
+ question: event.question,
231
344
  };
232
345
  case "AcceptPendingThreadExtensibleMessageAdminText":
233
346
  return {
234
347
  accepter_id: event.accepter_id,
235
- requester_id: event.requester_id
348
+ requester_id: event.requester_id,
236
349
  };
237
350
  case "ConfirmFriendRequestExtensibleMessageAdminText":
238
351
  return {
239
352
  friend_request_recipient: event.friend_request_recipient,
240
- friend_request_sender: event.friend_request_sender
353
+ friend_request_sender: event.friend_request_sender,
241
354
  };
242
355
  case "AddContactExtensibleMessageAdminText":
243
356
  return {
244
357
  contact_added_id: event.contact_added_id,
245
- contact_adder_id: event.contact_adder_id
358
+ contact_adder_id: event.contact_adder_id,
246
359
  };
247
360
  case "AdExtensibleMessageAdminText":
248
361
  return {
249
362
  ad_client_token: event.ad_client_token,
250
363
  ad_id: event.ad_id,
251
364
  ad_preferences_link: event.ad_preferences_link,
252
- ad_properties: event.ad_properties
365
+ ad_properties: event.ad_properties,
253
366
  };
254
367
  // never data
255
368
  case "ParticipantJoinedGroupCallExtensibleMessageAdminText":
@@ -264,15 +377,19 @@ function formatEventData(event) {
264
377
  case "LightweightEventDeleteExtensibleMessageAdminText":
265
378
  return {};
266
379
  default:
267
- return { error: "Don't know what to with event data type " + event.__typename };
380
+ return {
381
+ error: "Don't know what to with event data type " + event.__typename,
382
+ };
268
383
  }
269
384
  }
270
385
 
271
386
  function formatMessagesGraphQLResponse(data) {
272
- var messageThread = data.o0.data.message_thread;
273
- var threadID = messageThread.thread_key.thread_fbid ? messageThread.thread_key.thread_fbid : messageThread.thread_key.other_user_id;
387
+ const messageThread = data.o0.data.message_thread;
388
+ const threadID = messageThread.thread_key.thread_fbid
389
+ ? messageThread.thread_key.thread_fbid
390
+ : messageThread.thread_key.other_user_id;
274
391
 
275
- var messages = messageThread.messages.nodes.map(function (d) {
392
+ const messages = messageThread.messages.nodes.map(function (d) {
276
393
  switch (d.__typename) {
277
394
  case "UserMessage":
278
395
  // Give priority to stickers. They're seen as normal messages but we've
@@ -285,7 +402,7 @@ function formatMessagesGraphQLResponse(data) {
285
402
  ID: d.sticker.id,
286
403
  url: d.sticker.url,
287
404
 
288
- packID: d.sticker.pack.id,
405
+ packID: d.sticker.pack ? d.sticker.pack.id : null,
289
406
  spriteUrl: d.sticker.sprite_image,
290
407
  spriteUrl2x: d.sticker.sprite_image_2x,
291
408
  width: d.sticker.width,
@@ -301,14 +418,19 @@ function formatMessagesGraphQLResponse(data) {
301
418
 
302
419
  stickerID: d.sticker.id, // @Legacy
303
420
  spriteURI: d.sticker.sprite_image, // @Legacy
304
- spriteURI2x: d.sticker.sprite_image_2x // @Legacy
305
- }
421
+ spriteURI2x: d.sticker.sprite_image_2x, // @Legacy
422
+ },
306
423
  ];
307
424
  }
308
425
 
309
426
  var mentionsObj = {};
310
427
  if (d.message !== null) {
311
- d.message.ranges.forEach(e => mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length));
428
+ d.message.ranges.forEach((e) => {
429
+ mentionsObj[e.entity.id] = d.message.text.substr(
430
+ e.offset,
431
+ e.length,
432
+ );
433
+ });
312
434
  }
313
435
 
314
436
  return {
@@ -320,7 +442,7 @@ function formatMessagesGraphQLResponse(data) {
320
442
  : d.extensible_attachment
321
443
  ? [formatExtensibleAttachment(d.extensible_attachment)]
322
444
  : [],
323
- body: d.message !== null ? d.message.text : '',
445
+ body: d.message !== null ? d.message.text : "",
324
446
  isGroup: messageThread.thread_type === "GROUP",
325
447
  messageID: d.message_id,
326
448
  senderID: d.message_sender.id,
@@ -331,9 +453,11 @@ function formatMessagesGraphQLResponse(data) {
331
453
  isUnread: d.unread,
332
454
 
333
455
  // New
334
- messageReactions: d.message_reactions ? d.message_reactions.map(formatReactionsGraphQL) : null,
456
+ messageReactions: d.message_reactions
457
+ ? d.message_reactions.map(formatReactionsGraphQL)
458
+ : null,
335
459
  isSponsored: d.is_sponsored,
336
- snippet: d.snippet
460
+ snippet: d.snippet,
337
461
  };
338
462
  case "ThreadNameMessage":
339
463
  return {
@@ -345,12 +469,14 @@ function formatMessagesGraphQLResponse(data) {
345
469
  timestamp: d.timestamp_precise,
346
470
  eventType: "change_thread_name",
347
471
  snippet: d.snippet,
348
- eventData: { threadName: d.thread_name },
472
+ eventData: {
473
+ threadName: d.thread_name,
474
+ },
349
475
 
350
476
  // @Legacy
351
477
  author: d.message_sender.id,
352
478
  logMessageType: "log:thread-name",
353
- logMessageData: { name: d.thread_name }
479
+ logMessageData: { name: d.thread_name },
354
480
  };
355
481
  case "ThreadImageMessage":
356
482
  return {
@@ -362,21 +488,26 @@ function formatMessagesGraphQLResponse(data) {
362
488
  timestamp: d.timestamp_precise,
363
489
  eventType: "change_thread_image",
364
490
  snippet: d.snippet,
365
- eventData: d.image_with_metadata == null
366
- ? {} /* removed image */
367
- : {
368
- /* image added */
369
- threadImage: {
370
- attachmentID: d.image_with_metadata.legacy_attachment_id,
371
- width: d.image_with_metadata.original_dimensions.x,
372
- height: d.image_with_metadata.original_dimensions.y,
373
- url: d.image_with_metadata.preview.uri
374
- }
375
- },
491
+ eventData:
492
+ d.image_with_metadata == null
493
+ ? {} /* removed image */
494
+ : {
495
+ /* image added */
496
+ threadImage: {
497
+ attachmentID: d.image_with_metadata.legacy_attachment_id,
498
+ width: d.image_with_metadata.original_dimensions.x,
499
+ height: d.image_with_metadata.original_dimensions.y,
500
+ url: d.image_with_metadata.preview.uri,
501
+ },
502
+ },
376
503
 
377
504
  // @Legacy
378
505
  logMessageType: "log:thread-icon",
379
- logMessageData: { thread_icon: d.image_with_metadata ? d.image_with_metadata.preview.uri : null }
506
+ logMessageData: {
507
+ thread_icon: d.image_with_metadata
508
+ ? d.image_with_metadata.preview.uri
509
+ : null,
510
+ },
380
511
  };
381
512
  case "ParticipantLeftMessage":
382
513
  return {
@@ -392,7 +523,7 @@ function formatMessagesGraphQLResponse(data) {
392
523
  // Array of IDs.
393
524
  participantsRemoved: d.participants_removed.map(function (p) {
394
525
  return p.id;
395
- })
526
+ }),
396
527
  },
397
528
 
398
529
  // @Legacy
@@ -400,8 +531,8 @@ function formatMessagesGraphQLResponse(data) {
400
531
  logMessageData: {
401
532
  leftParticipantFbId: d.participants_removed.map(function (p) {
402
533
  return p.id;
403
- })
404
- }
534
+ }),
535
+ },
405
536
  };
406
537
  case "ParticipantsAddedMessage":
407
538
  return {
@@ -417,7 +548,7 @@ function formatMessagesGraphQLResponse(data) {
417
548
  // Array of IDs.
418
549
  participantsAdded: d.participants_added.map(function (p) {
419
550
  return p.id;
420
- })
551
+ }),
421
552
  },
422
553
 
423
554
  // @Legacy
@@ -425,8 +556,8 @@ function formatMessagesGraphQLResponse(data) {
425
556
  logMessageData: {
426
557
  addedParticipants: d.participants_added.map(function (p) {
427
558
  return p.id;
428
- })
429
- }
559
+ }),
560
+ },
430
561
  };
431
562
  case "VideoCallMessage":
432
563
  return {
@@ -440,7 +571,7 @@ function formatMessagesGraphQLResponse(data) {
440
571
  snippet: d.snippet,
441
572
 
442
573
  // @Legacy
443
- logMessageType: "other"
574
+ logMessageType: "other",
444
575
  };
445
576
  case "VoiceCallMessage":
446
577
  return {
@@ -454,7 +585,7 @@ function formatMessagesGraphQLResponse(data) {
454
585
  snippet: d.snippet,
455
586
 
456
587
  // @Legacy
457
- logMessageType: "other"
588
+ logMessageType: "other",
458
589
  };
459
590
  case "GenericAdminTextMessage":
460
591
  return {
@@ -470,9 +601,9 @@ function formatMessagesGraphQLResponse(data) {
470
601
 
471
602
  // @Legacy
472
603
  logMessageType: utils.getAdminTextMessageType(
473
- d.extensible_message_admin_text_type
604
+ d.extensible_message_admin_text_type,
474
605
  ),
475
- logMessageData: d.extensible_message_admin_text // Maybe different?
606
+ logMessageData: d.extensible_message_admin_text, // Maybe different?
476
607
  };
477
608
  default:
478
609
  return { error: "Don't know about message type " + d.__typename };
@@ -482,25 +613,32 @@ function formatMessagesGraphQLResponse(data) {
482
613
  }
483
614
 
484
615
  module.exports = function (defaultFuncs, api, ctx) {
485
- return function getThreadHistoryGraphQL(threadID, amount, timestamp, callback) {
486
- var resolveFunc = function () { };
487
- var rejectFunc = function () { };
488
- var returnPromise = new Promise(function (resolve, reject) {
616
+ return function getThreadHistoryGraphQL(
617
+ threadID,
618
+ amount,
619
+ timestamp,
620
+ callback,
621
+ ) {
622
+ let resolveFunc = function () {};
623
+ let rejectFunc = function () {};
624
+ const returnPromise = new Promise(function (resolve, reject) {
489
625
  resolveFunc = resolve;
490
626
  rejectFunc = reject;
491
627
  });
492
628
 
493
629
  if (!callback) {
494
630
  callback = function (err, data) {
495
- if (err) return rejectFunc(err);
631
+ if (err) {
632
+ return rejectFunc(err);
633
+ }
496
634
  resolveFunc(data);
497
635
  };
498
636
  }
499
637
 
500
638
  // `queries` has to be a string. I couldn't tell from the dev console. This
501
639
  // took me a really long time to figure out. I deserve a cookie for this.
502
- var form = {
503
- "av": ctx.globalOptions.pageID,
640
+ const form = {
641
+ av: ctx.globalOptions.pageID,
504
642
  queries: JSON.stringify({
505
643
  o0: {
506
644
  // This doc_id was valid on February 2nd 2017.
@@ -510,25 +648,30 @@ module.exports = function (defaultFuncs, api, ctx) {
510
648
  message_limit: amount,
511
649
  load_messages: 1,
512
650
  load_read_receipts: false,
513
- before: timestamp
514
- }
515
- }
516
- })
651
+ before: timestamp,
652
+ },
653
+ },
654
+ }),
517
655
  };
518
656
 
519
657
  defaultFuncs
520
658
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
521
659
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
522
660
  .then(function (resData) {
523
- if (resData.error) throw resData;
661
+ if (resData.error) {
662
+ throw resData;
663
+ }
524
664
  // This returns us an array of things. The last one is the success /
525
665
  // failure one.
526
666
  // @TODO What do we do in this case?
527
- if (resData[resData.length - 1].error_results !== 0) throw new Error("There was an error_result.");
667
+ if (resData[resData.length - 1].error_results !== 0) {
668
+ throw new Error("There was an error_result.");
669
+ }
670
+
528
671
  callback(null, formatMessagesGraphQLResponse(resData[0]));
529
672
  })
530
673
  .catch(function (err) {
531
- log.error("getThreadHistoryGraphQL", "Lỗi getThreadHistoryGraphQL Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !");
674
+ log.error("getThreadHistoryGraphQL", err);
532
675
  return callback(err);
533
676
  });
534
677