node-ainzfb-new 1.7.7-iu0tg78 → 1.7.10-11

Sign up to get free protection for your applications and to get access to all the features.
package/utils.js CHANGED
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable no-undef */
2
2
  /* eslint-disable no-prototype-builtins */
3
3
  "use strict";
4
- var StateCrypt = require("./StateCrypt");
5
4
  var logger = require("./logger");
6
5
  const bluebird = require("bluebird");
7
6
  var request = bluebird.promisify(require("request").defaults({ jar: true }));
@@ -11,55 +10,61 @@ var querystring = require("querystring");
11
10
  var url = require("url");
12
11
 
13
12
  function setProxy(url) {
14
- if (typeof url == undefined) return request = bluebird.promisify(require("request").defaults({ jar: true }));
15
- return request = bluebird.promisify(require("request").defaults({ jar: true, proxy: url }));
13
+ if (typeof url == undefined)
14
+ return (request = bluebird.promisify(
15
+ require("request").defaults({ jar: true })
16
+ ));
17
+ return (request = bluebird.promisify(
18
+ require("request").defaults({ jar: true, proxy: url })
19
+ ));
16
20
  }
17
21
 
18
22
  function getHeaders(url, options, ctx, customHeader) {
19
- var headers = {
20
- "Content-Type": "application/x-www-form-urlencoded",
21
- Referer: "https://www.facebook.com/",
22
- Host: url.replace("https://", "").split("/")[0],
23
- Origin: "https://www.facebook.com",
24
- "User-Agent": options.userAgent,
25
- Connection: "keep-alive",
26
- "sec-fetch-site": 'same-origin',
27
- "sec-fetch-mode": 'cors'
28
- };
29
- if (customHeader) Object.assign(headers, customHeader);
30
-
31
- if (ctx && ctx.region) headers["X-MSGR-Region"] = ctx.region;
32
-
33
- return headers;
23
+ var headers = {
24
+ "Content-Type": "application/x-www-form-urlencoded",
25
+ Referer: "https://www.facebook.com/",
26
+ Host: url.replace("https://", "").split("/")[0],
27
+ Origin: "https://www.facebook.com",
28
+ "User-Agent": options.userAgent,
29
+ Connection: "keep-alive",
30
+ "sec-fetch-site": "same-origin",
31
+ "sec-fetch-mode": "cors"
32
+ };
33
+ if (customHeader) Object.assign(headers, customHeader);
34
+
35
+ if (ctx && ctx.region) headers["X-MSGR-Region"] = ctx.region;
36
+
37
+ return headers;
34
38
  }
35
39
 
36
40
  function isReadableStream(obj) {
37
- return (
38
- obj instanceof stream.Stream &&
39
- (getType(obj._read) === "Function" ||
40
- getType(obj._read) === "AsyncFunction") &&
41
- getType(obj._readableState) === "Object"
42
- );
41
+ return (
42
+ obj instanceof stream.Stream &&
43
+ (getType(obj._read) === "Function" ||
44
+ getType(obj._read) === "AsyncFunction") &&
45
+ getType(obj._readableState) === "Object"
46
+ );
43
47
  }
44
48
 
45
49
  function get(url, jar, qs, options, ctx) {
46
- // I'm still confused about this
47
- if (getType(qs) === "Object")
48
- for (var prop in qs)
49
- if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") qs[prop] = JSON.stringify(qs[prop]);
50
- var op = {
51
- headers: getHeaders(url, options, ctx),
52
- timeout: 60000,
53
- qs: qs,
54
- url: url,
55
- method: "GET",
56
- jar: jar,
57
- gzip: true
58
- };
59
-
60
- return request(op).then(function(res) {
61
- return res[0];
62
- });
50
+ // I'm still confused about this
51
+ if (getType(qs) === "Object")
52
+ for (var prop in qs)
53
+ if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object")
54
+ qs[prop] = JSON.stringify(qs[prop]);
55
+ var op = {
56
+ headers: getHeaders(url, options, ctx),
57
+ timeout: 60000,
58
+ qs: qs,
59
+ url: url,
60
+ method: "GET",
61
+ jar: jar,
62
+ gzip: true
63
+ };
64
+
65
+ return request(op).then(function(res) {
66
+ return res[0];
67
+ });
63
68
  }
64
69
 
65
70
  /*function getv2(url, jar, qs, options, ctx) {
@@ -83,21 +88,21 @@ function get(url, jar, qs, options, ctx) {
83
88
  }*/
84
89
 
85
90
  function post(url, jar, form, options, ctx, customHeader) {
86
- let headers = getHeaders(url, options);
87
- headers['sec-fetch-site'] = 'same-origin';
88
- var op = {
89
- headers: headers,
90
- timeout: 60000,
91
- url: url,
92
- method: "POST",
93
- form: form,
94
- jar: jar,
95
- gzip: true
96
- };
97
-
98
- return request(op).then(function(res) {
99
- return res[0];
100
- });
91
+ let headers = getHeaders(url, options);
92
+ headers["sec-fetch-site"] = "same-origin";
93
+ var op = {
94
+ headers: headers,
95
+ timeout: 60000,
96
+ url: url,
97
+ method: "POST",
98
+ form: form,
99
+ jar: jar,
100
+ gzip: true
101
+ };
102
+
103
+ return request(op).then(function(res) {
104
+ return res[0];
105
+ });
101
106
  }
102
107
 
103
108
  /*function postv2(url, jar, form, options, ctx, customHeader) {
@@ -119,1124 +124,1505 @@ function post(url, jar, form, options, ctx, customHeader) {
119
124
  }*/
120
125
 
121
126
  function postFormData(url, jar, form, qs, options, ctx) {
122
- var headers = getHeaders(url, options, ctx);
123
- headers["Content-Type"] = "multipart/form-data";
124
- var op = {
125
- headers: headers,
126
- timeout: 60000,
127
- url: url,
128
- method: "POST",
129
- formData: form,
130
- qs: qs,
131
- jar: jar,
132
- gzip: true
133
- };
134
-
135
- return request(op).then(function(res) {
136
- return res[0];
137
- });
127
+ var headers = getHeaders(url, options, ctx);
128
+ headers["Content-Type"] = "multipart/form-data";
129
+ var op = {
130
+ headers: headers,
131
+ timeout: 60000,
132
+ url: url,
133
+ method: "POST",
134
+ formData: form,
135
+ qs: qs,
136
+ jar: jar,
137
+ gzip: true
138
+ };
139
+
140
+ return request(op).then(function(res) {
141
+ return res[0];
142
+ });
138
143
  }
139
144
 
140
145
  function padZeros(val, len) {
141
- val = String(val);
142
- len = len || 2;
143
- while (val.length < len) val = "0" + val;
144
- return val;
146
+ val = String(val);
147
+ len = len || 2;
148
+ while (val.length < len) val = "0" + val;
149
+ return val;
145
150
  }
146
151
 
147
152
  function generateThreadingID(clientID) {
148
- var k = Date.now();
149
- var l = Math.floor(Math.random() * 4294967295);
150
- var m = clientID;
151
- return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
153
+ var k = Date.now();
154
+ var l = Math.floor(Math.random() * 4294967295);
155
+ var m = clientID;
156
+ return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
157
+ }
158
+
159
+ function getCurrentTimestamp() {
160
+ const date = new Date();
161
+ const unixTime = date.getTime();
162
+ return unixTime;
152
163
  }
153
164
 
154
165
  function binaryToDecimal(data) {
155
- var ret = "";
156
- while (data !== "0") {
157
- var end = 0;
158
- var fullName = "";
159
- var i = 0;
160
- for (; i < data.length; i++) {
161
- end = 2 * end + parseInt(data[i], 10);
162
- if (end >= 10) {
163
- fullName += "1";
164
- end -= 10;
165
- } else fullName += "0";
166
- }
167
- ret = end.toString() + ret;
168
- data = fullName.slice(fullName.indexOf("1"));
166
+ var ret = "";
167
+ while (data !== "0") {
168
+ var end = 0;
169
+ var fullName = "";
170
+ var i = 0;
171
+ for (; i < data.length; i++) {
172
+ end = 2 * end + parseInt(data[i], 10);
173
+ if (end >= 10) {
174
+ fullName += "1";
175
+ end -= 10;
176
+ } else fullName += "0";
169
177
  }
170
- return ret;
178
+ ret = end.toString() + ret;
179
+ data = fullName.slice(fullName.indexOf("1"));
180
+ }
181
+ return ret;
171
182
  }
172
183
 
173
184
  function generateOfflineThreadingID() {
174
- var ret = Date.now();
175
- var value = Math.floor(Math.random() * 4294967295);
176
- var str = ("0000000000000000000000" + value.toString(2)).slice(-22);
177
- var msgs = ret.toString(2) + str;
178
- return binaryToDecimal(msgs);
185
+ var ret = Date.now();
186
+ var value = Math.floor(Math.random() * 4294967295);
187
+ var str = ("0000000000000000000000" + value.toString(2)).slice(-22);
188
+ var msgs = ret.toString(2) + str;
189
+ return binaryToDecimal(msgs);
179
190
  }
180
191
 
181
192
  var h;
182
193
  var i = {};
183
194
  var j = {
184
- _: "%",
185
- A: "%2",
186
- B: "000",
187
- C: "%7d",
188
- D: "%7b%22",
189
- E: "%2c%22",
190
- F: "%22%3a",
191
- G: "%2c%22ut%22%3a1",
192
- H: "%2c%22bls%22%3a",
193
- I: "%2c%22n%22%3a%22%",
194
- J: "%22%3a%7b%22i%22%3a0%7d",
195
- K: "%2c%22pt%22%3a0%2c%22vis%22%3a",
196
- L: "%2c%22ch%22%3a%7b%22h%22%3a%22",
197
- M: "%7b%22v%22%3a2%2c%22time%22%3a1",
198
- N: ".channel%22%2c%22sub%22%3a%5b",
199
- O: "%2c%22sb%22%3a1%2c%22t%22%3a%5b",
200
- P: "%2c%22ud%22%3a100%2c%22lc%22%3a0",
201
- Q: "%5d%2c%22f%22%3anull%2c%22uct%22%3a",
202
- R: ".channel%22%2c%22sub%22%3a%5b1%5d",
203
- S: "%22%2c%22m%22%3a0%7d%2c%7b%22i%22%3a",
204
- T: "%2c%22blc%22%3a1%2c%22snd%22%3a1%2c%22ct%22%3a",
205
- U: "%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
206
- V: "%2c%22blc%22%3a0%2c%22snd%22%3a0%2c%22ct%22%3a",
207
- W: "%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a",
208
- X: "%2c%22ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1",
209
- 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",
210
- 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"
195
+ _: "%",
196
+ A: "%2",
197
+ B: "000",
198
+ C: "%7d",
199
+ D: "%7b%22",
200
+ E: "%2c%22",
201
+ F: "%22%3a",
202
+ G: "%2c%22ut%22%3a1",
203
+ H: "%2c%22bls%22%3a",
204
+ I: "%2c%22n%22%3a%22%",
205
+ J: "%22%3a%7b%22i%22%3a0%7d",
206
+ K: "%2c%22pt%22%3a0%2c%22vis%22%3a",
207
+ L: "%2c%22ch%22%3a%7b%22h%22%3a%22",
208
+ M: "%7b%22v%22%3a2%2c%22time%22%3a1",
209
+ N: ".channel%22%2c%22sub%22%3a%5b",
210
+ O: "%2c%22sb%22%3a1%2c%22t%22%3a%5b",
211
+ P: "%2c%22ud%22%3a100%2c%22lc%22%3a0",
212
+ Q: "%5d%2c%22f%22%3anull%2c%22uct%22%3a",
213
+ R: ".channel%22%2c%22sub%22%3a%5b1%5d",
214
+ S: "%22%2c%22m%22%3a0%7d%2c%7b%22i%22%3a",
215
+ T: "%2c%22blc%22%3a1%2c%22snd%22%3a1%2c%22ct%22%3a",
216
+ U: "%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
217
+ V: "%2c%22blc%22%3a0%2c%22snd%22%3a0%2c%22ct%22%3a",
218
+ W: "%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a",
219
+ X: "%2c%22ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1",
220
+ Y:
221
+ "%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
222
+ Z:
223
+ "%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"
211
224
  };
212
225
  (function() {
213
- var l = [];
214
- for (var m in j) {
215
- i[j[m]] = m;
216
- l.push(j[m]);
217
- }
218
- l.reverse();
219
- h = new RegExp(l.join("|"), "g");
226
+ var l = [];
227
+ for (var m in j) {
228
+ i[j[m]] = m;
229
+ l.push(j[m]);
230
+ }
231
+ l.reverse();
232
+ h = new RegExp(l.join("|"), "g");
220
233
  })();
221
234
 
222
235
  function presenceEncode(str) {
223
- return encodeURIComponent(str)
224
- .replace(/([_A-Z])|%../g, function(m, n) {
225
- return n ? "%" + n.charCodeAt(0).toString(16) : m;
226
- })
227
- .toLowerCase()
228
- .replace(h, function(m) {
229
- return i[m];
230
- });
236
+ return encodeURIComponent(str)
237
+ .replace(/([_A-Z])|%../g, function(m, n) {
238
+ return n ? "%" + n.charCodeAt(0).toString(16) : m;
239
+ })
240
+ .toLowerCase()
241
+ .replace(h, function(m) {
242
+ return i[m];
243
+ });
231
244
  }
232
245
 
233
246
  // eslint-disable-next-line no-unused-vars
234
247
  function presenceDecode(str) {
235
- return decodeURIComponent(
236
- str.replace(/[_A-Z]/g, function(m) {
237
- return j[m];
238
- })
239
- );
248
+ return decodeURIComponent(
249
+ str.replace(/[_A-Z]/g, function(m) {
250
+ return j[m];
251
+ })
252
+ );
240
253
  }
241
254
 
242
255
  function generatePresence(userID) {
243
- var time = Date.now();
244
- return (
245
- "E" +
246
- presenceEncode(
247
- JSON.stringify({
248
- v: 3,
249
- time: parseInt(time / 1000, 10),
250
- user: userID,
251
- state: {
252
- ut: 0,
253
- t2: [],
254
- lm2: null,
255
- uct2: time,
256
- tr: null,
257
- tw: Math.floor(Math.random() * 4294967295) + 1,
258
- at: time
259
- },
260
- ch: {
261
- ["p_" + userID]: 0
262
- }
263
- })
264
- )
265
- );
256
+ var time = Date.now();
257
+ return (
258
+ "E" +
259
+ presenceEncode(
260
+ JSON.stringify({
261
+ v: 3,
262
+ time: parseInt(time / 1000, 10),
263
+ user: userID,
264
+ state: {
265
+ ut: 0,
266
+ t2: [],
267
+ lm2: null,
268
+ uct2: time,
269
+ tr: null,
270
+ tw: Math.floor(Math.random() * 4294967295) + 1,
271
+ at: time
272
+ },
273
+ ch: {
274
+ ["p_" + userID]: 0
275
+ }
276
+ })
277
+ )
278
+ );
266
279
  }
267
280
 
268
281
  function generateAccessiblityCookie() {
269
- var time = Date.now();
270
- return encodeURIComponent(
271
- JSON.stringify({
272
- sr: 0,
273
- "sr-ts": time,
274
- jk: 0,
275
- "jk-ts": time,
276
- kb: 0,
277
- "kb-ts": time,
278
- hcm: 0,
279
- "hcm-ts": time
280
- })
281
- );
282
+ var time = Date.now();
283
+ return encodeURIComponent(
284
+ JSON.stringify({
285
+ sr: 0,
286
+ "sr-ts": time,
287
+ jk: 0,
288
+ "jk-ts": time,
289
+ kb: 0,
290
+ "kb-ts": time,
291
+ hcm: 0,
292
+ "hcm-ts": time
293
+ })
294
+ );
282
295
  }
283
296
 
284
297
  function getGUID() {
298
+ /** @type {number} */
299
+ var sectionLength = Date.now();
300
+ /** @type {string} */
301
+ var id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
302
+ /** @type {number} */
303
+ var r = Math.floor((sectionLength + Math.random() * 16) % 16);
285
304
  /** @type {number} */
286
- var sectionLength = Date.now();
305
+ sectionLength = Math.floor(sectionLength / 16);
287
306
  /** @type {string} */
288
- var id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
289
- /** @type {number} */
290
- var r = Math.floor((sectionLength + Math.random() * 16) % 16);
291
- /** @type {number} */
292
- sectionLength = Math.floor(sectionLength / 16);
293
- /** @type {string} */
294
- var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
295
- return _guid;
296
- });
297
- return id;
307
+ var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
308
+ return _guid;
309
+ });
310
+ return id;
298
311
  }
299
312
 
300
313
  function _formatAttachment(attachment1, attachment2) {
301
- // TODO: THIS IS REALLY BAD
302
- // This is an attempt at fixing Facebook's inconsistencies. Sometimes they give us
303
- // two attachment objects, but sometimes only one. They each contain part of the
304
- // data that you'd want so we merge them for convenience.
305
- // Instead of having a bunch of if statements guarding every access to image_data,
306
- // we set it to empty object and use the fact that it'll return undefined.
307
- attachment2 = attachment2 || { id: "", image_data: {} };
308
- attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
309
- var blob = attachment1.blob_attachment;
310
- var type =
311
- blob && blob.__typename ? blob.__typename : attachment1.attach_type;
312
- if (!type && attachment1.sticker_attachment) {
313
- type = "StickerAttachment";
314
- blob = attachment1.sticker_attachment;
315
- } else if (!type && attachment1.extensible_attachment) {
316
- if (
317
- attachment1.extensible_attachment.story_attachment &&
318
- attachment1.extensible_attachment.story_attachment.target &&
319
- attachment1.extensible_attachment.story_attachment.target.__typename &&
320
- attachment1.extensible_attachment.story_attachment.target.__typename === "MessageLocation"
321
- ) type = "MessageLocation";
322
- else type = "ExtensibleAttachment";
323
-
324
- blob = attachment1.extensible_attachment;
325
- }
326
- // TODO: Determine whether "sticker", "photo", "file" etc are still used
327
- // KEEP IN SYNC WITH getThreadHistory
328
- switch (type) {
329
- case "sticker":
330
- return {
331
- type: "sticker",
332
- ID: attachment1.metadata.stickerID.toString(),
333
- url: attachment1.url,
334
-
335
- packID: attachment1.metadata.packID.toString(),
336
- spriteUrl: attachment1.metadata.spriteURI,
337
- spriteUrl2x: attachment1.metadata.spriteURI2x,
338
- width: attachment1.metadata.width,
339
- height: attachment1.metadata.height,
340
-
341
- caption: attachment2.caption,
342
- description: attachment2.description,
343
-
344
- frameCount: attachment1.metadata.frameCount,
345
- frameRate: attachment1.metadata.frameRate,
346
- framesPerRow: attachment1.metadata.framesPerRow,
347
- framesPerCol: attachment1.metadata.framesPerCol,
348
-
349
- stickerID: attachment1.metadata.stickerID.toString(), // @Legacy
350
- spriteURI: attachment1.metadata.spriteURI, // @Legacy
351
- spriteURI2x: attachment1.metadata.spriteURI2x // @Legacy
352
- };
353
- case "file":
354
- return {
355
- type: "file",
356
- filename: attachment1.name,
357
- ID: attachment2.id.toString(),
358
- url: attachment1.url,
359
-
360
- isMalicious: attachment2.is_malicious,
361
- contentType: attachment2.mime_type,
362
-
363
- name: attachment1.name, // @Legacy
364
- mimeType: attachment2.mime_type, // @Legacy
365
- fileSize: attachment2.file_size // @Legacy
366
- };
367
- case "photo":
368
- return {
369
- type: "photo",
370
- ID: attachment1.metadata.fbid.toString(),
371
- filename: attachment1.fileName,
372
- thumbnailUrl: attachment1.thumbnail_url,
373
-
374
- previewUrl: attachment1.preview_url,
375
- previewWidth: attachment1.preview_width,
376
- previewHeight: attachment1.preview_height,
377
-
378
- largePreviewUrl: attachment1.large_preview_url,
379
- largePreviewWidth: attachment1.large_preview_width,
380
- largePreviewHeight: attachment1.large_preview_height,
381
-
382
- url: attachment1.metadata.url, // @Legacy
383
- width: attachment1.metadata.dimensions.split(",")[0], // @Legacy
384
- height: attachment1.metadata.dimensions.split(",")[1], // @Legacy
385
- name: attachment1.fileName // @Legacy
386
- };
387
- case "animated_image":
388
- return {
389
- type: "animated_image",
390
- ID: attachment2.id.toString(),
391
- filename: attachment2.filename,
392
-
393
- previewUrl: attachment1.preview_url,
394
- previewWidth: attachment1.preview_width,
395
- previewHeight: attachment1.preview_height,
396
-
397
- url: attachment2.image_data.url,
398
- width: attachment2.image_data.width,
399
- height: attachment2.image_data.height,
400
-
401
- name: attachment1.name, // @Legacy
402
- facebookUrl: attachment1.url, // @Legacy
403
- thumbnailUrl: attachment1.thumbnail_url, // @Legacy
404
- mimeType: attachment2.mime_type, // @Legacy
405
- rawGifImage: attachment2.image_data.raw_gif_image, // @Legacy
406
- rawWebpImage: attachment2.image_data.raw_webp_image, // @Legacy
407
- animatedGifUrl: attachment2.image_data.animated_gif_url, // @Legacy
408
- animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url, // @Legacy
409
- animatedWebpUrl: attachment2.image_data.animated_webp_url, // @Legacy
410
- animatedWebpPreviewUrl: attachment2.image_data.animated_webp_preview_url // @Legacy
411
- };
412
- case "share":
413
- return {
414
- type: "share",
415
- ID: attachment1.share.share_id.toString(),
416
- url: attachment2.href,
417
-
418
- title: attachment1.share.title,
419
- description: attachment1.share.description,
420
- source: attachment1.share.source,
421
-
422
- image: attachment1.share.media.image,
423
- width: attachment1.share.media.image_size.width,
424
- height: attachment1.share.media.image_size.height,
425
- playable: attachment1.share.media.playable,
426
- duration: attachment1.share.media.duration,
427
-
428
- subattachments: attachment1.share.subattachments,
429
- properties: {},
430
-
431
- animatedImageSize: attachment1.share.media.animated_image_size, // @Legacy
432
- facebookUrl: attachment1.share.uri, // @Legacy
433
- target: attachment1.share.target, // @Legacy
434
- styleList: attachment1.share.style_list // @Legacy
435
- };
436
- case "video":
437
- return {
438
- type: "video",
439
- ID: attachment1.metadata.fbid.toString(),
440
- filename: attachment1.name,
441
-
442
- previewUrl: attachment1.preview_url,
443
- previewWidth: attachment1.preview_width,
444
- previewHeight: attachment1.preview_height,
445
-
446
- url: attachment1.url,
447
- width: attachment1.metadata.dimensions.width,
448
- height: attachment1.metadata.dimensions.height,
449
-
450
- duration: attachment1.metadata.duration,
451
- videoType: "unknown",
452
-
453
- thumbnailUrl: attachment1.thumbnail_url // @Legacy
454
- };
455
- case "error":
456
- return {
457
- type: "error",
458
-
459
- // Save error attachments because we're unsure of their format,
460
- // and whether there are cases they contain something useful for debugging.
461
- attachment1: attachment1,
462
- attachment2: attachment2
463
- };
464
- case "MessageImage":
465
- return {
466
- type: "photo",
467
- ID: blob.legacy_attachment_id,
468
- filename: blob.filename,
469
- thumbnailUrl: blob.thumbnail.uri,
470
-
471
- previewUrl: blob.preview.uri,
472
- previewWidth: blob.preview.width,
473
- previewHeight: blob.preview.height,
474
-
475
- largePreviewUrl: blob.large_preview.uri,
476
- largePreviewWidth: blob.large_preview.width,
477
- largePreviewHeight: blob.large_preview.height,
478
-
479
- url: blob.large_preview.uri, // @Legacy
480
- width: blob.original_dimensions.x, // @Legacy
481
- height: blob.original_dimensions.y, // @Legacy
482
- name: blob.filename // @Legacy
483
- };
484
- case "MessageAnimatedImage":
485
- return {
486
- type: "animated_image",
487
- ID: blob.legacy_attachment_id,
488
- filename: blob.filename,
489
-
490
- previewUrl: blob.preview_image.uri,
491
- previewWidth: blob.preview_image.width,
492
- previewHeight: blob.preview_image.height,
493
-
494
- url: blob.animated_image.uri,
495
- width: blob.animated_image.width,
496
- height: blob.animated_image.height,
497
-
498
- thumbnailUrl: blob.preview_image.uri, // @Legacy
499
- name: blob.filename, // @Legacy
500
- facebookUrl: blob.animated_image.uri, // @Legacy
501
- rawGifImage: blob.animated_image.uri, // @Legacy
502
- animatedGifUrl: blob.animated_image.uri, // @Legacy
503
- animatedGifPreviewUrl: blob.preview_image.uri, // @Legacy
504
- animatedWebpUrl: blob.animated_image.uri, // @Legacy
505
- animatedWebpPreviewUrl: blob.preview_image.uri // @Legacy
506
- };
507
- case "MessageVideo":
508
- return {
509
- type: "video",
510
- filename: blob.filename,
511
- ID: blob.legacy_attachment_id,
512
-
513
- previewUrl: blob.large_image.uri,
514
- previewWidth: blob.large_image.width,
515
- previewHeight: blob.large_image.height,
516
-
517
- url: blob.playable_url,
518
- width: blob.original_dimensions.x,
519
- height: blob.original_dimensions.y,
520
-
521
- duration: blob.playable_duration_in_ms,
522
- videoType: blob.video_type.toLowerCase(),
523
-
524
- thumbnailUrl: blob.large_image.uri // @Legacy
525
- };
526
- case "MessageAudio":
527
- return {
528
- type: "audio",
529
- filename: blob.filename,
530
- ID: blob.url_shimhash,
531
-
532
- audioType: blob.audio_type,
533
- duration: blob.playable_duration_in_ms,
534
- url: blob.playable_url,
535
-
536
- isVoiceMail: blob.is_voicemail
537
- };
538
- case "StickerAttachment":
539
- return {
540
- type: "sticker",
541
- ID: blob.id,
542
- url: blob.url,
543
-
544
- packID: blob.pack ? blob.pack.id : null,
545
- spriteUrl: blob.sprite_image,
546
- spriteUrl2x: blob.sprite_image_2x,
547
- width: blob.width,
548
- height: blob.height,
549
-
550
- caption: blob.label,
551
- description: blob.label,
552
-
553
- frameCount: blob.frame_count,
554
- frameRate: blob.frame_rate,
555
- framesPerRow: blob.frames_per_row,
556
- framesPerCol: blob.frames_per_column,
557
-
558
- stickerID: blob.id, // @Legacy
559
- spriteURI: blob.sprite_image, // @Legacy
560
- spriteURI2x: blob.sprite_image_2x // @Legacy
561
- };
562
- case "MessageLocation":
563
- var urlAttach = blob.story_attachment.url;
564
- var mediaAttach = blob.story_attachment.media;
565
-
566
- var u = querystring.parse(url.parse(urlAttach).query).u;
567
- var where1 = querystring.parse(url.parse(u).query).where1;
568
- var address = where1.split(", ");
569
-
570
- var latitude;
571
- var longitude;
572
-
573
- try {
574
- latitude = Number.parseFloat(address[0]);
575
- longitude = Number.parseFloat(address[1]);
576
- } catch (err) {
577
- /* empty */
578
- }
314
+ // TODO: THIS IS REALLY BAD
315
+ // This is an attempt at fixing Facebook's inconsistencies. Sometimes they give us
316
+ // two attachment objects, but sometimes only one. They each contain part of the
317
+ // data that you'd want so we merge them for convenience.
318
+ // Instead of having a bunch of if statements guarding every access to image_data,
319
+ // we set it to empty object and use the fact that it'll return undefined.
320
+ attachment2 = attachment2 || { id: "", image_data: {} };
321
+ attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
322
+ var blob = attachment1.blob_attachment;
323
+ var type =
324
+ blob && blob.__typename ? blob.__typename : attachment1.attach_type;
325
+ if (!type && attachment1.sticker_attachment) {
326
+ type = "StickerAttachment";
327
+ blob = attachment1.sticker_attachment;
328
+ } else if (!type && attachment1.extensible_attachment) {
329
+ if (
330
+ attachment1.extensible_attachment.story_attachment &&
331
+ attachment1.extensible_attachment.story_attachment.target &&
332
+ attachment1.extensible_attachment.story_attachment.target.__typename &&
333
+ attachment1.extensible_attachment.story_attachment.target.__typename ===
334
+ "MessageLocation"
335
+ )
336
+ type = "MessageLocation";
337
+ else type = "ExtensibleAttachment";
338
+
339
+ blob = attachment1.extensible_attachment;
340
+ }
341
+ // TODO: Determine whether "sticker", "photo", "file" etc are still used
342
+ // KEEP IN SYNC WITH getThreadHistory
343
+ switch (type) {
344
+ case "sticker":
345
+ return {
346
+ type: "sticker",
347
+ ID: attachment1.metadata.stickerID.toString(),
348
+ url: attachment1.url,
349
+
350
+ packID: attachment1.metadata.packID.toString(),
351
+ spriteUrl: attachment1.metadata.spriteURI,
352
+ spriteUrl2x: attachment1.metadata.spriteURI2x,
353
+ width: attachment1.metadata.width,
354
+ height: attachment1.metadata.height,
355
+
356
+ caption: attachment2.caption,
357
+ description: attachment2.description,
358
+
359
+ frameCount: attachment1.metadata.frameCount,
360
+ frameRate: attachment1.metadata.frameRate,
361
+ framesPerRow: attachment1.metadata.framesPerRow,
362
+ framesPerCol: attachment1.metadata.framesPerCol,
363
+
364
+ stickerID: attachment1.metadata.stickerID.toString(), // @Legacy
365
+ spriteURI: attachment1.metadata.spriteURI, // @Legacy
366
+ spriteURI2x: attachment1.metadata.spriteURI2x // @Legacy
367
+ };
368
+ case "file":
369
+ return {
370
+ type: "file",
371
+ filename: attachment1.name,
372
+ ID: attachment2.id.toString(),
373
+ url: attachment1.url,
374
+
375
+ isMalicious: attachment2.is_malicious,
376
+ contentType: attachment2.mime_type,
377
+
378
+ name: attachment1.name, // @Legacy
379
+ mimeType: attachment2.mime_type, // @Legacy
380
+ fileSize: attachment2.file_size // @Legacy
381
+ };
382
+ case "photo":
383
+ return {
384
+ type: "photo",
385
+ ID: attachment1.metadata.fbid.toString(),
386
+ filename: attachment1.fileName,
387
+ thumbnailUrl: attachment1.thumbnail_url,
388
+
389
+ previewUrl: attachment1.preview_url,
390
+ previewWidth: attachment1.preview_width,
391
+ previewHeight: attachment1.preview_height,
392
+
393
+ largePreviewUrl: attachment1.large_preview_url,
394
+ largePreviewWidth: attachment1.large_preview_width,
395
+ largePreviewHeight: attachment1.large_preview_height,
396
+
397
+ url: attachment1.metadata.url, // @Legacy
398
+ width: attachment1.metadata.dimensions.split(",")[0], // @Legacy
399
+ height: attachment1.metadata.dimensions.split(",")[1], // @Legacy
400
+ name: attachment1.fileName // @Legacy
401
+ };
402
+ case "animated_image":
403
+ return {
404
+ type: "animated_image",
405
+ ID: attachment2.id.toString(),
406
+ filename: attachment2.filename,
407
+
408
+ previewUrl: attachment1.preview_url,
409
+ previewWidth: attachment1.preview_width,
410
+ previewHeight: attachment1.preview_height,
411
+
412
+ url: attachment2.image_data.url,
413
+ width: attachment2.image_data.width,
414
+ height: attachment2.image_data.height,
415
+
416
+ name: attachment1.name, // @Legacy
417
+ facebookUrl: attachment1.url, // @Legacy
418
+ thumbnailUrl: attachment1.thumbnail_url, // @Legacy
419
+ mimeType: attachment2.mime_type, // @Legacy
420
+ rawGifImage: attachment2.image_data.raw_gif_image, // @Legacy
421
+ rawWebpImage: attachment2.image_data.raw_webp_image, // @Legacy
422
+ animatedGifUrl: attachment2.image_data.animated_gif_url, // @Legacy
423
+ animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url, // @Legacy
424
+ animatedWebpUrl: attachment2.image_data.animated_webp_url, // @Legacy
425
+ animatedWebpPreviewUrl: attachment2.image_data.animated_webp_preview_url // @Legacy
426
+ };
427
+ case "share":
428
+ return {
429
+ type: "share",
430
+ ID: attachment1.share.share_id.toString(),
431
+ url: attachment2.href,
432
+
433
+ title: attachment1.share.title,
434
+ description: attachment1.share.description,
435
+ source: attachment1.share.source,
436
+
437
+ image: attachment1.share.media.image,
438
+ width: attachment1.share.media.image_size.width,
439
+ height: attachment1.share.media.image_size.height,
440
+ playable: attachment1.share.media.playable,
441
+ duration: attachment1.share.media.duration,
442
+
443
+ subattachments: attachment1.share.subattachments,
444
+ properties: {},
445
+
446
+ animatedImageSize: attachment1.share.media.animated_image_size, // @Legacy
447
+ facebookUrl: attachment1.share.uri, // @Legacy
448
+ target: attachment1.share.target, // @Legacy
449
+ styleList: attachment1.share.style_list // @Legacy
450
+ };
451
+ case "video":
452
+ return {
453
+ type: "video",
454
+ ID: attachment1.metadata.fbid.toString(),
455
+ filename: attachment1.name,
456
+
457
+ previewUrl: attachment1.preview_url,
458
+ previewWidth: attachment1.preview_width,
459
+ previewHeight: attachment1.preview_height,
460
+
461
+ url: attachment1.url,
462
+ width: attachment1.metadata.dimensions.width,
463
+ height: attachment1.metadata.dimensions.height,
464
+
465
+ duration: attachment1.metadata.duration,
466
+ videoType: "unknown",
467
+
468
+ thumbnailUrl: attachment1.thumbnail_url // @Legacy
469
+ };
470
+ case "error":
471
+ return {
472
+ type: "error",
473
+
474
+ // Save error attachments because we're unsure of their format,
475
+ // and whether there are cases they contain something useful for debugging.
476
+ attachment1: attachment1,
477
+ attachment2: attachment2
478
+ };
479
+ case "MessageImage":
480
+ return {
481
+ type: "photo",
482
+ ID: blob.legacy_attachment_id,
483
+ filename: blob.filename,
484
+ thumbnailUrl: blob.thumbnail.uri,
485
+
486
+ previewUrl: blob.preview.uri,
487
+ previewWidth: blob.preview.width,
488
+ previewHeight: blob.preview.height,
489
+
490
+ largePreviewUrl: blob.large_preview.uri,
491
+ largePreviewWidth: blob.large_preview.width,
492
+ largePreviewHeight: blob.large_preview.height,
493
+
494
+ url: blob.large_preview.uri, // @Legacy
495
+ width: blob.original_dimensions.x, // @Legacy
496
+ height: blob.original_dimensions.y, // @Legacy
497
+ name: blob.filename // @Legacy
498
+ };
499
+ case "MessageAnimatedImage":
500
+ return {
501
+ type: "animated_image",
502
+ ID: blob.legacy_attachment_id,
503
+ filename: blob.filename,
504
+
505
+ previewUrl: blob.preview_image.uri,
506
+ previewWidth: blob.preview_image.width,
507
+ previewHeight: blob.preview_image.height,
508
+
509
+ url: blob.animated_image.uri,
510
+ width: blob.animated_image.width,
511
+ height: blob.animated_image.height,
512
+
513
+ thumbnailUrl: blob.preview_image.uri, // @Legacy
514
+ name: blob.filename, // @Legacy
515
+ facebookUrl: blob.animated_image.uri, // @Legacy
516
+ rawGifImage: blob.animated_image.uri, // @Legacy
517
+ animatedGifUrl: blob.animated_image.uri, // @Legacy
518
+ animatedGifPreviewUrl: blob.preview_image.uri, // @Legacy
519
+ animatedWebpUrl: blob.animated_image.uri, // @Legacy
520
+ animatedWebpPreviewUrl: blob.preview_image.uri // @Legacy
521
+ };
522
+ case "MessageVideo":
523
+ return {
524
+ type: "video",
525
+ filename: blob.filename,
526
+ ID: blob.legacy_attachment_id,
527
+
528
+ previewUrl: blob.large_image.uri,
529
+ previewWidth: blob.large_image.width,
530
+ previewHeight: blob.large_image.height,
531
+
532
+ url: blob.playable_url,
533
+ width: blob.original_dimensions.x,
534
+ height: blob.original_dimensions.y,
535
+
536
+ duration: blob.playable_duration_in_ms,
537
+ videoType: blob.video_type.toLowerCase(),
538
+
539
+ thumbnailUrl: blob.large_image.uri // @Legacy
540
+ };
541
+ case "MessageAudio":
542
+ return {
543
+ type: "audio",
544
+ filename: blob.filename,
545
+ ID: blob.url_shimhash,
546
+
547
+ audioType: blob.audio_type,
548
+ duration: blob.playable_duration_in_ms,
549
+ url: blob.playable_url,
550
+
551
+ isVoiceMail: blob.is_voicemail
552
+ };
553
+ case "StickerAttachment":
554
+ return {
555
+ type: "sticker",
556
+ ID: blob.id,
557
+ url: blob.url,
558
+
559
+ packID: blob.pack ? blob.pack.id : null,
560
+ spriteUrl: blob.sprite_image,
561
+ spriteUrl2x: blob.sprite_image_2x,
562
+ width: blob.width,
563
+ height: blob.height,
564
+
565
+ caption: blob.label,
566
+ description: blob.label,
567
+
568
+ frameCount: blob.frame_count,
569
+ frameRate: blob.frame_rate,
570
+ framesPerRow: blob.frames_per_row,
571
+ framesPerCol: blob.frames_per_column,
572
+
573
+ stickerID: blob.id, // @Legacy
574
+ spriteURI: blob.sprite_image, // @Legacy
575
+ spriteURI2x: blob.sprite_image_2x // @Legacy
576
+ };
577
+ case "MessageLocation":
578
+ var urlAttach = blob.story_attachment.url;
579
+ var mediaAttach = blob.story_attachment.media;
580
+
581
+ var u = querystring.parse(url.parse(urlAttach).query).u;
582
+ var where1 = querystring.parse(url.parse(u).query).where1;
583
+ var address = where1.split(", ");
584
+
585
+ var latitude;
586
+ var longitude;
587
+
588
+ try {
589
+ latitude = Number.parseFloat(address[0]);
590
+ longitude = Number.parseFloat(address[1]);
591
+ } catch (err) {
592
+ /* empty */
593
+ }
579
594
 
580
- var imageUrl;
581
- var width;
582
- var height;
595
+ var imageUrl;
596
+ var width;
597
+ var height;
583
598
 
584
- if (mediaAttach && mediaAttach.image) {
585
- imageUrl = mediaAttach.image.uri;
586
- width = mediaAttach.image.width;
587
- height = mediaAttach.image.height;
588
- }
599
+ if (mediaAttach && mediaAttach.image) {
600
+ imageUrl = mediaAttach.image.uri;
601
+ width = mediaAttach.image.width;
602
+ height = mediaAttach.image.height;
603
+ }
589
604
 
590
- return {
591
- type: "location",
592
- ID: blob.legacy_attachment_id,
593
- latitude: latitude,
594
- longitude: longitude,
595
- image: imageUrl,
596
- width: width,
597
- height: height,
598
- url: u || urlAttach,
599
- address: where1,
600
-
601
- facebookUrl: blob.story_attachment.url, // @Legacy
602
- target: blob.story_attachment.target, // @Legacy
603
- styleList: blob.story_attachment.style_list // @Legacy
604
- };
605
- case "ExtensibleAttachment":
606
- return {
607
- type: "share",
608
- ID: blob.legacy_attachment_id,
609
- url: blob.story_attachment.url,
610
-
611
- title: blob.story_attachment.title_with_entities.text,
612
- description: blob.story_attachment.description &&
613
- blob.story_attachment.description.text,
614
- source: blob.story_attachment.source ? blob.story_attachment.source.text : null,
615
-
616
- image: blob.story_attachment.media &&
617
- blob.story_attachment.media.image &&
618
- blob.story_attachment.media.image.uri,
619
- width: blob.story_attachment.media &&
620
- blob.story_attachment.media.image &&
621
- blob.story_attachment.media.image.width,
622
- height: blob.story_attachment.media &&
623
- blob.story_attachment.media.image &&
624
- blob.story_attachment.media.image.height,
625
- playable: blob.story_attachment.media &&
626
- blob.story_attachment.media.is_playable,
627
- duration: blob.story_attachment.media &&
628
- blob.story_attachment.media.playable_duration_in_ms,
629
- playableUrl: blob.story_attachment.media == null ? null : blob.story_attachment.media.playable_url,
630
-
631
- subattachments: blob.story_attachment.subattachments,
632
- properties: blob.story_attachment.properties.reduce(function(obj, cur) {
633
- obj[cur.key] = cur.value.text;
634
- return obj;
635
- }, {}),
636
-
637
- facebookUrl: blob.story_attachment.url, // @Legacy
638
- target: blob.story_attachment.target, // @Legacy
639
- styleList: blob.story_attachment.style_list // @Legacy
640
- };
641
- case "MessageFile":
642
- return {
643
- type: "file",
644
- filename: blob.filename,
645
- ID: blob.message_file_fbid,
646
-
647
- url: blob.url,
648
- isMalicious: blob.is_malicious,
649
- contentType: blob.content_type,
650
-
651
- name: blob.filename,
652
- mimeType: "",
653
- fileSize: -1
654
- };
655
- default:
656
- throw new Error(
657
- "unrecognized attach_file of type " +
658
- type +
659
- "`" +
660
- JSON.stringify(attachment1, null, 4) +
661
- " attachment2: " +
662
- JSON.stringify(attachment2, null, 4) +
663
- "`"
664
- );
665
- }
605
+ return {
606
+ type: "location",
607
+ ID: blob.legacy_attachment_id,
608
+ latitude: latitude,
609
+ longitude: longitude,
610
+ image: imageUrl,
611
+ width: width,
612
+ height: height,
613
+ url: u || urlAttach,
614
+ address: where1,
615
+
616
+ facebookUrl: blob.story_attachment.url, // @Legacy
617
+ target: blob.story_attachment.target, // @Legacy
618
+ styleList: blob.story_attachment.style_list // @Legacy
619
+ };
620
+ case "ExtensibleAttachment":
621
+ return {
622
+ type: "share",
623
+ ID: blob.legacy_attachment_id,
624
+ url: blob.story_attachment.url,
625
+
626
+ title: blob.story_attachment.title_with_entities.text,
627
+ description:
628
+ blob.story_attachment.description &&
629
+ blob.story_attachment.description.text,
630
+ source: blob.story_attachment.source
631
+ ? blob.story_attachment.source.text
632
+ : null,
633
+
634
+ image:
635
+ blob.story_attachment.media &&
636
+ blob.story_attachment.media.image &&
637
+ blob.story_attachment.media.image.uri,
638
+ width:
639
+ blob.story_attachment.media &&
640
+ blob.story_attachment.media.image &&
641
+ blob.story_attachment.media.image.width,
642
+ height:
643
+ blob.story_attachment.media &&
644
+ blob.story_attachment.media.image &&
645
+ blob.story_attachment.media.image.height,
646
+ playable:
647
+ blob.story_attachment.media &&
648
+ blob.story_attachment.media.is_playable,
649
+ duration:
650
+ blob.story_attachment.media &&
651
+ blob.story_attachment.media.playable_duration_in_ms,
652
+ playableUrl:
653
+ blob.story_attachment.media == null
654
+ ? null
655
+ : blob.story_attachment.media.playable_url,
656
+
657
+ subattachments: blob.story_attachment.subattachments,
658
+ properties: blob.story_attachment.properties.reduce(function(obj, cur) {
659
+ obj[cur.key] = cur.value.text;
660
+ return obj;
661
+ }, {}),
662
+
663
+ facebookUrl: blob.story_attachment.url, // @Legacy
664
+ target: blob.story_attachment.target, // @Legacy
665
+ styleList: blob.story_attachment.style_list // @Legacy
666
+ };
667
+ case "MessageFile":
668
+ return {
669
+ type: "file",
670
+ filename: blob.filename,
671
+ ID: blob.message_file_fbid,
672
+
673
+ url: blob.url,
674
+ isMalicious: blob.is_malicious,
675
+ contentType: blob.content_type,
676
+
677
+ name: blob.filename,
678
+ mimeType: "",
679
+ fileSize: -1
680
+ };
681
+ default:
682
+ throw new Error(
683
+ "unrecognized attach_file of type " +
684
+ type +
685
+ "`" +
686
+ JSON.stringify(attachment1, null, 4) +
687
+ " attachment2: " +
688
+ JSON.stringify(attachment2, null, 4) +
689
+ "`"
690
+ );
691
+ }
666
692
  }
667
693
 
668
694
  function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
669
- attachmentMap = shareMap || attachmentMap;
670
- return attachments ?
671
- attachments.map(function(val, i) {
672
- if (!attachmentMap ||
673
- !attachmentIds ||
674
- !attachmentMap[attachmentIds[i]]
675
- ) {
676
- return _formatAttachment(val);
677
- }
678
- return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
679
- }) : [];
695
+ attachmentMap = shareMap || attachmentMap;
696
+ return attachments
697
+ ? attachments.map(function(val, i) {
698
+ if (
699
+ !attachmentMap ||
700
+ !attachmentIds ||
701
+ !attachmentMap[attachmentIds[i]]
702
+ ) {
703
+ return _formatAttachment(val);
704
+ }
705
+ return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
706
+ })
707
+ : [];
680
708
  }
681
709
 
682
710
  function formatDeltaMessage(m) {
683
- var md = m.delta.messageMetadata;
684
- var mdata =
685
- m.delta.data === undefined ? [] :
686
- m.delta.data.prng === undefined ? [] :
687
- JSON.parse(m.delta.data.prng);
688
- var m_id = mdata.map(u => u.i);
689
- var m_offset = mdata.map(u => u.o);
690
- var m_length = mdata.map(u => u.l);
691
- var mentions = {};
692
- var body = m.delta.body || "";
693
- var args = body == "" ? [] : body.trim().split(/\s+/);
694
- 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]);
695
-
696
- return {
697
- type: "message",
698
- senderID: formatID(md.actorFbId.toString()),
699
- threadID: formatID((md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString()),
700
- messageID: md.messageId,
701
- args: args,
702
- body: body,
703
- attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
704
- mentions: mentions,
705
- timestamp: md.timestamp,
706
- isGroup: !!md.threadKey.threadFbId,
707
- participantIDs: m.delta.participants || []
708
- };
711
+ var md = m.delta.messageMetadata;
712
+ var mdata =
713
+ m.delta.data === undefined
714
+ ? []
715
+ : m.delta.data.prng === undefined ? [] : JSON.parse(m.delta.data.prng);
716
+ var m_id = mdata.map(u => u.i);
717
+ var m_offset = mdata.map(u => u.o);
718
+ var m_length = mdata.map(u => u.l);
719
+ var mentions = {};
720
+ var body = m.delta.body || "";
721
+ var args = body == "" ? [] : body.trim().split(/\s+/);
722
+ for (var i = 0; i < m_id.length; i++)
723
+ mentions[m_id[i]] = m.delta.body.substring(
724
+ m_offset[i],
725
+ m_offset[i] + m_length[i]
726
+ );
727
+
728
+ return {
729
+ type: "message",
730
+ senderID: formatID(md.actorFbId.toString()),
731
+ threadID: formatID(
732
+ (md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString()
733
+ ),
734
+ messageID: md.messageId,
735
+ args: args,
736
+ body: body,
737
+ attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
738
+ mentions: mentions,
739
+ timestamp: md.timestamp,
740
+ isGroup: !!md.threadKey.threadFbId,
741
+ participantIDs: m.delta.participants || []
742
+ };
709
743
  }
710
744
 
711
745
  function formatID(id) {
712
- if (id != undefined && id != null) return id.replace(/(fb)?id[:.]/, "");
713
- else return id;
746
+ if (id != undefined && id != null) return id.replace(/(fb)?id[:.]/, "");
747
+ else return id;
714
748
  }
715
749
 
716
750
  function formatMessage(m) {
717
- var originalMessage = m.message ? m.message : m;
718
- var obj = {
719
- type: "message",
720
- senderName: originalMessage.sender_name,
721
- senderID: formatID(originalMessage.sender_fbid.toString()),
722
- participantNames: originalMessage.group_thread_info ? originalMessage.group_thread_info.participant_names : [originalMessage.sender_name.split(" ")[0]],
723
- participantIDs: originalMessage.group_thread_info ?
724
- originalMessage.group_thread_info.participant_ids.map(function(v) {
725
- return formatID(v.toString());
726
- }) : [formatID(originalMessage.sender_fbid)],
727
- body: originalMessage.body || "",
728
- threadID: formatID((originalMessage.thread_fbid || originalMessage.other_user_fbid).toString()),
729
- threadName: originalMessage.group_thread_info ? originalMessage.group_thread_info.name : originalMessage.sender_name,
730
- location: originalMessage.coordinates ? originalMessage.coordinates : null,
731
- messageID: originalMessage.mid ? originalMessage.mid.toString() : originalMessage.message_id,
732
- attachments: formatAttachment(
733
- originalMessage.attachments,
734
- originalMessage.attachmentIds,
735
- originalMessage.attachment_map,
736
- originalMessage.share_map
737
- ),
738
- timestamp: originalMessage.timestamp,
739
- timestampAbsolute: originalMessage.timestamp_absolute,
740
- timestampRelative: originalMessage.timestamp_relative,
741
- timestampDatetime: originalMessage.timestamp_datetime,
742
- tags: originalMessage.tags,
743
- reactions: originalMessage.reactions ? originalMessage.reactions : [],
744
- isUnread: originalMessage.is_unread
745
- };
746
-
747
- if (m.type === "pages_messaging") obj.pageID = m.realtime_viewer_fbid.toString();
748
- obj.isGroup = obj.participantIDs.length > 2;
749
-
750
- return obj;
751
+ var originalMessage = m.message ? m.message : m;
752
+ var obj = {
753
+ type: "message",
754
+ senderName: originalMessage.sender_name,
755
+ senderID: formatID(originalMessage.sender_fbid.toString()),
756
+ participantNames: originalMessage.group_thread_info
757
+ ? originalMessage.group_thread_info.participant_names
758
+ : [originalMessage.sender_name.split(" ")[0]],
759
+ participantIDs: originalMessage.group_thread_info
760
+ ? originalMessage.group_thread_info.participant_ids.map(function(v) {
761
+ return formatID(v.toString());
762
+ })
763
+ : [formatID(originalMessage.sender_fbid)],
764
+ body: originalMessage.body || "",
765
+ threadID: formatID(
766
+ (
767
+ originalMessage.thread_fbid || originalMessage.other_user_fbid
768
+ ).toString()
769
+ ),
770
+ threadName: originalMessage.group_thread_info
771
+ ? originalMessage.group_thread_info.name
772
+ : originalMessage.sender_name,
773
+ location: originalMessage.coordinates ? originalMessage.coordinates : null,
774
+ messageID: originalMessage.mid
775
+ ? originalMessage.mid.toString()
776
+ : originalMessage.message_id,
777
+ attachments: formatAttachment(
778
+ originalMessage.attachments,
779
+ originalMessage.attachmentIds,
780
+ originalMessage.attachment_map,
781
+ originalMessage.share_map
782
+ ),
783
+ timestamp: originalMessage.timestamp,
784
+ timestampAbsolute: originalMessage.timestamp_absolute,
785
+ timestampRelative: originalMessage.timestamp_relative,
786
+ timestampDatetime: originalMessage.timestamp_datetime,
787
+ tags: originalMessage.tags,
788
+ reactions: originalMessage.reactions ? originalMessage.reactions : [],
789
+ isUnread: originalMessage.is_unread
790
+ };
791
+
792
+ if (m.type === "pages_messaging")
793
+ obj.pageID = m.realtime_viewer_fbid.toString();
794
+ obj.isGroup = obj.participantIDs.length > 2;
795
+
796
+ return obj;
751
797
  }
752
798
 
753
799
  function formatEvent(m) {
754
- var originalMessage = m.message ? m.message : m;
755
- var logMessageType = originalMessage.log_message_type;
756
- var logMessageData;
757
- if (logMessageType === "log:generic-admin-text") {
758
- logMessageData = originalMessage.log_message_data.untypedData;
759
- logMessageType = getAdminTextMessageType(originalMessage.log_message_data.message_type);
760
- } else logMessageData = originalMessage.log_message_data;
761
-
762
- return Object.assign(formatMessage(originalMessage), {
763
- type: "event",
764
- logMessageType: logMessageType,
765
- logMessageData: logMessageData,
766
- logMessageBody: originalMessage.log_message_body
767
- });
800
+ var originalMessage = m.message ? m.message : m;
801
+ var logMessageType = originalMessage.log_message_type;
802
+ var logMessageData;
803
+ if (logMessageType === "log:generic-admin-text") {
804
+ logMessageData = originalMessage.log_message_data.untypedData;
805
+ logMessageType = getAdminTextMessageType(
806
+ originalMessage.log_message_data.message_type
807
+ );
808
+ } else logMessageData = originalMessage.log_message_data;
809
+
810
+ return Object.assign(formatMessage(originalMessage), {
811
+ type: "event",
812
+ logMessageType: logMessageType,
813
+ logMessageData: logMessageData,
814
+ logMessageBody: originalMessage.log_message_body
815
+ });
768
816
  }
769
817
 
770
818
  function formatHistoryMessage(m) {
771
- switch (m.action_type) {
772
- case "ma-type:log-message":
773
- return formatEvent(m);
774
- default:
775
- return formatMessage(m);
776
- }
819
+ switch (m.action_type) {
820
+ case "ma-type:log-message":
821
+ return formatEvent(m);
822
+ default:
823
+ return formatMessage(m);
824
+ }
777
825
  }
778
826
 
779
827
  // Get a more readable message type for AdminTextMessages
780
828
  function getAdminTextMessageType(m) {
781
- switch (m.type) {
782
- case "change_thread_theme":
783
- return "log:thread-color";
784
- case "change_thread_icon":
785
- return "log:thread-icon";
786
- case "change_thread_nickname":
787
- return "log:user-nickname";
788
- case "change_thread_admins":
789
- return "log:thread-admins";
790
- case "group_poll":
791
- return "log:thread-poll";
792
- case "change_thread_approval_mode":
793
- return "log:thread-approval-mode";
794
- case "messenger_call_log":
795
- case "participant_joined_group_call":
796
- return "log:thread-call";
797
- }
829
+ switch (m.type) {
830
+ case "change_thread_theme":
831
+ return "log:thread-color";
832
+ case "change_thread_icon":
833
+ return "log:thread-icon";
834
+ case "change_thread_nickname":
835
+ return "log:user-nickname";
836
+ case "change_thread_admins":
837
+ return "log:thread-admins";
838
+ case "group_poll":
839
+ return "log:thread-poll";
840
+ case "change_thread_approval_mode":
841
+ return "log:thread-approval-mode";
842
+ case "messenger_call_log":
843
+ case "participant_joined_group_call":
844
+ return "log:thread-call";
845
+ }
798
846
  }
799
847
 
800
848
  function formatDeltaEvent(m) {
801
- var { updateData,getData,hasData } = require('./Extra/ExtraGetThread');
802
- var Database = require('./Extra/Database/index');
803
- var logMessageType;
804
- var logMessageData;
805
-
806
- // log:thread-color => {theme_color}
807
- // log:user-nickname => {participant_id, nickname}
808
- // log:thread-icon => {thread_icon}
809
- // log:thread-name => {name}
810
- // log:subscribe => {addedParticipants - [Array]}
811
- //log:unsubscribe => {leftParticipantFbId}
812
-
813
- switch (m.class) {
814
- case "AdminTextMessage":
815
- logMessageType = getAdminTextMessageType(m);
816
- logMessageData = m.untypedData;
817
- break;
818
- case "ThreadName":
819
- logMessageType = "log:thread-name";
820
- logMessageData = { name: m.name };
821
- break;
822
- case "ParticipantsAddedToGroupThread":
823
- logMessageType = "log:subscribe";
824
- logMessageData = { addedParticipants: m.addedParticipants };
825
- break;
826
- case "ParticipantLeftGroupThread":
827
- logMessageType = "log:unsubscribe";
828
- logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
829
- break;
849
+ var { updateData, getData, hasData } = require("./Extra/ExtraGetThread");
850
+ var logMessageType;
851
+ var logMessageData;
852
+
853
+ switch (m.class) {
854
+ case "AdminTextMessage":
855
+ logMessageType = getAdminTextMessageType(m);
856
+ logMessageData = m.untypedData;
857
+ break;
858
+ case "ThreadName":
859
+ logMessageType = "log:thread-name";
860
+ logMessageData = { name: m.name };
861
+ break;
862
+ case "ParticipantsAddedToGroupThread":
863
+ logMessageType = "log:subscribe";
864
+ logMessageData = { addedParticipants: m.addedParticipants };
865
+ break;
866
+ case "ParticipantLeftGroupThread":
867
+ logMessageType = "log:unsubscribe";
868
+ logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
869
+ break;
870
+ case "UserLocation": {
871
+ logMessageType = "log:user-location";
872
+ logMessageData = {
873
+ Image:
874
+ m.attachments[0].mercury.extensible_attachment.story_attachment.media
875
+ .image,
876
+ Location:
877
+ m.attachments[0].mercury.extensible_attachment.story_attachment.target
878
+ .location_title,
879
+ coordinates:
880
+ m.attachments[0].mercury.extensible_attachment.story_attachment.target
881
+ .coordinate,
882
+ url: m.attachments[0].mercury.extensible_attachment.story_attachment.url
883
+ };
830
884
  }
885
+ }
886
+ switch (hasData(
887
+ formatID(
888
+ (
889
+ m.messageMetadata.threadKey.threadFbId ||
890
+ m.messageMetadata.threadKey.otherUserFbId
891
+ ).toString()
892
+ )
893
+ )) {
894
+ case true: {
895
+ switch (logMessageType) {
896
+ case "log:thread-color":
897
+ {
898
+ let x = getData(
899
+ formatID(
900
+ (
901
+ m.messageMetadata.threadKey.threadFbId ||
902
+ m.messageMetadata.threadKey.otherUserFbId
903
+ ).toString()
904
+ )
905
+ );
906
+ x.emoji = logMessageData.theme_emoji || x.emoji;
907
+ x.color = logMessageData["theme_color"] || x.color;
908
+ updateData(
909
+ formatID(
910
+ (
911
+ m.messageMetadata.threadKey.threadFbId ||
912
+ m.messageMetadata.threadKey.otherUserFbId
913
+ ).toString()
914
+ ),
915
+ x
916
+ );
917
+ }
918
+ break;
919
+ case "log:thread-icon":
920
+ {
921
+ let x = getData(
922
+ formatID(
923
+ (
924
+ m.messageMetadata.threadKey.threadFbId ||
925
+ m.messageMetadata.threadKey.otherUserFbId
926
+ ).toString()
927
+ )
928
+ );
929
+ x.emoji = logMessageData["thread_icon"] || x.emoji;
930
+ updateData(
931
+ formatID(
932
+ (
933
+ m.messageMetadata.threadKey.threadFbId ||
934
+ m.messageMetadata.threadKey.otherUserFbId
935
+ ).toString()
936
+ ),
937
+ x
938
+ );
939
+ }
940
+ break;
941
+ case "log:user-nickname":
942
+ {
943
+ let x = getData(
944
+ formatID(
945
+ (
946
+ m.messageMetadata.threadKey.threadFbId ||
947
+ m.messageMetadata.threadKey.otherUserFbId
948
+ ).toString()
949
+ )
950
+ );
951
+ x.nicknames[logMessageData.participant_id] =
952
+ logMessageData.nickname.length == 0
953
+ ? x.userInfo.find(
954
+ i => i.id == String(logMessageData.participant_id)
955
+ ).name
956
+ : logMessageData.nickname;
957
+ updateData(
958
+ formatID(
959
+ (
960
+ m.messageMetadata.threadKey.threadFbId ||
961
+ m.messageMetadata.threadKey.otherUserFbId
962
+ ).toString()
963
+ ),
964
+ x
965
+ );
966
+ }
967
+ break;
968
+ case "log:thread-admins":
969
+ {
970
+ let x = getData(
971
+ formatID(
972
+ (
973
+ m.messageMetadata.threadKey.threadFbId ||
974
+ m.messageMetadata.threadKey.otherUserFbId
975
+ ).toString()
976
+ )
977
+ );
978
+ switch (logMessageData.ADMIN_EVENT) {
979
+ case "add_admin":
980
+ {
981
+ x.adminIDs.push({ id: logMessageData.TARGET_ID });
982
+ }
983
+ break;
984
+ case "remove_admin":
985
+ {
986
+ x.adminIDs = x.adminIDs.filter(
987
+ item => item.id != logMessageData.TARGET_ID
988
+ );
989
+ }
990
+ break;
991
+ }
992
+ updateData(
993
+ formatID(
994
+ (
995
+ m.messageMetadata.threadKey.threadFbId ||
996
+ m.messageMetadata.threadKey.otherUserFbId
997
+ ).toString()
998
+ ),
999
+ x
1000
+ );
1001
+ }
1002
+ break;
1003
+ case "log:thread-approval-mode":
1004
+ {
1005
+ let x = getData(
1006
+ formatID(
1007
+ (
1008
+ m.messageMetadata.threadKey.threadFbId ||
1009
+ m.messageMetadata.threadKey.otherUserFbId
1010
+ ).toString()
1011
+ )
1012
+ );
1013
+ if (x.approvalMode == true) {
1014
+ x.approvalMode = false;
1015
+ } else {
1016
+ x.approvalMode = true;
1017
+ }
1018
+ updateData(
1019
+ formatID(
1020
+ (
1021
+ m.messageMetadata.threadKey.threadFbId ||
1022
+ m.messageMetadata.threadKey.otherUserFbId
1023
+ ).toString()
1024
+ ),
1025
+ x
1026
+ );
1027
+ }
1028
+ break;
1029
+ case "log:thread-name":
1030
+ {
1031
+ let x = getData(
1032
+ formatID(
1033
+ (
1034
+ m.messageMetadata.threadKey.threadFbId ||
1035
+ m.messageMetadata.threadKey.otherUserFbId
1036
+ ).toString()
1037
+ )
1038
+ );
1039
+ x.threadName =
1040
+ logMessageData.name ||
1041
+ formatID(
1042
+ (
1043
+ m.messageMetadata.threadKey.threadFbId ||
1044
+ m.messageMetadata.threadKey.otherUserFbId
1045
+ ).toString()
1046
+ );
1047
+ updateData(
1048
+ formatID(
1049
+ (
1050
+ m.messageMetadata.threadKey.threadFbId ||
1051
+ m.messageMetadata.threadKey.otherUserFbId
1052
+ ).toString()
1053
+ ),
1054
+ x
1055
+ );
1056
+ }
1057
+ break;
1058
+ case "log:subscribe":
1059
+ {
1060
+ let x = getData(
1061
+ formatID(
1062
+ (
1063
+ m.messageMetadata.threadKey.threadFbId ||
1064
+ m.messageMetadata.threadKey.otherUserFbId
1065
+ ).toString()
1066
+ )
1067
+ );
1068
+ for (let o of logMessageData.addedParticipants) {
1069
+ if (x.userInfo.some(i => i.id == o.userFbId)) continue;
1070
+ else {
1071
+ x.userInfo.push({
1072
+ id: o.userFbId,
1073
+ name: o.fullName,
1074
+ gender: getGenderByPhysicalMethod(o.fullName)
1075
+ });
1076
+ x.participantIDs.push(o.userFbId);
1077
+ }
1078
+ }
1079
+ updateData(
1080
+ formatID(
1081
+ (
1082
+ m.messageMetadata.threadKey.threadFbId ||
1083
+ m.messageMetadata.threadKey.otherUserFbId
1084
+ ).toString()
1085
+ ),
1086
+ x
1087
+ );
1088
+ }
1089
+ break;
1090
+ case "log:unsubscribe":
1091
+ {
1092
+ let x = getData(
1093
+ formatID(
1094
+ (
1095
+ m.messageMetadata.threadKey.threadFbId ||
1096
+ m.messageMetadata.threadKey.otherUserFbId
1097
+ ).toString()
1098
+ )
1099
+ );
1100
+ x.participantIDs = x.participantIDs.filter(
1101
+ item => item != logMessageData.leftParticipantFbId
1102
+ );
1103
+ x.userInfo = x.userInfo.filter(
1104
+ item => item.id != logMessageData.leftParticipantFbId
1105
+ );
1106
+ if (
1107
+ x.adminIDs.some(i => i.id == logMessageData.leftParticipantFbId)
1108
+ ) {
1109
+ x.adminIDs = x.adminIDs.filter(
1110
+ item => item.id != logMessageData.leftParticipantFbId
1111
+ );
1112
+ }
1113
+ updateData(
1114
+ formatID(
1115
+ (
1116
+ m.messageMetadata.threadKey.threadFbId ||
1117
+ m.messageMetadata.threadKey.otherUserFbId
1118
+ ).toString()
1119
+ ),
1120
+ x
1121
+ );
1122
+ }
1123
+ break;
1124
+ }
1125
+ }
1126
+ }
831
1127
 
832
- 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;}}}
833
-
834
- return {
835
- type: "event",
836
- threadID: formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),
837
- logMessageType: logMessageType,
838
- logMessageData: logMessageData,
839
- logMessageBody: m.messageMetadata.adminText,
840
- author: m.messageMetadata.actorFbId,
841
- participantIDs: m.participants || []
842
- };
1128
+ return {
1129
+ type: "event",
1130
+ threadID: formatID(
1131
+ (
1132
+ m.messageMetadata.threadKey.threadFbId ||
1133
+ m.messageMetadata.threadKey.otherUserFbId
1134
+ ).toString()
1135
+ ),
1136
+ logMessageType: logMessageType,
1137
+ logMessageData: logMessageData,
1138
+ logMessageBody: m.messageMetadata.adminText,
1139
+ author: m.messageMetadata.actorFbId,
1140
+ participantIDs: m.participants || []
1141
+ };
843
1142
  }
844
1143
 
1144
+ /**
1145
+ * @param {{ st: any; from: { toString: () => any; }; to: any; thread_fbid: any; hasOwnProperty: (arg0: string) => any; from_mobile: any; realtime_viewer_fbid: any; }} event
1146
+ */
1147
+
845
1148
  function formatTyp(event) {
846
- return {
847
- isTyping: !!event.st,
848
- from: event.from.toString(),
849
- threadID: formatID((event.to || event.thread_fbid || event.from).toString()),
850
- // When receiving typ indication from mobile, `from_mobile` isn't set.
851
- // If it is, we just use that value.
852
- fromMobile: event.hasOwnProperty("from_mobile") ? event.from_mobile : true,
853
- userID: (event.realtime_viewer_fbid || event.from).toString(),
854
- type: "typ"
855
- };
1149
+ return {
1150
+ isTyping: !!event.st,
1151
+ from: event.from.toString(),
1152
+ threadID: formatID(
1153
+ (event.to || event.thread_fbid || event.from).toString()
1154
+ ),
1155
+ // When receiving typ indication from mobile, `from_mobile` isn't set.
1156
+ // If it is, we just use that value.
1157
+ fromMobile: event.hasOwnProperty("from_mobile") ? event.from_mobile : true,
1158
+ userID: (event.realtime_viewer_fbid || event.from).toString(),
1159
+ type: "typ"
1160
+ };
856
1161
  }
857
1162
 
858
1163
  function formatDeltaReadReceipt(delta) {
859
- // otherUserFbId seems to be used as both the readerID and the threadID in a 1-1 chat.
860
- // In a group chat actorFbId is used for the reader and threadFbId for the thread.
861
- return {
862
- reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
863
- time: delta.actionTimestampMs,
864
- threadID: formatID((delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString()),
865
- type: "read_receipt"
866
- };
1164
+ // otherUserFbId seems to be used as both the readerID and the threadID in a 1-1 chat.
1165
+ // In a group chat actorFbId is used for the reader and threadFbId for the thread.
1166
+ return {
1167
+ reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
1168
+ time: delta.actionTimestampMs,
1169
+ threadID: formatID(
1170
+ (delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString()
1171
+ ),
1172
+ type: "read_receipt"
1173
+ };
867
1174
  }
868
1175
 
869
1176
  function formatReadReceipt(event) {
870
- return {
871
- reader: event.reader.toString(),
872
- time: event.time,
873
- threadID: formatID((event.thread_fbid || event.reader).toString()),
874
- type: "read_receipt"
875
- };
1177
+ return {
1178
+ reader: event.reader.toString(),
1179
+ time: event.time,
1180
+ threadID: formatID((event.thread_fbid || event.reader).toString()),
1181
+ type: "read_receipt"
1182
+ };
876
1183
  }
877
1184
 
878
1185
  function formatRead(event) {
879
- return {
880
- threadID: formatID(((event.chat_ids && event.chat_ids[0]) || (event.thread_fbids && event.thread_fbids[0])).toString()),
881
- time: event.timestamp,
882
- type: "read"
883
- };
1186
+ return {
1187
+ threadID: formatID(
1188
+ (
1189
+ (event.chat_ids && event.chat_ids[0]) ||
1190
+ (event.thread_fbids && event.thread_fbids[0])
1191
+ ).toString()
1192
+ ),
1193
+ time: event.timestamp,
1194
+ type: "read"
1195
+ };
884
1196
  }
885
1197
 
886
1198
  function getFrom(str, startToken, endToken) {
887
- var start = str.indexOf(startToken) + startToken.length;
888
- if (start < startToken.length) return "";
889
-
890
- var lastHalf = str.substring(start);
891
- var end = lastHalf.indexOf(endToken);
892
- if (end === -1) throw Error("Could not find endTime `" + endToken + "` in the given string.");
893
- return lastHalf.substring(0, end);
1199
+ var start = str.indexOf(startToken) + startToken.length;
1200
+ if (start < startToken.length) return "";
1201
+
1202
+ var lastHalf = str.substring(start);
1203
+ var end = lastHalf.indexOf(endToken);
1204
+ if (end === -1)
1205
+ throw Error(
1206
+ "Could not find endTime `" + endToken + "` in the given string."
1207
+ );
1208
+ return lastHalf.substring(0, end);
894
1209
  }
895
1210
 
896
1211
  function makeParsable(html) {
897
- let withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, "");
898
-
899
- // (What the fuck FB, why windows style newlines?)
900
- // So sometimes FB will send us base multiple objects in the same response.
901
- // They're all valid JSON, one after the other, at the top level. We detect
902
- // that and make it parse-able by JSON.parse.
903
- // Ben - July 15th 2017
904
- //
905
- // It turns out that Facebook may insert random number of spaces before
906
- // next object begins (issue #616)
907
- // rav_kr - 2018-03-19
908
- let maybeMultipleObjects = withoutForLoop.split(/\}\r\n *\{/);
909
- if (maybeMultipleObjects.length === 1) return maybeMultipleObjects;
910
-
911
- return "[" + maybeMultipleObjects.join("},{") + "]";
1212
+ let withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, "");
1213
+
1214
+ // (What the fuck FB, why windows style newlines?)
1215
+ // So sometimes FB will send us base multiple objects in the same response.
1216
+ // They're all valid JSON, one after the other, at the top level. We detect
1217
+ // that and make it parse-able by JSON.parse.
1218
+ // Ben - July 15th 2017
1219
+ //
1220
+ // It turns out that Facebook may insert random number of spaces before
1221
+ // next object begins (issue #616)
1222
+ // rav_kr - 2018-03-19
1223
+ let maybeMultipleObjects = withoutForLoop.split(/\}\r\n *\{/);
1224
+ if (maybeMultipleObjects.length === 1) return maybeMultipleObjects;
1225
+
1226
+ return "[" + maybeMultipleObjects.join("},{") + "]";
912
1227
  }
913
1228
 
914
1229
  function arrToForm(form) {
915
- return arrayToObject(form,
916
- function(v) {
917
- return v.name;
918
- },
919
- function(v) {
920
- return v.val;
921
- }
922
- );
1230
+ return arrayToObject(
1231
+ form,
1232
+ function(v) {
1233
+ return v.name;
1234
+ },
1235
+ function(v) {
1236
+ return v.val;
1237
+ }
1238
+ );
923
1239
  }
924
1240
 
925
1241
  function arrayToObject(arr, getKey, getValue) {
926
- return arr.reduce(function(acc, val) {
927
- acc[getKey(val)] = getValue(val);
928
- return acc;
929
- }, {});
1242
+ return arr.reduce(function(acc, val) {
1243
+ acc[getKey(val)] = getValue(val);
1244
+ return acc;
1245
+ }, {});
930
1246
  }
931
1247
 
932
1248
  function getSignatureID() {
933
- return Math.floor(Math.random() * 2147483648).toString(16);
1249
+ return Math.floor(Math.random() * 2147483648).toString(16);
934
1250
  }
935
1251
 
936
1252
  function generateTimestampRelative() {
937
- var d = new Date();
938
- return d.getHours() + ":" + padZeros(d.getMinutes());
1253
+ var d = new Date();
1254
+ return d.getHours() + ":" + padZeros(d.getMinutes());
939
1255
  }
940
1256
 
941
1257
  function makeDefaults(html, userID, ctx) {
942
- var reqCounter = 1;
943
- var fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
944
-
945
- // @Hack Ok we've done hacky things, this is definitely on top 5.
946
- // We totally assume the object is flat and try parsing until a }.
947
- // If it works though it's cool because we get a bunch of extra data things.
1258
+ var reqCounter = 1;
1259
+ var fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
1260
+
1261
+ // @Hack Ok we've done hacky things, this is definitely on top 5.
1262
+ // We totally assume the object is flat and try parsing until a }.
1263
+ // If it works though it's cool because we get a bunch of extra data things.
1264
+ //
1265
+ // Update: we don't need this. Leaving it in in case we ever do.
1266
+ // Ben - July 15th 2017
1267
+
1268
+ // var siteData = getFrom(html, "[\"SiteData\",[],", "},");
1269
+ // try {
1270
+ // siteData = JSON.parse(siteData + "}");
1271
+ // } catch(e) {
1272
+ // log.warn("makeDefaults", "Couldn't parse SiteData. Won't have access to some variables.");
1273
+ // siteData = {};
1274
+ // }
1275
+
1276
+ var ttstamp = "2";
1277
+ for (var i = 0; i < fb_dtsg.length; i++) ttstamp += fb_dtsg.charCodeAt(i);
1278
+ var revision = getFrom(html, 'revision":', ",");
1279
+
1280
+ function mergeWithDefaults(obj) {
1281
+ // @TODO This is missing a key called __dyn.
1282
+ // After some investigation it seems like __dyn is some sort of set that FB
1283
+ // calls BitMap. It seems like certain responses have a "define" key in the
1284
+ // res.jsmods arrays. I think the code iterates over those and calls `set`
1285
+ // on the bitmap for each of those keys. Then it calls
1286
+ // bitmap.toCompressedString() which returns what __dyn is.
948
1287
  //
949
- // Update: we don't need this. Leaving it in in case we ever do.
950
- // Ben - July 15th 2017
951
-
952
- // var siteData = getFrom(html, "[\"SiteData\",[],", "},");
953
- // try {
954
- // siteData = JSON.parse(siteData + "}");
955
- // } catch(e) {
956
- // log.warn("makeDefaults", "Couldn't parse SiteData. Won't have access to some variables.");
957
- // siteData = {};
958
- // }
1288
+ // So far the API has been working without this.
1289
+ //
1290
+ // Ben - July 15th 2017
1291
+ var newObj = {
1292
+ __user: userID,
1293
+ __req: (reqCounter++).toString(36),
1294
+ __rev: revision,
1295
+ __a: 1,
1296
+ // __af: siteData.features,
1297
+ fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
1298
+ jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
1299
+ // __spin_r: siteData.__spin_r,
1300
+ // __spin_b: siteData.__spin_b,
1301
+ // __spin_t: siteData.__spin_t,
1302
+ };
959
1303
 
960
- var ttstamp = "2";
961
- for (var i = 0; i < fb_dtsg.length; i++) ttstamp += fb_dtsg.charCodeAt(i);
962
- var revision = getFrom(html, 'revision":', ",");
963
-
964
- function mergeWithDefaults(obj) {
965
- // @TODO This is missing a key called __dyn.
966
- // After some investigation it seems like __dyn is some sort of set that FB
967
- // calls BitMap. It seems like certain responses have a "define" key in the
968
- // res.jsmods arrays. I think the code iterates over those and calls `set`
969
- // on the bitmap for each of those keys. Then it calls
970
- // bitmap.toCompressedString() which returns what __dyn is.
971
- //
972
- // So far the API has been working without this.
973
- //
974
- // Ben - July 15th 2017
975
- var newObj = {
976
- __user: userID,
977
- __req: (reqCounter++).toString(36),
978
- __rev: revision,
979
- __a: 1,
980
- // __af: siteData.features,
981
- fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
982
- jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
983
- // __spin_r: siteData.__spin_r,
984
- // __spin_b: siteData.__spin_b,
985
- // __spin_t: siteData.__spin_t,
986
- };
1304
+ // @TODO this is probably not needed.
1305
+ // Ben - July 15th 2017
1306
+ // if (siteData.be_key) {
1307
+ // newObj[siteData.be_key] = siteData.be_mode;
1308
+ // }
1309
+ // if (siteData.pkg_cohort_key) {
1310
+ // newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
1311
+ // }
987
1312
 
988
- // @TODO this is probably not needed.
989
- // Ben - July 15th 2017
990
- // if (siteData.be_key) {
991
- // newObj[siteData.be_key] = siteData.be_mode;
992
- // }
993
- // if (siteData.pkg_cohort_key) {
994
- // newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
995
- // }
996
-
997
- if (!obj) return newObj;
998
- for (var prop in obj)
999
- if (obj.hasOwnProperty(prop))
1000
- if (!newObj[prop]) newObj[prop] = obj[prop];
1001
- return newObj;
1002
- }
1313
+ if (!obj) return newObj;
1314
+ for (var prop in obj)
1315
+ if (obj.hasOwnProperty(prop)) if (!newObj[prop]) newObj[prop] = obj[prop];
1316
+ return newObj;
1317
+ }
1003
1318
 
1004
- function postWithDefaults(url, jar, form, ctxx) {
1005
- return post(url, jar, mergeWithDefaults(form), ctx.globalOptions, ctxx || ctx);
1006
- }
1319
+ function postWithDefaults(url, jar, form, ctxx) {
1320
+ return post(
1321
+ url,
1322
+ jar,
1323
+ mergeWithDefaults(form),
1324
+ ctx.globalOptions,
1325
+ ctxx || ctx
1326
+ );
1327
+ }
1007
1328
 
1008
- function getWithDefaults(url, jar, qs, ctxx) {
1009
- return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
1010
- }
1329
+ function getWithDefaults(url, jar, qs, ctxx) {
1330
+ return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
1331
+ }
1011
1332
 
1012
- function postFormDataWithDefault(url, jar, form, qs, ctxx) {
1013
- return postFormData(url, jar, mergeWithDefaults(form), mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
1014
- }
1333
+ function postFormDataWithDefault(url, jar, form, qs, ctxx) {
1334
+ return postFormData(
1335
+ url,
1336
+ jar,
1337
+ mergeWithDefaults(form),
1338
+ mergeWithDefaults(qs),
1339
+ ctx.globalOptions,
1340
+ ctxx || ctx
1341
+ );
1342
+ }
1015
1343
 
1016
- return {
1017
- get: getWithDefaults,
1018
- post: postWithDefaults,
1019
- postFormData: postFormDataWithDefault
1020
- };
1344
+ return {
1345
+ get: getWithDefaults,
1346
+ post: postWithDefaults,
1347
+ postFormData: postFormDataWithDefault
1348
+ };
1021
1349
  }
1022
1350
 
1023
1351
  function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
1024
- if (retryCount == undefined) retryCount = 0;
1025
- return function(data) {
1026
- return bluebird.try(function() {
1027
- log.verbose("parseAndCheckLogin", data.body);
1028
- if (data.statusCode >= 500 && data.statusCode < 600) {
1029
- if (retryCount >= 5) {
1030
- throw {
1031
- error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
1032
- statusCode: data.statusCode,
1033
- res: data.body
1034
- };
1035
- }
1036
- retryCount++;
1037
- var retryTime = Math.floor(Math.random() * 5000);
1038
- log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
1039
- var url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
1040
- if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") {
1041
- return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {}))
1042
- .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1043
- } else {
1044
- return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData))
1045
- .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1046
- }
1047
- }
1048
- if (data.statusCode !== 200) throw new Error("parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.");
1049
-
1050
- var res = null;
1051
- try {
1052
- res = JSON.parse(makeParsable(data.body));
1053
- } catch (e) {
1054
- throw {
1055
- error: "JSON.parse error. Check the `detail` property on this error.",
1056
- detail: e,
1057
- res: data.body
1058
- };
1059
- }
1352
+ if (retryCount == undefined) retryCount = 0;
1353
+ return function(data) {
1354
+ return bluebird.try(function() {
1355
+ log.verbose("parseAndCheckLogin", data.body);
1356
+ if (data.statusCode >= 500 && data.statusCode < 600) {
1357
+ if (retryCount >= 5) {
1358
+ throw {
1359
+ error:
1360
+ "Request retry failed. Check the `res` and `statusCode` property on this error.",
1361
+ statusCode: data.statusCode,
1362
+ res: data.body
1363
+ };
1364
+ }
1365
+ retryCount++;
1366
+ var retryTime = Math.floor(Math.random() * 5000);
1367
+ log.warn(
1368
+ "parseAndCheckLogin",
1369
+ "Got status code " +
1370
+ data.statusCode +
1371
+ " - " +
1372
+ retryCount +
1373
+ ". attempt to retry in " +
1374
+ retryTime +
1375
+ " milliseconds..."
1376
+ );
1377
+ var url =
1378
+ data.request.uri.protocol +
1379
+ "//" +
1380
+ data.request.uri.hostname +
1381
+ data.request.uri.pathname;
1382
+ if (
1383
+ data.request.headers["Content-Type"].split(";")[0] ===
1384
+ "multipart/form-data"
1385
+ ) {
1386
+ return bluebird
1387
+ .delay(retryTime)
1388
+ .then(() =>
1389
+ defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {})
1390
+ )
1391
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1392
+ } else {
1393
+ return bluebird
1394
+ .delay(retryTime)
1395
+ .then(() => defaultFuncs.post(url, ctx.jar, data.request.formData))
1396
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1397
+ }
1398
+ }
1399
+ if (data.statusCode !== 200)
1400
+ throw new Error(
1401
+ "parseAndCheckLogin got status code: " +
1402
+ data.statusCode +
1403
+ ". Bailing out of trying to parse response."
1404
+ );
1060
1405
 
1061
- // In some cases the response contains only a redirect URL which should be followed
1062
- if (res.redirect && data.request.method === "GET") return defaultFuncs.get(res.redirect, ctx.jar).then(parseAndCheckLogin(ctx, defaultFuncs));
1406
+ var res = null;
1407
+ try {
1408
+ res = JSON.parse(makeParsable(data.body));
1409
+ } catch (e) {
1410
+ throw {
1411
+ error: "JSON.parse error. Check the `detail` property on this error.",
1412
+ detail: e,
1413
+ res: data.body
1414
+ };
1415
+ }
1063
1416
 
1064
- // TODO: handle multiple cookies?
1065
- if (res.jsmods && res.jsmods.require && Array.isArray(res.jsmods.require[0]) && res.jsmods.require[0][0] === "Cookie") {
1066
- res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace("_js_", "");
1067
- var cookie = formatCookie(res.jsmods.require[0][3], "facebook");
1068
- var cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
1069
- ctx.jar.setCookie(cookie, "https://www.facebook.com");
1070
- ctx.jar.setCookie(cookie2, "https://www.messenger.com");
1071
- }
1417
+ // In some cases the response contains only a redirect URL which should be followed
1418
+ if (res.redirect && data.request.method === "GET")
1419
+ return defaultFuncs
1420
+ .get(res.redirect, ctx.jar)
1421
+ .then(parseAndCheckLogin(ctx, defaultFuncs));
1422
+
1423
+ // TODO: handle multiple cookies?
1424
+ if (
1425
+ res.jsmods &&
1426
+ res.jsmods.require &&
1427
+ Array.isArray(res.jsmods.require[0]) &&
1428
+ res.jsmods.require[0][0] === "Cookie"
1429
+ ) {
1430
+ res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace(
1431
+ "_js_",
1432
+ ""
1433
+ );
1434
+ var cookie = formatCookie(res.jsmods.require[0][3], "facebook");
1435
+ var cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
1436
+ ctx.jar.setCookie(cookie, "https://www.facebook.com");
1437
+ ctx.jar.setCookie(cookie2, "https://www.messenger.com");
1438
+ }
1072
1439
 
1073
- // On every request we check if we got a DTSG and we mutate the context so that we use the latest
1074
- // one for the next requests.
1075
- if (res.jsmods && Array.isArray(res.jsmods.require)) {
1076
- var arr = res.jsmods.require;
1077
- for (var i in arr) {
1078
- if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
1079
- ctx.fb_dtsg = arr[i][3][0];
1080
-
1081
- // Update ttstamp since that depends on fb_dtsg
1082
- ctx.ttstamp = "2";
1083
- for (var j = 0; j < ctx.fb_dtsg.length; j++) ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
1084
- }
1085
- }
1086
- }
1440
+ // On every request we check if we got a DTSG and we mutate the context so that we use the latest
1441
+ // one for the next requests.
1442
+ if (res.jsmods && Array.isArray(res.jsmods.require)) {
1443
+ var arr = res.jsmods.require;
1444
+ for (var i in arr) {
1445
+ if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
1446
+ ctx.fb_dtsg = arr[i][3][0];
1447
+
1448
+ // Update ttstamp since that depends on fb_dtsg
1449
+ ctx.ttstamp = "2";
1450
+ for (var j = 0; j < ctx.fb_dtsg.length; j++)
1451
+ ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
1452
+ }
1453
+ }
1454
+ }
1087
1455
 
1088
- if (res.error === 1357001) throw { error: "Not logged in." };
1089
- return res;
1090
- });
1091
- };
1456
+ if (res.error === 1357001) throw { error: "Not logged in." };
1457
+ return res;
1458
+ });
1459
+ };
1092
1460
  }
1093
1461
 
1094
1462
  function saveCookies(jar) {
1095
- return function(res) {
1096
- var cookies = res.headers["set-cookie"] || [];
1097
- cookies.forEach(function(c) {
1098
- if (c.indexOf(".facebook.com") > -1) jar.setCookie(c, "https://www.facebook.com");
1099
- var c2 = c.replace(/domain=\.facebook\.com/, "domain=.messenger.com");
1100
- jar.setCookie(c2, "https://www.messenger.com");
1101
- });
1102
- return res;
1103
- };
1463
+ return function(res) {
1464
+ var cookies = res.headers["set-cookie"] || [];
1465
+ cookies.forEach(function(c) {
1466
+ if (c.indexOf(".facebook.com") > -1)
1467
+ jar.setCookie(c, "https://www.facebook.com");
1468
+ var c2 = c.replace(/domain=\.facebook\.com/, "domain=.messenger.com");
1469
+ jar.setCookie(c2, "https://www.messenger.com");
1470
+ });
1471
+ return res;
1472
+ };
1104
1473
  }
1105
1474
 
1106
1475
  var NUM_TO_MONTH = [
1107
- "Jan",
1108
- "Feb",
1109
- "Mar",
1110
- "Apr",
1111
- "May",
1112
- "Jun",
1113
- "Jul",
1114
- "Aug",
1115
- "Sep",
1116
- "Oct",
1117
- "Nov",
1118
- "Dec"
1476
+ "Jan",
1477
+ "Feb",
1478
+ "Mar",
1479
+ "Apr",
1480
+ "May",
1481
+ "Jun",
1482
+ "Jul",
1483
+ "Aug",
1484
+ "Sep",
1485
+ "Oct",
1486
+ "Nov",
1487
+ "Dec"
1119
1488
  ];
1120
1489
  var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1121
1490
 
1122
1491
  function formatDate(date) {
1123
- var d = date.getUTCDate();
1124
- d = d >= 10 ? d : "0" + d;
1125
- var h = date.getUTCHours();
1126
- h = h >= 10 ? h : "0" + h;
1127
- var m = date.getUTCMinutes();
1128
- m = m >= 10 ? m : "0" + m;
1129
- var s = date.getUTCSeconds();
1130
- s = s >= 10 ? s : "0" + s;
1131
- return (NUM_TO_DAY[date.getUTCDay()] + ", " + d + " " + NUM_TO_MONTH[date.getUTCMonth()] + " " + date.getUTCFullYear() + " " + h + ":" + m + ":" + s + " GMT");
1492
+ var d = date.getUTCDate();
1493
+ d = d >= 10 ? d : "0" + d;
1494
+ var h = date.getUTCHours();
1495
+ h = h >= 10 ? h : "0" + h;
1496
+ var m = date.getUTCMinutes();
1497
+ m = m >= 10 ? m : "0" + m;
1498
+ var s = date.getUTCSeconds();
1499
+ s = s >= 10 ? s : "0" + s;
1500
+ return (
1501
+ NUM_TO_DAY[date.getUTCDay()] +
1502
+ ", " +
1503
+ d +
1504
+ " " +
1505
+ NUM_TO_MONTH[date.getUTCMonth()] +
1506
+ " " +
1507
+ date.getUTCFullYear() +
1508
+ " " +
1509
+ h +
1510
+ ":" +
1511
+ m +
1512
+ ":" +
1513
+ s +
1514
+ " GMT"
1515
+ );
1132
1516
  }
1133
1517
 
1134
1518
  function formatCookie(arr, url) {
1135
- return arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com";
1519
+ return (
1520
+ arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com"
1521
+ );
1136
1522
  }
1137
1523
 
1138
1524
  function formatThread(data) {
1139
- return {
1140
- threadID: formatID(data.thread_fbid.toString()),
1141
- participants: data.participants.map(formatID),
1142
- participantIDs: data.participants.map(formatID),
1143
- name: data.name,
1144
- nicknames: data.custom_nickname,
1145
- snippet: data.snippet,
1146
- snippetAttachments: data.snippet_attachments,
1147
- snippetSender: formatID((data.snippet_sender || "").toString()),
1148
- unreadCount: data.unread_count,
1149
- messageCount: data.message_count,
1150
- imageSrc: data.image_src,
1151
- timestamp: data.timestamp,
1152
- serverTimestamp: data.server_timestamp, // what is this?
1153
- muteUntil: data.mute_until,
1154
- isCanonicalUser: data.is_canonical_user,
1155
- isCanonical: data.is_canonical,
1156
- isSubscribed: data.is_subscribed,
1157
- folder: data.folder,
1158
- isArchived: data.is_archived,
1159
- recipientsLoadable: data.recipients_loadable,
1160
- hasEmailParticipant: data.has_email_participant,
1161
- readOnly: data.read_only,
1162
- canReply: data.can_reply,
1163
- cannotReplyReason: data.cannot_reply_reason,
1164
- lastMessageTimestamp: data.last_message_timestamp,
1165
- lastReadTimestamp: data.last_read_timestamp,
1166
- lastMessageType: data.last_message_type,
1167
- emoji: data.custom_like_icon,
1168
- color: data.custom_color,
1169
- adminIDs: data.admin_ids,
1170
- threadType: data.thread_type
1171
- };
1525
+ return {
1526
+ threadID: formatID(data.thread_fbid.toString()),
1527
+ participants: data.participants.map(formatID),
1528
+ participantIDs: data.participants.map(formatID),
1529
+ name: data.name,
1530
+ nicknames: data.custom_nickname,
1531
+ snippet: data.snippet,
1532
+ snippetAttachments: data.snippet_attachments,
1533
+ snippetSender: formatID((data.snippet_sender || "").toString()),
1534
+ unreadCount: data.unread_count,
1535
+ messageCount: data.message_count,
1536
+ imageSrc: data.image_src,
1537
+ timestamp: data.timestamp,
1538
+ serverTimestamp: data.server_timestamp, // what is this?
1539
+ muteUntil: data.mute_until,
1540
+ isCanonicalUser: data.is_canonical_user,
1541
+ isCanonical: data.is_canonical,
1542
+ isSubscribed: data.is_subscribed,
1543
+ folder: data.folder,
1544
+ isArchived: data.is_archived,
1545
+ recipientsLoadable: data.recipients_loadable,
1546
+ hasEmailParticipant: data.has_email_participant,
1547
+ readOnly: data.read_only,
1548
+ canReply: data.can_reply,
1549
+ cannotReplyReason: data.cannot_reply_reason,
1550
+ lastMessageTimestamp: data.last_message_timestamp,
1551
+ lastReadTimestamp: data.last_read_timestamp,
1552
+ lastMessageType: data.last_message_type,
1553
+ emoji: data.custom_like_icon,
1554
+ color: data.custom_color,
1555
+ adminIDs: data.admin_ids,
1556
+ threadType: data.thread_type
1557
+ };
1172
1558
  }
1173
1559
 
1174
1560
  function getType(obj) {
1175
- return Object.prototype.toString.call(obj).slice(8, -1);
1561
+ return Object.prototype.toString.call(obj).slice(8, -1);
1176
1562
  }
1177
1563
 
1178
1564
  function formatProxyPresence(presence, userID) {
1179
- if (presence.lat === undefined || presence.p === undefined) return null;
1180
- return {
1181
- type: "presence",
1182
- timestamp: presence.lat * 1000,
1183
- userID: userID || '',
1184
- statuses: presence.p
1185
- };
1565
+ if (presence.lat === undefined || presence.p === undefined) return null;
1566
+ return {
1567
+ type: "presence",
1568
+ timestamp: presence.lat * 1000,
1569
+ userID: userID || "",
1570
+ statuses: presence.p
1571
+ };
1186
1572
  }
1187
1573
 
1188
1574
  function formatPresence(presence, userID) {
1189
- return {
1190
- type: "presence",
1191
- timestamp: presence.la * 1000,
1192
- userID: userID || '',
1193
- statuses: presence.a
1194
- };
1575
+ return {
1576
+ type: "presence",
1577
+ timestamp: presence.la * 1000,
1578
+ userID: userID || "",
1579
+ statuses: presence.a
1580
+ };
1195
1581
  }
1196
1582
 
1197
1583
  function decodeClientPayload(payload) {
1198
- /*
1584
+ /*
1199
1585
  Special function which Client using to "encode" clients JSON payload
1200
1586
  */
1201
- function Utf8ArrayToStr(array) {
1202
- var out, i, len, c;
1203
- var char2, char3;
1204
- out = "";
1205
- len = array.length;
1206
- i = 0;
1207
- while (i < len) {
1208
- c = array[i++];
1209
- switch (c >> 4) {
1210
- case 0:
1211
- case 1:
1212
- case 2:
1213
- case 3:
1214
- case 4:
1215
- case 5:
1216
- case 6:
1217
- case 7:
1218
- out += String.fromCharCode(c);
1219
- break;
1220
- case 12:
1221
- case 13:
1222
- char2 = array[i++];
1223
- out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
1224
- break;
1225
- case 14:
1226
- char2 = array[i++];
1227
- char3 = array[i++];
1228
- out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
1229
- break;
1230
- }
1231
- }
1232
- return out;
1587
+ function Utf8ArrayToStr(array) {
1588
+ var out, i, len, c;
1589
+ var char2, char3;
1590
+ out = "";
1591
+ len = array.length;
1592
+ i = 0;
1593
+ while (i < len) {
1594
+ c = array[i++];
1595
+ switch (c >> 4) {
1596
+ case 0:
1597
+ case 1:
1598
+ case 2:
1599
+ case 3:
1600
+ case 4:
1601
+ case 5:
1602
+ case 6:
1603
+ case 7:
1604
+ out += String.fromCharCode(c);
1605
+ break;
1606
+ case 12:
1607
+ case 13:
1608
+ char2 = array[i++];
1609
+ out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
1610
+ break;
1611
+ case 14:
1612
+ char2 = array[i++];
1613
+ char3 = array[i++];
1614
+ out += String.fromCharCode(
1615
+ ((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0)
1616
+ );
1617
+ break;
1618
+ }
1233
1619
  }
1234
- return JSON.parse(Utf8ArrayToStr(payload));
1620
+ return out;
1621
+ }
1622
+ return JSON.parse(Utf8ArrayToStr(payload));
1235
1623
  }
1236
1624
 
1237
-
1238
-
1239
- function getAppState(jar) {
1625
+ /*function getAppState(jar) {
1240
1626
  try {
1241
1627
  var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1242
1628
 
@@ -1258,46 +1644,77 @@ function getAppState(jar) {
1258
1644
  logger('Error retrieving cookies:', error, '[ FCA-SUS ]');
1259
1645
  throw error;
1260
1646
  }
1261
- }
1647
+ }*/
1648
+ function getAppState(jar) {
1649
+ const prettyMilliseconds = require("pretty-ms");
1650
+ var appstate = jar
1651
+ .getCookies("https://www.facebook.com")
1652
+ .concat(jar.getCookies("https://facebook.com"))
1653
+ .concat(jar.getCookies("https://www.messenger.com"));
1654
+ var StateCrypt = require("./StateCrypt");
1655
+ var logger = require("./logger");
1656
+ logger("Encrypted Appstate Successfully!", "[ FCA-SUS ]");
1657
+
1658
+ let processDuration = 0;
1659
+ if (process.env.startTime) {
1660
+ processDuration = Date.now() - parseInt(process.env.startTime);
1661
+ }
1262
1662
 
1663
+ if (isFinite(processDuration)) {
1664
+ logger(
1665
+ `Process Done: ${prettyMilliseconds(processDuration)}`,
1666
+ "[ FCA-SUS ]"
1667
+ );
1668
+ } else {
1669
+ logger(`Process Done: Unable to calculate duration`, "[ FCA-SUS ]");
1670
+ }
1671
+
1672
+ if (process.env["FBKEY"]) {
1673
+ return StateCrypt.encryptState(
1674
+ JSON.stringify(appstate),
1675
+ process.env["FBKEY"]
1676
+ );
1677
+ } else return appstate;
1678
+ }
1263
1679
 
1264
1680
  module.exports = {
1265
- isReadableStream:isReadableStream,
1266
- get,
1267
- post,
1268
- postFormData,
1269
- generateThreadingID,
1270
- generateOfflineThreadingID,
1271
- getGUID,
1272
- getFrom:getFrom,
1273
- makeParsable,
1274
- arrToForm,
1275
- getSignatureID,
1276
- getJar: request.jar,
1277
- generateTimestampRelative,
1278
- makeDefaults,
1279
- parseAndCheckLogin,
1280
- saveCookies,
1281
- getType,
1282
- _formatAttachment,
1283
- formatHistoryMessage,
1284
- formatID,
1285
- formatMessage,
1286
- formatDeltaEvent,
1287
- formatDeltaMessage,
1288
- formatProxyPresence,
1289
- formatPresence,
1290
- formatTyp,
1291
- formatDeltaReadReceipt,
1292
- formatCookie,
1293
- formatThread,
1294
- formatReadReceipt,
1295
- formatRead,
1296
- generatePresence,
1297
- generateAccessiblityCookie,
1298
- formatDate,
1299
- decodeClientPayload,
1300
- getAppState,
1301
- getAdminTextMessageType,
1302
- setProxy
1303
- };
1681
+ isReadableStream: isReadableStream,
1682
+ get,
1683
+ post,
1684
+ postFormData,
1685
+ generateThreadingID,
1686
+ generateOfflineThreadingID,
1687
+ getGUID,
1688
+ getFrom: getFrom,
1689
+ makeParsable,
1690
+ arrToForm,
1691
+ getSignatureID,
1692
+ getJar: request.jar,
1693
+ generateTimestampRelative,
1694
+ makeDefaults,
1695
+ parseAndCheckLogin,
1696
+ saveCookies,
1697
+ getType,
1698
+ _formatAttachment,
1699
+ formatHistoryMessage,
1700
+ formatID,
1701
+ formatMessage,
1702
+ formatDeltaEvent,
1703
+ formatDeltaMessage,
1704
+ formatProxyPresence,
1705
+ formatPresence,
1706
+ formatTyp,
1707
+ formatDeltaReadReceipt,
1708
+ formatCookie,
1709
+ formatThread,
1710
+ formatReadReceipt,
1711
+ formatRead,
1712
+ generatePresence,
1713
+ generateAccessiblityCookie,
1714
+ formatDate,
1715
+ decodeClientPayload,
1716
+ getAppState,
1717
+ getAdminTextMessageType,
1718
+ setProxy,
1719
+ getCurrentTimestamp
1720
+ };