alicezetion 1.2.9 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/index.js +2 -5
  4. package/leiamnash/addExternalModule.js +10 -6
  5. package/leiamnash/addUserToGroup.js +52 -16
  6. package/leiamnash/changeAdminStatus.js +69 -37
  7. package/leiamnash/changeArchivedStatus.js +26 -12
  8. package/leiamnash/changeBio.js +19 -6
  9. package/leiamnash/changeBlockedStatus.js +14 -3
  10. package/leiamnash/changeGroupImage.js +40 -16
  11. package/leiamnash/changeNickname.js +27 -11
  12. package/leiamnash/changeThreadColor.js +20 -10
  13. package/leiamnash/changeThreadEmoji.js +24 -10
  14. package/leiamnash/chat.js +414 -279
  15. package/leiamnash/createNewGroup.js +28 -12
  16. package/leiamnash/createPoll.js +25 -13
  17. package/leiamnash/deleteMessage.js +24 -12
  18. package/leiamnash/deleteThread.js +25 -11
  19. package/leiamnash/forwardAttachment.js +26 -13
  20. package/leiamnash/getCurrentUserID.js +1 -1
  21. package/leiamnash/getEmojiUrl.js +4 -2
  22. package/leiamnash/getFriendsList.js +21 -10
  23. package/leiamnash/getThreadHistory.js +166 -58
  24. package/leiamnash/getThreadHistoryDeprecated.js +42 -20
  25. package/leiamnash/getThreadInfo.js +60 -25
  26. package/leiamnash/getThreadInfoDeprecated.js +42 -18
  27. package/leiamnash/getThreadList.js +66 -41
  28. package/leiamnash/getThreadListDeprecated.js +43 -14
  29. package/leiamnash/getThreadPictures.js +37 -17
  30. package/leiamnash/getUserID.js +14 -9
  31. package/leiamnash/getUserInfo.js +18 -12
  32. package/leiamnash/handleFriendRequest.js +52 -37
  33. package/leiamnash/handleMessageRequest.js +32 -14
  34. package/leiamnash/httpGet.js +17 -12
  35. package/leiamnash/httpPost.js +17 -12
  36. package/leiamnash/listenMqtt.js +2 -1
  37. package/leiamnash/logout.js +20 -13
  38. package/leiamnash/markAsDelivered.js +22 -11
  39. package/leiamnash/markAsRead.js +21 -11
  40. package/leiamnash/markAsReadAll.js +20 -10
  41. package/leiamnash/markAsSeen.js +18 -7
  42. package/leiamnash/muteThread.js +18 -11
  43. package/leiamnash/removeUserFromGroup.js +48 -14
  44. package/leiamnash/resolvePhotoUrl.js +17 -8
  45. package/leiamnash/searchForThread.js +21 -10
  46. package/leiamnash/sendTypingIndicator.js +47 -14
  47. package/leiamnash/setMessageReaction.js +26 -12
  48. package/leiamnash/setPostReaction.js +26 -13
  49. package/leiamnash/setTitle.js +29 -13
  50. package/leiamnash/threadColors.js +44 -28
  51. package/leiamnash/unfriend.js +19 -9
  52. package/leiamnash/unsendMessage.js +19 -9
  53. package/package.json +1 -1
  54. package/replit.nix +3 -1
  55. package/utils.js +0 -0
  56. package/leiamnash/forwardMessage.js +0 -0
  57. package/leiamnash/listen.js +0 -553
  58. package/leiamnash/listenMqtt-Test.js +0 -687
@@ -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,54 @@ 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
  };
258
+ } else {
259
+ return { error: "Don't know what to do with extensible_attachment." };
186
260
  }
187
- else return { error: "Don't know what to do with extensible_attachment." };
188
261
  }
189
262
 
190
263
  function formatReactionsGraphQL(reaction) {
@@ -195,18 +268,24 @@ function formatReactionsGraphQL(reaction) {
195
268
  }
196
269
 
197
270
  function formatEventData(event) {
198
- if (event == null) return {}
271
+ if (event == null) {
272
+ return {};
273
+ }
199
274
 
200
275
  switch (event.__typename) {
201
276
  case "ThemeColorExtensibleMessageAdminText":
202
- return { color: event.theme_color };
277
+ return {
278
+ color: event.theme_color
279
+ };
203
280
  case "ThreadNicknameExtensibleMessageAdminText":
204
281
  return {
205
282
  nickname: event.nickname,
206
283
  participantID: event.participant_id
207
284
  };
208
285
  case "ThreadIconExtensibleMessageAdminText":
209
- return { threadIcon: event.thread_icon };
286
+ return {
287
+ threadIcon: event.thread_icon
288
+ };
210
289
  case "InstantGameUpdateExtensibleMessageAdminText":
211
290
  return {
212
291
  gameID: (event.game == null ? null : event.game.id),
@@ -216,7 +295,9 @@ function formatEventData(event) {
216
295
  instant_game_update_data: event.instant_game_update_data
217
296
  };
218
297
  case "GameScoreExtensibleMessageAdminText":
219
- return { game_type: event.game_type };
298
+ return {
299
+ game_type: event.game_type
300
+ };
220
301
  case "RtcCallLogExtensibleMessageAdminText":
221
302
  return {
222
303
  event: event.event,
@@ -264,15 +345,19 @@ function formatEventData(event) {
264
345
  case "LightweightEventDeleteExtensibleMessageAdminText":
265
346
  return {};
266
347
  default:
267
- return { error: "Don't know what to with event data type " + event.__typename };
348
+ return {
349
+ error: "Don't know what to with event data type " + event.__typename
350
+ };
268
351
  }
269
352
  }
270
353
 
271
354
  function formatMessagesGraphQLResponse(data) {
272
355
  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;
356
+ var threadID = messageThread.thread_key.thread_fbid
357
+ ? messageThread.thread_key.thread_fbid
358
+ : messageThread.thread_key.other_user_id;
274
359
 
275
- var messages = messageThread.messages.nodes.map(function (d) {
360
+ var messages = messageThread.messages.nodes.map(function(d) {
276
361
  switch (d.__typename) {
277
362
  case "UserMessage":
278
363
  // Give priority to stickers. They're seen as normal messages but we've
@@ -308,7 +393,9 @@ function formatMessagesGraphQLResponse(data) {
308
393
 
309
394
  var mentionsObj = {};
310
395
  if (d.message !== null) {
311
- d.message.ranges.forEach(e => mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length));
396
+ d.message.ranges.forEach(e => {
397
+ mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length);
398
+ });
312
399
  }
313
400
 
314
401
  return {
@@ -331,7 +418,9 @@ function formatMessagesGraphQLResponse(data) {
331
418
  isUnread: d.unread,
332
419
 
333
420
  // New
334
- messageReactions: d.message_reactions ? d.message_reactions.map(formatReactionsGraphQL) : null,
421
+ messageReactions: d.message_reactions
422
+ ? d.message_reactions.map(formatReactionsGraphQL)
423
+ : null,
335
424
  isSponsored: d.is_sponsored,
336
425
  snippet: d.snippet
337
426
  };
@@ -345,7 +434,9 @@ function formatMessagesGraphQLResponse(data) {
345
434
  timestamp: d.timestamp_precise,
346
435
  eventType: "change_thread_name",
347
436
  snippet: d.snippet,
348
- eventData: { threadName: d.thread_name },
437
+ eventData: {
438
+ threadName: d.thread_name
439
+ },
349
440
 
350
441
  // @Legacy
351
442
  author: d.message_sender.id,
@@ -362,21 +453,26 @@ function formatMessagesGraphQLResponse(data) {
362
453
  timestamp: d.timestamp_precise,
363
454
  eventType: "change_thread_image",
364
455
  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
- },
456
+ eventData:
457
+ d.image_with_metadata == null
458
+ ? {} /* removed image */
459
+ : {
460
+ /* image added */
461
+ threadImage: {
462
+ attachmentID: d.image_with_metadata.legacy_attachment_id,
463
+ width: d.image_with_metadata.original_dimensions.x,
464
+ height: d.image_with_metadata.original_dimensions.y,
465
+ url: d.image_with_metadata.preview.uri
466
+ }
467
+ },
376
468
 
377
469
  // @Legacy
378
470
  logMessageType: "log:thread-icon",
379
- logMessageData: { thread_icon: d.image_with_metadata ? d.image_with_metadata.preview.uri : null }
471
+ logMessageData: {
472
+ thread_icon: d.image_with_metadata
473
+ ? d.image_with_metadata.preview.uri
474
+ : null
475
+ }
380
476
  };
381
477
  case "ParticipantLeftMessage":
382
478
  return {
@@ -390,7 +486,7 @@ function formatMessagesGraphQLResponse(data) {
390
486
  snippet: d.snippet,
391
487
  eventData: {
392
488
  // Array of IDs.
393
- participantsRemoved: d.participants_removed.map(function (p) {
489
+ participantsRemoved: d.participants_removed.map(function(p) {
394
490
  return p.id;
395
491
  })
396
492
  },
@@ -398,7 +494,7 @@ function formatMessagesGraphQLResponse(data) {
398
494
  // @Legacy
399
495
  logMessageType: "log:unsubscribe",
400
496
  logMessageData: {
401
- leftParticipantFbId: d.participants_removed.map(function (p) {
497
+ leftParticipantFbId: d.participants_removed.map(function(p) {
402
498
  return p.id;
403
499
  })
404
500
  }
@@ -415,7 +511,7 @@ function formatMessagesGraphQLResponse(data) {
415
511
  snippet: d.snippet,
416
512
  eventData: {
417
513
  // Array of IDs.
418
- participantsAdded: d.participants_added.map(function (p) {
514
+ participantsAdded: d.participants_added.map(function(p) {
419
515
  return p.id;
420
516
  })
421
517
  },
@@ -423,7 +519,7 @@ function formatMessagesGraphQLResponse(data) {
423
519
  // @Legacy
424
520
  logMessageType: "log:subscribe",
425
521
  logMessageData: {
426
- addedParticipants: d.participants_added.map(function (p) {
522
+ addedParticipants: d.participants_added.map(function(p) {
427
523
  return p.id;
428
524
  })
429
525
  }
@@ -481,10 +577,15 @@ function formatMessagesGraphQLResponse(data) {
481
577
  return messages;
482
578
  }
483
579
 
484
- module.exports = function (defaultFuncs, api, ctx) {
485
- return function getThreadHistoryGraphQL(threadID, amount, timestamp, callback) {
486
- var resolveFunc = function () { };
487
- var rejectFunc = function () { };
580
+ module.exports = function(defaultFuncs, api, ctx) {
581
+ return function getThreadHistoryGraphQL(
582
+ threadID,
583
+ amount,
584
+ timestamp,
585
+ callback
586
+ ) {
587
+ var resolveFunc = function(){};
588
+ var rejectFunc = function(){};
488
589
  var returnPromise = new Promise(function (resolve, reject) {
489
590
  resolveFunc = resolve;
490
591
  rejectFunc = reject;
@@ -492,7 +593,9 @@ module.exports = function (defaultFuncs, api, ctx) {
492
593
 
493
594
  if (!callback) {
494
595
  callback = function (err, data) {
495
- if (err) return rejectFunc(err);
596
+ if (err) {
597
+ return rejectFunc(err);
598
+ }
496
599
  resolveFunc(data);
497
600
  };
498
601
  }
@@ -519,15 +622,20 @@ module.exports = function (defaultFuncs, api, ctx) {
519
622
  defaultFuncs
520
623
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
521
624
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
522
- .then(function (resData) {
523
- if (resData.error) throw resData;
625
+ .then(function(resData) {
626
+ if (resData.error) {
627
+ throw resData;
628
+ }
524
629
  // This returns us an array of things. The last one is the success /
525
630
  // failure one.
526
631
  // @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.");
632
+ if (resData[resData.length - 1].error_results !== 0) {
633
+ throw new Error("There was an error_result.");
634
+ }
635
+
528
636
  callback(null, formatMessagesGraphQLResponse(resData[0]));
529
637
  })
530
- .catch(function (err) {
638
+ .catch(function(err) {
531
639
  log.error("getThreadHistoryGraphQL", err);
532
640
  return callback(err);
533
641
  });
@@ -3,54 +3,73 @@
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 () { };
8
+ var resolveFunc = function(){};
9
+ var rejectFunc = function(){};
10
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) {
17
- if (err) return rejectFunc(err);
18
- resolveFunc(threadInfo);
16
+ callback = function (err, friendList) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(friendList);
19
21
  };
20
22
  }
21
23
 
22
- if (!callback) throw { error: "getThreadHistory: need callback" };
24
+ if (!callback) {
25
+ throw { error: "getThreadHistory: need callback" };
26
+ }
27
+
23
28
  var form = {
24
29
  client: "mercury"
25
30
  };
26
31
 
27
- api.getUserInfo(threadID, function (err, res) {
28
- if (err) return callback(err);
32
+ api.getUserInfo(threadID, function(err, res) {
33
+ if (err) {
34
+ return callback(err);
35
+ }
29
36
  var key = Object.keys(res).length > 0 ? "user_ids" : "thread_fbids";
30
37
  form["messages[" + key + "][" + threadID + "][offset]"] = 0;
31
38
  form["messages[" + key + "][" + threadID + "][timestamp]"] = timestamp;
32
39
  form["messages[" + key + "][" + threadID + "][limit]"] = amount;
33
40
 
34
- if (ctx.globalOptions.pageID) form.request_user_id = ctx.globalOptions.pageID;
41
+ if (ctx.globalOptions.pageID)
42
+ form.request_user_id = ctx.globalOptions.pageID;
35
43
 
36
44
  defaultFuncs
37
- .post("https://www.facebook.com/ajax/mercury/thread_info.php", ctx.jar, form)
45
+ .post(
46
+ "https://www.facebook.com/ajax/mercury/thread_info.php",
47
+ ctx.jar,
48
+ form
49
+ )
38
50
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
39
- .then(function (resData) {
40
- if (resData.error) throw resData;
41
- else if (!resData.payload) throw { error: "Could not retrieve thread history." };
51
+ .then(function(resData) {
52
+ if (resData.error) {
53
+ throw resData;
54
+ } else if (!resData.payload) {
55
+ throw { error: "Could not retrieve thread history." };
56
+ }
42
57
 
43
58
  // Asking for message history from a thread with no message history
44
59
  // will return undefined for actions here
45
- if (!resData.payload.actions) resData.payload.actions = [];
60
+ if (!resData.payload.actions) {
61
+ resData.payload.actions = [];
62
+ }
46
63
 
47
64
  var userIDs = {};
48
- resData.payload.actions.forEach(v => userIDs[v.author.split(":").pop()] = "");
65
+ resData.payload.actions.forEach(function(v) {
66
+ userIDs[v.author.split(":").pop()] = "";
67
+ });
49
68
 
50
- api.getUserInfo(Object.keys(userIDs), function (err, data) {
69
+ api.getUserInfo(Object.keys(userIDs), function(err, data) {
51
70
  if (err) return callback(err); //callback({error: "Could not retrieve user information in getThreadHistory."});
52
71
 
53
- resData.payload.actions.forEach(function (v) {
72
+ resData.payload.actions.forEach(function(v) {
54
73
  var sender = data[v.author.split(":").pop()];
55
74
  if (sender) v.sender_name = sender.name;
56
75
  else v.sender_name = "Facebook User";
@@ -58,10 +77,13 @@ module.exports = function (defaultFuncs, api, ctx) {
58
77
  delete v.author;
59
78
  });
60
79
 
61
- callback(null, resData.payload.actions.map(utils.formatHistoryMessage));
80
+ callback(
81
+ null,
82
+ resData.payload.actions.map(utils.formatHistoryMessage)
83
+ );
62
84
  });
63
85
  })
64
- .catch(function (err) {
86
+ .catch(function(err) {
65
87
  log.error("getThreadHistory", err);
66
88
  return callback(err);
67
89
  });
@@ -21,7 +21,7 @@ function formatEventReminders(reminder) {
21
21
  secondsToNotifyBefore: reminder.seconds_to_notify_before,
22
22
  allowsRsvp: reminder.allows_rsvp,
23
23
  relatedEvent: reminder.related_event,
24
- members: reminder.event_reminder_members.edges.map(function (member) {
24
+ members: reminder.event_reminder_members.edges.map(function(member) {
25
25
  return {
26
26
  memberID: member.node.id,
27
27
  state: member.guest_list_state.toLowerCase()
@@ -31,15 +31,33 @@ function formatEventReminders(reminder) {
31
31
  }
32
32
 
33
33
  function formatThreadGraphQLResponse(data) {
34
- var messageThread = data.o0.data.message_thread;
35
- var threadID = messageThread.thread_key.thread_fbid ? messageThread.thread_key.thread_fbid : messageThread.thread_key.other_user_id;
34
+ try{
35
+ var messageThread = data.o0.data.message_thread;
36
+ } catch (err){
37
+ console.error("GetThreadInfoGraphQL", "Can't get this thread info!");
38
+ return {err: err};
39
+ }
40
+ var threadID = messageThread.thread_key.thread_fbid
41
+ ? messageThread.thread_key.thread_fbid
42
+ : messageThread.thread_key.other_user_id;
36
43
 
37
44
  // Remove me
38
45
  var lastM = messageThread.last_message;
39
- var snippetID = lastM && lastM.nodes && lastM.nodes[0] && lastM.nodes[0].message_sender && lastM.nodes[0].message_sender.messaging_actor ? lastM.nodes[0].message_sender.messaging_actor.id : null;
40
- var snippetText = lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
46
+ var snippetID =
47
+ lastM &&
48
+ lastM.nodes &&
49
+ lastM.nodes[0] &&
50
+ lastM.nodes[0].message_sender &&
51
+ lastM.nodes[0].message_sender.messaging_actor
52
+ ? lastM.nodes[0].message_sender.messaging_actor.id
53
+ : null;
54
+ var snippetText =
55
+ lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
41
56
  var lastR = messageThread.last_read_receipt;
42
- var lastReadTimestamp = lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise ? lastR.nodes[0].timestamp_precise : null;
57
+ var lastReadTimestamp =
58
+ lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise
59
+ ? lastR.nodes[0].timestamp_precise
60
+ : null;
43
61
 
44
62
  return {
45
63
  threadID: threadID,
@@ -66,16 +84,27 @@ function formatThreadGraphQLResponse(data) {
66
84
  isArchived: messageThread.has_viewer_archived,
67
85
  folder: messageThread.folder,
68
86
  cannotReplyReason: messageThread.cannot_reply_reason,
69
- eventReminders: messageThread.event_reminders ? messageThread.event_reminders.nodes.map(formatEventReminders) : null,
70
- emoji: messageThread.customization_info ? messageThread.customization_info.emoji : null,
71
- color: messageThread.customization_info && messageThread.customization_info.outgoing_bubble_color ? messageThread.customization_info.outgoing_bubble_color.slice(2) : null,
87
+ eventReminders: messageThread.event_reminders
88
+ ? messageThread.event_reminders.nodes.map(formatEventReminders)
89
+ : null,
90
+ emoji: messageThread.customization_info
91
+ ? messageThread.customization_info.emoji
92
+ : null,
93
+ color:
94
+ messageThread.customization_info &&
95
+ messageThread.customization_info.outgoing_bubble_color
96
+ ? messageThread.customization_info.outgoing_bubble_color.slice(2)
97
+ : null,
72
98
  nicknames:
73
99
  messageThread.customization_info &&
74
- messageThread.customization_info.participant_customizations
75
- ? messageThread.customization_info.participant_customizations.reduce(function (res, val) {
76
- if (val.nickname) res[val.participant_id] = val.nickname;
77
- return res;
78
- }, {})
100
+ messageThread.customization_info.participant_customizations
101
+ ? messageThread.customization_info.participant_customizations.reduce(
102
+ function(res, val) {
103
+ if (val.nickname) res[val.participant_id] = val.nickname;
104
+ return res;
105
+ },
106
+ {}
107
+ )
79
108
  : {},
80
109
  adminIDs: messageThread.thread_admins,
81
110
  approvalMode: Boolean(messageThread.approval_mode),
@@ -105,17 +134,19 @@ function formatThreadGraphQLResponse(data) {
105
134
  hasEmailParticipant: false,
106
135
  readOnly: false,
107
136
  canReply: messageThread.cannot_reply_reason == null,
108
- lastMessageTimestamp: messageThread.last_message ? messageThread.last_message.timestamp_precise : null,
137
+ lastMessageTimestamp: messageThread.last_message
138
+ ? messageThread.last_message.timestamp_precise
139
+ : null,
109
140
  lastMessageType: "message",
110
141
  lastReadTimestamp: lastReadTimestamp,
111
142
  threadType: messageThread.thread_type == "GROUP" ? 2 : 1
112
143
  };
113
144
  }
114
145
 
115
- module.exports = function (defaultFuncs, api, ctx) {
146
+ module.exports = function(defaultFuncs, api, ctx) {
116
147
  return function getThreadInfoGraphQL(threadID, callback) {
117
- var resolveFunc = function () { };
118
- var rejectFunc = function () { };
148
+ var resolveFunc = function(){};
149
+ var rejectFunc = function(){};
119
150
  var returnPromise = new Promise(function (resolve, reject) {
120
151
  resolveFunc = resolve;
121
152
  rejectFunc = reject;
@@ -123,7 +154,9 @@ module.exports = function (defaultFuncs, api, ctx) {
123
154
 
124
155
  if (utils.getType(callback) != "Function" && utils.getType(callback) != "AsyncFunction") {
125
156
  callback = function (err, data) {
126
- if (err) return rejectFunc(err);
157
+ if (err) {
158
+ return rejectFunc(err);
159
+ }
127
160
  resolveFunc(data);
128
161
  };
129
162
  }
@@ -150,19 +183,21 @@ module.exports = function (defaultFuncs, api, ctx) {
150
183
  defaultFuncs
151
184
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
152
185
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
153
- .then(function (resData) {
154
- if (resData.error) throw resData;
186
+ .then(function(resData) {
187
+ if (resData.error) {
188
+ throw resData;
189
+ }
155
190
  // This returns us an array of things. The last one is the success /
156
191
  // failure one.
157
192
  // @TODO What do we do in this case?
158
193
  if (resData[resData.length - 1].error_results !== 0) {
159
- console.log(resData); //Log more info
160
- throw new Error("well darn there was an error_result");
194
+ console.error("GetThreadInfo", "Well darn there was an error_result");
161
195
  }
196
+
162
197
  callback(null, formatThreadGraphQLResponse(resData[0]));
163
198
  })
164
- .catch(function (err) {
165
- log.error("getThreadInfoGraphQL", "Can't get thread info");
199
+ .catch(function(err) {
200
+ log.error("getThreadInfoGraphQL", err);
166
201
  return callback(err);
167
202
  });
168
203