@cexy/hoonfca 1.0.0 → 1.0.2

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 (98) hide show
  1. package/.travis.yml +6 -0
  2. package/LICENSE-MIT +21 -0
  3. package/index.d.ts +620 -0
  4. package/index.js +745 -433
  5. package/package.json +45 -6
  6. package/src/addExternalModule.js +14 -16
  7. package/src/addUserToGroup.js +45 -30
  8. package/src/changeAdminStatus.js +39 -42
  9. package/src/changeApprovalMode.js +79 -0
  10. package/src/changeArchivedStatus.js +19 -15
  11. package/src/changeBio.js +18 -16
  12. package/src/changeBlockedStatus.js +14 -12
  13. package/src/changeBlockedStatusMqtt.js +38 -17
  14. package/src/changeGroupImage.js +100 -77
  15. package/src/changeNickname.js +12 -11
  16. package/src/changeThreadColor.js +25 -16
  17. package/src/changeThreadEmoji.js +11 -10
  18. package/src/createNewGroup.js +21 -14
  19. package/src/createPoll.js +87 -21
  20. package/src/deleteMessage.js +18 -17
  21. package/src/deleteThread.js +18 -17
  22. package/src/editMessage.js +28 -31
  23. package/src/forwardAttachment.js +22 -19
  24. package/src/forwardMessage.js +63 -0
  25. package/src/getCurrentUserID.js +4 -2
  26. package/src/getEmojiUrl.js +20 -9
  27. package/src/getFriendsList.js +21 -18
  28. package/src/getGroupsList.js +83 -0
  29. package/src/getMarketplace.js +84 -0
  30. package/src/getNotifications.js +86 -0
  31. package/src/getPagesList.js +83 -0
  32. package/src/getStories.js +88 -0
  33. package/src/getThreadHistory.js +277 -126
  34. package/src/getThreadInfo.js +143 -115
  35. package/src/getThreadList.js +216 -143
  36. package/src/getThreadPictures.js +26 -32
  37. package/src/getUserID.js +13 -14
  38. package/src/getUserInfo.js +107 -68
  39. package/src/handleFriendRequest.js +16 -15
  40. package/src/handleMessageRequest.js +15 -15
  41. package/src/httpGet.js +36 -31
  42. package/src/httpPost.js +36 -31
  43. package/src/listenMqtt.js +705 -370
  44. package/src/logout.js +26 -28
  45. package/src/markAsDelivered.js +22 -17
  46. package/src/markAsRead.js +63 -49
  47. package/src/markAsReadAll.js +17 -13
  48. package/src/markAsSeen.js +23 -19
  49. package/src/muteThread.js +17 -14
  50. package/src/pinMessage.js +23 -22
  51. package/src/removeUserFromGroup.js +42 -22
  52. package/src/resolvePhotoUrl.js +15 -17
  53. package/src/searchForThread.js +18 -20
  54. package/src/searchUsers.js +89 -0
  55. package/src/sendComment.js +161 -0
  56. package/src/sendMessage.js +65 -52
  57. package/src/sendTypingIndicator.js +173 -48
  58. package/src/setBio.js +86 -0
  59. package/src/setMessageReaction.js +76 -16
  60. package/src/setPostReaction.js +29 -61
  61. package/src/setTheme.js +313 -0
  62. package/src/setTitle.js +27 -37
  63. package/src/shareContact.js +34 -82
  64. package/src/shareLink.js +56 -99
  65. package/src/threadColors.js +35 -97
  66. package/src/unfriend.js +15 -20
  67. package/src/unsendMessage.js +71 -18
  68. package/utils.js +1000 -472
  69. package/README.md +0 -83
  70. package/replit.nix +0 -3
  71. package/src/changeAvatar.js +0 -89
  72. package/src/changeCover.js +0 -92
  73. package/src/changeName.js +0 -106
  74. package/src/changeUsername.js +0 -80
  75. package/src/createCommentPost.js +0 -196
  76. package/src/createPost.js +0 -285
  77. package/src/data/getThreadInfo.json +0 -1
  78. package/src/follow.js +0 -71
  79. package/src/getAccess.js +0 -130
  80. package/src/getAvatarUser.js +0 -88
  81. package/src/getBotInitialData.js +0 -59
  82. package/src/getCtx.js +0 -5
  83. package/src/getMessage.js +0 -827
  84. package/src/getOptions.js +0 -5
  85. package/src/getRegion.js +0 -7
  86. package/src/getThreadHistoryDeprecated.js +0 -95
  87. package/src/getThreadInfoDeprecated.js +0 -77
  88. package/src/getThreadListDeprecated.js +0 -86
  89. package/src/httpPostFormData.js +0 -58
  90. package/src/listenNotification.js +0 -96
  91. package/src/refreshFb_dtsg.js +0 -75
  92. package/src/searchStickers.js +0 -59
  93. package/src/sendMessageMqtt.js +0 -326
  94. package/src/setMessageReactionMqtt.js +0 -74
  95. package/src/setProfileGuard.js +0 -66
  96. package/src/setStoryReaction.js +0 -97
  97. package/src/stopListenMqtt.js +0 -47
  98. package/src/uploadAttachment.js +0 -98
@@ -1,17 +1,8 @@
1
1
  "use strict";
2
2
 
3
- const utils = require("../utils");
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
4
5
 
5
- // ফাইলের এক্সটেনশন বের করার হেল্পার ফাংশন
6
- function getExtension(original_extension, filename = "") {
7
- if (original_extension) {
8
- return original_extension;
9
- }
10
- const extension = filename.split(".").pop();
11
- return extension === filename ? "" : extension;
12
- }
13
-
14
- // গ্রাফকিউএল রেসপন্স থেকে বিভিন্ন মিডিয়া অ্যাটাচমেন্ট ফরম্যাট করার ফাংশন
15
6
  function formatAttachmentsGraphQLResponse(attachment) {
16
7
  switch (attachment.__typename) {
17
8
  case "MessageImage":
@@ -19,21 +10,23 @@ function formatAttachmentsGraphQLResponse(attachment) {
19
10
  type: "photo",
20
11
  ID: attachment.legacy_attachment_id,
21
12
  filename: attachment.filename,
22
- original_extension: getExtension(
23
- attachment.original_extension,
24
- attachment.filename
25
- ),
26
13
  thumbnailUrl: attachment.thumbnail.uri,
14
+
27
15
  previewUrl: attachment.preview.uri,
28
16
  previewWidth: attachment.preview.width,
29
17
  previewHeight: attachment.preview.height,
18
+
30
19
  largePreviewUrl: attachment.large_preview.uri,
31
20
  largePreviewHeight: attachment.large_preview.height,
32
21
  largePreviewWidth: attachment.large_preview.width,
33
- url: attachment.large_preview.uri,
34
- width: attachment.large_preview.width,
35
- height: attachment.large_preview.height,
36
- name: attachment.filename,
22
+
23
+ // You have to query for the real image. See below.
24
+ url: attachment.large_preview.uri, // @Legacy
25
+ width: attachment.large_preview.width, // @Legacy
26
+ height: attachment.large_preview.height, // @Legacy
27
+ name: attachment.filename, // @Legacy
28
+
29
+ // @Undocumented
37
30
  attributionApp: attachment.attribution_app
38
31
  ? {
39
32
  attributionAppID: attachment.attribution_app.id,
@@ -41,30 +34,48 @@ function formatAttachmentsGraphQLResponse(attachment) {
41
34
  logo: attachment.attribution_app.square_logo,
42
35
  }
43
36
  : null,
37
+
38
+ // @TODO No idea what this is, should we expose it?
39
+ // Ben - July 15th 2017
40
+ // renderAsSticker: attachment.render_as_sticker,
41
+
42
+ // This is _not_ the real URI, this is still just a large preview.
43
+ // To get the URL we'll need to support a POST query to
44
+ //
45
+ // https://www.facebook.com/webgraphql/query/
46
+ //
47
+ // With the following query params:
48
+ //
49
+ // query_id:728987990612546
50
+ // variables:{"id":"100009069356507","photoID":"10213724771692996"}
51
+ // dpr:1
52
+ //
53
+ // No special form though.
44
54
  };
45
55
  case "MessageAnimatedImage":
46
56
  return {
47
57
  type: "animated_image",
48
58
  ID: attachment.legacy_attachment_id,
49
59
  filename: attachment.filename,
50
- original_extension: getExtension(
51
- attachment.original_extension,
52
- attachment.filename
53
- ),
60
+
54
61
  previewUrl: attachment.preview_image.uri,
55
62
  previewWidth: attachment.preview_image.width,
56
63
  previewHeight: attachment.preview_image.height,
64
+
57
65
  url: attachment.animated_image.uri,
58
66
  width: attachment.animated_image.width,
59
67
  height: attachment.animated_image.height,
60
- thumbnailUrl: attachment.preview_image.uri,
61
- name: attachment.filename,
62
- facebookUrl: attachment.animated_image.uri,
63
- rawGifImage: attachment.animated_image.uri,
64
- animatedGifUrl: attachment.animated_image.uri,
65
- animatedGifPreviewUrl: attachment.preview_image.uri,
66
- animatedWebpUrl: attachment.animated_image.uri,
67
- animatedWebpPreviewUrl: attachment.preview_image.uri,
68
+
69
+ thumbnailUrl: attachment.preview_image.uri, // @Legacy
70
+ name: attachment.filename, // @Legacy
71
+ facebookUrl: attachment.animated_image.uri, // @Legacy
72
+ rawGifImage: attachment.animated_image.uri, // @Legacy
73
+ animatedGifUrl: attachment.animated_image.uri, // @Legacy
74
+ animatedGifPreviewUrl: attachment.preview_image.uri, // @Legacy
75
+ animatedWebpUrl: attachment.animated_image.uri, // @Legacy
76
+ animatedWebpPreviewUrl: attachment.preview_image.uri, // @Legacy
77
+
78
+ // @Undocumented
68
79
  attributionApp: attachment.attribution_app
69
80
  ? {
70
81
  attributionAppID: attachment.attribution_app.id,
@@ -76,107 +87,185 @@ function formatAttachmentsGraphQLResponse(attachment) {
76
87
  case "MessageVideo":
77
88
  return {
78
89
  type: "video",
79
- ID: attachment.legacy_attachment_id,
80
90
  filename: attachment.filename,
81
- original_extension: getExtension(
82
- attachment.original_extension,
83
- attachment.filename
84
- ),
85
- duration: attachment.playable_duration_in_ms,
86
- thumbnailUrl: attachment.large_image.uri,
91
+ ID: attachment.legacy_attachment_id,
92
+
93
+ thumbnailUrl: attachment.large_image.uri, // @Legacy
94
+
87
95
  previewUrl: attachment.large_image.uri,
88
96
  previewWidth: attachment.large_image.width,
89
97
  previewHeight: attachment.large_image.height,
98
+
90
99
  url: attachment.playable_url,
91
100
  width: attachment.original_dimensions.x,
92
101
  height: attachment.original_dimensions.y,
93
- videoType: attachment.video_type?.toLowerCase(),
102
+
103
+ duration: attachment.playable_duration_in_ms,
104
+ videoType: attachment.video_type.toLowerCase(),
94
105
  };
95
106
  case "MessageFile":
96
107
  return {
97
108
  type: "file",
98
- ID: attachment.message_file_fbid,
99
109
  filename: attachment.filename,
100
- original_extension: getExtension(
101
- attachment.original_extension,
102
- attachment.filename
103
- ),
110
+ ID: attachment.message_file_fbid,
111
+
104
112
  url: attachment.url,
105
113
  isMalicious: attachment.is_malicious,
106
114
  contentType: attachment.content_type,
107
- name: attachment.filename,
108
- mimeType: "",
109
- fileSize: -1,
115
+
116
+ name: attachment.filename, // @Legacy
117
+ mimeType: "", // @Legacy
118
+ fileSize: -1, // @Legacy
110
119
  };
111
120
  case "MessageAudio":
112
121
  return {
113
122
  type: "audio",
114
- ID: attachment.url_shimhash,
115
123
  filename: attachment.filename,
116
- original_extension: getExtension(
117
- attachment.original_extension,
118
- attachment.filename
119
- ),
120
- duration: attachment.playable_duration_in_ms,
124
+ ID: attachment.url_shimhash, // Not fowardable
125
+
121
126
  audioType: attachment.audio_type,
127
+ duration: attachment.playable_duration_in_ms,
122
128
  url: attachment.playable_url,
129
+
123
130
  isVoiceMail: attachment.is_voicemail,
124
131
  };
125
132
  default:
126
133
  return {
127
- error: `Don't know about attachment type ${attachment.__typename}`,
134
+ error: "Don't know about attachment type " + attachment.__typename,
128
135
  };
129
136
  }
130
137
  }
131
138
 
132
- // এক্সটেনসিবল শেয়ার কন্টেন্ট ফরম্যাট করার ফাংশন
133
139
  function formatExtensibleAttachment(attachment) {
134
140
  if (attachment.story_attachment) {
135
- const { story_attachment } = attachment;
136
- const media = story_attachment.media;
137
- const hasMedia = media != null && (media.animated_image != null || media.image != null);
138
- const mediaUri = hasMedia ? (media.animated_image || media.image).uri : null;
139
- const mediaWidth = hasMedia ? (media.animated_image || media.image).width : null;
140
- const mediaHeight = hasMedia ? (media.animated_image || media.image).height : null;
141
-
142
141
  return {
143
142
  type: "share",
144
143
  ID: attachment.legacy_attachment_id,
145
- url: story_attachment.url,
146
- title: story_attachment.title_with_entities?.text,
147
- description: story_attachment.description?.text,
148
- source: story_attachment.source?.text,
149
- image: mediaUri,
150
- width: mediaWidth,
151
- height: mediaHeight,
152
- playable: media?.is_playable,
153
- duration: media?.playable_duration_in_ms,
154
- playableUrl: media?.playable_url,
155
- subattachments: story_attachment.subattachments,
156
- properties: (story_attachment.properties || []).reduce((obj, cur) => {
157
- obj[cur.key] = cur.value?.text;
144
+ url: attachment.story_attachment.url,
145
+
146
+ title: attachment.story_attachment.title_with_entities.text,
147
+ description:
148
+ attachment.story_attachment.description &&
149
+ attachment.story_attachment.description.text,
150
+ source:
151
+ attachment.story_attachment.source == null
152
+ ? null
153
+ : attachment.story_attachment.source.text,
154
+
155
+ image:
156
+ attachment.story_attachment.media == null
157
+ ? null
158
+ : attachment.story_attachment.media.animated_image == null &&
159
+ attachment.story_attachment.media.image == null
160
+ ? null
161
+ : (
162
+ attachment.story_attachment.media.animated_image ||
163
+ attachment.story_attachment.media.image
164
+ ).uri,
165
+ width:
166
+ attachment.story_attachment.media == null
167
+ ? null
168
+ : attachment.story_attachment.media.animated_image == null &&
169
+ attachment.story_attachment.media.image == null
170
+ ? null
171
+ : (
172
+ attachment.story_attachment.media.animated_image ||
173
+ attachment.story_attachment.media.image
174
+ ).width,
175
+ height:
176
+ attachment.story_attachment.media == null
177
+ ? null
178
+ : attachment.story_attachment.media.animated_image == null &&
179
+ attachment.story_attachment.media.image == null
180
+ ? null
181
+ : (
182
+ attachment.story_attachment.media.animated_image ||
183
+ attachment.story_attachment.media.image
184
+ ).height,
185
+ playable:
186
+ attachment.story_attachment.media == null
187
+ ? null
188
+ : attachment.story_attachment.media.is_playable,
189
+ duration:
190
+ attachment.story_attachment.media == null
191
+ ? null
192
+ : attachment.story_attachment.media.playable_duration_in_ms,
193
+ playableUrl:
194
+ attachment.story_attachment.media == null
195
+ ? null
196
+ : attachment.story_attachment.media.playable_url,
197
+
198
+ subattachments: attachment.story_attachment.subattachments,
199
+
200
+ // Format example:
201
+ //
202
+ // [{
203
+ // key: "width",
204
+ // value: { text: "1280" }
205
+ // }]
206
+ //
207
+ // That we turn into:
208
+ //
209
+ // {
210
+ // width: "1280"
211
+ // }
212
+ //
213
+ properties: attachment.story_attachment.properties.reduce(function (
214
+ obj,
215
+ cur,
216
+ ) {
217
+ obj[cur.key] = cur.value.text;
158
218
  return obj;
159
219
  }, {}),
160
- animatedImageSize: "",
161
- facebookUrl: "",
162
- styleList: "",
163
- target: "",
164
- thumbnailUrl: mediaUri,
165
- thumbnailWidth: mediaWidth,
166
- thumbnailHeight: mediaHeight,
220
+
221
+ // Deprecated fields
222
+ animatedImageSize: "", // @Legacy
223
+ facebookUrl: "", // @Legacy
224
+ styleList: "", // @Legacy
225
+ target: "", // @Legacy
226
+ thumbnailUrl:
227
+ attachment.story_attachment.media == null
228
+ ? null
229
+ : attachment.story_attachment.media.animated_image == null &&
230
+ attachment.story_attachment.media.image == null
231
+ ? null
232
+ : (
233
+ attachment.story_attachment.media.animated_image ||
234
+ attachment.story_attachment.media.image
235
+ ).uri, // @Legacy
236
+ thumbnailWidth:
237
+ attachment.story_attachment.media == null
238
+ ? null
239
+ : attachment.story_attachment.media.animated_image == null &&
240
+ attachment.story_attachment.media.image == null
241
+ ? null
242
+ : (
243
+ attachment.story_attachment.media.animated_image ||
244
+ attachment.story_attachment.media.image
245
+ ).width, // @Legacy
246
+ thumbnailHeight:
247
+ attachment.story_attachment.media == null
248
+ ? null
249
+ : attachment.story_attachment.media.animated_image == null &&
250
+ attachment.story_attachment.media.image == null
251
+ ? null
252
+ : (
253
+ attachment.story_attachment.media.animated_image ||
254
+ attachment.story_attachment.media.image
255
+ ).height, // @Legacy
167
256
  };
257
+ } else {
258
+ return { error: "Don't know what to do with extensible_attachment." };
168
259
  }
169
- return { error: "Don't know what to do with extensible_attachment." };
170
260
  }
171
261
 
172
262
  function formatReactionsGraphQL(reaction) {
173
263
  return {
174
264
  reaction: reaction.reaction,
175
- userID: reaction.user?.id,
265
+ userID: reaction.user.id,
176
266
  };
177
267
  }
178
268
 
179
- // অ্যাডমিন ইভেন্ট ডাটা ম্যাপিং
180
269
  function formatEventData(event) {
181
270
  if (event == null) {
182
271
  return {};
@@ -184,24 +273,30 @@ function formatEventData(event) {
184
273
 
185
274
  switch (event.__typename) {
186
275
  case "ThemeColorExtensibleMessageAdminText":
187
- return { color: event.theme_color };
276
+ return {
277
+ color: event.theme_color,
278
+ };
188
279
  case "ThreadNicknameExtensibleMessageAdminText":
189
280
  return {
190
281
  nickname: event.nickname,
191
282
  participantID: event.participant_id,
192
283
  };
193
284
  case "ThreadIconExtensibleMessageAdminText":
194
- return { threadIcon: event.thread_icon };
285
+ return {
286
+ threadIcon: event.thread_icon,
287
+ };
195
288
  case "InstantGameUpdateExtensibleMessageAdminText":
196
289
  return {
197
- gameID: event.game?.id,
290
+ gameID: event.game == null ? null : event.game.id,
198
291
  update_type: event.update_type,
199
292
  collapsed_text: event.collapsed_text,
200
293
  expanded_text: event.expanded_text,
201
294
  instant_game_update_data: event.instant_game_update_data,
202
295
  };
203
296
  case "GameScoreExtensibleMessageAdminText":
204
- return { game_type: event.game_type };
297
+ return {
298
+ game_type: event.game_type,
299
+ };
205
300
  case "RtcCallLogExtensibleMessageAdminText":
206
301
  return {
207
302
  event: event.event,
@@ -236,6 +331,7 @@ function formatEventData(event) {
236
331
  ad_preferences_link: event.ad_preferences_link,
237
332
  ad_properties: event.ad_properties,
238
333
  };
334
+ // never data
239
335
  case "ParticipantJoinedGroupCallExtensibleMessageAdminText":
240
336
  case "ThreadEphemeralTtlModeExtensibleMessageAdminText":
241
337
  case "StartedSharingVideoExtensibleMessageAdminText":
@@ -249,50 +345,58 @@ function formatEventData(event) {
249
345
  return {};
250
346
  default:
251
347
  return {
252
- error: `Don't know what to with event data type ${event.__typename}`,
348
+ error: "Don't know what to with event data type " + event.__typename,
253
349
  };
254
350
  }
255
351
  }
256
352
 
257
- // সম্পূর্ণ চ্যাট হিস্ট্রি পার্স করার মেইন হেল্পার
258
353
  function formatMessagesGraphQLResponse(data) {
259
- const messageThread = data.o0.data.message_thread;
260
- const threadID = messageThread.thread_key.thread_fbid
354
+ var messageThread = data.o0.data.message_thread;
355
+ var threadID = messageThread.thread_key.thread_fbid
261
356
  ? messageThread.thread_key.thread_fbid
262
357
  : messageThread.thread_key.other_user_id;
263
358
 
264
- return messageThread.messages.nodes.map(d => {
359
+ var messages = messageThread.messages.nodes.map(function (d) {
265
360
  switch (d.__typename) {
266
361
  case "UserMessage":
267
- let maybeStickerAttachment = null;
362
+ // Give priority to stickers. They're seen as normal messages but we've
363
+ // been considering them as attachments.
364
+ var maybeStickerAttachment;
268
365
  if (d.sticker) {
269
366
  maybeStickerAttachment = [
270
367
  {
271
368
  type: "sticker",
272
369
  ID: d.sticker.id,
273
370
  url: d.sticker.url,
274
- packID: d.sticker.pack?.id,
371
+
372
+ packID: d.sticker.pack.id,
275
373
  spriteUrl: d.sticker.sprite_image,
276
374
  spriteUrl2x: d.sticker.sprite_image_2x,
277
375
  width: d.sticker.width,
278
376
  height: d.sticker.height,
279
- caption: d.snippet,
280
- description: d.sticker.label,
377
+
378
+ caption: d.snippet, // Not sure what the heck caption was.
379
+ description: d.sticker.label, // Not sure about this one either.
380
+
281
381
  frameCount: d.sticker.frame_count,
282
382
  frameRate: d.sticker.frame_rate,
283
383
  framesPerRow: d.sticker.frames_per_row,
284
384
  framesPerCol: d.sticker.frames_per_col,
285
- stickerID: d.sticker.id,
286
- spriteURI: d.sticker.sprite_image,
287
- spriteURI2x: d.sticker.sprite_image_2x,
385
+
386
+ stickerID: d.sticker.id, // @Legacy
387
+ spriteURI: d.sticker.sprite_image, // @Legacy
388
+ spriteURI2x: d.sticker.sprite_image_2x, // @Legacy
288
389
  },
289
390
  ];
290
391
  }
291
392
 
292
- const mentionsObj = {};
393
+ var mentionsObj = {};
293
394
  if (d.message !== null) {
294
- d.message.ranges.forEach(e => {
295
- mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length);
395
+ d.message.ranges.forEach((e) => {
396
+ mentionsObj[e.entity.id] = d.message.text.substr(
397
+ e.offset,
398
+ e.length,
399
+ );
296
400
  });
297
401
  }
298
402
 
@@ -311,8 +415,11 @@ function formatMessagesGraphQLResponse(data) {
311
415
  senderID: d.message_sender.id,
312
416
  threadID: threadID,
313
417
  timestamp: d.timestamp_precise,
418
+
314
419
  mentions: mentionsObj,
315
420
  isUnread: d.unread,
421
+
422
+ // New
316
423
  messageReactions: d.message_reactions
317
424
  ? d.message_reactions.map(formatReactionsGraphQL)
318
425
  : null,
@@ -329,7 +436,11 @@ function formatMessagesGraphQLResponse(data) {
329
436
  timestamp: d.timestamp_precise,
330
437
  eventType: "change_thread_name",
331
438
  snippet: d.snippet,
332
- eventData: { threadName: d.thread_name },
439
+ eventData: {
440
+ threadName: d.thread_name,
441
+ },
442
+
443
+ // @Legacy
333
444
  author: d.message_sender.id,
334
445
  logMessageType: "log:thread-name",
335
446
  logMessageData: { name: d.thread_name },
@@ -346,8 +457,9 @@ function formatMessagesGraphQLResponse(data) {
346
457
  snippet: d.snippet,
347
458
  eventData:
348
459
  d.image_with_metadata == null
349
- ? {}
460
+ ? {} /* removed image */
350
461
  : {
462
+ /* image added */
351
463
  threadImage: {
352
464
  attachmentID: d.image_with_metadata.legacy_attachment_id,
353
465
  width: d.image_with_metadata.original_dimensions.x,
@@ -355,9 +467,13 @@ function formatMessagesGraphQLResponse(data) {
355
467
  url: d.image_with_metadata.preview.uri,
356
468
  },
357
469
  },
470
+
471
+ // @Legacy
358
472
  logMessageType: "log:thread-icon",
359
473
  logMessageData: {
360
- thread_icon: d.image_with_metadata ? d.image_with_metadata.preview.uri : null,
474
+ thread_icon: d.image_with_metadata
475
+ ? d.image_with_metadata.preview.uri
476
+ : null,
361
477
  },
362
478
  };
363
479
  case "ParticipantLeftMessage":
@@ -371,11 +487,18 @@ function formatMessagesGraphQLResponse(data) {
371
487
  eventType: "remove_participants",
372
488
  snippet: d.snippet,
373
489
  eventData: {
374
- participantsRemoved: d.participants_removed.map(p => p.id),
490
+ // Array of IDs.
491
+ participantsRemoved: d.participants_removed.map(function (p) {
492
+ return p.id;
493
+ }),
375
494
  },
495
+
496
+ // @Legacy
376
497
  logMessageType: "log:unsubscribe",
377
498
  logMessageData: {
378
- leftParticipantFbId: d.participants_removed.map(p => p.id),
499
+ leftParticipantFbId: d.participants_removed.map(function (p) {
500
+ return p.id;
501
+ }),
379
502
  },
380
503
  };
381
504
  case "ParticipantsAddedMessage":
@@ -389,11 +512,18 @@ function formatMessagesGraphQLResponse(data) {
389
512
  eventType: "add_participants",
390
513
  snippet: d.snippet,
391
514
  eventData: {
392
- participantsAdded: d.participants_added.map(p => p.id),
515
+ // Array of IDs.
516
+ participantsAdded: d.participants_added.map(function (p) {
517
+ return p.id;
518
+ }),
393
519
  },
520
+
521
+ // @Legacy
394
522
  logMessageType: "log:subscribe",
395
523
  logMessageData: {
396
- addedParticipants: d.participants_added.map(p => p.id),
524
+ addedParticipants: d.participants_added.map(function (p) {
525
+ return p.id;
526
+ }),
397
527
  },
398
528
  };
399
529
  case "VideoCallMessage":
@@ -406,6 +536,8 @@ function formatMessagesGraphQLResponse(data) {
406
536
  timestamp: d.timestamp_precise,
407
537
  eventType: "video_call",
408
538
  snippet: d.snippet,
539
+
540
+ // @Legacy
409
541
  logMessageType: "other",
410
542
  };
411
543
  case "VoiceCallMessage":
@@ -418,6 +550,8 @@ function formatMessagesGraphQLResponse(data) {
418
550
  timestamp: d.timestamp_precise,
419
551
  eventType: "voice_call",
420
552
  snippet: d.snippet,
553
+
554
+ // @Legacy
421
555
  logMessageType: "other",
422
556
  };
423
557
  case "GenericAdminTextMessage":
@@ -431,37 +565,50 @@ function formatMessagesGraphQLResponse(data) {
431
565
  snippet: d.snippet,
432
566
  eventType: d.extensible_message_admin_text_type.toLowerCase(),
433
567
  eventData: formatEventData(d.extensible_message_admin_text),
568
+
569
+ // @Legacy
434
570
  logMessageType: utils.getAdminTextMessageType(
435
- d.extensible_message_admin_text_type
571
+ d.extensible_message_admin_text_type,
436
572
  ),
437
- logMessageData: d.extensible_message_admin_text,
573
+ logMessageData: d.extensible_message_admin_text, // Maybe different?
438
574
  };
439
575
  default:
440
- return { error: `Don't know about message type ${d.__typename}` };
576
+ return { error: "Don't know about message type " + d.__typename };
441
577
  }
442
578
  });
579
+ return messages;
443
580
  }
444
581
 
445
582
  module.exports = function (defaultFuncs, api, ctx) {
446
- return function getThreadHistoryGraphQL(threadID, amount, timestamp, callback) {
447
- let resolveFunc = () => {};
448
- let rejectFunc = () => {};
449
- const returnPromise = new Promise((resolve, reject) => {
583
+ return function getThreadHistoryGraphQL(
584
+ threadID,
585
+ amount,
586
+ timestamp,
587
+ callback,
588
+ ) {
589
+ var resolveFunc = function () {};
590
+ var rejectFunc = function () {};
591
+ var returnPromise = new Promise(function (resolve, reject) {
450
592
  resolveFunc = resolve;
451
593
  rejectFunc = reject;
452
594
  });
453
595
 
454
596
  if (!callback) {
455
- callback = (err, data) => {
456
- if (err) return rejectFunc(err);
597
+ callback = function (err, data) {
598
+ if (err) {
599
+ return rejectFunc(err);
600
+ }
457
601
  resolveFunc(data);
458
602
  };
459
603
  }
460
604
 
461
- const form = {
605
+ // `queries` has to be a string. I couldn't tell from the dev console. This
606
+ // took me a really long time to figure out. I deserve a cookie for this.
607
+ var form = {
462
608
  av: ctx.globalOptions.pageID,
463
609
  queries: JSON.stringify({
464
610
  o0: {
611
+ // This doc_id was valid on February 2nd 2017.
465
612
  doc_id: "1498317363570230",
466
613
  query_params: {
467
614
  id: threadID,
@@ -477,17 +624,21 @@ module.exports = function (defaultFuncs, api, ctx) {
477
624
  defaultFuncs
478
625
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
479
626
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
480
- .then(resData => {
627
+ .then(function (resData) {
481
628
  if (resData.error) {
482
629
  throw resData;
483
630
  }
631
+ // This returns us an array of things. The last one is the success /
632
+ // failure one.
633
+ // @TODO What do we do in this case?
484
634
  if (resData[resData.length - 1].error_results !== 0) {
485
- throw new Error("There was an error_result in GraphQLBatch.");
635
+ throw new Error("There was an error_result.");
486
636
  }
487
- return callback(null, formatMessagesGraphQLResponse(resData[0]));
637
+
638
+ callback(null, formatMessagesGraphQLResponse(resData[0]));
488
639
  })
489
- .catch(err => {
490
- utils.error("getThreadHistoryGraphQL", err);
640
+ .catch(function (err) {
641
+ log.error("getThreadHistoryGraphQL", err);
491
642
  return callback(err);
492
643
  });
493
644