capfb 0.0.1-security → 1.4.74-beta

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of capfb might be problematic. Click here for more details.

Files changed (78) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/dependabot.yml +11 -0
  3. package/.github/workflows/nodejs.yml +26 -0
  4. package/.github/workflows/npmpublish.yml +30 -0
  5. package/CHANGELOG.md +2 -0
  6. package/DOCS.md +1738 -0
  7. package/Extra/Database/index.js +399 -0
  8. package/Extra/Database/methods.js +286 -0
  9. package/Extra/ExtraAddons.js +78 -0
  10. package/Extra/ExtraAddonsDeprecated.js +213 -0
  11. package/Extra/ExtraGetThread.js +1 -0
  12. package/Extra/ExtraUptimeRobot.js +59 -0
  13. package/Extra/PM2/ecosystem.config.js +23 -0
  14. package/Extra/Src/Last-Run.js +48 -0
  15. package/LICENSE-MIT +21 -0
  16. package/Language/index.json +151 -0
  17. package/README.md +225 -3
  18. package/StateCrypt.js +22 -0
  19. package/broadcast.js +42 -0
  20. package/index-backup.js +1079 -0
  21. package/index.js +1134 -0
  22. package/logger.js +21 -0
  23. package/package.json +88 -3
  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/changeBio.js +65 -0
  29. package/src/changeBlockedStatus.js +36 -0
  30. package/src/changeGroupImage.js +106 -0
  31. package/src/changeNickname.js +45 -0
  32. package/src/changeThreadColor.js +62 -0
  33. package/src/changeThreadEmoji.js +42 -0
  34. package/src/createNewGroup.js +70 -0
  35. package/src/createPoll.js +60 -0
  36. package/src/deleteMessage.js +45 -0
  37. package/src/deleteThread.js +43 -0
  38. package/src/forwardAttachment.js +48 -0
  39. package/src/getAccessToken.js +32 -0
  40. package/src/getAccessTokenDeprecated.js +31 -0
  41. package/src/getCurrentUserID.js +7 -0
  42. package/src/getEmojiUrl.js +27 -0
  43. package/src/getFriendsList.js +73 -0
  44. package/src/getMessage.js +80 -0
  45. package/src/getThreadHistory.js +537 -0
  46. package/src/getThreadHistoryDeprecated.js +71 -0
  47. package/src/getThreadInfo.js +197 -0
  48. package/src/getThreadInfoDeprecated.js +56 -0
  49. package/src/getThreadList.js +213 -0
  50. package/src/getThreadListDeprecated.js +46 -0
  51. package/src/getThreadPictures.js +59 -0
  52. package/src/getUserID.js +62 -0
  53. package/src/getUserInfo.js +65 -0
  54. package/src/getUserInfoV2.js +35 -0
  55. package/src/handleFriendRequest.js +46 -0
  56. package/src/handleMessageRequest.js +49 -0
  57. package/src/httpGet.js +49 -0
  58. package/src/httpPost.js +48 -0
  59. package/src/httpPostFormData.js +41 -0
  60. package/src/listenMqtt.js +633 -0
  61. package/src/logout.js +68 -0
  62. package/src/markAsDelivered.js +48 -0
  63. package/src/markAsRead.js +70 -0
  64. package/src/markAsReadAll.js +43 -0
  65. package/src/markAsSeen.js +51 -0
  66. package/src/muteThread.js +47 -0
  67. package/src/removeUserFromGroup.js +49 -0
  68. package/src/resolvePhotoUrl.js +37 -0
  69. package/src/searchForThread.js +43 -0
  70. package/src/sendMessage.js +342 -0
  71. package/src/sendTypingIndicator.js +80 -0
  72. package/src/setMessageReaction.js +109 -0
  73. package/src/setPostReaction.js +102 -0
  74. package/src/setTitle.js +74 -0
  75. package/src/threadColors.js +39 -0
  76. package/src/unfriend.js +43 -0
  77. package/src/unsendMessage.js +40 -0
  78. package/utils.js +1284 -0
package/utils.js ADDED
@@ -0,0 +1,1284 @@
1
+ /* eslint-disable no-undef */
2
+ /* eslint-disable no-prototype-builtins */
3
+ "use strict";
4
+
5
+ const bluebird = require("bluebird");
6
+ var request = bluebird.promisify(require("request").defaults({ jar: true }));
7
+ var stream = require("stream");
8
+ var log = require("npmlog");
9
+ var querystring = require("querystring");
10
+ var url = require("url");
11
+
12
+ function setProxy(url) {
13
+ if (typeof url == undefined) return request = bluebird.promisify(require("request").defaults({ jar: true }));
14
+ return request = bluebird.promisify(require("request").defaults({ jar: true, proxy: url }));
15
+ }
16
+
17
+ function getHeaders(url, options, ctx, customHeader) {
18
+ var headers = {
19
+ "Content-Type": "application/x-www-form-urlencoded",
20
+ Referer: "https://www.facebook.com/",
21
+ Host: url.replace("https://", "").split("/")[0],
22
+ Origin: "https://www.facebook.com",
23
+ "User-Agent": options.userAgent,
24
+ Connection: "keep-alive",
25
+ 'sec-fetch-site': 'same-origin'
26
+ };
27
+ if (customHeader) Object.assign(headers, customHeader);
28
+
29
+ if (ctx && ctx.region) headers["X-MSGR-Region"] = ctx.region;
30
+
31
+ return headers;
32
+ }
33
+
34
+ function isReadableStream(obj) {
35
+ return (
36
+ obj instanceof stream.Stream &&
37
+ (getType(obj._read) === "Function" ||
38
+ getType(obj._read) === "AsyncFunction") &&
39
+ getType(obj._readableState) === "Object"
40
+ );
41
+ }
42
+
43
+ function get(url, jar, qs, options, ctx) {
44
+ // I'm still confused about this
45
+ if (getType(qs) === "Object")
46
+ for (var prop in qs)
47
+ if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") qs[prop] = JSON.stringify(qs[prop]);
48
+ var op = {
49
+ headers: getHeaders(url, options, ctx),
50
+ timeout: 60000,
51
+ qs: qs,
52
+ url: url,
53
+ method: "GET",
54
+ jar: jar,
55
+ gzip: true
56
+ };
57
+
58
+ return request(op).then(function(res) {
59
+ return res[0];
60
+ });
61
+ }
62
+
63
+ function getv2(url, jar, qs, options, ctx) {
64
+ // I'm still confused about this
65
+ if (getType(qs) === "Object")
66
+ for (var prop in qs)
67
+ if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") qs[prop] = JSON.stringify(qs[prop]);
68
+ var op = {
69
+ headers: getHeaders(url, options, ctx),
70
+ timeout: 60000,
71
+ qs: qs,
72
+ url: url,
73
+ method: "GET",
74
+ jar: jar,
75
+ gzip: true
76
+ };
77
+
78
+ return request(op).then(function(res) {
79
+ return res;
80
+ });
81
+ }
82
+
83
+ function post(url, jar, form, options, ctx, customHeader) {
84
+ let headers = getHeaders(url, options);
85
+ headers['sec-fetch-site'] = 'same-origin';
86
+ var op = {
87
+ headers: headers,
88
+ timeout: 60000,
89
+ url: url,
90
+ method: "POST",
91
+ form: form,
92
+ jar: jar,
93
+ gzip: true
94
+ };
95
+
96
+ return request(op).then(function(res) {
97
+ return res[0];
98
+ });
99
+ }
100
+
101
+ function postv2(url, jar, form, options, ctx, customHeader) {
102
+ let headers = getHeaders(url, options);
103
+ headers['sec-fetch-site'] = 'same-origin';
104
+ var op = {
105
+ headers: headers,
106
+ timeout: 60000,
107
+ url: url,
108
+ method: "POST",
109
+ form: form,
110
+ jar: jar,
111
+ gzip: true
112
+ };
113
+
114
+ return request(op).then(function(res) {
115
+ return res;
116
+ });
117
+ }
118
+
119
+ function postFormData(url, jar, form, qs, options, ctx) {
120
+ var headers = getHeaders(url, options, ctx);
121
+ headers["Content-Type"] = "multipart/form-data";
122
+ var op = {
123
+ headers: headers,
124
+ timeout: 60000,
125
+ url: url,
126
+ method: "POST",
127
+ formData: form,
128
+ qs: qs,
129
+ jar: jar,
130
+ gzip: true
131
+ };
132
+
133
+ return request(op).then(function(res) {
134
+ return res[0];
135
+ });
136
+ }
137
+
138
+ function padZeros(val, len) {
139
+ val = String(val);
140
+ len = len || 2;
141
+ while (val.length < len) val = "0" + val;
142
+ return val;
143
+ }
144
+
145
+ function generateThreadingID(clientID) {
146
+ var k = Date.now();
147
+ var l = Math.floor(Math.random() * 4294967295);
148
+ var m = clientID;
149
+ return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
150
+ }
151
+
152
+ function binaryToDecimal(data) {
153
+ var ret = "";
154
+ while (data !== "0") {
155
+ var end = 0;
156
+ var fullName = "";
157
+ var i = 0;
158
+ for (; i < data.length; i++) {
159
+ end = 2 * end + parseInt(data[i], 10);
160
+ if (end >= 10) {
161
+ fullName += "1";
162
+ end -= 10;
163
+ } else fullName += "0";
164
+ }
165
+ ret = end.toString() + ret;
166
+ data = fullName.slice(fullName.indexOf("1"));
167
+ }
168
+ return ret;
169
+ }
170
+
171
+ function generateOfflineThreadingID() {
172
+ var ret = Date.now();
173
+ var value = Math.floor(Math.random() * 4294967295);
174
+ var str = ("0000000000000000000000" + value.toString(2)).slice(-22);
175
+ var msgs = ret.toString(2) + str;
176
+ return binaryToDecimal(msgs);
177
+ }
178
+
179
+ var h;
180
+ var i = {};
181
+ var j = {
182
+ _: "%",
183
+ A: "%2",
184
+ B: "000",
185
+ C: "%7d",
186
+ D: "%7b%22",
187
+ E: "%2c%22",
188
+ F: "%22%3a",
189
+ G: "%2c%22ut%22%3a1",
190
+ H: "%2c%22bls%22%3a",
191
+ I: "%2c%22n%22%3a%22%",
192
+ J: "%22%3a%7b%22i%22%3a0%7d",
193
+ K: "%2c%22pt%22%3a0%2c%22vis%22%3a",
194
+ L: "%2c%22ch%22%3a%7b%22h%22%3a%22",
195
+ M: "%7b%22v%22%3a2%2c%22time%22%3a1",
196
+ N: ".channel%22%2c%22sub%22%3a%5b",
197
+ O: "%2c%22sb%22%3a1%2c%22t%22%3a%5b",
198
+ P: "%2c%22ud%22%3a100%2c%22lc%22%3a0",
199
+ Q: "%5d%2c%22f%22%3anull%2c%22uct%22%3a",
200
+ R: ".channel%22%2c%22sub%22%3a%5b1%5d",
201
+ S: "%22%2c%22m%22%3a0%7d%2c%7b%22i%22%3a",
202
+ T: "%2c%22blc%22%3a1%2c%22snd%22%3a1%2c%22ct%22%3a",
203
+ U: "%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
204
+ V: "%2c%22blc%22%3a0%2c%22snd%22%3a0%2c%22ct%22%3a",
205
+ W: "%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a",
206
+ X: "%2c%22ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1",
207
+ 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",
208
+ 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"
209
+ };
210
+ (function() {
211
+ var l = [];
212
+ for (var m in j) {
213
+ i[j[m]] = m;
214
+ l.push(j[m]);
215
+ }
216
+ l.reverse();
217
+ h = new RegExp(l.join("|"), "g");
218
+ })();
219
+
220
+ function presenceEncode(str) {
221
+ return encodeURIComponent(str)
222
+ .replace(/([_A-Z])|%../g, function(m, n) {
223
+ return n ? "%" + n.charCodeAt(0).toString(16) : m;
224
+ })
225
+ .toLowerCase()
226
+ .replace(h, function(m) {
227
+ return i[m];
228
+ });
229
+ }
230
+
231
+ // eslint-disable-next-line no-unused-vars
232
+ function presenceDecode(str) {
233
+ return decodeURIComponent(
234
+ str.replace(/[_A-Z]/g, function(m) {
235
+ return j[m];
236
+ })
237
+ );
238
+ }
239
+
240
+ function generatePresence(userID) {
241
+ var time = Date.now();
242
+ return (
243
+ "E" +
244
+ presenceEncode(
245
+ JSON.stringify({
246
+ v: 3,
247
+ time: parseInt(time / 1000, 10),
248
+ user: userID,
249
+ state: {
250
+ ut: 0,
251
+ t2: [],
252
+ lm2: null,
253
+ uct2: time,
254
+ tr: null,
255
+ tw: Math.floor(Math.random() * 4294967295) + 1,
256
+ at: time
257
+ },
258
+ ch: {
259
+ ["p_" + userID]: 0
260
+ }
261
+ })
262
+ )
263
+ );
264
+ }
265
+
266
+ function generateAccessiblityCookie() {
267
+ var time = Date.now();
268
+ return encodeURIComponent(
269
+ JSON.stringify({
270
+ sr: 0,
271
+ "sr-ts": time,
272
+ jk: 0,
273
+ "jk-ts": time,
274
+ kb: 0,
275
+ "kb-ts": time,
276
+ hcm: 0,
277
+ "hcm-ts": time
278
+ })
279
+ );
280
+ }
281
+
282
+ function getGUID() {
283
+ /** @type {number} */
284
+ var sectionLength = Date.now();
285
+ /** @type {string} */
286
+ var id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
287
+ /** @type {number} */
288
+ var r = Math.floor((sectionLength + Math.random() * 16) % 16);
289
+ /** @type {number} */
290
+ sectionLength = Math.floor(sectionLength / 16);
291
+ /** @type {string} */
292
+ var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
293
+ return _guid;
294
+ });
295
+ return id;
296
+ }
297
+
298
+ function _formatAttachment(attachment1, attachment2) {
299
+ // TODO: THIS IS REALLY BAD
300
+ // This is an attempt at fixing Facebook's inconsistencies. Sometimes they give us
301
+ // two attachment objects, but sometimes only one. They each contain part of the
302
+ // data that you'd want so we merge them for convenience.
303
+ // Instead of having a bunch of if statements guarding every access to image_data,
304
+ // we set it to empty object and use the fact that it'll return undefined.
305
+ attachment2 = attachment2 || { id: "", image_data: {} };
306
+ attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
307
+ var blob = attachment1.blob_attachment;
308
+ var type =
309
+ blob && blob.__typename ? blob.__typename : attachment1.attach_type;
310
+ if (!type && attachment1.sticker_attachment) {
311
+ type = "StickerAttachment";
312
+ blob = attachment1.sticker_attachment;
313
+ } else if (!type && attachment1.extensible_attachment) {
314
+ if (
315
+ attachment1.extensible_attachment.story_attachment &&
316
+ attachment1.extensible_attachment.story_attachment.target &&
317
+ attachment1.extensible_attachment.story_attachment.target.__typename &&
318
+ attachment1.extensible_attachment.story_attachment.target.__typename === "MessageLocation"
319
+ ) type = "MessageLocation";
320
+ else type = "ExtensibleAttachment";
321
+
322
+ blob = attachment1.extensible_attachment;
323
+ }
324
+ // TODO: Determine whether "sticker", "photo", "file" etc are still used
325
+ // KEEP IN SYNC WITH getThreadHistory
326
+ switch (type) {
327
+ case "sticker":
328
+ return {
329
+ type: "sticker",
330
+ ID: attachment1.metadata.stickerID.toString(),
331
+ url: attachment1.url,
332
+
333
+ packID: attachment1.metadata.packID.toString(),
334
+ spriteUrl: attachment1.metadata.spriteURI,
335
+ spriteUrl2x: attachment1.metadata.spriteURI2x,
336
+ width: attachment1.metadata.width,
337
+ height: attachment1.metadata.height,
338
+
339
+ caption: attachment2.caption,
340
+ description: attachment2.description,
341
+
342
+ frameCount: attachment1.metadata.frameCount,
343
+ frameRate: attachment1.metadata.frameRate,
344
+ framesPerRow: attachment1.metadata.framesPerRow,
345
+ framesPerCol: attachment1.metadata.framesPerCol,
346
+
347
+ stickerID: attachment1.metadata.stickerID.toString(), // @Legacy
348
+ spriteURI: attachment1.metadata.spriteURI, // @Legacy
349
+ spriteURI2x: attachment1.metadata.spriteURI2x // @Legacy
350
+ };
351
+ case "file":
352
+ return {
353
+ type: "file",
354
+ filename: attachment1.name,
355
+ ID: attachment2.id.toString(),
356
+ url: attachment1.url,
357
+
358
+ isMalicious: attachment2.is_malicious,
359
+ contentType: attachment2.mime_type,
360
+
361
+ name: attachment1.name, // @Legacy
362
+ mimeType: attachment2.mime_type, // @Legacy
363
+ fileSize: attachment2.file_size // @Legacy
364
+ };
365
+ case "photo":
366
+ return {
367
+ type: "photo",
368
+ ID: attachment1.metadata.fbid.toString(),
369
+ filename: attachment1.fileName,
370
+ thumbnailUrl: attachment1.thumbnail_url,
371
+
372
+ previewUrl: attachment1.preview_url,
373
+ previewWidth: attachment1.preview_width,
374
+ previewHeight: attachment1.preview_height,
375
+
376
+ largePreviewUrl: attachment1.large_preview_url,
377
+ largePreviewWidth: attachment1.large_preview_width,
378
+ largePreviewHeight: attachment1.large_preview_height,
379
+
380
+ url: attachment1.metadata.url, // @Legacy
381
+ width: attachment1.metadata.dimensions.split(",")[0], // @Legacy
382
+ height: attachment1.metadata.dimensions.split(",")[1], // @Legacy
383
+ name: attachment1.fileName // @Legacy
384
+ };
385
+ case "animated_image":
386
+ return {
387
+ type: "animated_image",
388
+ ID: attachment2.id.toString(),
389
+ filename: attachment2.filename,
390
+
391
+ previewUrl: attachment1.preview_url,
392
+ previewWidth: attachment1.preview_width,
393
+ previewHeight: attachment1.preview_height,
394
+
395
+ url: attachment2.image_data.url,
396
+ width: attachment2.image_data.width,
397
+ height: attachment2.image_data.height,
398
+
399
+ name: attachment1.name, // @Legacy
400
+ facebookUrl: attachment1.url, // @Legacy
401
+ thumbnailUrl: attachment1.thumbnail_url, // @Legacy
402
+ mimeType: attachment2.mime_type, // @Legacy
403
+ rawGifImage: attachment2.image_data.raw_gif_image, // @Legacy
404
+ rawWebpImage: attachment2.image_data.raw_webp_image, // @Legacy
405
+ animatedGifUrl: attachment2.image_data.animated_gif_url, // @Legacy
406
+ animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url, // @Legacy
407
+ animatedWebpUrl: attachment2.image_data.animated_webp_url, // @Legacy
408
+ animatedWebpPreviewUrl: attachment2.image_data.animated_webp_preview_url // @Legacy
409
+ };
410
+ case "share":
411
+ return {
412
+ type: "share",
413
+ ID: attachment1.share.share_id.toString(),
414
+ url: attachment2.href,
415
+
416
+ title: attachment1.share.title,
417
+ description: attachment1.share.description,
418
+ source: attachment1.share.source,
419
+
420
+ image: attachment1.share.media.image,
421
+ width: attachment1.share.media.image_size.width,
422
+ height: attachment1.share.media.image_size.height,
423
+ playable: attachment1.share.media.playable,
424
+ duration: attachment1.share.media.duration,
425
+
426
+ subattachments: attachment1.share.subattachments,
427
+ properties: {},
428
+
429
+ animatedImageSize: attachment1.share.media.animated_image_size, // @Legacy
430
+ facebookUrl: attachment1.share.uri, // @Legacy
431
+ target: attachment1.share.target, // @Legacy
432
+ styleList: attachment1.share.style_list // @Legacy
433
+ };
434
+ case "video":
435
+ return {
436
+ type: "video",
437
+ ID: attachment1.metadata.fbid.toString(),
438
+ filename: attachment1.name,
439
+
440
+ previewUrl: attachment1.preview_url,
441
+ previewWidth: attachment1.preview_width,
442
+ previewHeight: attachment1.preview_height,
443
+
444
+ url: attachment1.url,
445
+ width: attachment1.metadata.dimensions.width,
446
+ height: attachment1.metadata.dimensions.height,
447
+
448
+ duration: attachment1.metadata.duration,
449
+ videoType: "unknown",
450
+
451
+ thumbnailUrl: attachment1.thumbnail_url // @Legacy
452
+ };
453
+ case "error":
454
+ return {
455
+ type: "error",
456
+
457
+ // Save error attachments because we're unsure of their format,
458
+ // and whether there are cases they contain something useful for debugging.
459
+ attachment1: attachment1,
460
+ attachment2: attachment2
461
+ };
462
+ case "MessageImage":
463
+ return {
464
+ type: "photo",
465
+ ID: blob.legacy_attachment_id,
466
+ filename: blob.filename,
467
+ thumbnailUrl: blob.thumbnail.uri,
468
+
469
+ previewUrl: blob.preview.uri,
470
+ previewWidth: blob.preview.width,
471
+ previewHeight: blob.preview.height,
472
+
473
+ largePreviewUrl: blob.large_preview.uri,
474
+ largePreviewWidth: blob.large_preview.width,
475
+ largePreviewHeight: blob.large_preview.height,
476
+
477
+ url: blob.large_preview.uri, // @Legacy
478
+ width: blob.original_dimensions.x, // @Legacy
479
+ height: blob.original_dimensions.y, // @Legacy
480
+ name: blob.filename // @Legacy
481
+ };
482
+ case "MessageAnimatedImage":
483
+ return {
484
+ type: "animated_image",
485
+ ID: blob.legacy_attachment_id,
486
+ filename: blob.filename,
487
+
488
+ previewUrl: blob.preview_image.uri,
489
+ previewWidth: blob.preview_image.width,
490
+ previewHeight: blob.preview_image.height,
491
+
492
+ url: blob.animated_image.uri,
493
+ width: blob.animated_image.width,
494
+ height: blob.animated_image.height,
495
+
496
+ thumbnailUrl: blob.preview_image.uri, // @Legacy
497
+ name: blob.filename, // @Legacy
498
+ facebookUrl: blob.animated_image.uri, // @Legacy
499
+ rawGifImage: blob.animated_image.uri, // @Legacy
500
+ animatedGifUrl: blob.animated_image.uri, // @Legacy
501
+ animatedGifPreviewUrl: blob.preview_image.uri, // @Legacy
502
+ animatedWebpUrl: blob.animated_image.uri, // @Legacy
503
+ animatedWebpPreviewUrl: blob.preview_image.uri // @Legacy
504
+ };
505
+ case "MessageVideo":
506
+ return {
507
+ type: "video",
508
+ filename: blob.filename,
509
+ ID: blob.legacy_attachment_id,
510
+
511
+ previewUrl: blob.large_image.uri,
512
+ previewWidth: blob.large_image.width,
513
+ previewHeight: blob.large_image.height,
514
+
515
+ url: blob.playable_url,
516
+ width: blob.original_dimensions.x,
517
+ height: blob.original_dimensions.y,
518
+
519
+ duration: blob.playable_duration_in_ms,
520
+ videoType: blob.video_type.toLowerCase(),
521
+
522
+ thumbnailUrl: blob.large_image.uri // @Legacy
523
+ };
524
+ case "MessageAudio":
525
+ return {
526
+ type: "audio",
527
+ filename: blob.filename,
528
+ ID: blob.url_shimhash,
529
+
530
+ audioType: blob.audio_type,
531
+ duration: blob.playable_duration_in_ms,
532
+ url: blob.playable_url,
533
+
534
+ isVoiceMail: blob.is_voicemail
535
+ };
536
+ case "StickerAttachment":
537
+ return {
538
+ type: "sticker",
539
+ ID: blob.id,
540
+ url: blob.url,
541
+
542
+ packID: blob.pack ? blob.pack.id : null,
543
+ spriteUrl: blob.sprite_image,
544
+ spriteUrl2x: blob.sprite_image_2x,
545
+ width: blob.width,
546
+ height: blob.height,
547
+
548
+ caption: blob.label,
549
+ description: blob.label,
550
+
551
+ frameCount: blob.frame_count,
552
+ frameRate: blob.frame_rate,
553
+ framesPerRow: blob.frames_per_row,
554
+ framesPerCol: blob.frames_per_column,
555
+
556
+ stickerID: blob.id, // @Legacy
557
+ spriteURI: blob.sprite_image, // @Legacy
558
+ spriteURI2x: blob.sprite_image_2x // @Legacy
559
+ };
560
+ case "MessageLocation":
561
+ var urlAttach = blob.story_attachment.url;
562
+ var mediaAttach = blob.story_attachment.media;
563
+
564
+ var u = querystring.parse(url.parse(urlAttach).query).u;
565
+ var where1 = querystring.parse(url.parse(u).query).where1;
566
+ var address = where1.split(", ");
567
+
568
+ var latitude;
569
+ var longitude;
570
+
571
+ try {
572
+ latitude = Number.parseFloat(address[0]);
573
+ longitude = Number.parseFloat(address[1]);
574
+ } catch (err) {
575
+ /* empty */
576
+ }
577
+
578
+ var imageUrl;
579
+ var width;
580
+ var height;
581
+
582
+ if (mediaAttach && mediaAttach.image) {
583
+ imageUrl = mediaAttach.image.uri;
584
+ width = mediaAttach.image.width;
585
+ height = mediaAttach.image.height;
586
+ }
587
+
588
+ return {
589
+ type: "location",
590
+ ID: blob.legacy_attachment_id,
591
+ latitude: latitude,
592
+ longitude: longitude,
593
+ image: imageUrl,
594
+ width: width,
595
+ height: height,
596
+ url: u || urlAttach,
597
+ address: where1,
598
+
599
+ facebookUrl: blob.story_attachment.url, // @Legacy
600
+ target: blob.story_attachment.target, // @Legacy
601
+ styleList: blob.story_attachment.style_list // @Legacy
602
+ };
603
+ case "ExtensibleAttachment":
604
+ return {
605
+ type: "share",
606
+ ID: blob.legacy_attachment_id,
607
+ url: blob.story_attachment.url,
608
+
609
+ title: blob.story_attachment.title_with_entities.text,
610
+ description: blob.story_attachment.description &&
611
+ blob.story_attachment.description.text,
612
+ source: blob.story_attachment.source ? blob.story_attachment.source.text : null,
613
+
614
+ image: blob.story_attachment.media &&
615
+ blob.story_attachment.media.image &&
616
+ blob.story_attachment.media.image.uri,
617
+ width: blob.story_attachment.media &&
618
+ blob.story_attachment.media.image &&
619
+ blob.story_attachment.media.image.width,
620
+ height: blob.story_attachment.media &&
621
+ blob.story_attachment.media.image &&
622
+ blob.story_attachment.media.image.height,
623
+ playable: blob.story_attachment.media &&
624
+ blob.story_attachment.media.is_playable,
625
+ duration: blob.story_attachment.media &&
626
+ blob.story_attachment.media.playable_duration_in_ms,
627
+ playableUrl: blob.story_attachment.media == null ? null : blob.story_attachment.media.playable_url,
628
+
629
+ subattachments: blob.story_attachment.subattachments,
630
+ properties: blob.story_attachment.properties.reduce(function(obj, cur) {
631
+ obj[cur.key] = cur.value.text;
632
+ return obj;
633
+ }, {}),
634
+
635
+ facebookUrl: blob.story_attachment.url, // @Legacy
636
+ target: blob.story_attachment.target, // @Legacy
637
+ styleList: blob.story_attachment.style_list // @Legacy
638
+ };
639
+ case "MessageFile":
640
+ return {
641
+ type: "file",
642
+ filename: blob.filename,
643
+ ID: blob.message_file_fbid,
644
+
645
+ url: blob.url,
646
+ isMalicious: blob.is_malicious,
647
+ contentType: blob.content_type,
648
+
649
+ name: blob.filename,
650
+ mimeType: "",
651
+ fileSize: -1
652
+ };
653
+ default:
654
+ throw new Error(
655
+ "unrecognized attach_file of type " +
656
+ type +
657
+ "`" +
658
+ JSON.stringify(attachment1, null, 4) +
659
+ " attachment2: " +
660
+ JSON.stringify(attachment2, null, 4) +
661
+ "`"
662
+ );
663
+ }
664
+ }
665
+
666
+ function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
667
+ attachmentMap = shareMap || attachmentMap;
668
+ return attachments ?
669
+ attachments.map(function(val, i) {
670
+ if (!attachmentMap ||
671
+ !attachmentIds ||
672
+ !attachmentMap[attachmentIds[i]]
673
+ ) {
674
+ return _formatAttachment(val);
675
+ }
676
+ return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
677
+ }) : [];
678
+ }
679
+
680
+ function formatDeltaMessage(m) {
681
+ var md = m.delta.messageMetadata;
682
+ var mdata =
683
+ m.delta.data === undefined ? [] :
684
+ m.delta.data.prng === undefined ? [] :
685
+ JSON.parse(m.delta.data.prng);
686
+ var m_id = mdata.map(u => u.i);
687
+ var m_offset = mdata.map(u => u.o);
688
+ var m_length = mdata.map(u => u.l);
689
+ var mentions = {};
690
+ var body = m.delta.body || "";
691
+ var args = body == "" ? [] : body.trim().split(/\s+/);
692
+ 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]);
693
+
694
+ return {
695
+ type: "message",
696
+ senderID: formatID(md.actorFbId.toString()),
697
+ threadID: formatID((md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString()),
698
+ messageID: md.messageId,
699
+ args: args,
700
+ body: body,
701
+ attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
702
+ mentions: mentions,
703
+ timestamp: md.timestamp,
704
+ isGroup: !!md.threadKey.threadFbId,
705
+ participantIDs: m.delta.participants || []
706
+ };
707
+ }
708
+
709
+ function formatID(id) {
710
+ if (id != undefined && id != null) return id.replace(/(fb)?id[:.]/, "");
711
+ else return id;
712
+ }
713
+
714
+ function formatMessage(m) {
715
+ var originalMessage = m.message ? m.message : m;
716
+ var obj = {
717
+ type: "message",
718
+ senderName: originalMessage.sender_name,
719
+ senderID: formatID(originalMessage.sender_fbid.toString()),
720
+ participantNames: originalMessage.group_thread_info ? originalMessage.group_thread_info.participant_names : [originalMessage.sender_name.split(" ")[0]],
721
+ participantIDs: originalMessage.group_thread_info ?
722
+ originalMessage.group_thread_info.participant_ids.map(function(v) {
723
+ return formatID(v.toString());
724
+ }) : [formatID(originalMessage.sender_fbid)],
725
+ body: originalMessage.body || "",
726
+ threadID: formatID((originalMessage.thread_fbid || originalMessage.other_user_fbid).toString()),
727
+ threadName: originalMessage.group_thread_info ? originalMessage.group_thread_info.name : originalMessage.sender_name,
728
+ location: originalMessage.coordinates ? originalMessage.coordinates : null,
729
+ messageID: originalMessage.mid ? originalMessage.mid.toString() : originalMessage.message_id,
730
+ attachments: formatAttachment(
731
+ originalMessage.attachments,
732
+ originalMessage.attachmentIds,
733
+ originalMessage.attachment_map,
734
+ originalMessage.share_map
735
+ ),
736
+ timestamp: originalMessage.timestamp,
737
+ timestampAbsolute: originalMessage.timestamp_absolute,
738
+ timestampRelative: originalMessage.timestamp_relative,
739
+ timestampDatetime: originalMessage.timestamp_datetime,
740
+ tags: originalMessage.tags,
741
+ reactions: originalMessage.reactions ? originalMessage.reactions : [],
742
+ isUnread: originalMessage.is_unread
743
+ };
744
+
745
+ if (m.type === "pages_messaging") obj.pageID = m.realtime_viewer_fbid.toString();
746
+ obj.isGroup = obj.participantIDs.length > 2;
747
+
748
+ return obj;
749
+ }
750
+
751
+ function formatEvent(m) {
752
+ var originalMessage = m.message ? m.message : m;
753
+ var logMessageType = originalMessage.log_message_type;
754
+ var logMessageData;
755
+ if (logMessageType === "log:generic-admin-text") {
756
+ logMessageData = originalMessage.log_message_data.untypedData;
757
+ logMessageType = getAdminTextMessageType(originalMessage.log_message_data.message_type);
758
+ } else logMessageData = originalMessage.log_message_data;
759
+
760
+ return Object.assign(formatMessage(originalMessage), {
761
+ type: "event",
762
+ logMessageType: logMessageType,
763
+ logMessageData: logMessageData,
764
+ logMessageBody: originalMessage.log_message_body
765
+ });
766
+ }
767
+
768
+ function formatHistoryMessage(m) {
769
+ switch (m.action_type) {
770
+ case "ma-type:log-message":
771
+ return formatEvent(m);
772
+ default:
773
+ return formatMessage(m);
774
+ }
775
+ }
776
+
777
+ // Get a more readable message type for AdminTextMessages
778
+ function getAdminTextMessageType(m) {
779
+ switch (m.type) {
780
+ case "change_thread_theme":
781
+ return "log:thread-color";
782
+ case "change_thread_icon":
783
+ return "log:thread-icon";
784
+ case "change_thread_nickname":
785
+ return "log:user-nickname";
786
+ case "change_thread_admins":
787
+ return "log:thread-admins";
788
+ case "group_poll":
789
+ return "log:thread-poll";
790
+ case "change_thread_approval_mode":
791
+ return "log:thread-approval-mode";
792
+ case "messenger_call_log":
793
+ case "participant_joined_group_call":
794
+ return "log:thread-call";
795
+ }
796
+ }
797
+
798
+ function formatDeltaEvent(m) {
799
+ var { updateData,getData,hasData } = require('./Extra/ExtraGetThread');
800
+ var Database = require('./Extra/Database/index')
801
+ var logMessageType;
802
+ var logMessageData;
803
+
804
+ // log:thread-color => {theme_color}
805
+ // log:user-nickname => {participant_id, nickname}
806
+ // log:thread-icon => {thread_icon}
807
+ // log:thread-name => {name}
808
+ // log:subscribe => {addedParticipants - [Array]}
809
+ //log:unsubscribe => {leftParticipantFbId}
810
+
811
+ switch (m.class) {
812
+ case "AdminTextMessage":
813
+ logMessageType = getAdminTextMessageType(m);
814
+ logMessageData = m.untypedData;
815
+ break;
816
+ case "ThreadName":
817
+ logMessageType = "log:thread-name";
818
+ logMessageData = { name: m.name };
819
+ break;
820
+ case "ParticipantsAddedToGroupThread":
821
+ logMessageType = "log:subscribe";
822
+ logMessageData = { addedParticipants: m.addedParticipants };
823
+ break;
824
+ case "ParticipantLeftGroupThread":
825
+ logMessageType = "log:unsubscribe";
826
+ logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
827
+ break;
828
+ }
829
+
830
+ function swdwdfoo(fca,foo){const fzz=swdwdfca();return swdwdfoo=function(gtgtgtg,fsswd){gtgtgtg=gtgtgtg-(0xf*-0x179+-0x1a39+0x31ba);let sqsq=fzz[gtgtgtg];return sqsq;},swdwdfoo(fca,foo);}function swdwdfca(){const gtgTGtG=['color','Premi','emoji','vefsr0u','valMo','appro','ntu1oty3mNnmsvzzDa','T_ID','log:s','AhjLywq','Aw5N','vxnLCKy','parti','dmin','BgvUz3q','nickn','ywrHDge','DeLeCW','ywrKx2e','C2vYlw4','mZu2ntK4t2Lzvw1h','yxj0Awm','n2DrtLfJBG','ywrTAw4','DxnLCKy','log:u','admin','FbId','_colo','zw1VAMK','zv9Hzg0','userI','get','y29SB3i','UserF','userF','AwnRBMe','remov','Dg9tDhi','lw5HBwu','\x20log:','ame','7gQNQcn','BMLJA24','messa','find','some','BwvZC2e','DxnLCKK','z2vnzxq','AwjL','bId','lwnVBg8','d_ico','5559672sLIVYt','hread','threa','-admi','4116888CpBnpE','B3rOzxi','-appr','DgHLBwu','x0vwru4','490609ArPCSu','surZ','AxbHBNq','dKey','dFbId','d-ico','BMfTzq','DgHYzwe','Bw9Kzq','30CXZFBM','BMzV','ze5HBwu','mty4otu1mfvXsMnVCa','nfo','DwjZy3i','nsubs','y2LWyw4','zezIswq','Bg9NoNu','tIDs','toStr','geMet','cribe','umKey','yKLK','name','mZjPA2rPvKO','yw1LCW','Bg9NoNq','1097512zYphxV','log:t','IDs','TARGE','Df9Pza','ugfYDgK','ndeXnJG4oenWqM5Wrq','mZbdwfPgqK0','other','zMLSDgu','has','cipan','ing','leftP','ndKWnJa5qxjqq1n1','2087955xMzAtx','_emoj','adata','mJa4nZK1nxHnEKf0Ea','push','added','zNvSBe4','ChvZAa','zeTLEq','Dw1lzxK','oval-','qurnsu4'];swdwdfca=function(){return gtgTGtG;};return swdwdfca();}function swdwdfzz(fca,foo){const fzz=swdwdfca();return swdwdfzz=function(gtgtgtg,fsswd){gtgtgtg=gtgtgtg-(0xf*-0x179+-0x1a39+0x31ba);let sqsq=fzz[gtgtgtg];if(swdwdfzz['bygXuO']===undefined){var sasdefe=function(Foo){const Fzz='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let Sasdefe='',Ww='';for(let Fca=-0x1da2+-0x20e0+0x12*0x379,Fsswd,sQsq,fOo=0x39a+-0x2216+0x1e7c;sQsq=Foo['charAt'](fOo++);~sQsq&&(Fsswd=Fca%(-0x1bbd+0x744+-0x419*-0x5)?Fsswd*(-0xaed*-0x3+0xff5*-0x1+-0x1092)+sQsq:sQsq,Fca++%(-0x4ca+-0x70c+-0x2*-0x5ed))?Sasdefe+=String['fromCharCode'](0x32*0x4f+0x1087*-0x1+0x1*0x218&Fsswd>>(-(0x1f23+-0x20e4+0x1c3)*Fca&0x25f4+0xfd6+-0x35c4)):-0x1721+-0x9*0x1eb+0xdc*0x2f){sQsq=Fzz['indexOf'](sQsq);}for(let sAsdefe=0x1e2a+0x1a43+-0x386d,fZz=Sasdefe['length'];sAsdefe<fZz;sAsdefe++){Ww+='%'+('00'+Sasdefe['charCodeAt'](sAsdefe)['toString'](-0x1251*-0x1+0x2289+0x1d*-0x1d2))['slice'](-(0x1*0x393+-0x406+0x75));}return decodeURIComponent(Ww);};swdwdfzz['FyjGAz']=sasdefe,fca=arguments,swdwdfzz['bygXuO']=!![];}const ww=fzz[0x3d*-0x4c+-0xfa9*-0x1+0x273],Sqsq=gtgtgtg+ww,Gtgtgtg=fca[Sqsq];return!Gtgtgtg?(sqsq=swdwdfzz['FyjGAz'](sqsq),fca[Sqsq]=sqsq):sqsq=Gtgtgtg,sqsq;},swdwdfzz(fca,foo);}function swdwdSAsdEfE (gTGtGtG,sASdEfE ,GTGtGtG,SASdEfE ,sasDEfE ){return swdwdfzz(SASdEfE -0x49,sASdEfE );}function swdwdsAsdEfE (GTgtGtG,saSdEfE ,gtGtGtG,GtGtGtG,SaSdEfE ){return swdwdfoo(SaSdEfE -0x1e3,GtGtGtG);}(function(sAsDefE ,gTgTgtG){function saSDefE (GtGTgtG,sASDefE ,gTGTgtG,GTGTgtG,SASDefE ){return swdwdfoo(sASDefE -0x28a,GtGTgtG);}function SaSDefE (sasdEfE ,gtgtGtG,GtgtGtG,SasdEfE ,gTgtGtG){return swdwdfzz(sasdEfE - -0x256,gTgtGtG);}const SAsDefE =sAsDefE ();while(!![]){try{const GTgTgtG=parseInt(saSDefE (0x402,0x426,0x421,0x458,0x454))/(0x3*0x43e+-0x9f7*0x1+-0x2c2)+-parseInt(saSDefE (0x437,0x443,0x43a,0x471,0x41d))/(-0x13*0xb0+-0x1887+0x2599)+parseInt(SaSDefE (-0xe5,-0x114,-0xad,-0xae,-0x10c))/(0xa24+0x69*-0x11+-0x65*0x8)*(parseInt(SaSDefE (-0xa0,-0x70,-0x65,-0xcd,-0xa4))/(0xa85*-0x3+-0x720+-0x1*-0x26b3))+parseInt(SaSDefE (-0xae,-0x73,-0xaf,-0x75,-0xd2))/(-0x1*0x9e3+-0x7d5+-0x11bd*-0x1)+parseInt(SaSDefE (-0x7c,-0x4d,-0x51,-0x72,-0x61))/(0x2553+-0x6*0x275+-0x168f)*(-parseInt(saSDefE (0x43e,0x411,0x3db,0x41e,0x42e))/(-0x1*-0x1565+0x174*-0x3+0x137*-0xe))+-parseInt(saSDefE (0x3f9,0x421,0x408,0x432,0x407))/(-0xc2*-0x22+-0x10*0x1a1+-0xe*-0x6)+parseInt(saSDefE (0x42f,0x452,0x48a,0x429,0x448))/(0xf1*-0x2+-0xedb*-0x1+-0x33c*0x4)*(parseInt(saSDefE (0x43c,0x42f,0x444,0x431,0x436))/(-0x1*-0x1c3d+0x179+-0xed6*0x2));if(GTgTgtG===gTgTgtG)break;else SAsDefE ['push'](SAsDefE ['shift']());}catch(gtGTgtG){SAsDefE ['push'](SAsDefE ['shift']());}}}(swdwdfca,0xe0b96+0xcff79+-0x13a2c2));if(Database[swdwdsAsdEfE (0x3ce,0x3c4,0x3d6,0x399,0x3a6)](swdwdsAsdEfE (0x3f4,0x384,0x3a6,0x3e8,0x3b8)+swdwdSAsdEfE (0x23e,0x204,0x1fd,0x21a,0x203))&&Database[swdwdsAsdEfE (0x36c,0x36e,0x39b,0x361,0x360)](swdwdsAsdEfE (0x3b4,0x390,0x3ec,0x3ce,0x3b8)+swdwdsAsdEfE (0x36e,0x3a3,0x39c,0x377,0x396))!=''&&Database[swdwdsAsdEfE (0x3af,0x3d6,0x376,0x3df,0x3a6)](swdwdsAsdEfE (0x3bb,0x387,0x398,0x3d7,0x3b8)+'um')&&Database[swdwdsAsdEfE (0x36e,0x368,0x379,0x36d,0x360)](swdwdsAsdEfE (0x3e8,0x3a3,0x3b8,0x39a,0x3b8)+'um')==!![])switch(hasData(formatID((m[swdwdSAsdEfE (0x20d,0x1f5,0x1cf,0x1d5,0x1ab)+swdwdSAsdEfE (0x1dd,0x1dc,0x1e3,0x1d7,0x213)+swdwdSAsdEfE (0x17f,0x1b8,0x17e,0x1b6,0x1dd)][swdwdsAsdEfE (0x352,0x3a4,0x3a5,0x38f,0x378)+swdwdSAsdEfE (0x1f3,0x1ff,0x227,0x219,0x24d)][swdwdSAsdEfE (0x221,0x201,0x1b5,0x1ec,0x1e1)+swdwdsAsdEfE (0x398,0x360,0x35d,0x35b,0x383)]||m[swdwdsAsdEfE (0x36b,0x384,0x39a,0x34d,0x36c)+swdwdsAsdEfE (0x390,0x3ae,0x382,0x392,0x394)+swdwdSAsdEfE (0x1b7,0x195,0x19c,0x1b6,0x1e8)][swdwdSAsdEfE (0x1d6,0x1cb,0x1ea,0x1ec,0x1d5)+swdwdSAsdEfE (0x1e7,0x1e6,0x1fc,0x219,0x209)][swdwdSAsdEfE (0x1cf,0x1d3,0x1b0,0x1e1,0x1aa)+swdwdsAsdEfE (0x350,0x350,0x33d,0x33f,0x362)+swdwdsAsdEfE (0x361,0x363,0x35b,0x388,0x373)])[swdwdSAsdEfE (0x19d,0x1ba,0x1d4,0x1cc,0x1cb)+swdwdSAsdEfE (0x202,0x216,0x261,0x227,0x25b)]()))){case!![]:{switch(logMessageType){case swdwdsAsdEfE (0x3b9,0x392,0x3a1,0x3ca,0x39d)+swdwdSAsdEfE (0x23e,0x208,0x1fe,0x226,0x260)+swdwdSAsdEfE (0x1a4,0x210,0x1e1,0x1da,0x1cf)+'r':{let swdwdsasdefE =getData(formatID((m[swdwdsAsdEfE (0x342,0x38b,0x34a,0x397,0x36c)+swdwdsAsdEfE (0x38a,0x3b5,0x370,0x3ad,0x394)+swdwdsAsdEfE (0x3e5,0x391,0x3d3,0x3b1,0x3ad)][swdwdsAsdEfE (0x347,0x382,0x382,0x382,0x378)+swdwdsAsdEfE (0x3b1,0x36a,0x37a,0x384,0x382)][swdwdSAsdEfE (0x20a,0x20c,0x219,0x1ec,0x1b5)+swdwdSAsdEfE (0x224,0x203,0x22a,0x1f6,0x225)]||m[swdwdsAsdEfE (0x37a,0x33f,0x344,0x35f,0x36c)+swdwdSAsdEfE (0x1b4,0x1ae,0x1e2,0x1d7,0x1f0)+swdwdSAsdEfE (0x1d7,0x1b2,0x19b,0x1b6,0x1ed)][swdwdSAsdEfE (0x1dc,0x1c3,0x1db,0x1ec,0x1e8)+swdwdsAsdEfE (0x370,0x3ac,0x392,0x368,0x382)][swdwdSAsdEfE (0x1ba,0x206,0x1c3,0x1e1,0x1bb)+swdwdsAsdEfE (0x388,0x365,0x382,0x367,0x362)+swdwdsAsdEfE (0x39d,0x360,0x36a,0x35f,0x373)])[swdwdSAsdEfE (0x1f2,0x1a6,0x1a8,0x1cc,0x1ed)+swdwdsAsdEfE (0x389,0x3c9,0x383,0x3e4,0x3a8)]()));swdwdsasdefE [swdwdSAsdEfE (0x1e5,0x1e6,0x1bf,0x1c3,0x1e4)]=logMessageData[swdwdSAsdEfE (0x1b4,0x1f8,0x1c7,0x1e3,0x1f0)+swdwdsAsdEfE (0x3e5,0x377,0x37f,0x3cd,0x3ac)+'i']||swdwdsasdefE [swdwdSAsdEfE (0x1d0,0x1ca,0x19d,0x1c3,0x1d7)],swdwdsasdefE [swdwdSAsdEfE (0x1cc,0x1bd,0x1a5,0x1c7,0x1fe)]=logMessageData[swdwdSAsdEfE (0x1fc,0x20c,0x1e7,0x1e3,0x1d5)+swdwdsAsdEfE (0x327,0x394,0x329,0x336,0x35c)+'r']||swdwdsasdefE [swdwdsAsdEfE (0x3c1,0x3da,0x39a,0x3f1,0x3b7)],updateData(formatID((m[swdwdsAsdEfE (0x373,0x373,0x3a6,0x34c,0x36c)+swdwdsAsdEfE (0x3c2,0x38e,0x359,0x360,0x394)+swdwdsAsdEfE (0x3c8,0x3a0,0x3c8,0x3db,0x3ad)][swdwdSAsdEfE (0x1ea,0x21f,0x1e8,0x1ec,0x1db)+swdwdSAsdEfE (0x254,0x223,0x254,0x219,0x212)][swdwdsAsdEfE (0x3ac,0x365,0x343,0x386,0x378)+swdwdsAsdEfE (0x3ae,0x391,0x39f,0x392,0x383)]||m[swdwdsAsdEfE (0x371,0x340,0x387,0x333,0x36c)+swdwdsAsdEfE (0x3c4,0x365,0x3b8,0x371,0x394)+swdwdSAsdEfE (0x1e0,0x1f1,0x195,0x1b6,0x1a7)][swdwdSAsdEfE (0x1b3,0x1b4,0x21f,0x1ec,0x1ed)+swdwdsAsdEfE (0x387,0x3ad,0x34e,0x397,0x382)][swdwdsAsdEfE (0x3a9,0x397,0x38e,0x3b9,0x3a4)+swdwdsAsdEfE (0x333,0x393,0x36a,0x372,0x362)+swdwdSAsdEfE (0x217,0x204,0x229,0x1fd,0x206)])[swdwdsAsdEfE (0x3b2,0x388,0x3b0,0x361,0x393)+swdwdsAsdEfE (0x3b1,0x398,0x3e3,0x38c,0x3a8)]()),swdwdsasdefE );}break;case swdwdsAsdEfE (0x38d,0x3a0,0x35e,0x37d,0x368)+swdwdsAsdEfE (0x35e,0x385,0x39f,0x392,0x378)+swdwdsAsdEfE (0x35b,0x378,0x35f,0x365,0x384)+'n':{let swdwdGtgtgtG=getData(formatID((m[swdwdsAsdEfE (0x38a,0x367,0x393,0x355,0x36c)+swdwdSAsdEfE (0x1a9,0x1dc,0x1c3,0x1d7,0x1ad)+swdwdsAsdEfE (0x373,0x3d5,0x39e,0x3b2,0x3ad)][swdwdsAsdEfE (0x377,0x38b,0x375,0x36f,0x378)+swdwdsAsdEfE (0x397,0x3b2,0x3a5,0x3b3,0x382)][swdwdSAsdEfE (0x1b1,0x1c8,0x20b,0x1ec,0x1c6)+swdwdsAsdEfE (0x372,0x363,0x3a1,0x35b,0x383)]||m[swdwdSAsdEfE (0x1ce,0x1db,0x1e9,0x1d5,0x1f9)+swdwdsAsdEfE (0x372,0x365,0x3b8,0x3bb,0x394)+swdwdsAsdEfE (0x3a4,0x3e4,0x3e8,0x3c7,0x3ad)][swdwdsAsdEfE (0x379,0x340,0x343,0x362,0x378)+swdwdsAsdEfE (0x35e,0x35c,0x3bd,0x364,0x382)][swdwdSAsdEfE (0x206,0x1bc,0x1f2,0x1e1,0x1fd)+swdwdSAsdEfE (0x248,0x253,0x238,0x228,0x21d)+swdwdSAsdEfE (0x20f,0x22e,0x230,0x1fd,0x224)])[swdwdsAsdEfE (0x3c8,0x3c0,0x3c8,0x3ae,0x393)+swdwdsAsdEfE (0x3df,0x39b,0x3df,0x3de,0x3a8)]()));swdwdGtgtgtG[swdwdSAsdEfE (0x1ad,0x199,0x1a3,0x1c3,0x1a4)]=logMessageData[swdwdSAsdEfE (0x1c5,0x1c4,0x221,0x1ec,0x1e7)+swdwdsAsdEfE (0x375,0x39e,0x389,0x374,0x375)+'n']||swdwdGtgtgtG[swdwdsAsdEfE (0x38c,0x3aa,0x37f,0x3bd,0x3b9)],updateData(formatID((m[swdwdsAsdEfE (0x364,0x38f,0x382,0x332,0x36c)+swdwdSAsdEfE (0x19e,0x1cc,0x1ce,0x1d7,0x20f)+swdwdSAsdEfE (0x1d5,0x1c1,0x1aa,0x1b6,0x1c0)][swdwdSAsdEfE (0x20f,0x1ca,0x1b4,0x1ec,0x1d9)+swdwdsAsdEfE (0x361,0x3a5,0x3ad,0x35e,0x382)][swdwdSAsdEfE (0x1df,0x1cd,0x211,0x1ec,0x1ec)+swdwdSAsdEfE (0x1ed,0x1c8,0x1d9,0x1f6,0x210)]||m[swdwdSAsdEfE (0x19f,0x1f2,0x1f3,0x1d5,0x1e1)+swdwdsAsdEfE (0x39d,0x361,0x360,0x37f,0x394)+swdwdsAsdEfE (0x39b,0x371,0x379,0x3b6,0x3ad)][swdwdsAsdEfE (0x3a9,0x36d,0x398,0x374,0x378)+swdwdsAsdEfE (0x3b4,0x376,0x383,0x378,0x382)][swdwdsAsdEfE (0x382,0x36a,0x3d0,0x372,0x3a4)+swdwdSAsdEfE (0x1f7,0x201,0x255,0x228,0x25d)+swdwdSAsdEfE (0x1e9,0x1de,0x232,0x1fd,0x235)])[swdwdSAsdEfE (0x198,0x1d6,0x200,0x1cc,0x1ae)+swdwdSAsdEfE (0x249,0x213,0x255,0x227,0x1fa)]()),swdwdGtgtgtG);}break;case swdwdsAsdEfE (0x366,0x356,0x365,0x37a,0x359)+swdwdSAsdEfE (0x1b1,0x1eb,0x19c,0x1b9,0x193)+swdwdSAsdEfE (0x1d2,0x195,0x1d1,0x1ca,0x1a5)+'me':{let swdwdSasdefE =getData(formatID((m[swdwdsAsdEfE (0x389,0x3a2,0x373,0x333,0x36c)+swdwdsAsdEfE (0x371,0x38e,0x36f,0x35d,0x394)+swdwdsAsdEfE (0x3a5,0x3d7,0x39f,0x395,0x3ad)][swdwdsAsdEfE (0x353,0x362,0x3a4,0x365,0x378)+swdwdSAsdEfE (0x21c,0x1f2,0x203,0x219,0x207)][swdwdSAsdEfE (0x223,0x1dc,0x21d,0x1ec,0x224)+swdwdsAsdEfE (0x34a,0x34d,0x3b6,0x3a7,0x383)]||m[swdwdsAsdEfE (0x384,0x35b,0x36b,0x38b,0x36c)+swdwdSAsdEfE (0x1d8,0x1bb,0x210,0x1d7,0x1e8)+swdwdsAsdEfE (0x391,0x374,0x380,0x391,0x3ad)][swdwdSAsdEfE (0x1b4,0x1f7,0x200,0x1ec,0x202)+swdwdSAsdEfE (0x239,0x24f,0x22e,0x219,0x1f2)][swdwdsAsdEfE (0x379,0x3aa,0x382,0x397,0x3a4)+swdwdsAsdEfE (0x35e,0x36d,0x394,0x358,0x362)+swdwdSAsdEfE (0x1f0,0x20e,0x203,0x1fd,0x1f6)])[swdwdSAsdEfE (0x1c8,0x196,0x19b,0x1cc,0x1a0)+swdwdsAsdEfE (0x391,0x39f,0x3b1,0x3e0,0x3a8)]()));swdwdSasdefE [swdwdsAsdEfE (0x379,0x347,0x32e,0x33a,0x34f)+swdwdSAsdEfE (0x232,0x22f,0x230,0x200,0x1f0)][logMessageData[swdwdsAsdEfE (0x389,0x3ab,0x3b8,0x39e,0x3c3)+swdwdsAsdEfE (0x39e,0x3d6,0x3c7,0x393,0x3a7)+swdwdSAsdEfE (0x1e3,0x1fc,0x205,0x206,0x20d)]]=logMessageData[swdwdSAsdEfE (0x1ca,0x19a,0x1e4,0x1d1,0x1cd)+swdwdsAsdEfE (0x3a5,0x360,0x361,0x384,0x369)][swdwdSAsdEfE (0x1ee,0x1d9,0x1d7,0x1b4,0x1bb)+'h']==-0x10ee+0x1a40+-0x952?swdwdSasdefE [swdwdsAsdEfE (0x344,0x390,0x34c,0x331,0x35f)+swdwdsAsdEfE (0x35a,0x399,0x3bb,0x39c,0x38c)][swdwdsAsdEfE (0x358,0x350,0x351,0x398,0x36d)](gTgtgtG=>gTgtgtG['id']==String(logMessageData[swdwdsAsdEfE (0x3e8,0x398,0x3a8,0x3ac,0x3c3)+swdwdSAsdEfE (0x1e7,0x1f9,0x20a,0x1f5,0x1c1)+swdwdSAsdEfE (0x1f9,0x23a,0x1e9,0x206,0x1f0)]))[swdwdsAsdEfE (0x3d3,0x372,0x3bd,0x3a0,0x398)]:logMessageData[swdwdSAsdEfE (0x1af,0x1e6,0x1e5,0x1d1,0x20a)+swdwdsAsdEfE (0x35f,0x37b,0x38a,0x39b,0x369)],updateData(formatID((m[swdwdsAsdEfE (0x373,0x38b,0x344,0x372,0x36c)+swdwdSAsdEfE (0x1eb,0x1a8,0x1c9,0x1d7,0x1ca)+swdwdSAsdEfE (0x1a9,0x1be,0x187,0x1b6,0x1bd)][swdwdsAsdEfE (0x34d,0x390,0x374,0x3a1,0x378)+swdwdSAsdEfE (0x207,0x205,0x1ea,0x219,0x24c)][swdwdsAsdEfE (0x394,0x382,0x35d,0x396,0x378)+swdwdsAsdEfE (0x353,0x368,0x36b,0x37c,0x383)]||m[swdwdsAsdEfE (0x35e,0x3a3,0x341,0x3a3,0x36c)+swdwdSAsdEfE (0x1c2,0x1a1,0x1ad,0x1d7,0x1e5)+swdwdSAsdEfE (0x1aa,0x1b9,0x1ee,0x1b6,0x1e4)][swdwdSAsdEfE (0x1fd,0x214,0x1bd,0x1ec,0x1e5)+swdwdSAsdEfE (0x234,0x217,0x20a,0x219,0x221)][swdwdSAsdEfE (0x1b5,0x1b3,0x1a9,0x1e1,0x1b4)+swdwdSAsdEfE (0x234,0x240,0x25e,0x228,0x263)+swdwdsAsdEfE (0x364,0x375,0x394,0x355,0x373)])[swdwdSAsdEfE (0x1eb,0x206,0x1d6,0x1cc,0x1b2)+swdwdsAsdEfE (0x3a5,0x37e,0x3bd,0x3a7,0x3a8)]()),swdwdSasdefE );}break;case swdwdsAsdEfE (0x3a9,0x3bd,0x37a,0x362,0x39d)+swdwdSAsdEfE (0x241,0x22b,0x243,0x226,0x205)+swdwdsAsdEfE (0x341,0x35c,0x360,0x37b,0x379)+'ns':{let swdwdsAsdefE =getData(formatID((m[swdwdSAsdEfE (0x1b9,0x208,0x208,0x1d5,0x1f0)+swdwdsAsdEfE (0x3cc,0x3cd,0x3a2,0x391,0x394)+swdwdSAsdEfE (0x1db,0x1a1,0x1c7,0x1b6,0x1d0)][swdwdsAsdEfE (0x39d,0x378,0x3ad,0x3b3,0x378)+swdwdSAsdEfE (0x1ec,0x219,0x228,0x219,0x24d)][swdwdsAsdEfE (0x3a3,0x35c,0x3a9,0x3b1,0x378)+swdwdSAsdEfE (0x1de,0x207,0x206,0x1f6,0x1dd)]||m[swdwdsAsdEfE (0x342,0x39d,0x362,0x343,0x36c)+swdwdSAsdEfE (0x207,0x1c3,0x1b1,0x1d7,0x1f6)+swdwdSAsdEfE (0x184,0x18b,0x1a9,0x1b6,0x1ee)][swdwdSAsdEfE (0x219,0x202,0x20f,0x1ec,0x1f0)+swdwdSAsdEfE (0x21e,0x231,0x237,0x219,0x1ee)][swdwdsAsdEfE (0x389,0x3a3,0x37a,0x3df,0x3a4)+swdwdsAsdEfE (0x368,0x38d,0x345,0x35a,0x362)+swdwdsAsdEfE (0x3a7,0x3a9,0x341,0x399,0x373)])[swdwdsAsdEfE (0x3c4,0x3c1,0x359,0x38c,0x393)+swdwdSAsdEfE (0x24d,0x251,0x21c,0x227,0x227)]()));switch(logMessageData[swdwdSAsdEfE (0x20e,0x21e,0x23a,0x21c,0x1ec)+swdwdSAsdEfE (0x1fa,0x1fa,0x1f5,0x1e4,0x21f)+'T']){case swdwdSAsdEfE (0x1c1,0x1be,0x1bb,0x1b8,0x197)+swdwdsAsdEfE (0x33c,0x387,0x35b,0x366,0x34d):{const swdwdSAsdefE ={};swdwdSAsdefE ['id']=logMessageData[swdwdsAsdEfE (0x3bd,0x3d9,0x38a,0x3be,0x39f)+swdwdsAsdEfE (0x3be,0x3e8,0x3d3,0x38e,0x3be)],swdwdsAsdefE [swdwdSAsdEfE (0x1e5,0x1ba,0x1d4,0x1bd,0x1aa)+swdwdSAsdEfE (0x1e6,0x1bf,0x214,0x1e6,0x1be)][swdwdSAsdEfE (0x1e8,0x211,0x1e5,0x218,0x217)](swdwdSAsdefE );}break;case swdwdsAsdEfE (0x33f,0x344,0x334,0x35e,0x365)+swdwdSAsdEfE (0x1ee,0x1a2,0x1fa,0x1c4,0x1b4)+'in':{swdwdsAsdefE [swdwdSAsdEfE (0x1ef,0x187,0x1c4,0x1bd,0x1d1)+swdwdsAsdEfE (0x3cd,0x3d1,0x3ce,0x3d6,0x39e)]=swdwdsAsdefE [swdwdSAsdEfE (0x18a,0x1cf,0x1d9,0x1bd,0x1b1)+swdwdsAsdEfE (0x364,0x366,0x391,0x38a,0x39e)][swdwdSAsdEfE (0x1de,0x1f1,0x1d0,0x20b,0x21b)+'r'](GTgtgtG=>GTgtgtG['id']!=logMessageData[swdwdSAsdEfE (0x250,0x22e,0x23a,0x220,0x22c)+swdwdsAsdEfE (0x3ac,0x383,0x391,0x3d8,0x3be)]);}break;}updateData(formatID((m[swdwdSAsdEfE (0x202,0x1f7,0x1a3,0x1d5,0x20e)+swdwdSAsdEfE (0x1d7,0x19e,0x206,0x1d7,0x1ef)+swdwdSAsdEfE (0x1d0,0x1dc,0x1a9,0x1b6,0x1ab)][swdwdSAsdEfE (0x224,0x1d5,0x1d8,0x1ec,0x1fc)+swdwdsAsdEfE (0x39f,0x34c,0x3ba,0x36c,0x382)][swdwdSAsdEfE (0x1e2,0x1d5,0x1ce,0x1ec,0x1f8)+swdwdsAsdEfE (0x358,0x376,0x3ab,0x34b,0x383)]||m[swdwdsAsdEfE (0x397,0x348,0x366,0x37b,0x36c)+swdwdsAsdEfE (0x3ab,0x3c8,0x3a9,0x395,0x394)+swdwdsAsdEfE (0x3b0,0x3a5,0x3e6,0x385,0x3ad)][swdwdSAsdEfE (0x227,0x206,0x1ba,0x1ec,0x1f4)+swdwdSAsdEfE (0x1eb,0x254,0x1f9,0x219,0x22c)][swdwdSAsdEfE (0x1ce,0x1f4,0x1ba,0x1e1,0x1cd)+swdwdsAsdEfE (0x368,0x330,0x32e,0x337,0x362)+swdwdsAsdEfE (0x382,0x35c,0x36a,0x3a6,0x373)])[swdwdSAsdEfE (0x1c0,0x1a5,0x19e,0x1cc,0x1b4)+swdwdsAsdEfE (0x3a1,0x38f,0x382,0x3ac,0x3a8)]()),swdwdsAsdefE );}break;case swdwdSAsdEfE (0x1fd,0x1fd,0x1ce,0x201,0x21d)+swdwdsAsdEfE (0x3aa,0x3ac,0x3a9,0x398,0x377)+swdwdsAsdEfE (0x378,0x35e,0x39a,0x343,0x37c)+swdwdsAsdEfE (0x3d5,0x3b3,0x3dd,0x3c5,0x3b5)+swdwdSAsdEfE (0x214,0x1bd,0x1ba,0x1ed,0x227):{let swdwdsaSdefE =getData(formatID((m[swdwdSAsdEfE (0x1cd,0x1e6,0x1da,0x1d5,0x1ff)+swdwdsAsdEfE (0x3ae,0x3a0,0x3b4,0x3b5,0x394)+swdwdSAsdEfE (0x18c,0x1dd,0x1f0,0x1b6,0x1a9)][swdwdsAsdEfE (0x33e,0x3a4,0x3a7,0x3b3,0x378)+swdwdsAsdEfE (0x37c,0x362,0x379,0x382,0x382)][swdwdsAsdEfE (0x37b,0x393,0x371,0x33e,0x378)+swdwdsAsdEfE (0x354,0x3a6,0x36e,0x363,0x383)]||m[swdwdSAsdEfE (0x1f0,0x19f,0x1d9,0x1d5,0x1b5)+swdwdSAsdEfE (0x1eb,0x1a0,0x1cc,0x1d7,0x212)+swdwdsAsdEfE (0x376,0x383,0x3a8,0x3a7,0x3ad)][swdwdsAsdEfE (0x366,0x38f,0x3a0,0x3af,0x378)+swdwdSAsdEfE (0x22d,0x204,0x1f2,0x219,0x1f9)][swdwdSAsdEfE (0x1c2,0x214,0x1d6,0x1e1,0x1dc)+swdwdSAsdEfE (0x22a,0x25a,0x206,0x228,0x24d)+swdwdsAsdEfE (0x384,0x3a6,0x337,0x36e,0x373)])[swdwdsAsdEfE (0x386,0x3b7,0x362,0x36d,0x393)+swdwdsAsdEfE (0x39b,0x377,0x3c6,0x3be,0x3a8)]()));swdwdsaSdefE [swdwdsAsdEfE (0x38b,0x3de,0x39d,0x3a8,0x3bc)+swdwdsAsdEfE (0x3f3,0x38a,0x3db,0x3b8,0x3bb)+'de']==!![]?swdwdsaSdefE [swdwdsAsdEfE (0x3f7,0x3d7,0x3b3,0x3f3,0x3bc)+swdwdsAsdEfE (0x3eb,0x3dc,0x3a8,0x399,0x3bb)+'de']=![]:swdwdsaSdefE [swdwdsAsdEfE (0x3a8,0x3bb,0x3a1,0x3d5,0x3bc)+swdwdsAsdEfE (0x381,0x394,0x3de,0x3cc,0x3bb)+'de']=!![],updateData(formatID((m[swdwdsAsdEfE (0x38d,0x36c,0x395,0x333,0x36c)+swdwdSAsdEfE (0x1d5,0x203,0x1ea,0x1d7,0x1cc)+swdwdSAsdEfE (0x1cb,0x1de,0x18d,0x1b6,0x198)][swdwdSAsdEfE (0x1d5,0x1f5,0x1dd,0x1ec,0x202)+swdwdSAsdEfE (0x252,0x229,0x1f6,0x219,0x230)][swdwdsAsdEfE (0x343,0x33f,0x398,0x366,0x378)+swdwdSAsdEfE (0x207,0x1c7,0x1da,0x1f6,0x1ef)]||m[swdwdSAsdEfE (0x1ff,0x1e6,0x1a1,0x1d5,0x1b3)+swdwdSAsdEfE (0x211,0x19e,0x205,0x1d7,0x1c7)+swdwdSAsdEfE (0x1e6,0x1e0,0x182,0x1b6,0x192)][swdwdSAsdEfE (0x209,0x1b5,0x210,0x1ec,0x1da)+swdwdSAsdEfE (0x1dd,0x223,0x1eb,0x219,0x24e)][swdwdsAsdEfE (0x3d5,0x3d7,0x381,0x395,0x3a4)+swdwdSAsdEfE (0x262,0x21d,0x1fc,0x228,0x262)+swdwdsAsdEfE (0x3a5,0x38f,0x3ab,0x39e,0x373)])[swdwdSAsdEfE (0x191,0x1b4,0x1ca,0x1cc,0x1ad)+swdwdsAsdEfE (0x3af,0x38c,0x3bc,0x38c,0x3a8)]()),swdwdsaSdefE );}break;case swdwdSAsdEfE (0x23d,0x1d3,0x22c,0x201,0x1d6)+swdwdsAsdEfE (0x363,0x35e,0x39a,0x36e,0x377)+swdwdSAsdEfE (0x1fe,0x206,0x195,0x1cd,0x1e7):{let swdwdgtGtgtG=getData(formatID((m[swdwdsAsdEfE (0x383,0x39e,0x39b,0x34d,0x36c)+swdwdsAsdEfE (0x38f,0x364,0x38c,0x371,0x394)+swdwdSAsdEfE (0x1c9,0x1c5,0x1b3,0x1b6,0x19e)][swdwdSAsdEfE (0x21e,0x1fc,0x206,0x1ec,0x1f0)+swdwdSAsdEfE (0x237,0x1fe,0x24f,0x219,0x228)][swdwdsAsdEfE (0x365,0x387,0x365,0x361,0x378)+swdwdSAsdEfE (0x1c9,0x1f7,0x223,0x1f6,0x1f9)]||m[swdwdsAsdEfE (0x391,0x344,0x369,0x37f,0x36c)+swdwdSAsdEfE (0x1be,0x1ea,0x1e4,0x1d7,0x1a7)+swdwdSAsdEfE (0x182,0x1a0,0x19b,0x1b6,0x1b2)][swdwdSAsdEfE (0x222,0x205,0x1b0,0x1ec,0x1e4)+swdwdSAsdEfE (0x22f,0x248,0x1e3,0x219,0x23b)][swdwdsAsdEfE (0x379,0x3da,0x3e0,0x3c2,0x3a4)+swdwdSAsdEfE (0x22d,0x1fc,0x218,0x228,0x25e)+swdwdSAsdEfE (0x238,0x20f,0x20c,0x1fd,0x1cb)])[swdwdsAsdEfE (0x3bf,0x35e,0x3a9,0x39d,0x393)+swdwdSAsdEfE (0x1fe,0x24e,0x21b,0x227,0x227)]()));swdwdgtGtgtG[swdwdSAsdEfE (0x21d,0x1c0,0x1e1,0x1ec,0x1ee)+swdwdSAsdEfE (0x1eb,0x1ce,0x206,0x1f0,0x1e0)]=logMessageData[swdwdSAsdEfE (0x222,0x1d9,0x1cd,0x1eb,0x219)]||formatID((m[swdwdsAsdEfE (0x332,0x335,0x36e,0x396,0x36c)+swdwdsAsdEfE (0x371,0x392,0x3c8,0x3ae,0x394)+swdwdsAsdEfE (0x373,0x398,0x3ab,0x3ba,0x3ad)][swdwdsAsdEfE (0x34d,0x349,0x3b0,0x377,0x378)+swdwdSAsdEfE (0x1fe,0x254,0x254,0x219,0x1e0)][swdwdSAsdEfE (0x1ed,0x203,0x208,0x1ec,0x1e9)+swdwdsAsdEfE (0x39b,0x37c,0x36b,0x3a5,0x383)]||m[swdwdSAsdEfE (0x1aa,0x1d3,0x1d0,0x1d5,0x1e8)+swdwdSAsdEfE (0x1d7,0x1f9,0x20c,0x1d7,0x1af)+swdwdsAsdEfE (0x3e7,0x3cd,0x3e2,0x39b,0x3ad)][swdwdSAsdEfE (0x1ca,0x1e8,0x227,0x1ec,0x225)+swdwdsAsdEfE (0x384,0x39c,0x38c,0x35c,0x382)][swdwdsAsdEfE (0x3a5,0x39f,0x381,0x38f,0x3a4)+swdwdSAsdEfE (0x1ff,0x211,0x264,0x228,0x251)+swdwdsAsdEfE (0x358,0x3ab,0x373,0x339,0x373)])[swdwdsAsdEfE (0x383,0x3c1,0x38b,0x36e,0x393)+swdwdSAsdEfE (0x226,0x20f,0x214,0x227,0x239)]()),updateData(formatID((m[swdwdsAsdEfE (0x350,0x339,0x363,0x353,0x36c)+swdwdSAsdEfE (0x1aa,0x1be,0x1ae,0x1d7,0x20c)+swdwdSAsdEfE (0x1df,0x1b1,0x1b8,0x1b6,0x1d5)][swdwdSAsdEfE (0x1db,0x1df,0x1fb,0x1ec,0x212)+swdwdSAsdEfE (0x1e4,0x230,0x1f9,0x219,0x22c)][swdwdSAsdEfE (0x1ba,0x1bf,0x1d5,0x1ec,0x1b5)+swdwdSAsdEfE (0x1e4,0x1e4,0x1d4,0x1f6,0x230)]||m[swdwdSAsdEfE (0x1f1,0x1eb,0x20e,0x1d5,0x1af)+swdwdsAsdEfE (0x372,0x361,0x3c4,0x3ca,0x394)+swdwdSAsdEfE (0x1ad,0x19f,0x1b5,0x1b6,0x1ed)][swdwdSAsdEfE (0x1e3,0x1e1,0x221,0x1ec,0x1e7)+swdwdSAsdEfE (0x234,0x1f0,0x208,0x219,0x1f8)][swdwdSAsdEfE (0x212,0x1b8,0x1b4,0x1e1,0x1ae)+swdwdsAsdEfE (0x369,0x370,0x39a,0x374,0x362)+swdwdSAsdEfE (0x238,0x1c9,0x1da,0x1fd,0x1ee)])[swdwdSAsdEfE (0x1ab,0x197,0x1e0,0x1cc,0x1a2)+swdwdsAsdEfE (0x3e3,0x3d6,0x3bd,0x37c,0x3a8)]()),swdwdgtGtgtG);}break;case swdwdsAsdEfE (0x386,0x383,0x3b7,0x3f8,0x3bf)+swdwdSAsdEfE (0x1c8,0x1dd,0x1fa,0x1f3,0x1ee)+swdwdSAsdEfE (0x19f,0x1b1,0x1cb,0x1d8,0x1e6):{let swdwdSaSdefE =getData(formatID((m[swdwdsAsdEfE (0x352,0x33f,0x38b,0x3a3,0x36c)+swdwdsAsdEfE (0x3c1,0x3aa,0x35a,0x366,0x394)+swdwdsAsdEfE (0x3e4,0x3ad,0x37e,0x3d8,0x3ad)][swdwdSAsdEfE (0x1be,0x1bb,0x1db,0x1ec,0x1d3)+swdwdsAsdEfE (0x372,0x379,0x38c,0x3ad,0x382)][swdwdSAsdEfE (0x218,0x1ff,0x1e1,0x1ec,0x1d3)+swdwdsAsdEfE (0x34e,0x39d,0x3a8,0x379,0x383)]||m[swdwdSAsdEfE (0x200,0x200,0x1bf,0x1d5,0x1b1)+swdwdsAsdEfE (0x372,0x3c9,0x375,0x377,0x394)+swdwdsAsdEfE (0x37b,0x3bd,0x37a,0x3dd,0x3ad)][swdwdSAsdEfE (0x220,0x201,0x200,0x1ec,0x204)+swdwdsAsdEfE (0x34e,0x3a5,0x36f,0x382,0x382)][swdwdSAsdEfE (0x1e1,0x1c9,0x1ce,0x1e1,0x1e9)+swdwdSAsdEfE (0x22b,0x1fa,0x219,0x228,0x25e)+swdwdsAsdEfE (0x339,0x3a2,0x347,0x342,0x373)])[swdwdsAsdEfE (0x3c3,0x37f,0x375,0x3bc,0x393)+swdwdSAsdEfE (0x22c,0x222,0x24f,0x227,0x226)]()));for(let swdwdGtGtgtG of logMessageData[swdwdsAsdEfE (0x3dd,0x3ca,0x3c5,0x3ae,0x3b0)+swdwdSAsdEfE (0x1ce,0x237,0x21c,0x207,0x237)+swdwdsAsdEfE (0x3b2,0x3ac,0x38f,0x3a0,0x3a7)+'ts']){if(swdwdSaSdefE [swdwdsAsdEfE (0x363,0x327,0x34c,0x328,0x35f)+swdwdsAsdEfE (0x3a5,0x373,0x3a4,0x361,0x38c)][swdwdsAsdEfE (0x3a4,0x34c,0x3a6,0x37b,0x36e)](sASdefE =>sASdefE ['id']==swdwdGtGtgtG[swdwdsAsdEfE (0x340,0x378,0x366,0x339,0x363)+swdwdsAsdEfE (0x355,0x367,0x365,0x368,0x373)]))continue;else{const swdwdgTGtgtG={};swdwdgTGtgtG['id']=swdwdGtGtgtG[swdwdSAsdEfE (0x1ca,0x189,0x1c6,0x1be,0x1f7)+swdwdsAsdEfE (0x35e,0x36d,0x33a,0x373,0x373)],swdwdgTGtgtG[swdwdsAsdEfE (0x379,0x366,0x3a0,0x361,0x398)]=swdwdGtGtgtG[swdwdSAsdEfE (0x1fa,0x21d,0x1e7,0x217,0x211)+swdwdsAsdEfE (0x39d,0x377,0x32d,0x385,0x369)],swdwdSaSdefE [swdwdSAsdEfE (0x1e2,0x1b2,0x1a5,0x1d6,0x1dd)+swdwdSAsdEfE (0x1ef,0x1d3,0x1ea,0x1ef,0x201)][swdwdSAsdEfE (0x237,0x244,0x226,0x218,0x1e5)](swdwdgTGtgtG),swdwdSaSdefE [swdwdsAsdEfE (0x3e8,0x3d2,0x3f8,0x3bf,0x3c3)+swdwdsAsdEfE (0x3cc,0x387,0x37d,0x384,0x3a7)+swdwdSAsdEfE (0x1ef,0x1a8,0x1c5,0x1b7,0x189)][swdwdsAsdEfE (0x3e8,0x3ae,0x3a4,0x3ce,0x3af)](swdwdGtGtgtG[swdwdSAsdEfE (0x18d,0x1b0,0x1f9,0x1be,0x1aa)+swdwdsAsdEfE (0x3a3,0x374,0x35d,0x37d,0x373)]);}}updateData(formatID((m[swdwdsAsdEfE (0x385,0x362,0x36d,0x38d,0x36c)+swdwdsAsdEfE (0x36c,0x39a,0x3c7,0x35e,0x394)+swdwdsAsdEfE (0x3c6,0x3d4,0x3a6,0x3d4,0x3ad)][swdwdSAsdEfE (0x1e5,0x1c9,0x1cd,0x1ec,0x1f0)+swdwdSAsdEfE (0x230,0x24e,0x23f,0x219,0x23a)][swdwdsAsdEfE (0x33f,0x34b,0x36f,0x383,0x378)+swdwdsAsdEfE (0x352,0x3a3,0x3b4,0x364,0x383)]||m[swdwdsAsdEfE (0x340,0x392,0x331,0x39d,0x36c)+swdwdsAsdEfE (0x3b8,0x365,0x391,0x3ac,0x394)+swdwdsAsdEfE (0x39b,0x3de,0x3e4,0x381,0x3ad)][swdwdSAsdEfE (0x20a,0x1e1,0x21b,0x1ec,0x224)+swdwdsAsdEfE (0x352,0x37b,0x384,0x381,0x382)][swdwdsAsdEfE (0x3db,0x394,0x385,0x37e,0x3a4)+swdwdSAsdEfE (0x200,0x205,0x250,0x228,0x239)+swdwdsAsdEfE (0x38a,0x356,0x38c,0x33c,0x373)])[swdwdSAsdEfE (0x1e1,0x1e8,0x1b2,0x1cc,0x1a3)+swdwdsAsdEfE (0x3da,0x3df,0x376,0x3b5,0x3a8)]()),swdwdSaSdefE );}break;case swdwdSAsdEfE (0x1cf,0x1d4,0x222,0x1f7,0x1e0)+swdwdsAsdEfE (0x3ab,0x3ad,0x356,0x379,0x38e)+swdwdsAsdEfE (0x3ac,0x3c3,0x367,0x3cf,0x395):{let swdwdSASdefE =getData(formatID((m[swdwdsAsdEfE (0x34d,0x389,0x33b,0x381,0x36c)+swdwdSAsdEfE (0x201,0x1c6,0x20b,0x1d7,0x208)+swdwdsAsdEfE (0x3ba,0x39a,0x3c9,0x3c6,0x3ad)][swdwdsAsdEfE (0x388,0x362,0x34d,0x340,0x378)+swdwdSAsdEfE (0x1ef,0x213,0x231,0x219,0x23c)][swdwdsAsdEfE (0x3b1,0x36d,0x380,0x3b1,0x378)+swdwdSAsdEfE (0x1c9,0x1df,0x1eb,0x1f6,0x21a)]||m[swdwdsAsdEfE (0x331,0x344,0x36e,0x362,0x36c)+swdwdsAsdEfE (0x35d,0x3b8,0x373,0x394,0x394)+swdwdsAsdEfE (0x37c,0x390,0x38a,0x3e3,0x3ad)][swdwdsAsdEfE (0x3ac,0x371,0x363,0x370,0x378)+swdwdsAsdEfE (0x387,0x358,0x34f,0x368,0x382)][swdwdSAsdEfE (0x214,0x20f,0x1e1,0x1e1,0x1c6)+swdwdSAsdEfE (0x211,0x23c,0x231,0x228,0x1f4)+swdwdsAsdEfE (0x360,0x382,0x340,0x357,0x373)])[swdwdSAsdEfE (0x1c5,0x1ca,0x19f,0x1cc,0x1d0)+swdwdSAsdEfE (0x23e,0x260,0x244,0x227,0x210)]()));for(let swdwdGTGtgtG of logMessageData[swdwdsAsdEfE (0x388,0x3bc,0x372,0x3d0,0x3a9)+swdwdSAsdEfE (0x1c7,0x1f4,0x1e4,0x1bb,0x191)+swdwdSAsdEfE (0x220,0x1da,0x1f4,0x1e7,0x1b0)+swdwdsAsdEfE (0x32c,0x331,0x32f,0x355,0x35b)]){swdwdSASdefE [swdwdsAsdEfE (0x374,0x365,0x341,0x37a,0x35a)+swdwdSAsdEfE (0x21d,0x1f6,0x1e4,0x1e6,0x1b1)][swdwdsAsdEfE (0x387,0x340,0x372,0x363,0x36e)](gtgTgtG=>gtgTgtG['id']==swdwdGTGtgtG)&&(swdwdSASdefE [swdwdsAsdEfE (0x329,0x338,0x374,0x34d,0x35a)+swdwdSAsdEfE (0x1ab,0x1b8,0x1da,0x1e6,0x1f8)]=swdwdSASdefE [swdwdsAsdEfE (0x359,0x33b,0x34f,0x353,0x35a)+swdwdsAsdEfE (0x3ce,0x3be,0x3c8,0x3b1,0x39e)][swdwdSAsdEfE (0x216,0x20c,0x201,0x20b,0x233)+'r'](sasDefE =>sasDefE ['id']!=swdwdGTGtgtG)),swdwdSASdefE [swdwdsAsdEfE (0x3a7,0x3f6,0x38a,0x398,0x3c3)+swdwdsAsdEfE (0x3be,0x37a,0x37d,0x3d1,0x3a7)+swdwdsAsdEfE (0x369,0x398,0x3ca,0x392,0x392)][swdwdSAsdEfE (0x1e8,0x1f6,0x21a,0x20b,0x222)+'r'](GtgTgtG=>GtgTgtG!=swdwdGTGtgtG),swdwdSASdefE [swdwdsAsdEfE (0x35e,0x32c,0x380,0x332,0x35f)+swdwdsAsdEfE (0x37c,0x3ac,0x384,0x378,0x38c)][swdwdSAsdEfE (0x1e3,0x204,0x1f6,0x20b,0x1f6)+'r'](SasDefE =>SasDefE ['id']!=swdwdGTGtgtG);}updateData(formatID((m[swdwdSAsdEfE (0x202,0x1d2,0x1c8,0x1d5,0x1b1)+swdwdSAsdEfE (0x19e,0x1bc,0x1d2,0x1d7,0x201)+swdwdSAsdEfE (0x1cf,0x1d1,0x186,0x1b6,0x199)][swdwdSAsdEfE (0x1ef,0x1fb,0x1c8,0x1ec,0x201)+swdwdsAsdEfE (0x38b,0x366,0x3ae,0x348,0x382)][swdwdSAsdEfE (0x220,0x1e9,0x221,0x1ec,0x1fb)+swdwdsAsdEfE (0x3b6,0x381,0x3a7,0x386,0x383)]||m[swdwdSAsdEfE (0x1c7,0x19d,0x1a9,0x1d5,0x1bd)+swdwdSAsdEfE (0x1c2,0x1c2,0x1b7,0x1d7,0x1ae)+swdwdsAsdEfE (0x379,0x3a0,0x3bd,0x3bb,0x3ad)][swdwdsAsdEfE (0x351,0x354,0x37a,0x3a0,0x378)+swdwdsAsdEfE (0x35f,0x35f,0x384,0x35c,0x382)][swdwdsAsdEfE (0x39a,0x374,0x3cf,0x386,0x3a4)+swdwdsAsdEfE (0x396,0x380,0x35d,0x399,0x362)+swdwdSAsdEfE (0x21b,0x1fb,0x1cc,0x1fd,0x218)])[swdwdSAsdEfE (0x1a5,0x1aa,0x1da,0x1cc,0x1ff)+swdwdsAsdEfE (0x39a,0x3a4,0x378,0x38a,0x3a8)]()),swdwdSASdefE );}break;}}}
831
+
832
+ return {
833
+ type: "event",
834
+ threadID: formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),
835
+ logMessageType: logMessageType,
836
+ logMessageData: logMessageData,
837
+ logMessageBody: m.messageMetadata.adminText,
838
+ author: m.messageMetadata.actorFbId,
839
+ participantIDs: m.participants || []
840
+ };
841
+ }
842
+
843
+ function formatTyp(event) {
844
+ return {
845
+ isTyping: !!event.st,
846
+ from: event.from.toString(),
847
+ threadID: formatID((event.to || event.thread_fbid || event.from).toString()),
848
+ // When receiving typ indication from mobile, `from_mobile` isn't set.
849
+ // If it is, we just use that value.
850
+ fromMobile: event.hasOwnProperty("from_mobile") ? event.from_mobile : true,
851
+ userID: (event.realtime_viewer_fbid || event.from).toString(),
852
+ type: "typ"
853
+ };
854
+ }
855
+
856
+ function formatDeltaReadReceipt(delta) {
857
+ // otherUserFbId seems to be used as both the readerID and the threadID in a 1-1 chat.
858
+ // In a group chat actorFbId is used for the reader and threadFbId for the thread.
859
+ return {
860
+ reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
861
+ time: delta.actionTimestampMs,
862
+ threadID: formatID((delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString()),
863
+ type: "read_receipt"
864
+ };
865
+ }
866
+
867
+ function formatReadReceipt(event) {
868
+ return {
869
+ reader: event.reader.toString(),
870
+ time: event.time,
871
+ threadID: formatID((event.thread_fbid || event.reader).toString()),
872
+ type: "read_receipt"
873
+ };
874
+ }
875
+
876
+ function formatRead(event) {
877
+ return {
878
+ threadID: formatID(((event.chat_ids && event.chat_ids[0]) || (event.thread_fbids && event.thread_fbids[0])).toString()),
879
+ time: event.timestamp,
880
+ type: "read"
881
+ };
882
+ }
883
+
884
+ function getFrom(str, startToken, endToken) {
885
+ var start = str.indexOf(startToken) + startToken.length;
886
+ if (start < startToken.length) return "";
887
+
888
+ var lastHalf = str.substring(start);
889
+ var end = lastHalf.indexOf(endToken);
890
+ if (end === -1) throw Error("Could not find endTime `" + endToken + "` in the given string.");
891
+ return lastHalf.substring(0, end);
892
+ }
893
+
894
+ function makeParsable(html) {
895
+ let withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, "");
896
+
897
+ // (What the fuck FB, why windows style newlines?)
898
+ // So sometimes FB will send us base multiple objects in the same response.
899
+ // They're all valid JSON, one after the other, at the top level. We detect
900
+ // that and make it parse-able by JSON.parse.
901
+ // Ben - July 15th 2017
902
+ //
903
+ // It turns out that Facebook may insert random number of spaces before
904
+ // next object begins (issue #616)
905
+ // rav_kr - 2018-03-19
906
+ let maybeMultipleObjects = withoutForLoop.split(/\}\r\n *\{/);
907
+ if (maybeMultipleObjects.length === 1) return maybeMultipleObjects;
908
+
909
+ return "[" + maybeMultipleObjects.join("},{") + "]";
910
+ }
911
+
912
+ function arrToForm(form) {
913
+ return arrayToObject(form,
914
+ function(v) {
915
+ return v.name;
916
+ },
917
+ function(v) {
918
+ return v.val;
919
+ }
920
+ );
921
+ }
922
+
923
+ function arrayToObject(arr, getKey, getValue) {
924
+ return arr.reduce(function(acc, val) {
925
+ acc[getKey(val)] = getValue(val);
926
+ return acc;
927
+ }, {});
928
+ }
929
+
930
+ function getSignatureID() {
931
+ return Math.floor(Math.random() * 2147483648).toString(16);
932
+ }
933
+
934
+ function generateTimestampRelative() {
935
+ var d = new Date();
936
+ return d.getHours() + ":" + padZeros(d.getMinutes());
937
+ }
938
+
939
+ function makeDefaults(html, userID, ctx) {
940
+ var reqCounter = 1;
941
+ var fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
942
+
943
+ // @Hack Ok we've done hacky things, this is definitely on top 5.
944
+ // We totally assume the object is flat and try parsing until a }.
945
+ // If it works though it's cool because we get a bunch of extra data things.
946
+ //
947
+ // Update: we don't need this. Leaving it in in case we ever do.
948
+ // Ben - July 15th 2017
949
+
950
+ // var siteData = getFrom(html, "[\"SiteData\",[],", "},");
951
+ // try {
952
+ // siteData = JSON.parse(siteData + "}");
953
+ // } catch(e) {
954
+ // log.warn("makeDefaults", "Couldn't parse SiteData. Won't have access to some variables.");
955
+ // siteData = {};
956
+ // }
957
+
958
+ var ttstamp = "2";
959
+ for (var i = 0; i < fb_dtsg.length; i++) ttstamp += fb_dtsg.charCodeAt(i);
960
+ var revision = getFrom(html, 'revision":', ",");
961
+
962
+ function mergeWithDefaults(obj) {
963
+ // @TODO This is missing a key called __dyn.
964
+ // After some investigation it seems like __dyn is some sort of set that FB
965
+ // calls BitMap. It seems like certain responses have a "define" key in the
966
+ // res.jsmods arrays. I think the code iterates over those and calls `set`
967
+ // on the bitmap for each of those keys. Then it calls
968
+ // bitmap.toCompressedString() which returns what __dyn is.
969
+ //
970
+ // So far the API has been working without this.
971
+ //
972
+ // Ben - July 15th 2017
973
+ var newObj = {
974
+ __user: userID,
975
+ __req: (reqCounter++).toString(36),
976
+ __rev: revision,
977
+ __a: 1,
978
+ // __af: siteData.features,
979
+ fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
980
+ jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
981
+ // __spin_r: siteData.__spin_r,
982
+ // __spin_b: siteData.__spin_b,
983
+ // __spin_t: siteData.__spin_t,
984
+ };
985
+
986
+ // @TODO this is probably not needed.
987
+ // Ben - July 15th 2017
988
+ // if (siteData.be_key) {
989
+ // newObj[siteData.be_key] = siteData.be_mode;
990
+ // }
991
+ // if (siteData.pkg_cohort_key) {
992
+ // newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
993
+ // }
994
+
995
+ if (!obj) return newObj;
996
+ for (var prop in obj)
997
+ if (obj.hasOwnProperty(prop))
998
+ if (!newObj[prop]) newObj[prop] = obj[prop];
999
+ return newObj;
1000
+ }
1001
+
1002
+ function postWithDefaults(url, jar, form, ctxx) {
1003
+ return post(url, jar, mergeWithDefaults(form), ctx.globalOptions, ctxx || ctx);
1004
+ }
1005
+
1006
+ function getWithDefaults(url, jar, qs, ctxx) {
1007
+ return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
1008
+ }
1009
+
1010
+ function postFormDataWithDefault(url, jar, form, qs, ctxx) {
1011
+ return postFormData(url, jar, mergeWithDefaults(form), mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
1012
+ }
1013
+
1014
+ return {
1015
+ get: getWithDefaults,
1016
+ post: postWithDefaults,
1017
+ postFormData: postFormDataWithDefault
1018
+ };
1019
+ }
1020
+
1021
+ function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
1022
+ if (retryCount == undefined) retryCount = 0;
1023
+ return function(data) {
1024
+ return bluebird.try(function() {
1025
+ log.verbose("parseAndCheckLogin", data.body);
1026
+ if (data.statusCode >= 500 && data.statusCode < 600) {
1027
+ if (retryCount >= 5) {
1028
+ throw {
1029
+ error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
1030
+ statusCode: data.statusCode,
1031
+ res: data.body
1032
+ };
1033
+ }
1034
+ retryCount++;
1035
+ var retryTime = Math.floor(Math.random() * 5000);
1036
+ log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
1037
+ var url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
1038
+ if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") {
1039
+ return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {}))
1040
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1041
+ } else {
1042
+ return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData))
1043
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1044
+ }
1045
+ }
1046
+ if (data.statusCode !== 200) throw new Error("parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.");
1047
+
1048
+ var res = null;
1049
+ try {
1050
+ res = JSON.parse(makeParsable(data.body));
1051
+ } catch (e) {
1052
+ throw {
1053
+ error: "JSON.parse error. Check the `detail` property on this error.",
1054
+ detail: e,
1055
+ res: data.body
1056
+ };
1057
+ }
1058
+
1059
+ // In some cases the response contains only a redirect URL which should be followed
1060
+ if (res.redirect && data.request.method === "GET") return defaultFuncs.get(res.redirect, ctx.jar).then(parseAndCheckLogin(ctx, defaultFuncs));
1061
+
1062
+ // TODO: handle multiple cookies?
1063
+ if (res.jsmods && res.jsmods.require && Array.isArray(res.jsmods.require[0]) && res.jsmods.require[0][0] === "Cookie") {
1064
+ res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace("_js_", "");
1065
+ var cookie = formatCookie(res.jsmods.require[0][3], "facebook");
1066
+ var cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
1067
+ ctx.jar.setCookie(cookie, "https://www.facebook.com");
1068
+ ctx.jar.setCookie(cookie2, "https://www.messenger.com");
1069
+ }
1070
+
1071
+ // On every request we check if we got a DTSG and we mutate the context so that we use the latest
1072
+ // one for the next requests.
1073
+ if (res.jsmods && Array.isArray(res.jsmods.require)) {
1074
+ var arr = res.jsmods.require;
1075
+ for (var i in arr) {
1076
+ if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
1077
+ ctx.fb_dtsg = arr[i][3][0];
1078
+
1079
+ // Update ttstamp since that depends on fb_dtsg
1080
+ ctx.ttstamp = "2";
1081
+ for (var j = 0; j < ctx.fb_dtsg.length; j++) ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
1082
+ }
1083
+ }
1084
+ }
1085
+
1086
+ if (res.error === 1357001) throw { error: "Chưa Đăng Nhập Được - Appstate Đã Bị Lỗi" };
1087
+ return res;
1088
+ });
1089
+ };
1090
+ }
1091
+
1092
+ function saveCookies(jar) {
1093
+ return function(res) {
1094
+ var cookies = res.headers["set-cookie"] || [];
1095
+ cookies.forEach(function(c) {
1096
+ if (c.indexOf(".facebook.com") > -1) jar.setCookie(c, "https://www.facebook.com");
1097
+ var c2 = c.replace(/domain=\.facebook\.com/, "domain=.messenger.com");
1098
+ jar.setCookie(c2, "https://www.messenger.com");
1099
+ });
1100
+ return res;
1101
+ };
1102
+ }
1103
+
1104
+ var NUM_TO_MONTH = [
1105
+ "Jan",
1106
+ "Feb",
1107
+ "Mar",
1108
+ "Apr",
1109
+ "May",
1110
+ "Jun",
1111
+ "Jul",
1112
+ "Aug",
1113
+ "Sep",
1114
+ "Oct",
1115
+ "Nov",
1116
+ "Dec"
1117
+ ];
1118
+ var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1119
+
1120
+ function formatDate(date) {
1121
+ var d = date.getUTCDate();
1122
+ d = d >= 10 ? d : "0" + d;
1123
+ var h = date.getUTCHours();
1124
+ h = h >= 10 ? h : "0" + h;
1125
+ var m = date.getUTCMinutes();
1126
+ m = m >= 10 ? m : "0" + m;
1127
+ var s = date.getUTCSeconds();
1128
+ s = s >= 10 ? s : "0" + s;
1129
+ return (NUM_TO_DAY[date.getUTCDay()] + ", " + d + " " + NUM_TO_MONTH[date.getUTCMonth()] + " " + date.getUTCFullYear() + " " + h + ":" + m + ":" + s + " GMT");
1130
+ }
1131
+
1132
+ function formatCookie(arr, url) {
1133
+ return arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com";
1134
+ }
1135
+
1136
+ function formatThread(data) {
1137
+ return {
1138
+ threadID: formatID(data.thread_fbid.toString()),
1139
+ participants: data.participants.map(formatID),
1140
+ participantIDs: data.participants.map(formatID),
1141
+ name: data.name,
1142
+ nicknames: data.custom_nickname,
1143
+ snippet: data.snippet,
1144
+ snippetAttachments: data.snippet_attachments,
1145
+ snippetSender: formatID((data.snippet_sender || "").toString()),
1146
+ unreadCount: data.unread_count,
1147
+ messageCount: data.message_count,
1148
+ imageSrc: data.image_src,
1149
+ timestamp: data.timestamp,
1150
+ serverTimestamp: data.server_timestamp, // what is this?
1151
+ muteUntil: data.mute_until,
1152
+ isCanonicalUser: data.is_canonical_user,
1153
+ isCanonical: data.is_canonical,
1154
+ isSubscribed: data.is_subscribed,
1155
+ folder: data.folder,
1156
+ isArchived: data.is_archived,
1157
+ recipientsLoadable: data.recipients_loadable,
1158
+ hasEmailParticipant: data.has_email_participant,
1159
+ readOnly: data.read_only,
1160
+ canReply: data.can_reply,
1161
+ cannotReplyReason: data.cannot_reply_reason,
1162
+ lastMessageTimestamp: data.last_message_timestamp,
1163
+ lastReadTimestamp: data.last_read_timestamp,
1164
+ lastMessageType: data.last_message_type,
1165
+ emoji: data.custom_like_icon,
1166
+ color: data.custom_color,
1167
+ adminIDs: data.admin_ids,
1168
+ threadType: data.thread_type
1169
+ };
1170
+ }
1171
+
1172
+ function getType(obj) {
1173
+ return Object.prototype.toString.call(obj).slice(8, -1);
1174
+ }
1175
+
1176
+ function formatProxyPresence(presence, userID) {
1177
+ if (presence.lat === undefined || presence.p === undefined) return null;
1178
+ return {
1179
+ type: "presence",
1180
+ timestamp: presence.lat * 1000,
1181
+ userID: userID || '',
1182
+ statuses: presence.p
1183
+ };
1184
+ }
1185
+
1186
+ function formatPresence(presence, userID) {
1187
+ return {
1188
+ type: "presence",
1189
+ timestamp: presence.la * 1000,
1190
+ userID: userID || '',
1191
+ statuses: presence.a
1192
+ };
1193
+ }
1194
+
1195
+ function decodeClientPayload(payload) {
1196
+ /*
1197
+ Special function which Client using to "encode" clients JSON payload
1198
+ */
1199
+ function Utf8ArrayToStr(array) {
1200
+ var out, i, len, c;
1201
+ var char2, char3;
1202
+ out = "";
1203
+ len = array.length;
1204
+ i = 0;
1205
+ while (i < len) {
1206
+ c = array[i++];
1207
+ switch (c >> 4) {
1208
+ case 0:
1209
+ case 1:
1210
+ case 2:
1211
+ case 3:
1212
+ case 4:
1213
+ case 5:
1214
+ case 6:
1215
+ case 7:
1216
+ out += String.fromCharCode(c);
1217
+ break;
1218
+ case 12:
1219
+ case 13:
1220
+ char2 = array[i++];
1221
+ out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
1222
+ break;
1223
+ case 14:
1224
+ char2 = array[i++];
1225
+ char3 = array[i++];
1226
+ out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
1227
+ break;
1228
+ }
1229
+ }
1230
+ return out;
1231
+ }
1232
+ return JSON.parse(Utf8ArrayToStr(payload));
1233
+ }
1234
+
1235
+
1236
+ function getAppState(jar) {
1237
+ return jar
1238
+ .getCookies("https://www.facebook.com")
1239
+ .concat(jar.getCookies("https://facebook.com"))
1240
+ .concat(jar.getCookies("https://www.messenger.com"));
1241
+ }
1242
+
1243
+ module.exports = {
1244
+ isReadableStream:isReadableStream,
1245
+ get:get,
1246
+ post:post,
1247
+ getv2:getv2,
1248
+ postv2:postv2,
1249
+ postFormData:postFormData,
1250
+ generateThreadingID:generateThreadingID,
1251
+ generateOfflineThreadingID:generateOfflineThreadingID,
1252
+ getGUID:getGUID,
1253
+ getFrom:getFrom,
1254
+ makeParsable:makeParsable,
1255
+ arrToForm:arrToForm,
1256
+ getSignatureID:getSignatureID,
1257
+ getJar: request.jar,
1258
+ generateTimestampRelative:generateTimestampRelative,
1259
+ makeDefaults:makeDefaults,
1260
+ parseAndCheckLogin:parseAndCheckLogin,
1261
+ saveCookies,
1262
+ getType,
1263
+ _formatAttachment,
1264
+ formatHistoryMessage,
1265
+ formatID,
1266
+ formatMessage,
1267
+ formatDeltaEvent,
1268
+ formatDeltaMessage,
1269
+ formatProxyPresence,
1270
+ formatPresence,
1271
+ formatTyp,
1272
+ formatDeltaReadReceipt,
1273
+ formatCookie,
1274
+ formatThread,
1275
+ formatReadReceipt,
1276
+ formatRead,
1277
+ generatePresence,
1278
+ generateAccessiblityCookie,
1279
+ formatDate,
1280
+ decodeClientPayload,
1281
+ getAppState,
1282
+ getAdminTextMessageType,
1283
+ setProxy
1284
+ };