node-ainzfb-new 1.7.9-uOw19mf → 1.7.10-11
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +83 -41
- package/package.json +2 -2
- package/src/changeAvt.js +73 -73
- package/src/editMessage.js +29 -26
- package/src/getAccessToken.js +21 -21
- package/src/getThreadInfo.js +3423 -18
- package/src/getUserInfoV2.js +19 -22
- package/src/pinMessage.js +61 -0
- package/src/shareContact.js +56 -0
- package/src/shareLink.js +57 -0
- package/utils.js +1452 -1131
package/utils.js
CHANGED
@@ -10,55 +10,61 @@ var querystring = require("querystring");
|
|
10
10
|
var url = require("url");
|
11
11
|
|
12
12
|
function setProxy(url) {
|
13
|
-
|
14
|
-
return request = bluebird.promisify(
|
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
|
+
));
|
15
20
|
}
|
16
21
|
|
17
22
|
function getHeaders(url, options, ctx, customHeader) {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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;
|
33
38
|
}
|
34
39
|
|
35
40
|
function isReadableStream(obj) {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
return (
|
42
|
+
obj instanceof stream.Stream &&
|
43
|
+
(getType(obj._read) === "Function" ||
|
44
|
+
getType(obj._read) === "AsyncFunction") &&
|
45
|
+
getType(obj._readableState) === "Object"
|
46
|
+
);
|
42
47
|
}
|
43
48
|
|
44
49
|
function get(url, jar, qs, options, ctx) {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
+
});
|
62
68
|
}
|
63
69
|
|
64
70
|
/*function getv2(url, jar, qs, options, ctx) {
|
@@ -82,21 +88,21 @@ function get(url, jar, qs, options, ctx) {
|
|
82
88
|
}*/
|
83
89
|
|
84
90
|
function post(url, jar, form, options, ctx, customHeader) {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
+
});
|
100
106
|
}
|
101
107
|
|
102
108
|
/*function postv2(url, jar, form, options, ctx, customHeader) {
|
@@ -118,809 +124,1021 @@ function post(url, jar, form, options, ctx, customHeader) {
|
|
118
124
|
}*/
|
119
125
|
|
120
126
|
function postFormData(url, jar, form, qs, options, ctx) {
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
+
});
|
137
143
|
}
|
138
144
|
|
139
145
|
function padZeros(val, len) {
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
146
|
+
val = String(val);
|
147
|
+
len = len || 2;
|
148
|
+
while (val.length < len) val = "0" + val;
|
149
|
+
return val;
|
144
150
|
}
|
145
151
|
|
146
152
|
function generateThreadingID(clientID) {
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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;
|
151
163
|
}
|
152
164
|
|
153
165
|
function binaryToDecimal(data) {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
}
|
166
|
-
ret = end.toString() + ret;
|
167
|
-
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";
|
168
177
|
}
|
169
|
-
|
178
|
+
ret = end.toString() + ret;
|
179
|
+
data = fullName.slice(fullName.indexOf("1"));
|
180
|
+
}
|
181
|
+
return ret;
|
170
182
|
}
|
171
183
|
|
172
184
|
function generateOfflineThreadingID() {
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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);
|
178
190
|
}
|
179
191
|
|
180
192
|
var h;
|
181
193
|
var i = {};
|
182
194
|
var j = {
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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"
|
210
224
|
};
|
211
225
|
(function() {
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
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");
|
219
233
|
})();
|
220
234
|
|
221
235
|
function presenceEncode(str) {
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
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
|
+
});
|
230
244
|
}
|
231
245
|
|
232
246
|
// eslint-disable-next-line no-unused-vars
|
233
247
|
function presenceDecode(str) {
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
248
|
+
return decodeURIComponent(
|
249
|
+
str.replace(/[_A-Z]/g, function(m) {
|
250
|
+
return j[m];
|
251
|
+
})
|
252
|
+
);
|
239
253
|
}
|
240
254
|
|
241
255
|
function generatePresence(userID) {
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
+
);
|
265
279
|
}
|
266
280
|
|
267
281
|
function generateAccessiblityCookie() {
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
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
|
+
);
|
281
295
|
}
|
282
296
|
|
283
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);
|
284
304
|
/** @type {number} */
|
285
|
-
|
305
|
+
sectionLength = Math.floor(sectionLength / 16);
|
286
306
|
/** @type {string} */
|
287
|
-
var
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
sectionLength = Math.floor(sectionLength / 16);
|
292
|
-
/** @type {string} */
|
293
|
-
var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
|
294
|
-
return _guid;
|
295
|
-
});
|
296
|
-
return id;
|
307
|
+
var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
|
308
|
+
return _guid;
|
309
|
+
});
|
310
|
+
return id;
|
297
311
|
}
|
298
312
|
|
299
313
|
function _formatAttachment(attachment1, attachment2) {
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
latitude = Number.parseFloat(address[0]);
|
574
|
-
longitude = Number.parseFloat(address[1]);
|
575
|
-
} catch (err) {
|
576
|
-
/* empty */
|
577
|
-
}
|
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;
|
578
587
|
|
579
|
-
|
580
|
-
|
581
|
-
|
588
|
+
try {
|
589
|
+
latitude = Number.parseFloat(address[0]);
|
590
|
+
longitude = Number.parseFloat(address[1]);
|
591
|
+
} catch (err) {
|
592
|
+
/* empty */
|
593
|
+
}
|
582
594
|
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
height = mediaAttach.image.height;
|
587
|
-
}
|
595
|
+
var imageUrl;
|
596
|
+
var width;
|
597
|
+
var height;
|
588
598
|
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
599
|
+
if (mediaAttach && mediaAttach.image) {
|
600
|
+
imageUrl = mediaAttach.image.uri;
|
601
|
+
width = mediaAttach.image.width;
|
602
|
+
height = mediaAttach.image.height;
|
603
|
+
}
|
604
|
+
|
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
|
+
}
|
665
692
|
}
|
666
693
|
|
667
694
|
function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
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
|
+
: [];
|
679
708
|
}
|
680
709
|
|
681
710
|
function formatDeltaMessage(m) {
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
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
|
+
};
|
708
743
|
}
|
709
744
|
|
710
745
|
function formatID(id) {
|
711
|
-
|
712
|
-
|
746
|
+
if (id != undefined && id != null) return id.replace(/(fb)?id[:.]/, "");
|
747
|
+
else return id;
|
713
748
|
}
|
714
749
|
|
715
750
|
function formatMessage(m) {
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
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;
|
750
797
|
}
|
751
798
|
|
752
799
|
function formatEvent(m) {
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
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
|
+
});
|
767
816
|
}
|
768
817
|
|
769
818
|
function formatHistoryMessage(m) {
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
819
|
+
switch (m.action_type) {
|
820
|
+
case "ma-type:log-message":
|
821
|
+
return formatEvent(m);
|
822
|
+
default:
|
823
|
+
return formatMessage(m);
|
824
|
+
}
|
776
825
|
}
|
777
826
|
|
778
827
|
// Get a more readable message type for AdminTextMessages
|
779
828
|
function getAdminTextMessageType(m) {
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
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
|
+
}
|
797
846
|
}
|
798
847
|
|
799
848
|
function formatDeltaEvent(m) {
|
800
|
-
|
801
|
-
|
802
|
-
|
849
|
+
var { updateData, getData, hasData } = require("./Extra/ExtraGetThread");
|
850
|
+
var logMessageType;
|
851
|
+
var logMessageData;
|
803
852
|
|
804
|
-
switch (m.class) {
|
853
|
+
switch (m.class) {
|
805
854
|
case "AdminTextMessage":
|
806
|
-
|
807
|
-
|
808
|
-
|
855
|
+
logMessageType = getAdminTextMessageType(m);
|
856
|
+
logMessageData = m.untypedData;
|
857
|
+
break;
|
809
858
|
case "ThreadName":
|
810
|
-
|
811
|
-
|
812
|
-
|
859
|
+
logMessageType = "log:thread-name";
|
860
|
+
logMessageData = { name: m.name };
|
861
|
+
break;
|
813
862
|
case "ParticipantsAddedToGroupThread":
|
814
|
-
|
815
|
-
|
816
|
-
|
863
|
+
logMessageType = "log:subscribe";
|
864
|
+
logMessageData = { addedParticipants: m.addedParticipants };
|
865
|
+
break;
|
817
866
|
case "ParticipantLeftGroupThread":
|
818
|
-
|
819
|
-
|
820
|
-
|
867
|
+
logMessageType = "log:unsubscribe";
|
868
|
+
logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
|
869
|
+
break;
|
821
870
|
case "UserLocation": {
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
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
|
+
};
|
829
884
|
}
|
830
|
-
}
|
831
|
-
switch (hasData(
|
885
|
+
}
|
886
|
+
switch (hasData(
|
887
|
+
formatID(
|
888
|
+
(
|
889
|
+
m.messageMetadata.threadKey.threadFbId ||
|
890
|
+
m.messageMetadata.threadKey.otherUserFbId
|
891
|
+
).toString()
|
892
|
+
)
|
893
|
+
)) {
|
832
894
|
case true: {
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
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 });
|
864
982
|
}
|
865
|
-
updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
|
866
|
-
}
|
867
983
|
break;
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
else {
|
874
|
-
x.approvalMode = true;
|
984
|
+
case "remove_admin":
|
985
|
+
{
|
986
|
+
x.adminIDs = x.adminIDs.filter(
|
987
|
+
item => item.id != logMessageData.TARGET_ID
|
988
|
+
);
|
875
989
|
}
|
876
|
-
updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
|
877
|
-
}
|
878
990
|
break;
|
879
|
-
case "log:thread-name": {
|
880
|
-
let x = getData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
|
881
|
-
x.threadName = (logMessageData.name || formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()));
|
882
|
-
updateData(formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),x);
|
883
991
|
}
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
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;
|
899
1017
|
}
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
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
|
+
}
|
909
1078
|
}
|
910
|
-
|
911
|
-
|
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
|
+
}
|
912
1125
|
}
|
913
|
-
}
|
1126
|
+
}
|
914
1127
|
|
915
|
-
return {
|
1128
|
+
return {
|
916
1129
|
type: "event",
|
917
|
-
threadID: formatID(
|
1130
|
+
threadID: formatID(
|
1131
|
+
(
|
1132
|
+
m.messageMetadata.threadKey.threadFbId ||
|
1133
|
+
m.messageMetadata.threadKey.otherUserFbId
|
1134
|
+
).toString()
|
1135
|
+
),
|
918
1136
|
logMessageType: logMessageType,
|
919
1137
|
logMessageData: logMessageData,
|
920
1138
|
logMessageBody: m.messageMetadata.adminText,
|
921
1139
|
author: m.messageMetadata.actorFbId,
|
922
1140
|
participantIDs: m.participants || []
|
923
|
-
|
1141
|
+
};
|
924
1142
|
}
|
925
1143
|
|
926
1144
|
/**
|
@@ -928,399 +1146,482 @@ return {
|
|
928
1146
|
*/
|
929
1147
|
|
930
1148
|
function formatTyp(event) {
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
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
|
+
};
|
941
1161
|
}
|
942
1162
|
|
943
1163
|
function formatDeltaReadReceipt(delta) {
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
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
|
+
};
|
952
1174
|
}
|
953
1175
|
|
954
1176
|
function formatReadReceipt(event) {
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
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
|
+
};
|
961
1183
|
}
|
962
1184
|
|
963
1185
|
function formatRead(event) {
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
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
|
+
};
|
969
1196
|
}
|
970
1197
|
|
971
1198
|
function getFrom(str, startToken, endToken) {
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
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);
|
979
1209
|
}
|
980
1210
|
|
981
1211
|
function makeParsable(html) {
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
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("},{") + "]";
|
997
1227
|
}
|
998
1228
|
|
999
1229
|
function arrToForm(form) {
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1230
|
+
return arrayToObject(
|
1231
|
+
form,
|
1232
|
+
function(v) {
|
1233
|
+
return v.name;
|
1234
|
+
},
|
1235
|
+
function(v) {
|
1236
|
+
return v.val;
|
1237
|
+
}
|
1238
|
+
);
|
1008
1239
|
}
|
1009
1240
|
|
1010
1241
|
function arrayToObject(arr, getKey, getValue) {
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1242
|
+
return arr.reduce(function(acc, val) {
|
1243
|
+
acc[getKey(val)] = getValue(val);
|
1244
|
+
return acc;
|
1245
|
+
}, {});
|
1015
1246
|
}
|
1016
1247
|
|
1017
1248
|
function getSignatureID() {
|
1018
|
-
|
1249
|
+
return Math.floor(Math.random() * 2147483648).toString(16);
|
1019
1250
|
}
|
1020
1251
|
|
1021
1252
|
function generateTimestampRelative() {
|
1022
|
-
|
1023
|
-
|
1253
|
+
var d = new Date();
|
1254
|
+
return d.getHours() + ":" + padZeros(d.getMinutes());
|
1024
1255
|
}
|
1025
1256
|
|
1026
1257
|
function makeDefaults(html, userID, ctx) {
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
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.
|
1033
1287
|
//
|
1034
|
-
//
|
1035
|
-
//
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
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
|
+
};
|
1044
1303
|
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
// res.jsmods arrays. I think the code iterates over those and calls `set`
|
1054
|
-
// on the bitmap for each of those keys. Then it calls
|
1055
|
-
// bitmap.toCompressedString() which returns what __dyn is.
|
1056
|
-
//
|
1057
|
-
// So far the API has been working without this.
|
1058
|
-
//
|
1059
|
-
// Ben - July 15th 2017
|
1060
|
-
var newObj = {
|
1061
|
-
__user: userID,
|
1062
|
-
__req: (reqCounter++).toString(36),
|
1063
|
-
__rev: revision,
|
1064
|
-
__a: 1,
|
1065
|
-
// __af: siteData.features,
|
1066
|
-
fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
|
1067
|
-
jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
|
1068
|
-
// __spin_r: siteData.__spin_r,
|
1069
|
-
// __spin_b: siteData.__spin_b,
|
1070
|
-
// __spin_t: siteData.__spin_t,
|
1071
|
-
};
|
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
|
+
// }
|
1072
1312
|
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
// if (siteData.pkg_cohort_key) {
|
1079
|
-
// newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
|
1080
|
-
// }
|
1081
|
-
|
1082
|
-
if (!obj) return newObj;
|
1083
|
-
for (var prop in obj)
|
1084
|
-
if (obj.hasOwnProperty(prop))
|
1085
|
-
if (!newObj[prop]) newObj[prop] = obj[prop];
|
1086
|
-
return newObj;
|
1087
|
-
}
|
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
|
+
}
|
1088
1318
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
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
|
+
}
|
1092
1328
|
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1329
|
+
function getWithDefaults(url, jar, qs, ctxx) {
|
1330
|
+
return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
|
1331
|
+
}
|
1096
1332
|
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
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
|
+
}
|
1100
1343
|
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1344
|
+
return {
|
1345
|
+
get: getWithDefaults,
|
1346
|
+
post: postWithDefaults,
|
1347
|
+
postFormData: postFormDataWithDefault
|
1348
|
+
};
|
1106
1349
|
}
|
1107
1350
|
|
1108
1351
|
function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
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
|
+
);
|
1145
1405
|
|
1146
|
-
|
1147
|
-
|
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
|
+
}
|
1148
1416
|
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
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
|
+
}
|
1157
1439
|
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
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
|
+
}
|
1172
1455
|
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1456
|
+
if (res.error === 1357001) throw { error: "Not logged in." };
|
1457
|
+
return res;
|
1458
|
+
});
|
1459
|
+
};
|
1177
1460
|
}
|
1178
1461
|
|
1179
1462
|
function saveCookies(jar) {
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
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
|
+
};
|
1189
1473
|
}
|
1190
1474
|
|
1191
1475
|
var NUM_TO_MONTH = [
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1476
|
+
"Jan",
|
1477
|
+
"Feb",
|
1478
|
+
"Mar",
|
1479
|
+
"Apr",
|
1480
|
+
"May",
|
1481
|
+
"Jun",
|
1482
|
+
"Jul",
|
1483
|
+
"Aug",
|
1484
|
+
"Sep",
|
1485
|
+
"Oct",
|
1486
|
+
"Nov",
|
1487
|
+
"Dec"
|
1204
1488
|
];
|
1205
1489
|
var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
1206
1490
|
|
1207
1491
|
function formatDate(date) {
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
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
|
+
);
|
1217
1516
|
}
|
1218
1517
|
|
1219
1518
|
function formatCookie(arr, url) {
|
1220
|
-
|
1519
|
+
return (
|
1520
|
+
arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com"
|
1521
|
+
);
|
1221
1522
|
}
|
1222
1523
|
|
1223
1524
|
function formatThread(data) {
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
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
|
+
};
|
1257
1558
|
}
|
1258
1559
|
|
1259
1560
|
function getType(obj) {
|
1260
|
-
|
1561
|
+
return Object.prototype.toString.call(obj).slice(8, -1);
|
1261
1562
|
}
|
1262
1563
|
|
1263
1564
|
function formatProxyPresence(presence, userID) {
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
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
|
+
};
|
1271
1572
|
}
|
1272
1573
|
|
1273
1574
|
function formatPresence(presence, userID) {
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1575
|
+
return {
|
1576
|
+
type: "presence",
|
1577
|
+
timestamp: presence.la * 1000,
|
1578
|
+
userID: userID || "",
|
1579
|
+
statuses: presence.a
|
1580
|
+
};
|
1280
1581
|
}
|
1281
1582
|
|
1282
1583
|
function decodeClientPayload(payload) {
|
1283
|
-
|
1584
|
+
/*
|
1284
1585
|
Special function which Client using to "encode" clients JSON payload
|
1285
1586
|
*/
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
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
|
+
}
|
1318
1619
|
}
|
1319
|
-
return
|
1620
|
+
return out;
|
1621
|
+
}
|
1622
|
+
return JSON.parse(Utf8ArrayToStr(payload));
|
1320
1623
|
}
|
1321
1624
|
|
1322
|
-
|
1323
|
-
|
1324
1625
|
/*function getAppState(jar) {
|
1325
1626
|
try {
|
1326
1627
|
var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
|
@@ -1345,55 +1646,75 @@ function decodeClientPayload(payload) {
|
|
1345
1646
|
}
|
1346
1647
|
}*/
|
1347
1648
|
function getAppState(jar) {
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
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
|
+
}
|
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;
|
1358
1678
|
}
|
1359
1679
|
|
1360
1680
|
module.exports = {
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
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
|
+
};
|