fca-rqzax-remake 0.0.1-security → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fca-rqzax-remake might be problematic. Click here for more details.

Files changed (87) hide show
  1. package/.breakpoints +58 -0
  2. package/.cache/replit/__replit_disk_meta.json +1 -0
  3. package/.cache/replit/modules.stamp +1 -0
  4. package/.cache/replit/nix/env.json +1 -0
  5. package/.gitattributes +2 -0
  6. package/.replit +1 -0
  7. package/.travis.yml +6 -0
  8. package/.upm/store.json +1 -0
  9. package/CHANGELOG.md +2 -0
  10. package/DOCS.md +1738 -0
  11. package/GetThreads/GetThreadInfo.js +118 -0
  12. package/LICENSE-MIT +21 -0
  13. package/README.md +126 -3
  14. package/StateCrypt.js +28 -0
  15. package/broadcast.js +1 -0
  16. package/index.js +694 -0
  17. package/languages/index.json +150 -0
  18. package/lib/getInfoNew.js +34 -0
  19. package/lib/getToken.js +44 -0
  20. package/logger.js +24 -0
  21. package/package.json +133 -3
  22. package/replit.nix +9 -0
  23. package/src/ReportV1.js +55 -0
  24. package/src/addExternalModule.js +16 -0
  25. package/src/addUserToGroup.js +78 -0
  26. package/src/changeAdminStatus.js +79 -0
  27. package/src/changeArchivedStatus.js +41 -0
  28. package/src/changeAvt.js +86 -0
  29. package/src/changeBio.js +65 -0
  30. package/src/changeBlockedStatus.js +36 -0
  31. package/src/changeGroupImage.js +106 -0
  32. package/src/changeNickname.js +45 -0
  33. package/src/changeThreadColor.js +62 -0
  34. package/src/changeThreadEmoji.js +42 -0
  35. package/src/createNewGroup.js +70 -0
  36. package/src/createPoll.js +60 -0
  37. package/src/data/getThreadInfo.json +25094 -0
  38. package/src/deleteMessage.js +45 -0
  39. package/src/deleteThread.js +43 -0
  40. package/src/forwardAttachment.js +48 -0
  41. package/src/getAccessToken.js +33 -0
  42. package/src/getCurrentUserID.js +7 -0
  43. package/src/getEmojiUrl.js +27 -0
  44. package/src/getFriendsList.js +73 -0
  45. package/src/getMessage.js +80 -0
  46. package/src/getThreadHistory.js +537 -0
  47. package/src/getThreadHistoryDeprecated.js +71 -0
  48. package/src/getThreadInfo.js +193 -0
  49. package/src/getThreadInfoDeprecated.js +56 -0
  50. package/src/getThreadList.js +213 -0
  51. package/src/getThreadListDeprecated.js +46 -0
  52. package/src/getThreadMain.js +219 -0
  53. package/src/getThreadPictures.js +59 -0
  54. package/src/getUserID.js +62 -0
  55. package/src/getUserInfo.js +66 -0
  56. package/src/getUserInfoMain.js +65 -0
  57. package/src/getUserInfoV2.js +36 -0
  58. package/src/getUserInfoV3.js +63 -0
  59. package/src/getUserInfoV4.js +55 -0
  60. package/src/getUserInfoV5.js +61 -0
  61. package/src/handleFriendRequest.js +46 -0
  62. package/src/handleMessageRequest.js +49 -0
  63. package/src/httpGet.js +49 -0
  64. package/src/httpPost.js +48 -0
  65. package/src/httpPostFormData.js +41 -0
  66. package/src/listenMqtt.js +629 -0
  67. package/src/logout.js +68 -0
  68. package/src/markAsDelivered.js +48 -0
  69. package/src/markAsRead.js +70 -0
  70. package/src/markAsReadAll.js +43 -0
  71. package/src/markAsSeen.js +51 -0
  72. package/src/muteThread.js +47 -0
  73. package/src/removeUserFromGroup.js +49 -0
  74. package/src/resolvePhotoUrl.js +37 -0
  75. package/src/searchForThread.js +43 -0
  76. package/src/sendMessage.js +321 -0
  77. package/src/sendTypingIndicator.js +80 -0
  78. package/src/setMessageReaction.js +109 -0
  79. package/src/setPostReaction.js +102 -0
  80. package/src/setTitle.js +74 -0
  81. package/src/threadColors.js +39 -0
  82. package/src/unfriend.js +43 -0
  83. package/src/unsendMessage.js +40 -0
  84. package/test/example-config.json +18 -0
  85. package/test/test-page.js +140 -0
  86. package/test/test.js +385 -0
  87. package/utils.js +1246 -0
package/utils.js ADDED
@@ -0,0 +1,1246 @@
1
+ /* eslint-disable no-prototype-builtins */
2
+ "use strict";
3
+
4
+ const bluebird = require("bluebird");
5
+ var request = bluebird.promisify(require("request").defaults({ jar: true }));
6
+ var stream = require("stream");
7
+ var log = require("npmlog");
8
+ var querystring = require("querystring");
9
+ var url = require("url");
10
+
11
+ function setProxy(url) {
12
+ if (typeof url == undefined) return request = bluebird.promisify(require("request").defaults({ jar: true }));
13
+ return request = bluebird.promisify(require("request").defaults({ jar: true, proxy: url }));
14
+ }
15
+
16
+ function getHeaders(url, options, ctx, customHeader) {
17
+ var headers = {
18
+ "Content-Type": "application/x-www-form-urlencoded",
19
+ Referer: "https://www.facebook.com/",
20
+ Host: url.replace("https://", "").split("/")[0],
21
+ Origin: "https://www.facebook.com",
22
+ "User-Agent": options.userAgent,
23
+ Connection: "keep-alive",
24
+ 'sec-fetch-site': 'same-origin'
25
+ };
26
+ if (customHeader) Object.assign(headers, customHeader);
27
+
28
+ if (ctx && ctx.region) headers["X-MSGR-Region"] = ctx.region;
29
+
30
+ return headers;
31
+ }
32
+
33
+ function isReadableStream(obj) {
34
+ return (
35
+ obj instanceof stream.Stream &&
36
+ (getType(obj._read) === "Function" ||
37
+ getType(obj._read) === "AsyncFunction") &&
38
+ getType(obj._readableState) === "Object"
39
+ );
40
+ }
41
+
42
+ function get(url, jar, qs, options, ctx) {
43
+ // I'm still confused about this
44
+ if (getType(qs) === "Object")
45
+ for (var prop in qs)
46
+ if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") qs[prop] = JSON.stringify(qs[prop]);
47
+ var op = {
48
+ headers: getHeaders(url, options, ctx),
49
+ timeout: 60000,
50
+ qs: qs,
51
+ url: url,
52
+ method: "GET",
53
+ jar: jar,
54
+ gzip: true
55
+ };
56
+
57
+ return request(op).then(function(res) {
58
+ return res[0];
59
+ });
60
+ }
61
+
62
+ function post(url, jar, form, options, ctx, customHeader) {
63
+ let headers = getHeaders(url, options);
64
+ headers['sec-fetch-site'] = 'same-origin';
65
+ var op = {
66
+ headers: headers,
67
+ timeout: 60000,
68
+ url: url,
69
+ method: "POST",
70
+ form: form,
71
+ jar: jar,
72
+ gzip: true
73
+ };
74
+
75
+ return request(op).then(function(res) {
76
+ return res[0];
77
+ });
78
+ }
79
+
80
+ function postFormData(url, jar, form, qs, options, ctx) {
81
+ var headers = getHeaders(url, options, ctx);
82
+ headers["Content-Type"] = "multipart/form-data";
83
+ var op = {
84
+ headers: headers,
85
+ timeout: 60000,
86
+ url: url,
87
+ method: "POST",
88
+ formData: form,
89
+ qs: qs,
90
+ jar: jar,
91
+ gzip: true
92
+ };
93
+
94
+ return request(op).then(function(res) {
95
+ return res[0];
96
+ });
97
+ }
98
+
99
+ function padZeros(val, len) {
100
+ val = String(val);
101
+ len = len || 2;
102
+ while (val.length < len) val = "0" + val;
103
+ return val;
104
+ }
105
+
106
+ function generateThreadingID(clientID) {
107
+ var k = Date.now();
108
+ var l = Math.floor(Math.random() * 4294967295);
109
+ var m = clientID;
110
+ return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
111
+ }
112
+
113
+ function binaryToDecimal(data) {
114
+ var ret = "";
115
+ while (data !== "0") {
116
+ var end = 0;
117
+ var fullName = "";
118
+ var i = 0;
119
+ for (; i < data.length; i++) {
120
+ end = 2 * end + parseInt(data[i], 10);
121
+ if (end >= 10) {
122
+ fullName += "1";
123
+ end -= 10;
124
+ } else fullName += "0";
125
+ }
126
+ ret = end.toString() + ret;
127
+ data = fullName.slice(fullName.indexOf("1"));
128
+ }
129
+ return ret;
130
+ }
131
+
132
+ function generateOfflineThreadingID() {
133
+ var ret = Date.now();
134
+ var value = Math.floor(Math.random() * 4294967295);
135
+ var str = ("0000000000000000000000" + value.toString(2)).slice(-22);
136
+ var msgs = ret.toString(2) + str;
137
+ return binaryToDecimal(msgs);
138
+ }
139
+
140
+ var h;
141
+ var i = {};
142
+ var j = {
143
+ _: "%",
144
+ A: "%2",
145
+ B: "000",
146
+ C: "%7d",
147
+ D: "%7b%22",
148
+ E: "%2c%22",
149
+ F: "%22%3a",
150
+ G: "%2c%22ut%22%3a1",
151
+ H: "%2c%22bls%22%3a",
152
+ I: "%2c%22n%22%3a%22%",
153
+ J: "%22%3a%7b%22i%22%3a0%7d",
154
+ K: "%2c%22pt%22%3a0%2c%22vis%22%3a",
155
+ L: "%2c%22ch%22%3a%7b%22h%22%3a%22",
156
+ M: "%7b%22v%22%3a2%2c%22time%22%3a1",
157
+ N: ".channel%22%2c%22sub%22%3a%5b",
158
+ O: "%2c%22sb%22%3a1%2c%22t%22%3a%5b",
159
+ P: "%2c%22ud%22%3a100%2c%22lc%22%3a0",
160
+ Q: "%5d%2c%22f%22%3anull%2c%22uct%22%3a",
161
+ R: ".channel%22%2c%22sub%22%3a%5b1%5d",
162
+ S: "%22%2c%22m%22%3a0%7d%2c%7b%22i%22%3a",
163
+ T: "%2c%22blc%22%3a1%2c%22snd%22%3a1%2c%22ct%22%3a",
164
+ U: "%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
165
+ V: "%2c%22blc%22%3a0%2c%22snd%22%3a0%2c%22ct%22%3a",
166
+ W: "%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a",
167
+ X: "%2c%22ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1",
168
+ Y: "%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
169
+ Z: "%2c%22sb%22%3a1%2c%22t%22%3a%5b%5d%2c%22f%22%3anull%2c%22uct%22%3a0%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a"
170
+ };
171
+ (function() {
172
+ var l = [];
173
+ for (var m in j) {
174
+ i[j[m]] = m;
175
+ l.push(j[m]);
176
+ }
177
+ l.reverse();
178
+ h = new RegExp(l.join("|"), "g");
179
+ })();
180
+
181
+ function presenceEncode(str) {
182
+ return encodeURIComponent(str)
183
+ .replace(/([_A-Z])|%../g, function(m, n) {
184
+ return n ? "%" + n.charCodeAt(0).toString(16) : m;
185
+ })
186
+ .toLowerCase()
187
+ .replace(h, function(m) {
188
+ return i[m];
189
+ });
190
+ }
191
+
192
+ // eslint-disable-next-line no-unused-vars
193
+ function presenceDecode(str) {
194
+ return decodeURIComponent(
195
+ str.replace(/[_A-Z]/g, function(m) {
196
+ return j[m];
197
+ })
198
+ );
199
+ }
200
+
201
+ function generatePresence(userID) {
202
+ var time = Date.now();
203
+ return (
204
+ "E" +
205
+ presenceEncode(
206
+ JSON.stringify({
207
+ v: 3,
208
+ time: parseInt(time / 1000, 10),
209
+ user: userID,
210
+ state: {
211
+ ut: 0,
212
+ t2: [],
213
+ lm2: null,
214
+ uct2: time,
215
+ tr: null,
216
+ tw: Math.floor(Math.random() * 4294967295) + 1,
217
+ at: time
218
+ },
219
+ ch: {
220
+ ["p_" + userID]: 0
221
+ }
222
+ })
223
+ )
224
+ );
225
+ }
226
+
227
+ function generateAccessiblityCookie() {
228
+ var time = Date.now();
229
+ return encodeURIComponent(
230
+ JSON.stringify({
231
+ sr: 0,
232
+ "sr-ts": time,
233
+ jk: 0,
234
+ "jk-ts": time,
235
+ kb: 0,
236
+ "kb-ts": time,
237
+ hcm: 0,
238
+ "hcm-ts": time
239
+ })
240
+ );
241
+ }
242
+
243
+ function getGUID() {
244
+ /** @type {number} */
245
+ var sectionLength = Date.now();
246
+ /** @type {string} */
247
+ var id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
248
+ /** @type {number} */
249
+ var r = Math.floor((sectionLength + Math.random() * 16) % 16);
250
+ /** @type {number} */
251
+ sectionLength = Math.floor(sectionLength / 16);
252
+ /** @type {string} */
253
+ var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
254
+ return _guid;
255
+ });
256
+ return id;
257
+ }
258
+
259
+ function _formatAttachment(attachment1, attachment2) {
260
+ // TODO: THIS IS REALLY BAD
261
+ // This is an attempt at fixing Facebook's inconsistencies. Sometimes they give us
262
+ // two attachment objects, but sometimes only one. They each contain part of the
263
+ // data that you'd want so we merge them for convenience.
264
+ // Instead of having a bunch of if statements guarding every access to image_data,
265
+ // we set it to empty object and use the fact that it'll return undefined.
266
+ attachment2 = attachment2 || { id: "", image_data: {} };
267
+ attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
268
+ var blob = attachment1.blob_attachment;
269
+ var type =
270
+ blob && blob.__typename ? blob.__typename : attachment1.attach_type;
271
+ if (!type && attachment1.sticker_attachment) {
272
+ type = "StickerAttachment";
273
+ blob = attachment1.sticker_attachment;
274
+ } else if (!type && attachment1.extensible_attachment) {
275
+ if (
276
+ attachment1.extensible_attachment.story_attachment &&
277
+ attachment1.extensible_attachment.story_attachment.target &&
278
+ attachment1.extensible_attachment.story_attachment.target.__typename &&
279
+ attachment1.extensible_attachment.story_attachment.target.__typename === "MessageLocation"
280
+ ) type = "MessageLocation";
281
+ else type = "ExtensibleAttachment";
282
+
283
+ blob = attachment1.extensible_attachment;
284
+ }
285
+ // TODO: Determine whether "sticker", "photo", "file" etc are still used
286
+ // KEEP IN SYNC WITH getThreadHistory
287
+ switch (type) {
288
+ case "sticker":
289
+ return {
290
+ type: "sticker",
291
+ ID: attachment1.metadata.stickerID.toString(),
292
+ url: attachment1.url,
293
+
294
+ packID: attachment1.metadata.packID.toString(),
295
+ spriteUrl: attachment1.metadata.spriteURI,
296
+ spriteUrl2x: attachment1.metadata.spriteURI2x,
297
+ width: attachment1.metadata.width,
298
+ height: attachment1.metadata.height,
299
+
300
+ caption: attachment2.caption,
301
+ description: attachment2.description,
302
+
303
+ frameCount: attachment1.metadata.frameCount,
304
+ frameRate: attachment1.metadata.frameRate,
305
+ framesPerRow: attachment1.metadata.framesPerRow,
306
+ framesPerCol: attachment1.metadata.framesPerCol,
307
+
308
+ stickerID: attachment1.metadata.stickerID.toString(), // @Legacy
309
+ spriteURI: attachment1.metadata.spriteURI, // @Legacy
310
+ spriteURI2x: attachment1.metadata.spriteURI2x // @Legacy
311
+ };
312
+ case "file":
313
+ return {
314
+ type: "file",
315
+ filename: attachment1.name,
316
+ ID: attachment2.id.toString(),
317
+ url: attachment1.url,
318
+
319
+ isMalicious: attachment2.is_malicious,
320
+ contentType: attachment2.mime_type,
321
+
322
+ name: attachment1.name, // @Legacy
323
+ mimeType: attachment2.mime_type, // @Legacy
324
+ fileSize: attachment2.file_size // @Legacy
325
+ };
326
+ case "photo":
327
+ return {
328
+ type: "photo",
329
+ ID: attachment1.metadata.fbid.toString(),
330
+ filename: attachment1.fileName,
331
+ thumbnailUrl: attachment1.thumbnail_url,
332
+
333
+ previewUrl: attachment1.preview_url,
334
+ previewWidth: attachment1.preview_width,
335
+ previewHeight: attachment1.preview_height,
336
+
337
+ largePreviewUrl: attachment1.large_preview_url,
338
+ largePreviewWidth: attachment1.large_preview_width,
339
+ largePreviewHeight: attachment1.large_preview_height,
340
+
341
+ url: attachment1.metadata.url, // @Legacy
342
+ width: attachment1.metadata.dimensions.split(",")[0], // @Legacy
343
+ height: attachment1.metadata.dimensions.split(",")[1], // @Legacy
344
+ name: attachment1.fileName // @Legacy
345
+ };
346
+ case "animated_image":
347
+ return {
348
+ type: "animated_image",
349
+ ID: attachment2.id.toString(),
350
+ filename: attachment2.filename,
351
+
352
+ previewUrl: attachment1.preview_url,
353
+ previewWidth: attachment1.preview_width,
354
+ previewHeight: attachment1.preview_height,
355
+
356
+ url: attachment2.image_data.url,
357
+ width: attachment2.image_data.width,
358
+ height: attachment2.image_data.height,
359
+
360
+ name: attachment1.name, // @Legacy
361
+ facebookUrl: attachment1.url, // @Legacy
362
+ thumbnailUrl: attachment1.thumbnail_url, // @Legacy
363
+ mimeType: attachment2.mime_type, // @Legacy
364
+ rawGifImage: attachment2.image_data.raw_gif_image, // @Legacy
365
+ rawWebpImage: attachment2.image_data.raw_webp_image, // @Legacy
366
+ animatedGifUrl: attachment2.image_data.animated_gif_url, // @Legacy
367
+ animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url, // @Legacy
368
+ animatedWebpUrl: attachment2.image_data.animated_webp_url, // @Legacy
369
+ animatedWebpPreviewUrl: attachment2.image_data.animated_webp_preview_url // @Legacy
370
+ };
371
+ case "share":
372
+ return {
373
+ type: "share",
374
+ ID: attachment1.share.share_id.toString(),
375
+ url: attachment2.href,
376
+
377
+ title: attachment1.share.title,
378
+ description: attachment1.share.description,
379
+ source: attachment1.share.source,
380
+
381
+ image: attachment1.share.media.image,
382
+ width: attachment1.share.media.image_size.width,
383
+ height: attachment1.share.media.image_size.height,
384
+ playable: attachment1.share.media.playable,
385
+ duration: attachment1.share.media.duration,
386
+
387
+ subattachments: attachment1.share.subattachments,
388
+ properties: {},
389
+
390
+ animatedImageSize: attachment1.share.media.animated_image_size, // @Legacy
391
+ facebookUrl: attachment1.share.uri, // @Legacy
392
+ target: attachment1.share.target, // @Legacy
393
+ styleList: attachment1.share.style_list // @Legacy
394
+ };
395
+ case "video":
396
+ return {
397
+ type: "video",
398
+ ID: attachment1.metadata.fbid.toString(),
399
+ filename: attachment1.name,
400
+
401
+ previewUrl: attachment1.preview_url,
402
+ previewWidth: attachment1.preview_width,
403
+ previewHeight: attachment1.preview_height,
404
+
405
+ url: attachment1.url,
406
+ width: attachment1.metadata.dimensions.width,
407
+ height: attachment1.metadata.dimensions.height,
408
+
409
+ duration: attachment1.metadata.duration,
410
+ videoType: "unknown",
411
+
412
+ thumbnailUrl: attachment1.thumbnail_url // @Legacy
413
+ };
414
+ case "error":
415
+ return {
416
+ type: "error",
417
+
418
+ // Save error attachments because we're unsure of their format,
419
+ // and whether there are cases they contain something useful for debugging.
420
+ attachment1: attachment1,
421
+ attachment2: attachment2
422
+ };
423
+ case "MessageImage":
424
+ return {
425
+ type: "photo",
426
+ ID: blob.legacy_attachment_id,
427
+ filename: blob.filename,
428
+ thumbnailUrl: blob.thumbnail.uri,
429
+
430
+ previewUrl: blob.preview.uri,
431
+ previewWidth: blob.preview.width,
432
+ previewHeight: blob.preview.height,
433
+
434
+ largePreviewUrl: blob.large_preview.uri,
435
+ largePreviewWidth: blob.large_preview.width,
436
+ largePreviewHeight: blob.large_preview.height,
437
+
438
+ url: blob.large_preview.uri, // @Legacy
439
+ width: blob.original_dimensions.x, // @Legacy
440
+ height: blob.original_dimensions.y, // @Legacy
441
+ name: blob.filename // @Legacy
442
+ };
443
+ case "MessageAnimatedImage":
444
+ return {
445
+ type: "animated_image",
446
+ ID: blob.legacy_attachment_id,
447
+ filename: blob.filename,
448
+
449
+ previewUrl: blob.preview_image.uri,
450
+ previewWidth: blob.preview_image.width,
451
+ previewHeight: blob.preview_image.height,
452
+
453
+ url: blob.animated_image.uri,
454
+ width: blob.animated_image.width,
455
+ height: blob.animated_image.height,
456
+
457
+ thumbnailUrl: blob.preview_image.uri, // @Legacy
458
+ name: blob.filename, // @Legacy
459
+ facebookUrl: blob.animated_image.uri, // @Legacy
460
+ rawGifImage: blob.animated_image.uri, // @Legacy
461
+ animatedGifUrl: blob.animated_image.uri, // @Legacy
462
+ animatedGifPreviewUrl: blob.preview_image.uri, // @Legacy
463
+ animatedWebpUrl: blob.animated_image.uri, // @Legacy
464
+ animatedWebpPreviewUrl: blob.preview_image.uri // @Legacy
465
+ };
466
+ case "MessageVideo":
467
+ return {
468
+ type: "video",
469
+ filename: blob.filename,
470
+ ID: blob.legacy_attachment_id,
471
+
472
+ previewUrl: blob.large_image.uri,
473
+ previewWidth: blob.large_image.width,
474
+ previewHeight: blob.large_image.height,
475
+
476
+ url: blob.playable_url,
477
+ width: blob.original_dimensions.x,
478
+ height: blob.original_dimensions.y,
479
+
480
+ duration: blob.playable_duration_in_ms,
481
+ videoType: blob.video_type.toLowerCase(),
482
+
483
+ thumbnailUrl: blob.large_image.uri // @Legacy
484
+ };
485
+ case "MessageAudio":
486
+ return {
487
+ type: "audio",
488
+ filename: blob.filename,
489
+ ID: blob.url_shimhash,
490
+
491
+ audioType: blob.audio_type,
492
+ duration: blob.playable_duration_in_ms,
493
+ url: blob.playable_url,
494
+
495
+ isVoiceMail: blob.is_voicemail
496
+ };
497
+ case "StickerAttachment":
498
+ return {
499
+ type: "sticker",
500
+ ID: blob.id,
501
+ url: blob.url,
502
+
503
+ packID: blob.pack ? blob.pack.id : null,
504
+ spriteUrl: blob.sprite_image,
505
+ spriteUrl2x: blob.sprite_image_2x,
506
+ width: blob.width,
507
+ height: blob.height,
508
+
509
+ caption: blob.label,
510
+ description: blob.label,
511
+
512
+ frameCount: blob.frame_count,
513
+ frameRate: blob.frame_rate,
514
+ framesPerRow: blob.frames_per_row,
515
+ framesPerCol: blob.frames_per_column,
516
+
517
+ stickerID: blob.id, // @Legacy
518
+ spriteURI: blob.sprite_image, // @Legacy
519
+ spriteURI2x: blob.sprite_image_2x // @Legacy
520
+ };
521
+ case "MessageLocation":
522
+ var urlAttach = blob.story_attachment.url;
523
+ var mediaAttach = blob.story_attachment.media;
524
+
525
+ var u = querystring.parse(url.parse(urlAttach).query).u;
526
+ var where1 = querystring.parse(url.parse(u).query).where1;
527
+ var address = where1.split(", ");
528
+
529
+ var latitude;
530
+ var longitude;
531
+
532
+ try {
533
+ latitude = Number.parseFloat(address[0]);
534
+ longitude = Number.parseFloat(address[1]);
535
+ } catch (err) {
536
+ /* empty */
537
+ }
538
+
539
+ var imageUrl;
540
+ var width;
541
+ var height;
542
+
543
+ if (mediaAttach && mediaAttach.image) {
544
+ imageUrl = mediaAttach.image.uri;
545
+ width = mediaAttach.image.width;
546
+ height = mediaAttach.image.height;
547
+ }
548
+
549
+ return {
550
+ type: "location",
551
+ ID: blob.legacy_attachment_id,
552
+ latitude: latitude,
553
+ longitude: longitude,
554
+ image: imageUrl,
555
+ width: width,
556
+ height: height,
557
+ url: u || urlAttach,
558
+ address: where1,
559
+
560
+ facebookUrl: blob.story_attachment.url, // @Legacy
561
+ target: blob.story_attachment.target, // @Legacy
562
+ styleList: blob.story_attachment.style_list // @Legacy
563
+ };
564
+ case "ExtensibleAttachment":
565
+ return {
566
+ type: "share",
567
+ ID: blob.legacy_attachment_id,
568
+ url: blob.story_attachment.url,
569
+
570
+ title: blob.story_attachment.title_with_entities.text,
571
+ description: blob.story_attachment.description &&
572
+ blob.story_attachment.description.text,
573
+ source: blob.story_attachment.source ? blob.story_attachment.source.text : null,
574
+
575
+ image: blob.story_attachment.media &&
576
+ blob.story_attachment.media.image &&
577
+ blob.story_attachment.media.image.uri,
578
+ width: blob.story_attachment.media &&
579
+ blob.story_attachment.media.image &&
580
+ blob.story_attachment.media.image.width,
581
+ height: blob.story_attachment.media &&
582
+ blob.story_attachment.media.image &&
583
+ blob.story_attachment.media.image.height,
584
+ playable: blob.story_attachment.media &&
585
+ blob.story_attachment.media.is_playable,
586
+ duration: blob.story_attachment.media &&
587
+ blob.story_attachment.media.playable_duration_in_ms,
588
+ playableUrl: blob.story_attachment.media == null ? null : blob.story_attachment.media.playable_url,
589
+
590
+ subattachments: blob.story_attachment.subattachments,
591
+ properties: blob.story_attachment.properties.reduce(function(obj, cur) {
592
+ obj[cur.key] = cur.value.text;
593
+ return obj;
594
+ }, {}),
595
+
596
+ facebookUrl: blob.story_attachment.url, // @Legacy
597
+ target: blob.story_attachment.target, // @Legacy
598
+ styleList: blob.story_attachment.style_list // @Legacy
599
+ };
600
+ case "MessageFile":
601
+ return {
602
+ type: "file",
603
+ filename: blob.filename,
604
+ ID: blob.message_file_fbid,
605
+
606
+ url: blob.url,
607
+ isMalicious: blob.is_malicious,
608
+ contentType: blob.content_type,
609
+
610
+ name: blob.filename,
611
+ mimeType: "",
612
+ fileSize: -1
613
+ };
614
+ default:
615
+ throw new Error(
616
+ "unrecognized attach_file of type " +
617
+ type +
618
+ "`" +
619
+ JSON.stringify(attachment1, null, 4) +
620
+ " attachment2: " +
621
+ JSON.stringify(attachment2, null, 4) +
622
+ "`"
623
+ );
624
+ }
625
+ }
626
+
627
+ function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
628
+ attachmentMap = shareMap || attachmentMap;
629
+ return attachments ?
630
+ attachments.map(function(val, i) {
631
+ if (!attachmentMap ||
632
+ !attachmentIds ||
633
+ !attachmentMap[attachmentIds[i]]
634
+ ) {
635
+ return _formatAttachment(val);
636
+ }
637
+ return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
638
+ }) : [];
639
+ }
640
+
641
+ function formatDeltaMessage(m) {
642
+ var md = m.delta.messageMetadata;
643
+ var mdata =
644
+ m.delta.data === undefined ? [] :
645
+ m.delta.data.prng === undefined ? [] :
646
+ JSON.parse(m.delta.data.prng);
647
+ var m_id = mdata.map(u => u.i);
648
+ var m_offset = mdata.map(u => u.o);
649
+ var m_length = mdata.map(u => u.l);
650
+ var mentions = {};
651
+ var body = m.delta.body || "";
652
+ var args = body == "" ? [] : body.trim().split(/\s+/);
653
+ for (var i = 0; i < m_id.length; i++) mentions[m_id[i]] = m.delta.body.substring(m_offset[i], m_offset[i] + m_length[i]);
654
+
655
+ return {
656
+ type: "message",
657
+ senderID: formatID(md.actorFbId.toString()),
658
+ threadID: formatID((md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString()),
659
+ messageID: md.messageId,
660
+ args: args,
661
+ body: body,
662
+ attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
663
+ mentions: mentions,
664
+ timestamp: md.timestamp,
665
+ isGroup: !!md.threadKey.threadFbId,
666
+ participantIDs: m.delta.participants || []
667
+ };
668
+ }
669
+
670
+ function formatID(id) {
671
+ if (id != undefined && id != null) return id.replace(/(fb)?id[:.]/, "");
672
+ else return id;
673
+ }
674
+
675
+ function formatMessage(m) {
676
+ var originalMessage = m.message ? m.message : m;
677
+ var obj = {
678
+ type: "message",
679
+ senderName: originalMessage.sender_name,
680
+ senderID: formatID(originalMessage.sender_fbid.toString()),
681
+ participantNames: originalMessage.group_thread_info ? originalMessage.group_thread_info.participant_names : [originalMessage.sender_name.split(" ")[0]],
682
+ participantIDs: originalMessage.group_thread_info ?
683
+ originalMessage.group_thread_info.participant_ids.map(function(v) {
684
+ return formatID(v.toString());
685
+ }) : [formatID(originalMessage.sender_fbid)],
686
+ body: originalMessage.body || "",
687
+ threadID: formatID((originalMessage.thread_fbid || originalMessage.other_user_fbid).toString()),
688
+ threadName: originalMessage.group_thread_info ? originalMessage.group_thread_info.name : originalMessage.sender_name,
689
+ location: originalMessage.coordinates ? originalMessage.coordinates : null,
690
+ messageID: originalMessage.mid ? originalMessage.mid.toString() : originalMessage.message_id,
691
+ attachments: formatAttachment(
692
+ originalMessage.attachments,
693
+ originalMessage.attachmentIds,
694
+ originalMessage.attachment_map,
695
+ originalMessage.share_map
696
+ ),
697
+ timestamp: originalMessage.timestamp,
698
+ timestampAbsolute: originalMessage.timestamp_absolute,
699
+ timestampRelative: originalMessage.timestamp_relative,
700
+ timestampDatetime: originalMessage.timestamp_datetime,
701
+ tags: originalMessage.tags,
702
+ reactions: originalMessage.reactions ? originalMessage.reactions : [],
703
+ isUnread: originalMessage.is_unread
704
+ };
705
+
706
+ if (m.type === "pages_messaging") obj.pageID = m.realtime_viewer_fbid.toString();
707
+ obj.isGroup = obj.participantIDs.length > 2;
708
+
709
+ return obj;
710
+ }
711
+
712
+ function formatEvent(m) {
713
+ var originalMessage = m.message ? m.message : m;
714
+ var logMessageType = originalMessage.log_message_type;
715
+ var logMessageData;
716
+ if (logMessageType === "log:generic-admin-text") {
717
+ logMessageData = originalMessage.log_message_data.untypedData;
718
+ logMessageType = getAdminTextMessageType(originalMessage.log_message_data.message_type);
719
+ } else logMessageData = originalMessage.log_message_data;
720
+
721
+ return Object.assign(formatMessage(originalMessage), {
722
+ type: "event",
723
+ logMessageType: logMessageType,
724
+ logMessageData: logMessageData,
725
+ logMessageBody: originalMessage.log_message_body
726
+ });
727
+ }
728
+
729
+ function formatHistoryMessage(m) {
730
+ switch (m.action_type) {
731
+ case "ma-type:log-message":
732
+ return formatEvent(m);
733
+ default:
734
+ return formatMessage(m);
735
+ }
736
+ }
737
+
738
+ // Get a more readable message type for AdminTextMessages
739
+ function getAdminTextMessageType(m) {
740
+ switch (m.type) {
741
+ case "change_thread_theme":
742
+ return "log:thread-color";
743
+ case "change_thread_icon":
744
+ return "log:thread-icon";
745
+ case "change_thread_nickname":
746
+ return "log:user-nickname";
747
+ case "change_thread_admins":
748
+ return "log:thread-admins";
749
+ case "group_poll":
750
+ return "log:thread-poll";
751
+ case "change_thread_approval_mode":
752
+ return "log:thread-approval-mode";
753
+ case "messenger_call_log":
754
+ case "participant_joined_group_call":
755
+ return "log:thread-call";
756
+ }
757
+ }
758
+
759
+ function formatDeltaEvent(m) {
760
+ var logMessageType;
761
+ var logMessageData;
762
+
763
+ // log:thread-color => {theme_color}
764
+ // log:user-nickname => {participant_id, nickname}
765
+ // log:thread-icon => {thread_icon}
766
+ // log:thread-name => {name}
767
+ // log:subscribe => {addedParticipants - [Array]}
768
+ //log:unsubscribe => {leftParticipantFbId}
769
+
770
+ switch (m.class) {
771
+ case "AdminTextMessage":
772
+ logMessageType = getAdminTextMessageType(m);
773
+ logMessageData = m.untypedData;
774
+ break;
775
+ case "ThreadName":
776
+ logMessageType = "log:thread-name";
777
+ logMessageData = { name: m.name };
778
+ break;
779
+ case "ParticipantsAddedToGroupThread":
780
+ logMessageType = "log:subscribe";
781
+ logMessageData = { addedParticipants: m.addedParticipants };
782
+ break;
783
+ case "ParticipantLeftGroupThread":
784
+ logMessageType = "log:unsubscribe";
785
+ logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
786
+ break;
787
+ }
788
+
789
+ return {
790
+ type: "event",
791
+ threadID: formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),
792
+ logMessageType: logMessageType,
793
+ logMessageData: logMessageData,
794
+ logMessageBody: m.messageMetadata.adminText,
795
+ author: m.messageMetadata.actorFbId,
796
+ participantIDs: m.participants || []
797
+ };
798
+ }
799
+
800
+ function formatTyp(event) {
801
+ return {
802
+ isTyping: !!event.st,
803
+ from: event.from.toString(),
804
+ threadID: formatID((event.to || event.thread_fbid || event.from).toString()),
805
+ // When receiving typ indication from mobile, `from_mobile` isn't set.
806
+ // If it is, we just use that value.
807
+ fromMobile: event.hasOwnProperty("from_mobile") ? event.from_mobile : true,
808
+ userID: (event.realtime_viewer_fbid || event.from).toString(),
809
+ type: "typ"
810
+ };
811
+ }
812
+
813
+ function formatDeltaReadReceipt(delta) {
814
+ // otherUserFbId seems to be used as both the readerID and the threadID in a 1-1 chat.
815
+ // In a group chat actorFbId is used for the reader and threadFbId for the thread.
816
+ return {
817
+ reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
818
+ time: delta.actionTimestampMs,
819
+ threadID: formatID((delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString()),
820
+ type: "read_receipt"
821
+ };
822
+ }
823
+
824
+ function formatReadReceipt(event) {
825
+ return {
826
+ reader: event.reader.toString(),
827
+ time: event.time,
828
+ threadID: formatID((event.thread_fbid || event.reader).toString()),
829
+ type: "read_receipt"
830
+ };
831
+ }
832
+
833
+ function formatRead(event) {
834
+ return {
835
+ threadID: formatID(((event.chat_ids && event.chat_ids[0]) || (event.thread_fbids && event.thread_fbids[0])).toString()),
836
+ time: event.timestamp,
837
+ type: "read"
838
+ };
839
+ }
840
+
841
+ function getFrom(str, startToken, endToken) {
842
+ var start = str.indexOf(startToken) + startToken.length;
843
+ if (start < startToken.length) return "";
844
+
845
+ var lastHalf = str.substring(start);
846
+ var end = lastHalf.indexOf(endToken);
847
+ if (end === -1) throw Error("Could not find endTime `" + endToken + "` in the given string.");
848
+ return lastHalf.substring(0, end);
849
+ }
850
+
851
+ function makeParsable(html) {
852
+ let withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, "");
853
+
854
+ // (What the fuck FB, why windows style newlines?)
855
+ // So sometimes FB will send us base multiple objects in the same response.
856
+ // They're all valid JSON, one after the other, at the top level. We detect
857
+ // that and make it parse-able by JSON.parse.
858
+ // Ben - July 15th 2017
859
+ //
860
+ // It turns out that Facebook may insert random number of spaces before
861
+ // next object begins (issue #616)
862
+ // rav_kr - 2018-03-19
863
+ let maybeMultipleObjects = withoutForLoop.split(/\}\r\n *\{/);
864
+ if (maybeMultipleObjects.length === 1) return maybeMultipleObjects;
865
+
866
+ return "[" + maybeMultipleObjects.join("},{") + "]";
867
+ }
868
+
869
+ function arrToForm(form) {
870
+ return arrayToObject(form,
871
+ function(v) {
872
+ return v.name;
873
+ },
874
+ function(v) {
875
+ return v.val;
876
+ }
877
+ );
878
+ }
879
+
880
+ function arrayToObject(arr, getKey, getValue) {
881
+ return arr.reduce(function(acc, val) {
882
+ acc[getKey(val)] = getValue(val);
883
+ return acc;
884
+ }, {});
885
+ }
886
+
887
+ function getSignatureID() {
888
+ return Math.floor(Math.random() * 2147483648).toString(16);
889
+ }
890
+
891
+ function generateTimestampRelative() {
892
+ var d = new Date();
893
+ return d.getHours() + ":" + padZeros(d.getMinutes());
894
+ }
895
+
896
+ function makeDefaults(html, userID, ctx) {
897
+ var reqCounter = 1;
898
+ var fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
899
+
900
+ // @Hack Ok we've done hacky things, this is definitely on top 5.
901
+ // We totally assume the object is flat and try parsing until a }.
902
+ // If it works though it's cool because we get a bunch of extra data things.
903
+ //
904
+ // Update: we don't need this. Leaving it in in case we ever do.
905
+ // Ben - July 15th 2017
906
+
907
+ // var siteData = getFrom(html, "[\"SiteData\",[],", "},");
908
+ // try {
909
+ // siteData = JSON.parse(siteData + "}");
910
+ // } catch(e) {
911
+ // log.warn("makeDefaults", "Couldn't parse SiteData. Won't have access to some variables.");
912
+ // siteData = {};
913
+ // }
914
+
915
+ var ttstamp = "2";
916
+ for (var i = 0; i < fb_dtsg.length; i++) ttstamp += fb_dtsg.charCodeAt(i);
917
+ var revision = getFrom(html, 'revision":', ",");
918
+
919
+ function mergeWithDefaults(obj) {
920
+ // @TODO This is missing a key called __dyn.
921
+ // After some investigation it seems like __dyn is some sort of set that FB
922
+ // calls BitMap. It seems like certain responses have a "define" key in the
923
+ // res.jsmods arrays. I think the code iterates over those and calls `set`
924
+ // on the bitmap for each of those keys. Then it calls
925
+ // bitmap.toCompressedString() which returns what __dyn is.
926
+ //
927
+ // So far the API has been working without this.
928
+ //
929
+ // Ben - July 15th 2017
930
+ var newObj = {
931
+ __user: userID,
932
+ __req: (reqCounter++).toString(36),
933
+ __rev: revision,
934
+ __a: 1,
935
+ // __af: siteData.features,
936
+ fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
937
+ jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
938
+ // __spin_r: siteData.__spin_r,
939
+ // __spin_b: siteData.__spin_b,
940
+ // __spin_t: siteData.__spin_t,
941
+ };
942
+
943
+ // @TODO this is probably not needed.
944
+ // Ben - July 15th 2017
945
+ // if (siteData.be_key) {
946
+ // newObj[siteData.be_key] = siteData.be_mode;
947
+ // }
948
+ // if (siteData.pkg_cohort_key) {
949
+ // newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
950
+ // }
951
+
952
+ if (!obj) return newObj;
953
+ for (var prop in obj)
954
+ if (obj.hasOwnProperty(prop))
955
+ if (!newObj[prop]) newObj[prop] = obj[prop];
956
+ return newObj;
957
+ }
958
+
959
+ function postWithDefaults(url, jar, form, ctxx) {
960
+ return post(url, jar, mergeWithDefaults(form), ctx.globalOptions, ctxx || ctx);
961
+ }
962
+
963
+ function getWithDefaults(url, jar, qs, ctxx) {
964
+ return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
965
+ }
966
+
967
+ function postFormDataWithDefault(url, jar, form, qs, ctxx) {
968
+ return postFormData(url, jar, mergeWithDefaults(form), mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
969
+ }
970
+
971
+ return {
972
+ get: getWithDefaults,
973
+ post: postWithDefaults,
974
+ postFormData: postFormDataWithDefault
975
+ };
976
+ }
977
+
978
+ function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
979
+ if (retryCount == undefined) retryCount = 0;
980
+ return function(data) {
981
+ return bluebird.try(function() {
982
+ log.verbose("parseAndCheckLogin", data.body);
983
+ if (data.statusCode >= 500 && data.statusCode < 600) {
984
+ if (retryCount >= 5) {
985
+ throw {
986
+ error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
987
+ statusCode: data.statusCode,
988
+ res: data.body
989
+ };
990
+ }
991
+ retryCount++;
992
+ var retryTime = Math.floor(Math.random() * 5000);
993
+ log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
994
+ var url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
995
+ if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") {
996
+ return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {}))
997
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
998
+ } else {
999
+ return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData))
1000
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1001
+ }
1002
+ }
1003
+ if (data.statusCode !== 200) throw new Error("parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.");
1004
+
1005
+ var res = null;
1006
+ try {
1007
+ res = JSON.parse(makeParsable(data.body));
1008
+ } catch (e) {
1009
+ throw {
1010
+ error: "JSON.parse error. Check the `detail` property on this error.",
1011
+ detail: e,
1012
+ res: data.body
1013
+ };
1014
+ }
1015
+
1016
+ // In some cases the response contains only a redirect URL which should be followed
1017
+ if (res.redirect && data.request.method === "GET") return defaultFuncs.get(res.redirect, ctx.jar).then(parseAndCheckLogin(ctx, defaultFuncs));
1018
+
1019
+ // TODO: handle multiple cookies?
1020
+ if (res.jsmods && res.jsmods.require && Array.isArray(res.jsmods.require[0]) && res.jsmods.require[0][0] === "Cookie") {
1021
+ res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace("_js_", "");
1022
+ var cookie = formatCookie(res.jsmods.require[0][3], "facebook");
1023
+ var cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
1024
+ ctx.jar.setCookie(cookie, "https://www.facebook.com");
1025
+ ctx.jar.setCookie(cookie2, "https://www.messenger.com");
1026
+ }
1027
+
1028
+ // On every request we check if we got a DTSG and we mutate the context so that we use the latest
1029
+ // one for the next requests.
1030
+ if (res.jsmods && Array.isArray(res.jsmods.require)) {
1031
+ var arr = res.jsmods.require;
1032
+ for (var i in arr) {
1033
+ if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
1034
+ ctx.fb_dtsg = arr[i][3][0];
1035
+
1036
+ // Update ttstamp since that depends on fb_dtsg
1037
+ ctx.ttstamp = "2";
1038
+ for (var j = 0; j < ctx.fb_dtsg.length; j++) ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
1039
+ }
1040
+ }
1041
+ }
1042
+
1043
+ if (res.error === 1357001) throw { error: "Appstate Đã Bị Lỗi" };
1044
+ return res;
1045
+ });
1046
+ };
1047
+ }
1048
+
1049
+ function saveCookies(jar) {
1050
+ return function(res) {
1051
+ var cookies = res.headers["set-cookie"] || [];
1052
+ cookies.forEach(function(c) {
1053
+ if (c.indexOf(".facebook.com") > -1) jar.setCookie(c, "https://www.facebook.com");
1054
+ var c2 = c.replace(/domain=\.facebook\.com/, "domain=.messenger.com");
1055
+ jar.setCookie(c2, "https://www.messenger.com");
1056
+ });
1057
+ return res;
1058
+ };
1059
+ }
1060
+
1061
+ var NUM_TO_MONTH = [
1062
+ "Jan",
1063
+ "Feb",
1064
+ "Mar",
1065
+ "Apr",
1066
+ "May",
1067
+ "Jun",
1068
+ "Jul",
1069
+ "Aug",
1070
+ "Sep",
1071
+ "Oct",
1072
+ "Nov",
1073
+ "Dec"
1074
+ ];
1075
+ var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1076
+
1077
+ function formatDate(date) {
1078
+ var d = date.getUTCDate();
1079
+ d = d >= 10 ? d : "0" + d;
1080
+ var h = date.getUTCHours();
1081
+ h = h >= 10 ? h : "0" + h;
1082
+ var m = date.getUTCMinutes();
1083
+ m = m >= 10 ? m : "0" + m;
1084
+ var s = date.getUTCSeconds();
1085
+ s = s >= 10 ? s : "0" + s;
1086
+ return (NUM_TO_DAY[date.getUTCDay()] + ", " + d + " " + NUM_TO_MONTH[date.getUTCMonth()] + " " + date.getUTCFullYear() + " " + h + ":" + m + ":" + s + " GMT");
1087
+ }
1088
+
1089
+ function formatCookie(arr, url) {
1090
+ return arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com";
1091
+ }
1092
+
1093
+ function formatThread(data) {
1094
+ return {
1095
+ threadID: formatID(data.thread_fbid.toString()),
1096
+ participants: data.participants.map(formatID),
1097
+ participantIDs: data.participants.map(formatID),
1098
+ name: data.name,
1099
+ nicknames: data.custom_nickname,
1100
+ snippet: data.snippet,
1101
+ snippetAttachments: data.snippet_attachments,
1102
+ snippetSender: formatID((data.snippet_sender || "").toString()),
1103
+ unreadCount: data.unread_count,
1104
+ messageCount: data.message_count,
1105
+ imageSrc: data.image_src,
1106
+ timestamp: data.timestamp,
1107
+ serverTimestamp: data.server_timestamp, // what is this?
1108
+ muteUntil: data.mute_until,
1109
+ isCanonicalUser: data.is_canonical_user,
1110
+ isCanonical: data.is_canonical,
1111
+ isSubscribed: data.is_subscribed,
1112
+ folder: data.folder,
1113
+ isArchived: data.is_archived,
1114
+ recipientsLoadable: data.recipients_loadable,
1115
+ hasEmailParticipant: data.has_email_participant,
1116
+ readOnly: data.read_only,
1117
+ canReply: data.can_reply,
1118
+ cannotReplyReason: data.cannot_reply_reason,
1119
+ lastMessageTimestamp: data.last_message_timestamp,
1120
+ lastReadTimestamp: data.last_read_timestamp,
1121
+ lastMessageType: data.last_message_type,
1122
+ emoji: data.custom_like_icon,
1123
+ color: data.custom_color,
1124
+ adminIDs: data.admin_ids,
1125
+ threadType: data.thread_type
1126
+ };
1127
+ }
1128
+
1129
+ function getType(obj) {
1130
+ return Object.prototype.toString.call(obj).slice(8, -1);
1131
+ }
1132
+
1133
+ function formatProxyPresence(presence, userID) {
1134
+ if (presence.lat === undefined || presence.p === undefined) return null;
1135
+ return {
1136
+ type: "presence",
1137
+ timestamp: presence.lat * 1000,
1138
+ userID: userID || '',
1139
+ statuses: presence.p
1140
+ };
1141
+ }
1142
+
1143
+ function formatPresence(presence, userID) {
1144
+ return {
1145
+ type: "presence",
1146
+ timestamp: presence.la * 1000,
1147
+ userID: userID || '',
1148
+ statuses: presence.a
1149
+ };
1150
+ }
1151
+
1152
+ function decodeClientPayload(payload) {
1153
+ /*
1154
+ Special function which Client using to "encode" clients JSON payload
1155
+ */
1156
+ function Utf8ArrayToStr(array) {
1157
+ var out, i, len, c;
1158
+ var char2, char3;
1159
+ out = "";
1160
+ len = array.length;
1161
+ i = 0;
1162
+ while (i < len) {
1163
+ c = array[i++];
1164
+ switch (c >> 4) {
1165
+ case 0:
1166
+ case 1:
1167
+ case 2:
1168
+ case 3:
1169
+ case 4:
1170
+ case 5:
1171
+ case 6:
1172
+ case 7:
1173
+ out += String.fromCharCode(c);
1174
+ break;
1175
+ case 12:
1176
+ case 13:
1177
+ char2 = array[i++];
1178
+ out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
1179
+ break;
1180
+ case 14:
1181
+ char2 = array[i++];
1182
+ char3 = array[i++];
1183
+ out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
1184
+ break;
1185
+ }
1186
+ }
1187
+ return out;
1188
+ }
1189
+ return JSON.parse(Utf8ArrayToStr(payload));
1190
+ }
1191
+ function getAppState(jar) {
1192
+ var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1193
+ if (global.fca.ObjFcaConfig['encryptSt']) {
1194
+ var StateCrypt = require('./StateCrypt');
1195
+ var logger = require('./logger');
1196
+ logger(global.fca.languages.encAppstate,'[ FCA-DUONG ]');
1197
+ var keyy = process.env['FBKEY'];
1198
+
1199
+ if (process.env['FBKEY']) {
1200
+
1201
+ return StateCrypt.encryptState(JSON.stringify(appstate),process.env['FBKEY']);
1202
+
1203
+ }
1204
+ }
1205
+ else return appstate;
1206
+ }
1207
+ module.exports = {
1208
+ isReadableStream:isReadableStream,
1209
+ get:get,
1210
+ post:post,
1211
+ postFormData:postFormData,
1212
+ generateThreadingID:generateThreadingID,
1213
+ generateOfflineThreadingID:generateOfflineThreadingID,
1214
+ getGUID:getGUID,
1215
+ getFrom:getFrom,
1216
+ makeParsable:makeParsable,
1217
+ arrToForm:arrToForm,
1218
+ getSignatureID:getSignatureID,
1219
+ getJar: request.jar,
1220
+ generateTimestampRelative:generateTimestampRelative,
1221
+ makeDefaults:makeDefaults,
1222
+ parseAndCheckLogin:parseAndCheckLogin,
1223
+ saveCookies,
1224
+ getType,
1225
+ _formatAttachment,
1226
+ formatHistoryMessage,
1227
+ formatID,
1228
+ formatMessage,
1229
+ formatDeltaEvent,
1230
+ formatDeltaMessage,
1231
+ formatProxyPresence,
1232
+ formatPresence,
1233
+ formatTyp,
1234
+ formatDeltaReadReceipt,
1235
+ formatCookie,
1236
+ formatThread,
1237
+ formatReadReceipt,
1238
+ formatRead,
1239
+ generatePresence,
1240
+ generateAccessiblityCookie,
1241
+ formatDate,
1242
+ decodeClientPayload,
1243
+ getAppState,
1244
+ getAdminTextMessageType,
1245
+ setProxy
1246
+ };