node-ainzfb-new 1.6.2902-test → 1.6.2911-test

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. package/package.json +7 -7
  2. package/src/addExternalModule.js +13 -6
  3. package/src/addUserToGroup.js +35 -12
  4. package/src/changeAdminStatus.js +32 -16
  5. package/src/changeArchivedStatus.js +15 -9
  6. package/src/changeAvt.js +75 -69
  7. package/src/changeBio.js +12 -8
  8. package/src/changeBlockedStatus.js +14 -8
  9. package/src/changeGroupImage.js +27 -13
  10. package/src/changeNickname.js +19 -10
  11. package/src/changeThreadColor.js +15 -10
  12. package/src/changeThreadEmoji.js +17 -9
  13. package/src/createNewGroup.js +18 -10
  14. package/src/createPoll.js +16 -11
  15. package/src/deleteMessage.js +16 -10
  16. package/src/deleteThread.js +16 -10
  17. package/src/forwardAttachment.js +14 -9
  18. package/src/getAccessToken.js +21 -21
  19. package/src/getCurrentUserID.js +1 -1
  20. package/src/getEmojiUrl.js +3 -2
  21. package/src/getFriendsList.js +18 -10
  22. package/src/getMessage.js +52 -48
  23. package/src/getThreadHistory.js +156 -59
  24. package/src/getThreadHistoryDeprecated.js +26 -15
  25. package/src/getThreadInfo.js +3423 -18
  26. package/src/getThreadInfoDeprecated.js +25 -13
  27. package/src/getThreadList.js +112 -53
  28. package/src/getThreadListDeprecated.js +30 -12
  29. package/src/getThreadPictures.js +25 -13
  30. package/src/getUserID.js +7 -7
  31. package/src/getUserInfo.js +12 -9
  32. package/src/getUserInfoV2.js +19 -22
  33. package/src/handleFriendRequest.js +10 -9
  34. package/src/handleMessageRequest.js +16 -10
  35. package/src/httpGet.js +18 -13
  36. package/src/httpPost.js +18 -13
  37. package/src/httpPostFormData.js +14 -9
  38. package/src/listenMqtt.js +1218 -571
  39. package/src/logout.js +18 -13
  40. package/src/markAsDelivered.js +16 -10
  41. package/src/markAsRead.js +36 -24
  42. package/src/markAsReadAll.js +14 -10
  43. package/src/markAsSeen.js +18 -11
  44. package/src/muteThread.js +12 -8
  45. package/src/removeUserFromGroup.js +33 -10
  46. package/src/resolvePhotoUrl.js +8 -6
  47. package/src/searchForThread.js +13 -8
  48. package/src/sendMessage.js +172 -78
  49. package/src/sendTypingIndicator.js +29 -14
  50. package/src/setMessageReaction.js +13 -8
  51. package/src/setPostReaction.js +97 -95
  52. package/src/setTitle.js +18 -12
  53. package/src/threadColors.js +17 -17
  54. package/src/unfriend.js +14 -9
  55. package/src/unsendMessage.js +7 -7
  56. package/utils.js +2 -2
package/src/getMessage.js CHANGED
@@ -5,76 +5,80 @@ var utils = require("../utils");
5
5
  var log = require("npmlog");
6
6
 
7
7
  module.exports = function(defaultFuncs, api, ctx) {
8
- return function getMessage(threadID, messageID, callback) {
9
- if (!callback) {
10
- return callback({ error: "getMessage: need callback" });
11
- }
8
+ return function getMessage(threadID, messageID, callback) {
9
+ if (!callback) {
10
+ return callback({ error: "getMessage: need callback" });
11
+ }
12
12
 
13
- if (!threadID || !messageID) {
14
- return callback({ error: "getMessage: need threadID and messageID" });
15
- }
13
+ if (!threadID || !messageID) {
14
+ return callback({ error: "getMessage: need threadID and messageID" });
15
+ }
16
16
 
17
- const form = {
18
- "av": ctx.globalOptions.pageID,
19
- "queries": JSON.stringify({
20
- "o0": {
21
- //This doc_id is valid as of ? (prob January 18, 2020)
22
- "doc_id": "1768656253222505",
23
- "query_params": {
24
- "thread_and_message_id": {
25
- "thread_id": threadID,
26
- "message_id": messageID,
27
- }
17
+ const form = {
18
+ av: ctx.globalOptions.pageID,
19
+ queries: JSON.stringify({
20
+ o0: {
21
+ //This doc_id is valid as of ? (prob January 18, 2020)
22
+ doc_id: "1768656253222505",
23
+ query_params: {
24
+ thread_and_message_id: {
25
+ thread_id: threadID,
26
+ message_id: messageID
28
27
  }
29
28
  }
30
- })
31
- };
29
+ }
30
+ })
31
+ };
32
32
 
33
- defaultFuncs
33
+ defaultFuncs
34
34
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
35
35
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
- .then((resData) => {
36
+ .then(resData => {
37
37
  if (resData[resData.length - 1].error_results > 0) {
38
38
  throw resData[0].o0.errors;
39
39
  }
40
40
 
41
41
  if (resData[resData.length - 1].successful_results === 0) {
42
- throw { error: "getMessage: there was no successful_results", res: resData };
42
+ throw {
43
+ error: "getMessage: there was no successful_results",
44
+ res: resData
45
+ };
43
46
  }
44
47
 
45
48
  var fetchData = resData[0].o0.data.message;
46
49
  if (fetchData) {
47
50
  (!ctx.globalOptions.selfListen &&
48
51
  fetchData.message_sender.id.toString() === ctx.userID) ||
49
- !ctx.loggedIn ?
50
- undefined :
51
- (function () { callback(null, {
52
- threadID: threadID,
53
- messageID: fetchData.message_id,
54
- senderID: fetchData.message_sender.id,
55
- attachments: fetchData.blob_attachments.map(att => {
52
+ !ctx.loggedIn
53
+ ? undefined
54
+ : (function() {
55
+ callback(null, {
56
+ threadID: threadID,
57
+ messageID: fetchData.message_id,
58
+ senderID: fetchData.message_sender.id,
59
+ attachments: fetchData.blob_attachments.map(att => {
56
60
  var x;
57
61
  try {
58
- x = utils._formatAttachment(att);
62
+ x = utils._formatAttachment(att);
59
63
  } catch (ex) {
60
- x = att;
61
- x.error = ex;
62
- x.type = "unknown";
64
+ x = att;
65
+ x.error = ex;
66
+ x.type = "unknown";
63
67
  }
64
68
  return x;
65
- }),
66
- body: fetchData.message.text,
67
- mentions: fetchData.message.ranges,
68
- timestamp: fetchData.timestamp_precise,
69
- messageReply: fetchData.replied_to_message,
70
- raw: fetchData,
71
- }); })();
69
+ }),
70
+ body: fetchData.message.text,
71
+ mentions: fetchData.message.ranges,
72
+ timestamp: fetchData.timestamp_precise,
73
+ messageReply: fetchData.replied_to_message,
74
+ raw: fetchData
75
+ });
76
+ })();
72
77
  }
73
- })
74
- .catch((err) => {
75
- log.error("getMessage", err);
76
- callback(err);
77
- });
78
-
78
+ })
79
+ .catch(err => {
80
+ log.error("getMessage", err);
81
+ callback(err);
82
+ });
79
83
  };
80
- };
84
+ };
@@ -29,10 +29,10 @@ function formatAttachmentsGraphQLResponse(attachment) {
29
29
  // @Undocumented
30
30
  attributionApp: attachment.attribution_app
31
31
  ? {
32
- attributionAppID: attachment.attribution_app.id,
33
- name: attachment.attribution_app.name,
34
- logo: attachment.attribution_app.square_logo
35
- }
32
+ attributionAppID: attachment.attribution_app.id,
33
+ name: attachment.attribution_app.name,
34
+ logo: attachment.attribution_app.square_logo
35
+ }
36
36
  : null
37
37
 
38
38
  // @TODO No idea what this is, should we expose it?
@@ -78,10 +78,10 @@ function formatAttachmentsGraphQLResponse(attachment) {
78
78
  // @Undocumented
79
79
  attributionApp: attachment.attribution_app
80
80
  ? {
81
- attributionAppID: attachment.attribution_app.id,
82
- name: attachment.attribution_app.name,
83
- logo: attachment.attribution_app.square_logo
84
- }
81
+ attributionAppID: attachment.attribution_app.id,
82
+ name: attachment.attribution_app.name,
83
+ logo: attachment.attribution_app.square_logo
84
+ }
85
85
  : null
86
86
  };
87
87
  case "MessageVideo":
@@ -144,15 +144,56 @@ function formatExtensibleAttachment(attachment) {
144
144
  url: attachment.story_attachment.url,
145
145
 
146
146
  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,
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,
156
197
 
157
198
  subattachments: attachment.story_attachment.subattachments,
158
199
 
@@ -169,22 +210,52 @@ function formatExtensibleAttachment(attachment) {
169
210
  // width: "1280"
170
211
  // }
171
212
  //
172
- properties: attachment.story_attachment.properties.reduce(function (obj, cur) {
213
+ properties: attachment.story_attachment.properties.reduce(function(
214
+ obj,
215
+ cur
216
+ ) {
173
217
  obj[cur.key] = cur.value.text;
174
218
  return obj;
175
- }, {}),
219
+ },
220
+ {}),
176
221
 
177
222
  // Deprecated fields
178
223
  animatedImageSize: "", // @Legacy
179
224
  facebookUrl: "", // @Legacy
180
225
  styleList: "", // @Legacy
181
226
  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
227
+ thumbnailUrl:
228
+ attachment.story_attachment.media == null
229
+ ? null
230
+ : attachment.story_attachment.media.animated_image == null &&
231
+ attachment.story_attachment.media.image == null
232
+ ? null
233
+ : (
234
+ attachment.story_attachment.media.animated_image ||
235
+ attachment.story_attachment.media.image
236
+ ).uri, // @Legacy
237
+ thumbnailWidth:
238
+ attachment.story_attachment.media == null
239
+ ? null
240
+ : attachment.story_attachment.media.animated_image == null &&
241
+ attachment.story_attachment.media.image == null
242
+ ? null
243
+ : (
244
+ attachment.story_attachment.media.animated_image ||
245
+ attachment.story_attachment.media.image
246
+ ).width, // @Legacy
247
+ thumbnailHeight:
248
+ attachment.story_attachment.media == null
249
+ ? null
250
+ : attachment.story_attachment.media.animated_image == null &&
251
+ attachment.story_attachment.media.image == null
252
+ ? null
253
+ : (
254
+ attachment.story_attachment.media.animated_image ||
255
+ attachment.story_attachment.media.image
256
+ ).height // @Legacy
185
257
  };
186
- }
187
- else return { error: "Don't know what to do with extensible_attachment." };
258
+ } else return { error: "Don't know what to do with extensible_attachment." };
188
259
  }
189
260
 
190
261
  function formatReactionsGraphQL(reaction) {
@@ -195,7 +266,7 @@ function formatReactionsGraphQL(reaction) {
195
266
  }
196
267
 
197
268
  function formatEventData(event) {
198
- if (event == null) return {}
269
+ if (event == null) return {};
199
270
 
200
271
  switch (event.__typename) {
201
272
  case "ThemeColorExtensibleMessageAdminText":
@@ -209,7 +280,7 @@ function formatEventData(event) {
209
280
  return { threadIcon: event.thread_icon };
210
281
  case "InstantGameUpdateExtensibleMessageAdminText":
211
282
  return {
212
- gameID: (event.game == null ? null : event.game.id),
283
+ gameID: event.game == null ? null : event.game.id,
213
284
  update_type: event.update_type,
214
285
  collapsed_text: event.collapsed_text,
215
286
  expanded_text: event.expanded_text,
@@ -264,15 +335,19 @@ function formatEventData(event) {
264
335
  case "LightweightEventDeleteExtensibleMessageAdminText":
265
336
  return {};
266
337
  default:
267
- return { error: "Don't know what to with event data type " + event.__typename };
338
+ return {
339
+ error: "Don't know what to with event data type " + event.__typename
340
+ };
268
341
  }
269
342
  }
270
343
 
271
344
  function formatMessagesGraphQLResponse(data) {
272
345
  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;
346
+ var threadID = messageThread.thread_key.thread_fbid
347
+ ? messageThread.thread_key.thread_fbid
348
+ : messageThread.thread_key.other_user_id;
274
349
 
275
- var messages = messageThread.messages.nodes.map(function (d) {
350
+ var messages = messageThread.messages.nodes.map(function(d) {
276
351
  switch (d.__typename) {
277
352
  case "UserMessage":
278
353
  // Give priority to stickers. They're seen as normal messages but we've
@@ -308,7 +383,13 @@ function formatMessagesGraphQLResponse(data) {
308
383
 
309
384
  var mentionsObj = {};
310
385
  if (d.message !== null) {
311
- d.message.ranges.forEach(e => mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length));
386
+ d.message.ranges.forEach(
387
+ e =>
388
+ (mentionsObj[e.entity.id] = d.message.text.substr(
389
+ e.offset,
390
+ e.length
391
+ ))
392
+ );
312
393
  }
313
394
 
314
395
  return {
@@ -320,7 +401,7 @@ function formatMessagesGraphQLResponse(data) {
320
401
  : d.extensible_attachment
321
402
  ? [formatExtensibleAttachment(d.extensible_attachment)]
322
403
  : [],
323
- body: d.message !== null ? d.message.text : '',
404
+ body: d.message !== null ? d.message.text : "",
324
405
  isGroup: messageThread.thread_type === "GROUP",
325
406
  messageID: d.message_id,
326
407
  senderID: d.message_sender.id,
@@ -331,7 +412,9 @@ function formatMessagesGraphQLResponse(data) {
331
412
  isUnread: d.unread,
332
413
 
333
414
  // New
334
- messageReactions: d.message_reactions ? d.message_reactions.map(formatReactionsGraphQL) : null,
415
+ messageReactions: d.message_reactions
416
+ ? d.message_reactions.map(formatReactionsGraphQL)
417
+ : null,
335
418
  isSponsored: d.is_sponsored,
336
419
  snippet: d.snippet
337
420
  };
@@ -362,21 +445,26 @@ function formatMessagesGraphQLResponse(data) {
362
445
  timestamp: d.timestamp_precise,
363
446
  eventType: "change_thread_image",
364
447
  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
- },
448
+ eventData:
449
+ d.image_with_metadata == null
450
+ ? {} /* removed image */
451
+ : {
452
+ /* image added */
453
+ threadImage: {
454
+ attachmentID: d.image_with_metadata.legacy_attachment_id,
455
+ width: d.image_with_metadata.original_dimensions.x,
456
+ height: d.image_with_metadata.original_dimensions.y,
457
+ url: d.image_with_metadata.preview.uri
458
+ }
459
+ },
376
460
 
377
461
  // @Legacy
378
462
  logMessageType: "log:thread-icon",
379
- logMessageData: { thread_icon: d.image_with_metadata ? d.image_with_metadata.preview.uri : null }
463
+ logMessageData: {
464
+ thread_icon: d.image_with_metadata
465
+ ? d.image_with_metadata.preview.uri
466
+ : null
467
+ }
380
468
  };
381
469
  case "ParticipantLeftMessage":
382
470
  return {
@@ -390,7 +478,7 @@ function formatMessagesGraphQLResponse(data) {
390
478
  snippet: d.snippet,
391
479
  eventData: {
392
480
  // Array of IDs.
393
- participantsRemoved: d.participants_removed.map(function (p) {
481
+ participantsRemoved: d.participants_removed.map(function(p) {
394
482
  return p.id;
395
483
  })
396
484
  },
@@ -398,7 +486,7 @@ function formatMessagesGraphQLResponse(data) {
398
486
  // @Legacy
399
487
  logMessageType: "log:unsubscribe",
400
488
  logMessageData: {
401
- leftParticipantFbId: d.participants_removed.map(function (p) {
489
+ leftParticipantFbId: d.participants_removed.map(function(p) {
402
490
  return p.id;
403
491
  })
404
492
  }
@@ -415,7 +503,7 @@ function formatMessagesGraphQLResponse(data) {
415
503
  snippet: d.snippet,
416
504
  eventData: {
417
505
  // Array of IDs.
418
- participantsAdded: d.participants_added.map(function (p) {
506
+ participantsAdded: d.participants_added.map(function(p) {
419
507
  return p.id;
420
508
  })
421
509
  },
@@ -423,7 +511,7 @@ function formatMessagesGraphQLResponse(data) {
423
511
  // @Legacy
424
512
  logMessageType: "log:subscribe",
425
513
  logMessageData: {
426
- addedParticipants: d.participants_added.map(function (p) {
514
+ addedParticipants: d.participants_added.map(function(p) {
427
515
  return p.id;
428
516
  })
429
517
  }
@@ -481,17 +569,22 @@ function formatMessagesGraphQLResponse(data) {
481
569
  return messages;
482
570
  }
483
571
 
484
- 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) {
572
+ module.exports = function(defaultFuncs, api, ctx) {
573
+ return function getThreadHistoryGraphQL(
574
+ threadID,
575
+ amount,
576
+ timestamp,
577
+ callback
578
+ ) {
579
+ var resolveFunc = function() {};
580
+ var rejectFunc = function() {};
581
+ var returnPromise = new Promise(function(resolve, reject) {
489
582
  resolveFunc = resolve;
490
583
  rejectFunc = reject;
491
584
  });
492
585
 
493
586
  if (!callback) {
494
- callback = function (err, data) {
587
+ callback = function(err, data) {
495
588
  if (err) return rejectFunc(err);
496
589
  resolveFunc(data);
497
590
  };
@@ -500,7 +593,7 @@ module.exports = function (defaultFuncs, api, ctx) {
500
593
  // `queries` has to be a string. I couldn't tell from the dev console. This
501
594
  // took me a really long time to figure out. I deserve a cookie for this.
502
595
  var form = {
503
- "av": ctx.globalOptions.pageID,
596
+ av: ctx.globalOptions.pageID,
504
597
  queries: JSON.stringify({
505
598
  o0: {
506
599
  // This doc_id was valid on February 2nd 2017.
@@ -519,16 +612,20 @@ module.exports = function (defaultFuncs, api, ctx) {
519
612
  defaultFuncs
520
613
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
521
614
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
522
- .then(function (resData) {
615
+ .then(function(resData) {
523
616
  if (resData.error) throw resData;
524
617
  // This returns us an array of things. The last one is the success /
525
618
  // failure one.
526
619
  // @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.");
620
+ if (resData[resData.length - 1].error_results !== 0)
621
+ throw new Error("There was an error_result.");
528
622
  callback(null, formatMessagesGraphQLResponse(resData[0]));
529
623
  })
530
- .catch(function (err) {
531
- log.error("getThreadHistoryGraphQL", "Lỗi getThreadHistoryGraphQL Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !");
624
+ .catch(function(err) {
625
+ log.error(
626
+ "getThreadHistoryGraphQL",
627
+ "Lỗi getThreadHistoryGraphQL Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !"
628
+ );
532
629
  return callback(err);
533
630
  });
534
631
 
@@ -3,17 +3,17 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function (defaultFuncs, api, ctx) {
6
+ module.exports = function(defaultFuncs, api, ctx) {
7
7
  return function getThreadHistory(threadID, amount, timestamp, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
- var returnPromise = new Promise(function (resolve, reject) {
8
+ var resolveFunc = function() {};
9
+ var rejectFunc = function() {};
10
+ var returnPromise = new Promise(function(resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
15
  if (!callback) {
16
- callback = function (err, threadInfo) {
16
+ callback = function(err, threadInfo) {
17
17
  if (err) return rejectFunc(err);
18
18
  resolveFunc(threadInfo);
19
19
  };
@@ -24,33 +24,41 @@ module.exports = function (defaultFuncs, api, ctx) {
24
24
  client: "mercury"
25
25
  };
26
26
 
27
- api.getUserInfo(threadID, function (err, res) {
27
+ api.getUserInfo(threadID, function(err, res) {
28
28
  if (err) return callback(err);
29
29
  var key = Object.keys(res).length > 0 ? "user_ids" : "thread_fbids";
30
30
  form["messages[" + key + "][" + threadID + "][offset]"] = 0;
31
31
  form["messages[" + key + "][" + threadID + "][timestamp]"] = timestamp;
32
32
  form["messages[" + key + "][" + threadID + "][limit]"] = amount;
33
33
 
34
- if (ctx.globalOptions.pageID) form.request_user_id = ctx.globalOptions.pageID;
34
+ if (ctx.globalOptions.pageID)
35
+ form.request_user_id = ctx.globalOptions.pageID;
35
36
 
36
37
  defaultFuncs
37
- .post("https://www.facebook.com/ajax/mercury/thread_info.php", ctx.jar, form)
38
+ .post(
39
+ "https://www.facebook.com/ajax/mercury/thread_info.php",
40
+ ctx.jar,
41
+ form
42
+ )
38
43
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
39
- .then(function (resData) {
44
+ .then(function(resData) {
40
45
  if (resData.error) throw resData;
41
- else if (!resData.payload) throw { error: "Could not retrieve thread history." };
46
+ else if (!resData.payload)
47
+ throw { error: "Could not retrieve thread history." };
42
48
 
43
49
  // Asking for message history from a thread with no message history
44
50
  // will return undefined for actions here
45
51
  if (!resData.payload.actions) resData.payload.actions = [];
46
52
 
47
53
  var userIDs = {};
48
- resData.payload.actions.forEach(v => userIDs[v.author.split(":").pop()] = "");
54
+ resData.payload.actions.forEach(
55
+ v => (userIDs[v.author.split(":").pop()] = "")
56
+ );
49
57
 
50
- api.getUserInfo(Object.keys(userIDs), function (err, data) {
58
+ api.getUserInfo(Object.keys(userIDs), function(err, data) {
51
59
  if (err) return callback(err); //callback({error: "Could not retrieve user information in getThreadHistory."});
52
60
 
53
- resData.payload.actions.forEach(function (v) {
61
+ resData.payload.actions.forEach(function(v) {
54
62
  var sender = data[v.author.split(":").pop()];
55
63
  if (sender) v.sender_name = sender.name;
56
64
  else v.sender_name = "Facebook User";
@@ -58,10 +66,13 @@ module.exports = function (defaultFuncs, api, ctx) {
58
66
  delete v.author;
59
67
  });
60
68
 
61
- callback(null, resData.payload.actions.map(utils.formatHistoryMessage));
69
+ callback(
70
+ null,
71
+ resData.payload.actions.map(utils.formatHistoryMessage)
72
+ );
62
73
  });
63
74
  })
64
- .catch(function (err) {
75
+ .catch(function(err) {
65
76
  log.error("getThreadHistory", err);
66
77
  return callback(err);
67
78
  });