alicezetion 1.0.9 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) 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 +558 -490
  4. package/leiamnash/addExternalModule.js +19 -0
  5. package/{src → leiamnash}/addUserToGroup.js +52 -16
  6. package/leiamnash/changeAdminStatus.js +79 -0
  7. package/leiamnash/changeArchivedStatus.js +55 -0
  8. package/{src → leiamnash}/changeBio.js +19 -6
  9. package/{src → leiamnash}/changeBlockedStatus.js +14 -3
  10. package/{src → leiamnash}/changeGroupImage.js +40 -16
  11. package/leiamnash/changeNickname.js +59 -0
  12. package/{src → leiamnash}/changeThreadColor.js +20 -10
  13. package/leiamnash/changeThreadEmoji.js +55 -0
  14. package/leiamnash/chat.js +459 -0
  15. package/{src → leiamnash}/createNewGroup.js +28 -12
  16. package/{src → leiamnash}/createPoll.js +25 -13
  17. package/leiamnash/deleteMessage.js +56 -0
  18. package/leiamnash/deleteThread.js +56 -0
  19. package/leiamnash/forwardAttachment.js +60 -0
  20. package/{src → leiamnash}/getCurrentUserID.js +1 -1
  21. package/{src → leiamnash}/getEmojiUrl.js +4 -2
  22. package/{src → leiamnash}/getFriendsList.js +21 -10
  23. package/{src → leiamnash}/getThreadHistory.js +166 -58
  24. package/{src → leiamnash}/getThreadHistoryDeprecated.js +42 -20
  25. package/{src → leiamnash}/getThreadInfo.js +60 -25
  26. package/leiamnash/getThreadInfoDeprecated.js +80 -0
  27. package/{src → leiamnash}/getThreadList.js +66 -41
  28. package/leiamnash/getThreadListDeprecated.js +75 -0
  29. package/leiamnash/getThreadPictures.js +79 -0
  30. package/{src → leiamnash}/getUserID.js +14 -9
  31. package/{src → leiamnash}/getUserInfo.js +18 -12
  32. package/leiamnash/handleFriendRequest.js +61 -0
  33. package/leiamnash/handleMessageRequest.js +65 -0
  34. package/{src → leiamnash}/httpGet.js +17 -12
  35. package/{src → leiamnash}/httpPost.js +17 -12
  36. package/leiamnash/listenMqtt.js +687 -0
  37. package/{src → leiamnash}/logout.js +20 -13
  38. package/{src → leiamnash}/markAsDelivered.js +22 -11
  39. package/{src → leiamnash}/markAsRead.js +21 -11
  40. package/{src → leiamnash}/markAsReadAll.js +20 -10
  41. package/{src → leiamnash}/markAsSeen.js +18 -7
  42. package/{src → leiamnash}/muteThread.js +18 -11
  43. package/leiamnash/removeUserFromGroup.js +79 -0
  44. package/{src → leiamnash}/resolvePhotoUrl.js +17 -8
  45. package/{src → leiamnash}/searchForThread.js +21 -10
  46. package/{src → leiamnash}/sendTypingIndicator.js +47 -14
  47. package/{src → leiamnash}/setMessageReaction.js +26 -12
  48. package/{src → leiamnash}/setPostReaction.js +26 -13
  49. package/{src → leiamnash}/setTitle.js +29 -13
  50. package/leiamnash/threadColors.js +57 -0
  51. package/{src → leiamnash}/unfriend.js +19 -9
  52. package/{src → leiamnash}/unsendMessage.js +19 -9
  53. package/package.json +9 -14
  54. package/replit.nix +0 -1
  55. package/utils.js +1193 -1023
  56. package/src/addExternalModule.js +0 -15
  57. package/src/changeAdminStatus.js +0 -47
  58. package/src/changeArchivedStatus.js +0 -41
  59. package/src/changeNickname.js +0 -43
  60. package/src/changeThreadEmoji.js +0 -41
  61. package/src/chat.js +0 -315
  62. package/src/deleteMessage.js +0 -44
  63. package/src/deleteThread.js +0 -42
  64. package/src/forwardAttachment.js +0 -47
  65. package/src/forwardMessage.js +0 -0
  66. package/src/getThreadInfoDeprecated.js +0 -56
  67. package/src/getThreadListDeprecated.js +0 -46
  68. package/src/getThreadPictures.js +0 -59
  69. package/src/handleFriendRequest.js +0 -46
  70. package/src/handleMessageRequest.js +0 -47
  71. package/src/listen.js +0 -553
  72. package/src/listenMqtt-Test.js +0 -687
  73. package/src/listenMqtt.js +0 -677
  74. package/src/removeUserFromGroup.js +0 -45
  75. package/src/threadColors.js +0 -41
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, api, ctx) {
7
+ return function deleteThread(threadOrThreads, callback) {
8
+ var resolveFunc = function(){};
9
+ var rejectFunc = function(){};
10
+ var returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+ if (!callback) {
15
+ callback = function(err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+
23
+ var form = {
24
+ client: "mercury"
25
+ };
26
+
27
+ if (utils.getType(threadOrThreads) !== "Array") {
28
+ threadOrThreads = [threadOrThreads];
29
+ }
30
+
31
+ for (var i = 0; i < threadOrThreads.length; i++) {
32
+ form["ids[" + i + "]"] = threadOrThreads[i];
33
+ }
34
+
35
+ defaultFuncs
36
+ .post(
37
+ "https://www.facebook.com/ajax/mercury/delete_thread.php",
38
+ ctx.jar,
39
+ form
40
+ )
41
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
42
+ .then(function(resData) {
43
+ if (resData.error) {
44
+ throw resData;
45
+ }
46
+
47
+ return callback();
48
+ })
49
+ .catch(function(err) {
50
+ log.error("deleteThread", err);
51
+ return callback(err);
52
+ });
53
+
54
+ return returnPromise;
55
+ };
56
+ };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, api, ctx) {
7
+ return function forwardAttachment(attachmentID, userOrUsers, callback) {
8
+ var resolveFunc = function(){};
9
+ var rejectFunc = function(){};
10
+ var returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+ if (!callback) {
15
+ callback = function(err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+
23
+ var form = {
24
+ attachment_id: attachmentID
25
+ };
26
+
27
+ if (utils.getType(userOrUsers) !== "Array") {
28
+ userOrUsers = [userOrUsers];
29
+ }
30
+
31
+ var timestamp = Math.floor(Date.now() / 1000);
32
+
33
+ for (var i = 0; i < userOrUsers.length; i++) {
34
+ //That's good, the key of the array is really timestmap in seconds + index
35
+ //Probably time when the attachment will be sent?
36
+ form["recipient_map[" + (timestamp + i) + "]"] = userOrUsers[i];
37
+ }
38
+
39
+ defaultFuncs
40
+ .post(
41
+ "https://www.facebook.com/mercury/attachments/forward/",
42
+ ctx.jar,
43
+ form
44
+ )
45
+ .then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
46
+ .then(function(resData) {
47
+ if (resData.error) {
48
+ throw resData;
49
+ }
50
+
51
+ return callback();
52
+ })
53
+ .catch(function(err) {
54
+ log.error("forwardAttachment", err);
55
+ return callback(err);
56
+ });
57
+
58
+ return returnPromise;
59
+ };
60
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- module.exports = function (defaultFuncs, api, ctx) {
3
+ module.exports = function(defaultFuncs, api, ctx) {
4
4
  return function getCurrentUserID() {
5
5
  return ctx.userID;
6
6
  };
@@ -2,7 +2,7 @@
2
2
 
3
3
  const util = require("util");
4
4
 
5
- module.exports = function () {
5
+ module.exports = function() {
6
6
  return function getEmojiUrl(c, size, pixelRatio) {
7
7
  /*
8
8
  Resolves Facebook Messenger emoji image asset URL for an emoji character.
@@ -19,7 +19,9 @@ module.exports = function () {
19
19
  c.codePointAt(0).toString(16)
20
20
  );
21
21
  let base = 317426846;
22
- for (let i = 0; i < ending.length; i++) base = (base << 5) - base + ending.charCodeAt(i);
22
+ for (let i = 0; i < ending.length; i++) {
23
+ base = (base << 5) - base + ending.charCodeAt(i);
24
+ }
23
25
 
24
26
  let hashed = (base & 255).toString(16);
25
27
  return util.format(baseUrl, hashed, ending);
@@ -21,7 +21,7 @@ var GENDERS = {
21
21
  };
22
22
 
23
23
  function formatData(obj) {
24
- return Object.keys(obj).map(function (key) {
24
+ return Object.keys(obj).map(function(key) {
25
25
  var user = obj[key];
26
26
  return {
27
27
  alternateName: user.alternateName,
@@ -39,10 +39,10 @@ function formatData(obj) {
39
39
  });
40
40
  }
41
41
 
42
- module.exports = function (defaultFuncs, api, ctx) {
42
+ module.exports = function(defaultFuncs, api, ctx) {
43
43
  return function getFriendsList(callback) {
44
- var resolveFunc = function () { };
45
- var rejectFunc = function () { };
44
+ var resolveFunc = function(){};
45
+ var rejectFunc = function(){};
46
46
  var returnPromise = new Promise(function (resolve, reject) {
47
47
  resolveFunc = resolve;
48
48
  rejectFunc = reject;
@@ -50,20 +50,31 @@ module.exports = function (defaultFuncs, api, ctx) {
50
50
 
51
51
  if (!callback) {
52
52
  callback = function (err, friendList) {
53
- if (err) return rejectFunc(err);
53
+ if (err) {
54
+ return rejectFunc(err);
55
+ }
54
56
  resolveFunc(friendList);
55
57
  };
56
58
  }
57
59
 
58
60
  defaultFuncs
59
- .postFormData("https://www.facebook.com/chat/user_info_all", ctx.jar, {}, { viewer: ctx.userID })
61
+ .postFormData(
62
+ "https://www.facebook.com/chat/user_info_all",
63
+ ctx.jar,
64
+ {},
65
+ { viewer: ctx.userID }
66
+ )
60
67
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
61
- .then(function (resData) {
62
- if (!resData) throw { error: "getFriendsList returned empty object." };
63
- if (resData.error) throw resData;
68
+ .then(function(resData) {
69
+ if (!resData) {
70
+ throw { error: "getFriendsList returned empty object." };
71
+ }
72
+ if (resData.error) {
73
+ throw resData;
74
+ }
64
75
  callback(null, formatData(resData.payload));
65
76
  })
66
- .catch(function (err) {
77
+ .catch(function(err) {
67
78
  log.error("getFriendsList", err);
68
79
  return callback(err);
69
80
  });
@@ -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
  });