rapido-fca 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/index.js +415 -419
  2. package/package.json +1 -1
  3. package/readme.md +39 -237
  4. package/src/addExternalModule.js +23 -19
  5. package/src/addUserToGroup.js +97 -99
  6. package/src/changeAdminStatus.js +62 -86
  7. package/src/changeArchivedStatus.js +49 -49
  8. package/src/changeAvatar.js +108 -118
  9. package/src/changeBio.js +64 -63
  10. package/src/changeBlockedStatus.js +38 -40
  11. package/src/changeGroupImage.js +126 -129
  12. package/src/changeNickname.js +49 -49
  13. package/src/changeThreadColor.js +53 -53
  14. package/src/changeThreadEmoji.js +45 -45
  15. package/src/createNewGroup.js +72 -74
  16. package/src/createPoll.js +59 -59
  17. package/src/deleteMessage.js +50 -50
  18. package/src/deleteThread.js +50 -50
  19. package/src/editMessage.js +49 -51
  20. package/src/forwardAttachment.js +54 -54
  21. package/src/getCurrentUserID.js +3 -3
  22. package/src/getEmojiUrl.js +17 -17
  23. package/src/getFriendsList.js +67 -67
  24. package/src/getMessage.js +767 -806
  25. package/src/getThreadHistory.js +642 -656
  26. package/src/getThreadInfo.js +1 -1
  27. package/src/getThreadList.js +227 -199
  28. package/src/getThreadPictures.js +71 -51
  29. package/src/getUserID.js +58 -53
  30. package/src/getUserInfo.js +60 -52
  31. package/src/handleFriendRequest.js +65 -41
  32. package/src/handleMessageRequest.js +60 -42
  33. package/src/httpGet.js +57 -49
  34. package/src/httpPost.js +57 -48
  35. package/src/httpPostFormData.js +63 -0
  36. package/src/listenMqtt.js +895 -827
  37. package/src/logout.js +61 -61
  38. package/src/markAsDelivered.js +53 -42
  39. package/src/markAsRead.js +69 -59
  40. package/src/markAsReadAll.js +42 -32
  41. package/src/markAsSeen.js +54 -43
  42. package/src/muteThread.js +47 -40
  43. package/src/refreshFb_dtsg.js +69 -77
  44. package/src/removeUserFromGroup.js +67 -67
  45. package/src/resolvePhotoUrl.js +34 -34
  46. package/src/searchForThread.js +43 -43
  47. package/src/sendMessage.js +228 -80
  48. package/src/sendTypingIndicator.js +88 -86
  49. package/src/setMessageReaction.js +109 -110
  50. package/src/setPostReaction.js +87 -90
  51. package/src/setTitle.js +72 -76
  52. package/src/threadColors.js +121 -121
  53. package/src/unfriend.js +43 -43
  54. package/src/unsendMessage.js +38 -34
  55. package/src/uploadAttachment.js +81 -79
  56. package/utils.js +1401 -2732
  57. package/src/changeAvatarV2.js +0 -86
  58. package/src/changeAvt.js +0 -85
  59. package/src/changeBlockedStatusMqtt.js +0 -80
  60. package/src/changeCover.js +0 -72
  61. package/src/changeName.js +0 -79
  62. package/src/changeUsername.js +0 -59
  63. package/src/createCommentPost.js +0 -230
  64. package/src/createPost.js +0 -276
  65. package/src/editMessageOld.js +0 -67
  66. package/src/follow.js +0 -74
  67. package/src/getAccess.js +0 -112
  68. package/src/getAvatarUser.js +0 -78
  69. package/src/getRegion.js +0 -7
  70. package/src/getThreadHistoryDeprecated.js +0 -71
  71. package/src/getThreadInfoDeprecated.js +0 -56
  72. package/src/getThreadListDeprecated.js +0 -46
  73. package/src/getUID.js +0 -119
  74. package/src/searchStickers.js +0 -53
  75. package/src/sendMessageMqtt.js +0 -322
  76. package/src/sendTypingIndicatorV2.js +0 -28
  77. package/src/setMessageReactionMqtt.js +0 -62
  78. package/src/setStoryReaction.js +0 -64
  79. package/src/shareContact.js +0 -110
  80. package/src/shareLink.js +0 -59
  81. package/src/stopListenMqtt.js +0 -23
package/utils.js CHANGED
@@ -1,2876 +1,1545 @@
1
- // @ts-nocheck
2
- /* eslint-disable no-undef */
3
-
4
1
  /* eslint-disable no-prototype-builtins */
5
-
6
2
  "use strict";
7
- var url = require("url");
8
- var log = require("npmlog");
9
- var stream = require("stream");
10
- var bluebird = require("bluebird");
11
- var querystring = require("querystring");
12
- var request = bluebird.promisify(require("request").defaults({ jar: true }));
13
3
 
14
- /**
15
- * @param {any} url
16
- */
4
+ let request = promisifyPromise(require("request").defaults({ jar: true, proxy: process.env.FB_PROXY }));
5
+ const stream = require("stream");
6
+ const log = require("npmlog");
7
+ const querystring = require("querystring");
8
+ const url = require("url");
9
+
10
+ class CustomError extends Error {
11
+ constructor(obj) {
12
+ if (typeof obj === 'string')
13
+ obj = { message: obj };
14
+ if (typeof obj !== 'object' || obj === null)
15
+ throw new TypeError('Object required');
16
+ obj.message ? super(obj.message) : super();
17
+ Object.assign(this, obj);
18
+ }
19
+ }
17
20
 
18
- function setProxy(url) {
19
- if (typeof url == "undefined") return request = bluebird.promisify(require("request").defaults({ jar: true }));
20
- return request = bluebird.promisify(require("request").defaults({ jar: true, proxy: url }));
21
+ function callbackToPromise(func) {
22
+ return function (...args) {
23
+ return new Promise((resolve, reject) => {
24
+ func(...args, (err, data) => {
25
+ if (err)
26
+ reject(err);
27
+ else
28
+ resolve(data);
29
+ });
30
+ });
31
+ };
21
32
  }
22
33
 
23
- /**
24
- * @param {string | URL} url
25
- * @param {{ userAgent: any; }} options
26
- * @param {{ region: any; }} [ctx]
27
- * @param {undefined} [customHeader]
28
- */
34
+ function isHasCallback(func) {
35
+ if (typeof func !== "function")
36
+ return false;
37
+ return func.toString().split("\n")[0].match(/(callback|cb)\s*\)/) !== null;
38
+ }
29
39
 
30
- function getHeaders(url, options, ctx, customHeader) {
31
- var headers = {
32
- "Content-Type": "application/x-www-form-urlencoded",
33
- Referer: "https://www.facebook.com/",
34
- Host: url.replace("https://", "").split("/")[0],
35
- Origin: "https://www.facebook.com",
36
- "user-agent": (options.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36"),
37
- Connection: "keep-alive",
38
- "sec-fetch-site": 'same-origin',
39
- "sec-fetch-mode": 'cors'
40
- };
41
- if (customHeader) Object.assign(headers, customHeader);
42
- if (ctx && ctx.region) headers["X-MSGR-Region"] = ctx.region;
43
-
44
- return headers;
40
+ // replace for bluebird.promisify (but this only applies best to the `request` package)
41
+ function promisifyPromise(promise) {
42
+ const keys = Object.keys(promise);
43
+ let promise_;
44
+ if (
45
+ typeof promise === "function"
46
+ && isHasCallback(promise)
47
+ )
48
+ promise_ = callbackToPromise(promise);
49
+ else
50
+ promise_ = promise;
51
+
52
+ for (const key of keys) {
53
+ if (!promise[key]?.toString)
54
+ continue;
55
+
56
+ if (
57
+ typeof promise[key] === "function"
58
+ && isHasCallback(promise[key])
59
+ ) {
60
+ promise_[key] = callbackToPromise(promise[key]);
61
+ }
62
+ else {
63
+ promise_[key] = promise[key];
64
+ }
65
+ }
66
+
67
+ return promise_;
45
68
  }
46
69
 
47
- /**
48
- * @param {{ _read: any; _readableState: any; }} obj
49
- */
70
+ // replace for bluebird.delay
71
+ function delay(ms) {
72
+ return new Promise(resolve => setTimeout(resolve, ms));
73
+ }
50
74
 
51
- function isReadableStream(obj) {
52
- return (
53
- obj instanceof stream.Stream &&
54
- (getType(obj._read) === "Function" ||
55
- getType(obj._read) === "AsyncFunction") &&
56
- getType(obj._readableState) === "Object"
57
- );
75
+ // replace for bluebird.try
76
+ function tryPromise(tryFunc) {
77
+ return new Promise((resolve, reject) => {
78
+ try {
79
+ resolve(tryFunc());
80
+ } catch (error) {
81
+ reject(error);
82
+ }
83
+ });
58
84
  }
59
85
 
60
- /**
61
- * @param {any} url
62
- * @param {any} jar
63
- * @param {{ [x: string]: any; fb_dtsg?: any; jazoest?: any; hasOwnProperty?: any; }} qs
64
- * @param {any} options
65
- * @param {any} ctx
66
- */
86
+ function setProxy(url) {
87
+ if (typeof url == "undefined")
88
+ return request = promisifyPromise(require("request").defaults({
89
+ jar: true
90
+ }));
91
+ return request = promisifyPromise(require("request").defaults({
92
+ jar: true,
93
+ proxy: url
94
+ }));
95
+ }
96
+
97
+ function getHeaders(url, options, ctx, customHeader) {
98
+ const headers = {
99
+ "Content-Type": "application/x-www-form-urlencoded",
100
+ Referer: "https://www.facebook.com/",
101
+ Host: url.replace("https://", "").split("/")[0],
102
+ Origin: "https://www.facebook.com",
103
+ "User-Agent": options.userAgent,
104
+ Connection: "keep-alive",
105
+ "sec-fetch-site": "same-origin"
106
+ };
107
+ if (customHeader) {
108
+ Object.assign(headers, customHeader);
109
+ }
110
+ if (ctx && ctx.region) {
111
+ headers["X-MSGR-Region"] = ctx.region;
112
+ }
113
+
114
+ return headers;
115
+ }
116
+
117
+ function isReadableStream(obj) {
118
+ return (
119
+ obj instanceof stream.Stream &&
120
+ (getType(obj._read) === "Function" ||
121
+ getType(obj._read) === "AsyncFunction") &&
122
+ getType(obj._readableState) === "Object"
123
+ );
124
+ }
67
125
 
68
126
  function get(url, jar, qs, options, ctx) {
69
- // I'm still confused about this
70
- if (getType(qs) === "Object")
71
- for (var prop in qs)
72
- if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") qs[prop] = JSON.stringify(qs[prop]);
73
- var op = {
74
- headers: getHeaders(url, options, ctx),
75
- timeout: 60000,
76
- qs: qs,
77
- url: url,
78
- method: "GET",
79
- jar: jar,
80
- gzip: true
81
- };
82
-
83
- return request(op).then(function (res) {
84
- return res;
85
- });
127
+ // I'm still confused about this
128
+ if (getType(qs) === "Object") {
129
+ for (const prop in qs) {
130
+ if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") {
131
+ qs[prop] = JSON.stringify(qs[prop]);
132
+ }
133
+ }
134
+ }
135
+ const op = {
136
+ headers: getHeaders(url, options, ctx),
137
+ timeout: 60000,
138
+ qs: qs,
139
+ url: url,
140
+ method: "GET",
141
+ jar: jar,
142
+ gzip: true
143
+ };
144
+
145
+ return request(op).then(function (res) {
146
+ return Array.isArray(res) ? res[0] : res;
147
+ });
86
148
  }
87
149
 
88
150
  function post(url, jar, form, options, ctx, customHeader) {
89
- var op = {
90
- headers: getHeaders(url, options),
91
- timeout: 60000,
92
- url: url,
93
- method: "POST",
94
- form: form,
95
- jar: jar,
96
- gzip: true
97
- };
98
- return request(op).then(function (res) {
99
- return res;
100
- });
151
+ const op = {
152
+ headers: getHeaders(url, options, ctx, customHeader),
153
+ timeout: 60000,
154
+ url: url,
155
+ method: "POST",
156
+ form: form,
157
+ jar: jar,
158
+ gzip: true
159
+ };
160
+
161
+ return request(op).then(function (res) {
162
+ return Array.isArray(res) ? res[0] : res;
163
+ });
101
164
  }
102
165
 
103
- /**
104
- * @param {any} url
105
- * @param {any} jar
106
- * @param {{ __user: any; __req: string; __rev: any; __a: number;
107
- // __af: siteData.features,
108
- fb_dtsg: any; jazoest: any; }} form
109
- * @param {{ __user: any; __req: string; __rev: any; __a: number;
110
- // __af: siteData.features,
111
- fb_dtsg: any; jazoest: any; }} qs
112
- * @param {any} options
113
- * @param {any} ctx
114
- */
115
-
116
166
  function postFormData(url, jar, form, qs, options, ctx) {
117
- var headers = getHeaders(url, options, ctx);
118
- headers["Content-Type"] = "multipart/form-data";
119
- var op = {
120
- headers: headers,
121
- timeout: 60000,
122
- url: url,
123
- method: "POST",
124
- formData: form,
125
- qs: qs,
126
- jar: jar,
127
- gzip: true
128
- };
129
-
130
- return request(op).then(function (res) {
131
- return res;
132
- });
167
+ const headers = getHeaders(url, options, ctx);
168
+ headers["Content-Type"] = "multipart/form-data";
169
+ const op = {
170
+ headers: headers,
171
+ timeout: 60000,
172
+ url: url,
173
+ method: "POST",
174
+ formData: form,
175
+ qs: qs,
176
+ jar: jar,
177
+ gzip: true
178
+ };
179
+
180
+ return request(op).then(function (res) {
181
+ return Array.isArray(res) ? res[0] : res;
182
+ });
133
183
  }
134
184
 
135
- /**
136
- * @param {string | number | any[]} val
137
- * @param {number} [len]
138
- */
139
-
140
185
  function padZeros(val, len) {
141
- val = String(val);
142
- len = len || 2;
143
- while (val.length < len) val = "0" + val;
144
- return val;
186
+ val = String(val);
187
+ len = len || 2;
188
+ while (val.length < len) val = "0" + val;
189
+ return val;
145
190
  }
146
191
 
147
- /**
148
- * @param {any} clientID
149
- */
150
-
151
192
  function generateThreadingID(clientID) {
152
- var k = Date.now();
153
- var l = Math.floor(Math.random() * 4294967295);
154
- var m = clientID;
155
- return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
193
+ const k = Date.now();
194
+ const l = Math.floor(Math.random() * 4294967295);
195
+ const m = clientID;
196
+ return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
156
197
  }
157
198
 
158
- /**
159
- * @param {string | any[]} data
160
- */
161
-
162
199
  function binaryToDecimal(data) {
163
- var ret = "";
164
- while (data !== "0") {
165
- var end = 0;
166
- var fullName = "";
167
- var i = 0;
168
- for (; i < data.length; i++) {
169
- end = 2 * end + parseInt(data[i], 10);
170
- if (end >= 10) {
171
- fullName += "1";
172
- end -= 10;
173
- } else fullName += "0";
174
- }
175
- ret = end.toString() + ret;
176
- data = fullName.slice(fullName.indexOf("1"));
177
- }
178
- return ret;
200
+ let ret = "";
201
+ while (data !== "0") {
202
+ let end = 0;
203
+ let fullName = "";
204
+ let i = 0;
205
+ for (; i < data.length; i++) {
206
+ end = 2 * end + parseInt(data[i], 10);
207
+ if (end >= 10) {
208
+ fullName += "1";
209
+ end -= 10;
210
+ }
211
+ else {
212
+ fullName += "0";
213
+ }
214
+ }
215
+ ret = end.toString() + ret;
216
+ data = fullName.slice(fullName.indexOf("1"));
217
+ }
218
+ return ret;
179
219
  }
180
220
 
181
221
  function generateOfflineThreadingID() {
182
- var ret = Date.now();
183
- var value = Math.floor(Math.random() * 4294967295);
184
- var str = ("0000000000000000000000" + value.toString(2)).slice(-22);
185
- var msgs = ret.toString(2) + str;
186
- return binaryToDecimal(msgs);
222
+ const ret = Date.now();
223
+ const value = Math.floor(Math.random() * 4294967295);
224
+ const str = ("0000000000000000000000" + value.toString(2)).slice(-22);
225
+ const msgs = ret.toString(2) + str;
226
+ return binaryToDecimal(msgs);
187
227
  }
188
228
 
189
- var h;
190
- var i = {};
191
- var j = {
192
- _: "%",
193
- A: "%2",
194
- B: "000",
195
- C: "%7d",
196
- D: "%7b%22",
197
- E: "%2c%22",
198
- F: "%22%3a",
199
- G: "%2c%22ut%22%3a1",
200
- H: "%2c%22bls%22%3a",
201
- I: "%2c%22n%22%3a%22%",
202
- J: "%22%3a%7b%22i%22%3a0%7d",
203
- K: "%2c%22pt%22%3a0%2c%22vis%22%3a",
204
- L: "%2c%22ch%22%3a%7b%22h%22%3a%22",
205
- M: "%7b%22v%22%3a2%2c%22time%22%3a1",
206
- N: ".channel%22%2c%22sub%22%3a%5b",
207
- O: "%2c%22sb%22%3a1%2c%22t%22%3a%5b",
208
- P: "%2c%22ud%22%3a100%2c%22lc%22%3a0",
209
- Q: "%5d%2c%22f%22%3anull%2c%22uct%22%3a",
210
- R: ".channel%22%2c%22sub%22%3a%5b1%5d",
211
- S: "%22%2c%22m%22%3a0%7d%2c%7b%22i%22%3a",
212
- T: "%2c%22blc%22%3a1%2c%22snd%22%3a1%2c%22ct%22%3a",
213
- U: "%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
214
- V: "%2c%22blc%22%3a0%2c%22snd%22%3a0%2c%22ct%22%3a",
215
- W: "%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a",
216
- X: "%2c%22ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1",
217
- 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",
218
- 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"
229
+ let h;
230
+ const i = {};
231
+ const j = {
232
+ _: "%",
233
+ A: "%2",
234
+ B: "000",
235
+ C: "%7d",
236
+ D: "%7b%22",
237
+ E: "%2c%22",
238
+ F: "%22%3a",
239
+ G: "%2c%22ut%22%3a1",
240
+ H: "%2c%22bls%22%3a",
241
+ I: "%2c%22n%22%3a%22%",
242
+ J: "%22%3a%7b%22i%22%3a0%7d",
243
+ K: "%2c%22pt%22%3a0%2c%22vis%22%3a",
244
+ L: "%2c%22ch%22%3a%7b%22h%22%3a%22",
245
+ M: "%7b%22v%22%3a2%2c%22time%22%3a1",
246
+ N: ".channel%22%2c%22sub%22%3a%5b",
247
+ O: "%2c%22sb%22%3a1%2c%22t%22%3a%5b",
248
+ P: "%2c%22ud%22%3a100%2c%22lc%22%3a0",
249
+ Q: "%5d%2c%22f%22%3anull%2c%22uct%22%3a",
250
+ R: ".channel%22%2c%22sub%22%3a%5b1%5d",
251
+ S: "%22%2c%22m%22%3a0%7d%2c%7b%22i%22%3a",
252
+ T: "%2c%22blc%22%3a1%2c%22snd%22%3a1%2c%22ct%22%3a",
253
+ U: "%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
254
+ V: "%2c%22blc%22%3a0%2c%22snd%22%3a0%2c%22ct%22%3a",
255
+ W: "%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a",
256
+ X: "%2c%22ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1",
257
+ Y:
258
+ "%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
259
+ Z:
260
+ "%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"
219
261
  };
220
262
  (function () {
221
- var l = [];
222
- for (var m in j) {
223
- i[j[m]] = m;
224
- l.push(j[m]);
225
- }
226
- l.reverse();
227
- h = new RegExp(l.join("|"), "g");
263
+ const l = [];
264
+ for (const m in j) {
265
+ i[j[m]] = m;
266
+ l.push(j[m]);
267
+ }
268
+ l.reverse();
269
+ h = new RegExp(l.join("|"), "g");
228
270
  })();
229
271
 
230
- /**
231
- * @param {string | number | boolean} str
232
- */
233
-
234
272
  function presenceEncode(str) {
235
- return encodeURIComponent(str)
236
- .replace(/([_A-Z])|%../g, function (m, n) {
237
- return n ? "%" + n.charCodeAt(0).toString(16) : m;
238
- })
239
- .toLowerCase()
240
- .replace(h, function (m) {
241
- return i[m];
242
- });
273
+ return encodeURIComponent(str)
274
+ .replace(/([_A-Z])|%../g, function (m, n) {
275
+ return n ? "%" + n.charCodeAt(0).toString(16) : m;
276
+ })
277
+ .toLowerCase()
278
+ .replace(h, function (m) {
279
+ return i[m];
280
+ });
243
281
  }
244
282
 
245
283
  // eslint-disable-next-line no-unused-vars
246
- /**
247
- * @param {string} str
248
- */
249
-
250
284
  function presenceDecode(str) {
251
- return decodeURIComponent(
252
- str.replace(/[_A-Z]/g, function (/** @type {string | number} */m) {
253
- return j[m];
254
- })
255
- );
285
+ return decodeURIComponent(
286
+ str.replace(/[_A-Z]/g, function (m) {
287
+ return j[m];
288
+ })
289
+ );
256
290
  }
257
291
 
258
- /**
259
- * @param {string} userID
260
- */
261
-
262
292
  function generatePresence(userID) {
263
- var time = Date.now();
264
- return (
265
- "E" +
266
- presenceEncode(
267
- JSON.stringify({
268
- v: 3,
269
- time: parseInt(time / 1000, 10),
270
- user: userID,
271
- state: {
272
- ut: 0,
273
- t2: [],
274
- lm2: null,
275
- uct2: time,
276
- tr: null,
277
- tw: Math.floor(Math.random() * 4294967295) + 1,
278
- at: time
279
- },
280
- ch: {
281
- ["p_" + userID]: 0
282
- }
283
- })
284
- )
285
- );
293
+ const time = Date.now();
294
+ return (
295
+ "E" +
296
+ presenceEncode(
297
+ JSON.stringify({
298
+ v: 3,
299
+ time: parseInt(time / 1000, 10),
300
+ user: userID,
301
+ state: {
302
+ ut: 0,
303
+ t2: [],
304
+ lm2: null,
305
+ uct2: time,
306
+ tr: null,
307
+ tw: Math.floor(Math.random() * 4294967295) + 1,
308
+ at: time
309
+ },
310
+ ch: {
311
+ ["p_" + userID]: 0
312
+ }
313
+ })
314
+ )
315
+ );
286
316
  }
287
317
 
288
318
  function generateAccessiblityCookie() {
289
- var time = Date.now();
290
- return encodeURIComponent(
291
- JSON.stringify({
292
- sr: 0,
293
- "sr-ts": time,
294
- jk: 0,
295
- "jk-ts": time,
296
- kb: 0,
297
- "kb-ts": time,
298
- hcm: 0,
299
- "hcm-ts": time
300
- })
301
- );
319
+ const time = Date.now();
320
+ return encodeURIComponent(
321
+ JSON.stringify({
322
+ sr: 0,
323
+ "sr-ts": time,
324
+ jk: 0,
325
+ "jk-ts": time,
326
+ kb: 0,
327
+ "kb-ts": time,
328
+ hcm: 0,
329
+ "hcm-ts": time
330
+ })
331
+ );
302
332
  }
303
333
 
304
334
  function getGUID() {
305
- /** @type {number} */
306
-
307
- var sectionLength = Date.now();
308
- /** @type {string} */
309
-
310
- var id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
311
- /** @type {number} */
312
-
313
- var r = Math.floor((sectionLength + Math.random() * 16) % 16);
314
- /** @type {number} */
315
-
316
- sectionLength = Math.floor(sectionLength / 16);
317
- /** @type {string} */
318
-
319
- var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
320
- return _guid;
321
- });
322
- return id;
335
+ /** @type {number} */
336
+ let sectionLength = Date.now();
337
+ /** @type {string} */
338
+ const id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
339
+ /** @type {number} */
340
+ const r = Math.floor((sectionLength + Math.random() * 16) % 16);
341
+ /** @type {number} */
342
+ sectionLength = Math.floor(sectionLength / 16);
343
+ /** @type {string} */
344
+ const _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
345
+ return _guid;
346
+ });
347
+ return id;
323
348
  }
324
349
 
325
- /**
326
- * @param {{ mercury: any; blob_attachment: any; attach_type: any; sticker_attachment: any; extensible_attachment: { story_attachment: { target: { __typename: string; }; }; }; metadata: { stickerID: { toString: () => any; }; packID: { toString: () => any; }; spriteURI: any; spriteURI2x: any; width: any; height: any; frameCount: any; frameRate: any; framesPerRow: any; framesPerCol: any; fbid: { toString: () => any; }; url: any; dimensions: { split: (arg0: string) => any[]; width: any; height: any; }; duration: any; }; url: any; name: any; fileName: any; thumbnail_url: any; preview_url: any; preview_width: any; preview_height: any; large_preview_url: any; large_preview_width: any; large_preview_height: any; share: { share_id: { toString: () => any; }; title: any; description: any; source: any; media: { image: any; image_size: { width: any; height: any; }; playable: any; duration: any; animated_image_size: any; }; subattachments: any; uri: any; target: any; style_list: any; }; }} attachment1
327
- * @param {{ caption?: any; description?: any; id: any; is_malicious?: any; mime_type?: any; file_size?: any; filename?: any; image_data: any; href?: any; }} [attachment2]
328
- */
350
+ function getExtension(original_extension, fullFileName = "") {
351
+ if (original_extension) {
352
+ return original_extension;
353
+ }
354
+ else {
355
+ const extension = fullFileName.split(".").pop();
356
+ if (extension === fullFileName) {
357
+ return "";
358
+ }
359
+ else {
360
+ return extension;
361
+ }
362
+ }
363
+ }
329
364
 
330
365
  function _formatAttachment(attachment1, attachment2) {
331
- // TODO: THIS IS REALLY BAD
332
- // This is an attempt at fixing Facebook's inconsistencies. Sometimes they give us
333
- // two attachment objects, but sometimes only one. They each contain part of the
334
- // data that you'd want so we merge them for convenience.
335
- // Instead of having a bunch of if statements guarding every access to image_data,
336
- // we set it to empty object and use the fact that it'll return undefined.
337
-
338
- attachment2 = attachment2 || { id: "", image_data: {} };
339
- attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
340
- var blob = attachment1.blob_attachment;
341
- var type =
342
- blob && blob.__typename ? blob.__typename : attachment1.attach_type;
343
- if (!type && attachment1.sticker_attachment) {
344
- type = "StickerAttachment";
345
- blob = attachment1.sticker_attachment;
346
- } else if (!type && attachment1.extensible_attachment) {
347
- if (
348
- attachment1.extensible_attachment.story_attachment &&
349
- attachment1.extensible_attachment.story_attachment.target &&
350
- attachment1.extensible_attachment.story_attachment.target.__typename &&
351
- attachment1.extensible_attachment.story_attachment.target.__typename === "MessageLocation"
352
- ) type = "MessageLocation";
353
- else type = "ExtensibleAttachment";
354
-
355
- blob = attachment1.extensible_attachment;
356
- }
357
- // TODO: Determine whether "sticker", "photo", "file" etc are still used
358
- // KEEP IN SYNC WITH getThreadHistory
359
- switch (type) {
360
- case "sticker":
361
- return {
362
- type: "sticker",
363
- ID: attachment1.metadata.stickerID.toString(),
364
- url: attachment1.url,
365
-
366
- packID: attachment1.metadata.packID.toString(),
367
- spriteUrl: attachment1.metadata.spriteURI,
368
- spriteUrl2x: attachment1.metadata.spriteURI2x,
369
- width: attachment1.metadata.width,
370
- height: attachment1.metadata.height,
371
-
372
- caption: attachment2.caption,
373
- description: attachment2.description,
374
-
375
- frameCount: attachment1.metadata.frameCount,
376
- frameRate: attachment1.metadata.frameRate,
377
- framesPerRow: attachment1.metadata.framesPerRow,
378
- framesPerCol: attachment1.metadata.framesPerCol,
379
-
380
- stickerID: attachment1.metadata.stickerID.toString(), // @Legacy
381
- spriteURI: attachment1.metadata.spriteURI, // @Legacy
382
- spriteURI2x: attachment1.metadata.spriteURI2x // @Legacy
383
- };
384
- case "file":
385
- return {
386
- type: "file",
387
- filename: attachment1.name,
388
- ID: attachment2.id.toString(),
389
- url: attachment1.url,
390
-
391
- isMalicious: attachment2.is_malicious,
392
- contentType: attachment2.mime_type,
393
-
394
- name: attachment1.name, // @Legacy
395
- mimeType: attachment2.mime_type, // @Legacy
396
- fileSize: attachment2.file_size // @Legacy
397
- };
398
- case "photo":
399
- return {
400
- type: "photo",
401
- ID: attachment1.metadata.fbid.toString(),
402
- filename: attachment1.fileName,
403
- thumbnailUrl: attachment1.thumbnail_url,
404
-
405
- previewUrl: attachment1.preview_url,
406
- previewWidth: attachment1.preview_width,
407
- previewHeight: attachment1.preview_height,
408
-
409
- largePreviewUrl: attachment1.large_preview_url,
410
- largePreviewWidth: attachment1.large_preview_width,
411
- largePreviewHeight: attachment1.large_preview_height,
412
-
413
- url: attachment1.metadata.url, // @Legacy
414
- width: attachment1.metadata.dimensions.split(",")[0], // @Legacy
415
- height: attachment1.metadata.dimensions.split(",")[1], // @Legacy
416
- name: attachment1.fileName // @Legacy
417
- };
418
- case "animated_image":
419
- return {
420
- type: "animated_image",
421
- ID: attachment2.id.toString(),
422
- filename: attachment2.filename,
423
-
424
- previewUrl: attachment1.preview_url,
425
- previewWidth: attachment1.preview_width,
426
- previewHeight: attachment1.preview_height,
427
-
428
- url: attachment2.image_data.url,
429
- width: attachment2.image_data.width,
430
- height: attachment2.image_data.height,
431
-
432
- name: attachment1.name, // @Legacy
433
- facebookUrl: attachment1.url, // @Legacy
434
- thumbnailUrl: attachment1.thumbnail_url, // @Legacy
435
- mimeType: attachment2.mime_type, // @Legacy
436
- rawGifImage: attachment2.image_data.raw_gif_image, // @Legacy
437
- rawWebpImage: attachment2.image_data.raw_webp_image, // @Legacy
438
- animatedGifUrl: attachment2.image_data.animated_gif_url, // @Legacy
439
- animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url, // @Legacy
440
- animatedWebpUrl: attachment2.image_data.animated_webp_url, // @Legacy
441
- animatedWebpPreviewUrl: attachment2.image_data.animated_webp_preview_url // @Legacy
442
- };
443
- case "share":
444
- return {
445
- type: "share",
446
- ID: attachment1.share.share_id.toString(),
447
- url: attachment2.href,
448
-
449
- title: attachment1.share.title,
450
- description: attachment1.share.description,
451
- source: attachment1.share.source,
452
-
453
- image: attachment1.share.media.image,
454
- width: attachment1.share.media.image_size.width,
455
- height: attachment1.share.media.image_size.height,
456
- playable: attachment1.share.media.playable,
457
- duration: attachment1.share.media.duration,
458
-
459
- subattachments: attachment1.share.subattachments,
460
- properties: {},
461
-
462
- animatedImageSize: attachment1.share.media.animated_image_size, // @Legacy
463
- facebookUrl: attachment1.share.uri, // @Legacy
464
- target: attachment1.share.target, // @Legacy
465
- styleList: attachment1.share.style_list // @Legacy
466
- };
467
- case "video":
468
- return {
469
- type: "video",
470
- ID: attachment1.metadata.fbid.toString(),
471
- filename: attachment1.name,
472
-
473
- previewUrl: attachment1.preview_url,
474
- previewWidth: attachment1.preview_width,
475
- previewHeight: attachment1.preview_height,
476
-
477
- url: attachment1.url,
478
- width: attachment1.metadata.dimensions.width,
479
- height: attachment1.metadata.dimensions.height,
480
-
481
- duration: attachment1.metadata.duration,
482
- videoType: "unknown",
483
-
484
- thumbnailUrl: attachment1.thumbnail_url // @Legacy
485
- };
486
- case "error":
487
- return {
488
- type: "error",
489
-
490
- // Save error attachments because we're unsure of their format,
491
- // and whether there are cases they contain something useful for debugging.
492
- attachment1: attachment1,
493
- attachment2: attachment2
494
- };
495
- case "MessageImage":
496
- return {
497
- type: "photo",
498
- ID: blob.legacy_attachment_id,
499
- filename: blob.filename,
500
- thumbnailUrl: blob.thumbnail.uri,
501
-
502
- previewUrl: blob.preview.uri,
503
- previewWidth: blob.preview.width,
504
- previewHeight: blob.preview.height,
505
-
506
- largePreviewUrl: blob.large_preview.uri,
507
- largePreviewWidth: blob.large_preview.width,
508
- largePreviewHeight: blob.large_preview.height,
509
-
510
- url: blob.large_preview.uri, // @Legacy
511
- width: blob.original_dimensions.x, // @Legacy
512
- height: blob.original_dimensions.y, // @Legacy
513
- name: blob.filename // @Legacy
514
- };
515
- case "MessageAnimatedImage":
516
- return {
517
- type: "animated_image",
518
- ID: blob.legacy_attachment_id,
519
- filename: blob.filename,
520
-
521
- previewUrl: blob.preview_image.uri,
522
- previewWidth: blob.preview_image.width,
523
- previewHeight: blob.preview_image.height,
524
-
525
- url: blob.animated_image.uri,
526
- width: blob.animated_image.width,
527
- height: blob.animated_image.height,
528
-
529
- thumbnailUrl: blob.preview_image.uri, // @Legacy
530
- name: blob.filename, // @Legacy
531
- facebookUrl: blob.animated_image.uri, // @Legacy
532
- rawGifImage: blob.animated_image.uri, // @Legacy
533
- animatedGifUrl: blob.animated_image.uri, // @Legacy
534
- animatedGifPreviewUrl: blob.preview_image.uri, // @Legacy
535
- animatedWebpUrl: blob.animated_image.uri, // @Legacy
536
- animatedWebpPreviewUrl: blob.preview_image.uri // @Legacy
537
- };
538
- case "MessageVideo":
539
- return {
540
- type: "video",
541
- filename: blob.filename,
542
- ID: blob.legacy_attachment_id,
543
-
544
- previewUrl: blob.large_image.uri,
545
- previewWidth: blob.large_image.width,
546
- previewHeight: blob.large_image.height,
547
-
548
- url: blob.playable_url,
549
- width: blob.original_dimensions.x,
550
- height: blob.original_dimensions.y,
551
-
552
- duration: blob.playable_duration_in_ms,
553
- videoType: blob.video_type.toLowerCase(),
554
-
555
- thumbnailUrl: blob.large_image.uri // @Legacy
556
- };
557
- case "MessageAudio":
558
- return {
559
- type: "audio",
560
- filename: blob.filename,
561
- ID: blob.url_shimhash,
562
-
563
- audioType: blob.audio_type,
564
- duration: blob.playable_duration_in_ms,
565
- url: blob.playable_url,
566
-
567
- isVoiceMail: blob.is_voicemail
568
- };
569
- case "StickerAttachment":
570
- return {
571
- type: "sticker",
572
- ID: blob.id,
573
- url: blob.url,
574
-
575
- packID: blob.pack ? blob.pack.id : null,
576
- spriteUrl: blob.sprite_image,
577
- spriteUrl2x: blob.sprite_image_2x,
578
- width: blob.width,
579
- height: blob.height,
580
-
581
- caption: blob.label,
582
- description: blob.label,
583
-
584
- frameCount: blob.frame_count,
585
- frameRate: blob.frame_rate,
586
- framesPerRow: blob.frames_per_row,
587
- framesPerCol: blob.frames_per_column,
588
-
589
- stickerID: blob.id, // @Legacy
590
- spriteURI: blob.sprite_image, // @Legacy
591
- spriteURI2x: blob.sprite_image_2x // @Legacy
592
- };
593
- case "MessageLocation":
594
- var urlAttach = blob.story_attachment.url;
595
- var mediaAttach = blob.story_attachment.media;
596
-
597
- var u = querystring.parse(url.parse(urlAttach).query).u;
598
- var where1 = querystring.parse(url.parse(u).query).where1;
599
- var address = where1.split(", ");
600
-
601
- var latitude;
602
- var longitude;
603
-
604
- try {
605
- latitude = Number.parseFloat(address[0]);
606
- longitude = Number.parseFloat(address[1]);
607
- } catch (err) {
608
- /* empty */
609
-
610
- }
611
-
612
- var imageUrl;
613
- var width;
614
- var height;
615
-
616
- if (mediaAttach && mediaAttach.image) {
617
- imageUrl = mediaAttach.image.uri;
618
- width = mediaAttach.image.width;
619
- height = mediaAttach.image.height;
620
- }
621
-
622
- return {
623
- type: "location",
624
- ID: blob.legacy_attachment_id,
625
- latitude: latitude,
626
- longitude: longitude,
627
- image: imageUrl,
628
- width: width,
629
- height: height,
630
- url: u || urlAttach,
631
- address: where1,
632
-
633
- facebookUrl: blob.story_attachment.url, // @Legacy
634
- target: blob.story_attachment.target, // @Legacy
635
- styleList: blob.story_attachment.style_list // @Legacy
636
- };
637
- case "ExtensibleAttachment":
638
- return {
639
- type: "share",
640
- ID: blob.legacy_attachment_id,
641
- url: blob.story_attachment.url,
642
-
643
- title: blob.story_attachment.title_with_entities.text,
644
- description: blob.story_attachment.description &&
645
- blob.story_attachment.description.text,
646
- source: blob.story_attachment.source ? blob.story_attachment.source.text : null,
647
-
648
- image: blob.story_attachment.media &&
649
- blob.story_attachment.media.image &&
650
- blob.story_attachment.media.image.uri,
651
- width: blob.story_attachment.media &&
652
- blob.story_attachment.media.image &&
653
- blob.story_attachment.media.image.width,
654
- height: blob.story_attachment.media &&
655
- blob.story_attachment.media.image &&
656
- blob.story_attachment.media.image.height,
657
- playable: blob.story_attachment.media &&
658
- blob.story_attachment.media.is_playable,
659
- duration: blob.story_attachment.media &&
660
- blob.story_attachment.media.playable_duration_in_ms,
661
- playableUrl: blob.story_attachment.media == null ? null : blob.story_attachment.media.playable_url,
662
-
663
- subattachments: blob.story_attachment.subattachments,
664
- properties: blob.story_attachment.properties.reduce(function (/** @type {{ [x: string]: any; }} */obj, /** @type {{ key: string | number; value: { text: any; }; }} */cur) {
665
- obj[cur.key] = cur.value.text;
666
- return obj;
667
- }, {}),
668
-
669
- facebookUrl: blob.story_attachment.url, // @Legacy
670
- target: blob.story_attachment.target, // @Legacy
671
- styleList: blob.story_attachment.style_list // @Legacy
672
- };
673
- case "MessageFile":
674
- return {
675
- type: "file",
676
- filename: blob.filename,
677
- ID: blob.message_file_fbid,
678
-
679
- url: blob.url,
680
- isMalicious: blob.is_malicious,
681
- contentType: blob.content_type,
682
-
683
- name: blob.filename,
684
- mimeType: "",
685
- fileSize: -1
686
- };
687
- default:
688
- throw new Error(
689
- "unrecognized attach_file of type " +
690
- type +
691
- "`" +
692
- JSON.stringify(attachment1, null, 4) +
693
- " attachment2: " +
694
- JSON.stringify(attachment2, null, 4) +
695
- "`"
696
- );
697
- }
366
+ // TODO: THIS IS REALLY BAD
367
+ // This is an attempt at fixing Facebook's inconsistencies. Sometimes they give us
368
+ // two attachment objects, but sometimes only one. They each contain part of the
369
+ // data that you'd want so we merge them for convenience.
370
+ // Instead of having a bunch of if statements guarding every access to image_data,
371
+ // we set it to empty object and use the fact that it'll return undefined.
372
+ const fullFileName = attachment1.filename;
373
+ const fileSize = Number(attachment1.fileSize || 0);
374
+ const durationVideo = attachment1.genericMetadata ? Number(attachment1.genericMetadata.videoLength) : undefined;
375
+ const durationAudio = attachment1.genericMetadata ? Number(attachment1.genericMetadata.duration) : undefined;
376
+ const mimeType = attachment1.mimeType;
377
+
378
+ attachment2 = attachment2 || { id: "", image_data: {} };
379
+ attachment1 = attachment1.mercury || attachment1;
380
+ let blob = attachment1.blob_attachment || attachment1.sticker_attachment;
381
+ let type =
382
+ blob && blob.__typename ? blob.__typename : attachment1.attach_type;
383
+ if (!type && attachment1.sticker_attachment) {
384
+ type = "StickerAttachment";
385
+ blob = attachment1.sticker_attachment;
386
+ }
387
+ else if (!type && attachment1.extensible_attachment) {
388
+ if (
389
+ attachment1.extensible_attachment.story_attachment &&
390
+ attachment1.extensible_attachment.story_attachment.target &&
391
+ attachment1.extensible_attachment.story_attachment.target.__typename &&
392
+ attachment1.extensible_attachment.story_attachment.target.__typename === "MessageLocation"
393
+ ) {
394
+ type = "MessageLocation";
395
+ }
396
+ else {
397
+ type = "ExtensibleAttachment";
398
+ }
399
+
400
+ blob = attachment1.extensible_attachment;
401
+ }
402
+ // TODO: Determine whether "sticker", "photo", "file" etc are still used
403
+ // KEEP IN SYNC WITH getThreadHistory
404
+ switch (type) {
405
+ case "sticker":
406
+ return {
407
+ type: "sticker",
408
+ ID: attachment1.metadata.stickerID.toString(),
409
+ url: attachment1.url,
410
+
411
+ packID: attachment1.metadata.packID.toString(),
412
+ spriteUrl: attachment1.metadata.spriteURI,
413
+ spriteUrl2x: attachment1.metadata.spriteURI2x,
414
+ width: attachment1.metadata.width,
415
+ height: attachment1.metadata.height,
416
+
417
+ caption: attachment2.caption,
418
+ description: attachment2.description,
419
+
420
+ frameCount: attachment1.metadata.frameCount,
421
+ frameRate: attachment1.metadata.frameRate,
422
+ framesPerRow: attachment1.metadata.framesPerRow,
423
+ framesPerCol: attachment1.metadata.framesPerCol,
424
+
425
+ stickerID: attachment1.metadata.stickerID.toString(), // @Legacy
426
+ spriteURI: attachment1.metadata.spriteURI, // @Legacy
427
+ spriteURI2x: attachment1.metadata.spriteURI2x // @Legacy
428
+ };
429
+ case "file":
430
+ return {
431
+ type: "file",
432
+ ID: attachment2.id.toString(),
433
+ fullFileName: fullFileName,
434
+ filename: attachment1.name,
435
+ fileSize: fileSize,
436
+ original_extension: getExtension(attachment1.original_extension, fullFileName),
437
+ mimeType: mimeType,
438
+ url: attachment1.url,
439
+
440
+ isMalicious: attachment2.is_malicious,
441
+ contentType: attachment2.mime_type,
442
+
443
+ name: attachment1.name // @Legacy
444
+ };
445
+ case "photo":
446
+ return {
447
+ type: "photo",
448
+ ID: attachment1.metadata.fbid.toString(),
449
+ filename: attachment1.fileName,
450
+ fullFileName: fullFileName,
451
+ fileSize: fileSize,
452
+ original_extension: getExtension(attachment1.original_extension, fullFileName),
453
+ mimeType: mimeType,
454
+ thumbnailUrl: attachment1.thumbnail_url,
455
+
456
+ previewUrl: attachment1.preview_url,
457
+ previewWidth: attachment1.preview_width,
458
+ previewHeight: attachment1.preview_height,
459
+
460
+ largePreviewUrl: attachment1.large_preview_url,
461
+ largePreviewWidth: attachment1.large_preview_width,
462
+ largePreviewHeight: attachment1.large_preview_height,
463
+
464
+ url: attachment1.metadata.url, // @Legacy
465
+ width: attachment1.metadata.dimensions.split(",")[0], // @Legacy
466
+ height: attachment1.metadata.dimensions.split(",")[1], // @Legacy
467
+ name: fullFileName // @Legacy
468
+ };
469
+ case "animated_image":
470
+ return {
471
+ type: "animated_image",
472
+ ID: attachment2.id.toString(),
473
+ filename: attachment2.filename,
474
+ fullFileName: fullFileName,
475
+ original_extension: getExtension(attachment2.original_extension, fullFileName),
476
+ mimeType: mimeType,
477
+
478
+ previewUrl: attachment1.preview_url,
479
+ previewWidth: attachment1.preview_width,
480
+ previewHeight: attachment1.preview_height,
481
+
482
+ url: attachment2.image_data.url,
483
+ width: attachment2.image_data.width,
484
+ height: attachment2.image_data.height,
485
+
486
+ name: attachment1.name, // @Legacy
487
+ facebookUrl: attachment1.url, // @Legacy
488
+ thumbnailUrl: attachment1.thumbnail_url, // @Legacy
489
+ rawGifImage: attachment2.image_data.raw_gif_image, // @Legacy
490
+ rawWebpImage: attachment2.image_data.raw_webp_image, // @Legacy
491
+ animatedGifUrl: attachment2.image_data.animated_gif_url, // @Legacy
492
+ animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url, // @Legacy
493
+ animatedWebpUrl: attachment2.image_data.animated_webp_url, // @Legacy
494
+ animatedWebpPreviewUrl: attachment2.image_data.animated_webp_preview_url // @Legacy
495
+ };
496
+ case "share":
497
+ return {
498
+ type: "share",
499
+ ID: attachment1.share.share_id.toString(),
500
+ url: attachment2.href,
501
+
502
+ title: attachment1.share.title,
503
+ description: attachment1.share.description,
504
+ source: attachment1.share.source,
505
+
506
+ image: attachment1.share.media.image,
507
+ width: attachment1.share.media.image_size.width,
508
+ height: attachment1.share.media.image_size.height,
509
+ playable: attachment1.share.media.playable,
510
+ duration: attachment1.share.media.duration,
511
+
512
+ subattachments: attachment1.share.subattachments,
513
+ properties: {},
514
+
515
+ animatedImageSize: attachment1.share.media.animated_image_size, // @Legacy
516
+ facebookUrl: attachment1.share.uri, // @Legacy
517
+ target: attachment1.share.target, // @Legacy
518
+ styleList: attachment1.share.style_list // @Legacy
519
+ };
520
+ case "video":
521
+ return {
522
+ type: "video",
523
+ ID: attachment1.metadata.fbid.toString(),
524
+ filename: attachment1.name,
525
+ fullFileName: fullFileName,
526
+ original_extension: getExtension(attachment1.original_extension, fullFileName),
527
+ mimeType: mimeType,
528
+ duration: durationVideo,
529
+
530
+ previewUrl: attachment1.preview_url,
531
+ previewWidth: attachment1.preview_width,
532
+ previewHeight: attachment1.preview_height,
533
+
534
+ url: attachment1.url,
535
+ width: attachment1.metadata.dimensions.width,
536
+ height: attachment1.metadata.dimensions.height,
537
+
538
+ videoType: "unknown",
539
+
540
+ thumbnailUrl: attachment1.thumbnail_url // @Legacy
541
+ };
542
+ case "error":
543
+ return {
544
+ type: "error",
545
+
546
+ // Save error attachments because we're unsure of their format,
547
+ // and whether there are cases they contain something useful for debugging.
548
+ attachment1: attachment1,
549
+ attachment2: attachment2
550
+ };
551
+ case "MessageImage":
552
+ return {
553
+ type: "photo",
554
+ ID: blob.legacy_attachment_id,
555
+ filename: blob.filename,
556
+ fullFileName: fullFileName,
557
+ fileSize: fileSize,
558
+ original_extension: getExtension(blob.original_extension, fullFileName),
559
+ mimeType: mimeType,
560
+ thumbnailUrl: blob.thumbnail.uri,
561
+
562
+ previewUrl: blob.preview.uri,
563
+ previewWidth: blob.preview.width,
564
+ previewHeight: blob.preview.height,
565
+
566
+ largePreviewUrl: blob.large_preview.uri,
567
+ largePreviewWidth: blob.large_preview.width,
568
+ largePreviewHeight: blob.large_preview.height,
569
+
570
+ url: blob.large_preview.uri, // @Legacy
571
+ width: blob.original_dimensions.x, // @Legacy
572
+ height: blob.original_dimensions.y, // @Legacy
573
+ name: blob.filename // @Legacy
574
+ };
575
+ case "MessageAnimatedImage":
576
+ return {
577
+ type: "animated_image",
578
+ ID: blob.legacy_attachment_id,
579
+ filename: blob.filename,
580
+ fullFileName: fullFileName,
581
+ original_extension: getExtension(blob.original_extension, fullFileName),
582
+ mimeType: mimeType,
583
+
584
+ previewUrl: blob.preview_image.uri,
585
+ previewWidth: blob.preview_image.width,
586
+ previewHeight: blob.preview_image.height,
587
+
588
+ url: blob.animated_image.uri,
589
+ width: blob.animated_image.width,
590
+ height: blob.animated_image.height,
591
+
592
+ thumbnailUrl: blob.preview_image.uri, // @Legacy
593
+ name: blob.filename, // @Legacy
594
+ facebookUrl: blob.animated_image.uri, // @Legacy
595
+ rawGifImage: blob.animated_image.uri, // @Legacy
596
+ animatedGifUrl: blob.animated_image.uri, // @Legacy
597
+ animatedGifPreviewUrl: blob.preview_image.uri, // @Legacy
598
+ animatedWebpUrl: blob.animated_image.uri, // @Legacy
599
+ animatedWebpPreviewUrl: blob.preview_image.uri // @Legacy
600
+ };
601
+ case "MessageVideo":
602
+ return {
603
+ type: "video",
604
+ ID: blob.legacy_attachment_id,
605
+ filename: blob.filename,
606
+ fullFileName: fullFileName,
607
+ original_extension: getExtension(blob.original_extension, fullFileName),
608
+ fileSize: fileSize,
609
+ duration: durationVideo,
610
+ mimeType: mimeType,
611
+
612
+ previewUrl: blob.large_image.uri,
613
+ previewWidth: blob.large_image.width,
614
+ previewHeight: blob.large_image.height,
615
+
616
+ url: blob.playable_url,
617
+ width: blob.original_dimensions.x,
618
+ height: blob.original_dimensions.y,
619
+
620
+ videoType: blob.video_type.toLowerCase(),
621
+
622
+ thumbnailUrl: blob.large_image.uri // @Legacy
623
+ };
624
+ case "MessageAudio":
625
+ return {
626
+ type: "audio",
627
+ ID: blob.url_shimhash,
628
+ filename: blob.filename,
629
+ fullFileName: fullFileName,
630
+ fileSize: fileSize,
631
+ duration: durationAudio,
632
+ original_extension: getExtension(blob.original_extension, fullFileName),
633
+ mimeType: mimeType,
634
+
635
+ audioType: blob.audio_type,
636
+ url: blob.playable_url,
637
+
638
+ isVoiceMail: blob.is_voicemail
639
+ };
640
+ case "StickerAttachment":
641
+ case "Sticker":
642
+ return {
643
+ type: "sticker",
644
+ ID: blob.id,
645
+ url: blob.url,
646
+
647
+ packID: blob.pack ? blob.pack.id : null,
648
+ spriteUrl: blob.sprite_image,
649
+ spriteUrl2x: blob.sprite_image_2x,
650
+ width: blob.width,
651
+ height: blob.height,
652
+
653
+ caption: blob.label,
654
+ description: blob.label,
655
+
656
+ frameCount: blob.frame_count,
657
+ frameRate: blob.frame_rate,
658
+ framesPerRow: blob.frames_per_row,
659
+ framesPerCol: blob.frames_per_column,
660
+
661
+ stickerID: blob.id, // @Legacy
662
+ spriteURI: blob.sprite_image, // @Legacy
663
+ spriteURI2x: blob.sprite_image_2x // @Legacy
664
+ };
665
+ case "MessageLocation":
666
+ var urlAttach = blob.story_attachment.url;
667
+ var mediaAttach = blob.story_attachment.media;
668
+
669
+ var u = querystring.parse(url.parse(urlAttach).query).u;
670
+ var where1 = querystring.parse(url.parse(u).query).where1;
671
+ var address = where1.split(", ");
672
+
673
+ var latitude;
674
+ var longitude;
675
+
676
+ try {
677
+ latitude = Number.parseFloat(address[0]);
678
+ longitude = Number.parseFloat(address[1]);
679
+ } catch (err) {
680
+ /* empty */
681
+ }
682
+
683
+ var imageUrl;
684
+ var width;
685
+ var height;
686
+
687
+ if (mediaAttach && mediaAttach.image) {
688
+ imageUrl = mediaAttach.image.uri;
689
+ width = mediaAttach.image.width;
690
+ height = mediaAttach.image.height;
691
+ }
692
+
693
+ return {
694
+ type: "location",
695
+ ID: blob.legacy_attachment_id,
696
+ latitude: latitude,
697
+ longitude: longitude,
698
+ image: imageUrl,
699
+ width: width,
700
+ height: height,
701
+ url: u || urlAttach,
702
+ address: where1,
703
+
704
+ facebookUrl: blob.story_attachment.url, // @Legacy
705
+ target: blob.story_attachment.target, // @Legacy
706
+ styleList: blob.story_attachment.style_list // @Legacy
707
+ };
708
+ case "ExtensibleAttachment":
709
+ return {
710
+ type: "share",
711
+ ID: blob.legacy_attachment_id,
712
+ url: blob.story_attachment.url,
713
+
714
+ title: blob.story_attachment.title_with_entities.text,
715
+ description:
716
+ blob.story_attachment.description &&
717
+ blob.story_attachment.description.text,
718
+ source: blob.story_attachment.source
719
+ ? blob.story_attachment.source.text
720
+ : null,
721
+
722
+ image:
723
+ blob.story_attachment.media &&
724
+ blob.story_attachment.media.image &&
725
+ blob.story_attachment.media.image.uri,
726
+ width:
727
+ blob.story_attachment.media &&
728
+ blob.story_attachment.media.image &&
729
+ blob.story_attachment.media.image.width,
730
+ height:
731
+ blob.story_attachment.media &&
732
+ blob.story_attachment.media.image &&
733
+ blob.story_attachment.media.image.height,
734
+ playable:
735
+ blob.story_attachment.media &&
736
+ blob.story_attachment.media.is_playable,
737
+ duration:
738
+ blob.story_attachment.media &&
739
+ blob.story_attachment.media.playable_duration_in_ms,
740
+ playableUrl:
741
+ blob.story_attachment.media == null
742
+ ? null
743
+ : blob.story_attachment.media.playable_url,
744
+
745
+ subattachments: blob.story_attachment.subattachments,
746
+ properties: blob.story_attachment.properties.reduce(function (obj, cur) {
747
+ obj[cur.key] = cur.value.text;
748
+ return obj;
749
+ }, {}),
750
+
751
+ facebookUrl: blob.story_attachment.url, // @Legacy
752
+ target: blob.story_attachment.target, // @Legacy
753
+ styleList: blob.story_attachment.style_list // @Legacy
754
+ };
755
+ case "MessageFile":
756
+ return {
757
+ type: "file",
758
+ ID: blob.message_file_fbid,
759
+ fullFileName: fullFileName,
760
+ filename: blob.filename,
761
+ fileSize: fileSize,
762
+ mimeType: blob.mimetype,
763
+ original_extension: blob.original_extension || fullFileName.split(".").pop(),
764
+
765
+ url: blob.url,
766
+ isMalicious: blob.is_malicious,
767
+ contentType: blob.content_type,
768
+
769
+ name: blob.filename
770
+ };
771
+ default:
772
+ throw new Error(
773
+ "unrecognized attach_file of type " +
774
+ type +
775
+ "`" +
776
+ JSON.stringify(attachment1, null, 4) +
777
+ " attachment2: " +
778
+ JSON.stringify(attachment2, null, 4) +
779
+ "`"
780
+ );
781
+ }
698
782
  }
699
783
 
700
- /**
701
- * @param {any[]} attachments
702
- * @param {{ [x: string]: string | number; }} attachmentIds
703
- * @param {{ [x: string]: any; }} attachmentMap
704
- * @param {any} shareMap
705
- */
706
-
707
784
  function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
708
- attachmentMap = shareMap || attachmentMap;
709
- return attachments ?
710
- attachments.map(function (/** @type {any} */val, /** @type {string | number} */i) {
711
- if (!attachmentMap ||
712
- !attachmentIds ||
713
- !attachmentMap[attachmentIds[i]]
714
- ) {
715
- return _formatAttachment(val);
716
- }
717
- return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
718
- }) : [];
785
+ attachmentMap = shareMap || attachmentMap;
786
+ return attachments
787
+ ? attachments.map(function (val, i) {
788
+ if (
789
+ !attachmentMap ||
790
+ !attachmentIds ||
791
+ !attachmentMap[attachmentIds[i]]
792
+ ) {
793
+ return _formatAttachment(val);
794
+ }
795
+ return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
796
+ })
797
+ : [];
719
798
  }
720
799
 
721
- /**
722
- * @param {{ delta: { messageMetadata: any; data: { prng: string; }; body: string; attachments: any; participants: any; }; }} m
723
- */
724
-
725
800
  function formatDeltaMessage(m) {
726
- var md = m.delta.messageMetadata;
727
- var mdata = m.delta.data === undefined ? [] : m.delta.data.prng === undefined ? [] : JSON.parse(m.delta.data.prng);
728
- var m_id = mdata.map(u => u.i);
729
- var m_offset = mdata.map(u => u.o);
730
- var m_length = mdata.map(u => u.l);
731
- var mentions = {};
732
- var body = m.delta.body || "";
733
- var args = body == "" ? [] : body.trim().split(/\s+/);
734
- 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]);
735
-
736
- return {
737
- type: "message",
738
- senderID: formatID(md.actorFbId.toString()),
739
- threadID: formatID((md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString()),
740
- messageID: md.messageId,
741
- args: args,
742
- body: body,
743
- attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
744
- mentions: mentions,
745
- timestamp: md.timestamp,
746
- isGroup: !!md.threadKey.threadFbId,
747
- participantIDs: m.delta.participants || (md.cid ? md.cid.canonicalParticipantFbids : []) || []
748
- };
801
+ const md = m.delta.messageMetadata;
802
+
803
+ const mdata =
804
+ m.delta.data === undefined
805
+ ? []
806
+ : m.delta.data.prng === undefined
807
+ ? []
808
+ : JSON.parse(m.delta.data.prng);
809
+ const m_id = mdata.map(u => u.i);
810
+ const m_offset = mdata.map(u => u.o);
811
+ const m_length = mdata.map(u => u.l);
812
+ const mentions = {};
813
+ for (let i = 0; i < m_id.length; i++) {
814
+ mentions[m_id[i]] = m.delta.body.substring(
815
+ m_offset[i],
816
+ m_offset[i] + m_length[i]
817
+ );
818
+ }
819
+ return {
820
+ type: "message",
821
+ senderID: formatID(md.actorFbId.toString()),
822
+ body: m.delta.body || "",
823
+ threadID: formatID(
824
+ (md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString()
825
+ ),
826
+ messageID: md.messageId,
827
+ attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
828
+ mentions: mentions,
829
+ timestamp: md.timestamp,
830
+ isGroup: !!md.threadKey.threadFbId,
831
+ participantIDs: m.delta.participants || (md.cid ? md.cid.canonicalParticipantFbids : []) || []
832
+ };
749
833
  }
750
834
 
751
835
  function formatID(id) {
752
- if (id != undefined && id != null) return id.replace(/(fb)?id[:.]/, "");
753
- else return id;
836
+ if (id != undefined && id != null) {
837
+ return id.replace(/(fb)?id[:.]/, "");
838
+ }
839
+ else {
840
+ return id;
841
+ }
754
842
  }
755
843
 
756
844
  function formatMessage(m) {
757
- var originalMessage = m.message ? m.message : m;
758
- var obj = {
759
- type: "message",
760
- senderName: originalMessage.sender_name,
761
- senderID: formatID(originalMessage.sender_fbid.toString()),
762
- participantNames: originalMessage.group_thread_info ? originalMessage.group_thread_info.participant_names : [originalMessage.sender_name.split(" ")[0]],
763
- participantIDs: originalMessage.group_thread_info
764
- ? originalMessage.group_thread_info.participant_ids.map(function (v) {
765
- return formatID(v.toString());
766
- })
767
- : [formatID(originalMessage.sender_fbid)],
768
- body: originalMessage.body || "",
769
- threadID: formatID((originalMessage.thread_fbid || originalMessage.other_user_fbid).toString()),
770
- threadName: originalMessage.group_thread_info ? originalMessage.group_thread_info.name : originalMessage.sender_name,
771
- location: originalMessage.coordinates ? originalMessage.coordinates : null,
772
- messageID: originalMessage.mid ? originalMessage.mid.toString() : originalMessage.message_id,
773
- attachments: formatAttachment(originalMessage.attachments, originalMessage.attachmentIds, originalMessage.attachment_map, originalMessage.share_map),
774
- timestamp: originalMessage.timestamp,
775
- timestampAbsolute: originalMessage.timestamp_absolute,
776
- timestampRelative: originalMessage.timestamp_relative,
777
- timestampDatetime: originalMessage.timestamp_datetime,
778
- tags: originalMessage.tags,
779
- reactions: originalMessage.reactions ? originalMessage.reactions : [],
780
- isUnread: originalMessage.is_unread
781
- };
782
-
783
- if (m.type === "pages_messaging") obj.pageID = m.realtime_viewer_fbid.toString();
784
- obj.isGroup = obj.participantIDs.length > 2;
785
-
786
- return obj;
845
+ const originalMessage = m.message ? m.message : m;
846
+ const obj = {
847
+ type: "message",
848
+ senderName: originalMessage.sender_name,
849
+ senderID: formatID(originalMessage.sender_fbid.toString()),
850
+ participantNames: originalMessage.group_thread_info
851
+ ? originalMessage.group_thread_info.participant_names
852
+ : [originalMessage.sender_name.split(" ")[0]],
853
+ participantIDs: originalMessage.group_thread_info
854
+ ? originalMessage.group_thread_info.participant_ids.map(function (v) {
855
+ return formatID(v.toString());
856
+ })
857
+ : [formatID(originalMessage.sender_fbid)],
858
+ body: originalMessage.body || "",
859
+ threadID: formatID(
860
+ (
861
+ originalMessage.thread_fbid || originalMessage.other_user_fbid
862
+ ).toString()
863
+ ),
864
+ threadName: originalMessage.group_thread_info
865
+ ? originalMessage.group_thread_info.name
866
+ : originalMessage.sender_name,
867
+ location: originalMessage.coordinates ? originalMessage.coordinates : null,
868
+ messageID: originalMessage.mid
869
+ ? originalMessage.mid.toString()
870
+ : originalMessage.message_id,
871
+ attachments: formatAttachment(
872
+ originalMessage.attachments,
873
+ originalMessage.attachmentIds,
874
+ originalMessage.attachment_map,
875
+ originalMessage.share_map
876
+ ),
877
+ timestamp: originalMessage.timestamp,
878
+ timestampAbsolute: originalMessage.timestamp_absolute,
879
+ timestampRelative: originalMessage.timestamp_relative,
880
+ timestampDatetime: originalMessage.timestamp_datetime,
881
+ tags: originalMessage.tags,
882
+ reactions: originalMessage.reactions ? originalMessage.reactions : [],
883
+ isUnread: originalMessage.is_unread
884
+ };
885
+
886
+ if (m.type === "pages_messaging")
887
+ obj.pageID = m.realtime_viewer_fbid.toString();
888
+ obj.isGroup = obj.participantIDs.length > 2;
889
+
890
+ return obj;
787
891
  }
788
892
 
789
893
  function formatEvent(m) {
790
- var originalMessage = m.message ? m.message : m;
791
- var logMessageType = originalMessage.log_message_type;
792
- var logMessageData;
793
- if (logMessageType === "log:generic-admin-text") {
794
- logMessageData = originalMessage.log_message_data.untypedData;
795
- logMessageType = getAdminTextMessageType(originalMessage.log_message_data.message_type);
796
- }
797
- else logMessageData = originalMessage.log_message_data;
798
-
799
- return Object.assign(formatMessage(originalMessage), {
800
- type: "event",
801
- logMessageType: logMessageType,
802
- logMessageData: logMessageData,
803
- logMessageBody: originalMessage.log_message_body
804
- });
894
+ const originalMessage = m.message ? m.message : m;
895
+ let logMessageType = originalMessage.log_message_type;
896
+ let logMessageData;
897
+ if (logMessageType === "log:generic-admin-text") {
898
+ logMessageData = originalMessage.log_message_data.untypedData;
899
+ logMessageType = getAdminTextMessageType(
900
+ originalMessage.log_message_data.message_type
901
+ );
902
+ }
903
+ else {
904
+ logMessageData = originalMessage.log_message_data;
905
+ }
906
+
907
+ return Object.assign(formatMessage(originalMessage), {
908
+ type: "event",
909
+ logMessageType: logMessageType,
910
+ logMessageData: logMessageData,
911
+ logMessageBody: originalMessage.log_message_body
912
+ });
805
913
  }
806
914
 
807
915
  function formatHistoryMessage(m) {
808
- switch (m.action_type) {
809
- case "ma-type:log-message":
810
- return formatEvent(m);
811
- default:
812
- return formatMessage(m);
813
- }
916
+ switch (m.action_type) {
917
+ case "ma-type:log-message":
918
+ return formatEvent(m);
919
+ default:
920
+ return formatMessage(m);
921
+ }
814
922
  }
815
923
 
816
924
  // Get a more readable message type for AdminTextMessages
817
- /**
818
- * @param {{ type: any; }} m
819
- */
820
-
821
- function getAdminTextMessageType(m) {
822
- switch (m.type) {
823
- case "joinable_group_link_mode_change":
824
- return "log:link-status";
825
- case "magic_words":
826
- return "log:magic-words";
827
- case "change_thread_theme":
828
- return "log:thread-color";
829
- case "change_thread_icon":
830
- return "log:thread-icon";
831
- case "change_thread_nickname":
832
- return "log:user-nickname";
833
- case "change_thread_admins":
834
- return "log:thread-admins";
835
- case "group_poll":
836
- return "log:thread-poll";
837
- case "change_thread_approval_mode":
838
- return "log:thread-approval-mode";
839
- case "messenger_call_log":
840
- case "participant_joined_group_call":
841
- return "log:thread-call";
842
- case "pin_messages_v2":
843
- return "log:thread-pinned";
844
- }
845
- }
846
-
847
- /**
848
- * @param {string} name
849
- */
850
-
851
- function getGenderByPhysicalMethod(name) {
852
- const female_name = [
853
- "Phương Chi",
854
- "An Bình",
855
- "An Di",
856
- "An Hạ",
857
- "An Hằng",
858
- "An Khê",
859
- "An Nhiên",
860
- "An Nhàn",
861
- "Anh Chi",
862
- "Anh Hương",
863
- "Anh Mai",
864
- "Anh Phương",
865
- "Anh Thi",
866
- "Anh Thy",
867
- "Anh Thơ",
868
- "Anh Thư",
869
- "Anh Thảo",
870
- "Anh Vũ",
871
- "Anh Ðào",
872
- "Ban Mai",
873
- "Bình Minh",
874
- "Bình Yên",
875
- "Bích Chiêu",
876
- "Bích Châu",
877
- "Bích Duyên",
878
- "Bích Hiền",
879
- "Bích Huệ",
880
- "Bích Hà",
881
- "Bích Hạnh",
882
- "Bích Hải",
883
- "Bích Hảo",
884
- "Bích Hậu",
885
- "Bích Hằng",
886
- "Bích Hồng",
887
- "Bích Hợp",
888
- "Bích Lam",
889
- "Bích Liên",
890
- "Bích Loan",
891
- "Bích Nga",
892
- "Bích Ngà",
893
- "Bích Ngân",
894
- "Bích Ngọc",
895
- "Bích Như",
896
- "Bích Phượng",
897
- "Bích Quyên",
898
- "Bích Quân",
899
- "Bích San",
900
- "Bích Thoa",
901
- "Bích Thu",
902
- "Bích Thảo",
903
- "Bích Thủy",
904
- "Bích Trang",
905
- "Bích Trâm",
906
- "Bích Ty",
907
- "Bích Vân",
908
- "Bích Ðiệp",
909
- "Bích Ðào",
910
- "Băng Băng",
911
- "Băng Tâm",
912
- "Bạch Cúc",
913
- "Bạch Hoa",
914
- "Bạch Kim",
915
- "Bạch Liên",
916
- "Bạch Loan",
917
- "Bạch Mai",
918
- "Bạch Quỳnh",
919
- "Bạch Trà",
920
- "Bạch Tuyết",
921
- "Bạch Vân",
922
- "Bạch Yến",
923
- "Bảo Anh",
924
- "Bảo Bình",
925
- "Bảo Châu",
926
- "Bảo Huệ",
927
- "Bảo Hà",
928
- "Bảo Hân",
929
- "Bảo Lan",
930
- "Bảo Lễ",
931
- "Bảo Ngọc",
932
- "Bảo Phương",
933
- "Bảo Quyên",
934
- "Bảo Quỳnh",
935
- "Bảo Thoa",
936
- "Bảo Thúy",
937
- "Bảo Tiên",
938
- "Bảo Trâm",
939
- "Bảo Trân",
940
- "Bảo Trúc",
941
- "Bảo Uyên",
942
- "Bảo Vy",
943
- "Bảo Vân",
944
- "Bội Linh",
945
- "Cam Thảo",
946
- "Chi Lan",
947
- "Chi Mai",
948
- "Chiêu Dương",
949
- "Cát Cát",
950
- "Cát Linh",
951
- "Cát Ly",
952
- "Cát Tiên",
953
- "Cát Tường",
954
- "Cẩm Hiền",
955
- "Cẩm Hường",
956
- "Cẩm Hạnh",
957
- "Cẩm Linh",
958
- "Cẩm Liên",
959
- "Cẩm Ly",
960
- "Cẩm Nhi",
961
- "Cẩm Nhung",
962
- "Cẩm Thúy",
963
- "Cẩm Tú",
964
- "Cẩm Vân",
965
- "Cẩm Yến",
966
- "Di Nhiên",
967
- "Diên Vỹ",
968
- "Diễm Chi",
969
- "Diễm Châu",
970
- "Diễm Hương",
971
- "Diễm Hạnh",
972
- "Diễm Hằng",
973
- "Diễm Khuê",
974
- "Diễm Kiều",
975
- "Diễm Liên",
976
- "Diễm Lộc",
977
- "Diễm My",
978
- "Diễm Phúc",
979
- "Diễm Phương",
980
- "Diễm Phước",
981
- "Diễm Phượng",
982
- "Diễm Quyên",
983
- "Diễm Quỳnh",
984
- "Diễm Thúy",
985
- "Diễm Thư",
986
- "Diễm Thảo",
987
- "Diễm Trang",
988
- "Diễm Trinh",
989
- "Diễm Uyên",
990
- "Diệp Anh",
991
- "Diệp Vy",
992
- "Diệu Anh",
993
- "Diệu Hiền",
994
- "Diệu Hoa",
995
- "Diệu Huyền",
996
- "Diệu Hương",
997
- "Diệu Hạnh",
998
- "Diệu Hằng",
999
- "Diệu Hồng",
1000
- "Diệu Lan",
1001
- "Diệu Linh",
1002
- "Diệu Loan",
1003
- "Diệu Nga",
1004
- "Diệu Ngà",
1005
- "Diệu Ngọc",
1006
- "Diệu Nương",
1007
- "Diệu Thiện",
1008
- "Diệu Thúy",
1009
- "Diệu Vân",
1010
- "Diệu Ái",
1011
- "Duy Hạnh",
1012
- "Duy Mỹ",
1013
- "Duy Uyên",
1014
- "Duyên Hồng",
1015
- "Duyên My",
1016
- "Duyên Mỹ",
1017
- "Duyên Nương",
1018
- "Dã Lan",
1019
- "Dã Lâm",
1020
- "Dã Thảo",
1021
- "Dạ Hương",
1022
- "Dạ Lan",
1023
- "Dạ Nguyệt",
1024
- "Dạ Thi",
1025
- "Dạ Thảo",
1026
- "Dạ Yến",
1027
- "Gia Hân",
1028
- "Gia Khanh",
1029
- "Gia Linh",
1030
- "Gia Nhi",
1031
- "Gia Quỳnh",
1032
- "Giang Thanh",
1033
- "Giang Thiên",
1034
- "Giao Hưởng",
1035
- "Giao Kiều",
1036
- "Giao Linh",
1037
- "Giáng Ngọc",
1038
- "Giáng Tiên",
1039
- "Giáng Uyên",
1040
- "Hiếu Giang",
1041
- "Hiếu Hạnh",
1042
- "Hiếu Khanh",
1043
- "Hiếu Minh",
1044
- "Hiền Chung",
1045
- "Hiền Hòa",
1046
- "Hiền Mai",
1047
- "Hiền Nhi",
1048
- "Hiền Nương",
1049
- "Hiền Thục",
1050
- "Hiểu Lam",
1051
- "Hiểu Vân",
1052
- "Hoa Liên",
1053
- "Hoa Lý",
1054
- "Hoa Thiên",
1055
- "Hoa Tiên",
1056
- "Hoa Tranh",
1057
- "Hoài An",
1058
- "Hoài Giang",
1059
- "Hoài Hương",
1060
- "Hoài Phương",
1061
- "Hoài Thương",
1062
- "Hoài Trang",
1063
- "Hoài Vỹ",
1064
- "Hoàn Châu",
1065
- "Hoàn Vi",
1066
- "Hoàng Cúc",
1067
- "Hoàng Hà",
1068
- "Hoàng Kim",
1069
- "Hoàng Lan",
1070
- "Hoàng Mai",
1071
- "Hoàng Miên",
1072
- "Hoàng Nguyên",
1073
- "Hoàng Oanh",
1074
- "Hoàng Sa",
1075
- "Hoàng Thư",
1076
- "Hoàng Xuân",
1077
- "Hoàng Yến",
1078
- "Hoạ Mi",
1079
- "Huyền Anh",
1080
- "Huyền Diệu",
1081
- "Huyền Linh",
1082
- "Huyền Ngọc",
1083
- "Huyền Nhi",
1084
- "Huyền Thoại",
1085
- "Huyền Thư",
1086
- "Huyền Trang",
1087
- "Huyền Trâm",
1088
- "Huyền Trân",
1089
- "Huệ An",
1090
- "Huệ Hương",
1091
- "Huệ Hồng",
1092
- "Huệ Lan",
1093
- "Huệ Linh",
1094
- "Huệ Lâm",
1095
- "Huệ My",
1096
- "Huệ Phương",
1097
- "Huệ Thương",
1098
- "Huệ Ân",
1099
- "Huỳnh Anh",
1100
- "Hà Giang",
1101
- "Hà Liên",
1102
- "Hà Mi",
1103
- "Hà My",
1104
- "Hà Nhi",
1105
- "Hà Phương",
1106
- "Hà Thanh",
1107
- "Hà Tiên",
1108
- "Hàm Duyên",
1109
- "Hàm Nghi",
1110
- "Hàm Thơ",
1111
- "Hàm Ý",
1112
- "Hương Chi",
1113
- "Hương Giang",
1114
- "Hương Lan",
1115
- "Hương Liên",
1116
- "Hương Ly",
1117
- "Hương Lâm",
1118
- "Hương Mai",
1119
- "Hương Nhi",
1120
- "Hương Thu",
1121
- "Hương Thảo",
1122
- "Hương Thủy",
1123
- "Hương Tiên",
1124
- "Hương Trang",
1125
- "Hương Trà",
1126
- "Hương Xuân",
1127
- "Hướng Dương",
1128
- "Hạ Băng",
1129
- "Hạ Giang",
1130
- "Hạ Phương",
1131
- "Hạ Tiên",
1132
- "Hạ Uyên",
1133
- "Hạ Vy",
1134
- "Hạc Cúc",
1135
- "Hạnh Chi",
1136
- "Hạnh Dung",
1137
- "Hạnh Linh",
1138
- "Hạnh My",
1139
- "Hạnh Nga",
1140
- "Hạnh Nhơn",
1141
- "Hạnh Phương",
1142
- "Hạnh San",
1143
- "Hạnh Thảo",
1144
- "Hạnh Trang",
1145
- "Hạnh Vi",
1146
- "Hải Anh",
1147
- "Hải Châu",
1148
- "Hải Duyên",
1149
- "Hải Dương",
1150
- "Hải Miên",
1151
- "Hải My",
1152
- "Hải Mỹ",
1153
- "Hải Ngân",
1154
- "Hải Nhi",
1155
- "Hải Phương",
1156
- "Hải Phượng",
1157
- "Hải San",
1158
- "Hải Sinh",
1159
- "Hải Thanh",
1160
- "Hải Thảo",
1161
- "Hải Thụy",
1162
- "Hải Uyên",
1163
- "Hải Vy",
1164
- "Hải Vân",
1165
- "Hải Yến",
1166
- "Hải Ân",
1167
- "Hải Ðường",
1168
- "Hảo Nhi",
1169
- "Hằng Anh",
1170
- "Hằng Nga",
1171
- "Họa Mi",
1172
- "Hồ Diệp",
1173
- "Hồng Anh",
1174
- "Hồng Bạch Thảo",
1175
- "Hồng Châu",
1176
- "Hồng Diễm",
1177
- "Hồng Giang",
1178
- "Hồng Hoa",
1179
- "Hồng Hà",
1180
- "Hồng Hạnh",
1181
- "Hồng Khanh",
1182
- "Hồng Khuê",
1183
- "Hồng Khôi",
1184
- "Hồng Linh",
1185
- "Hồng Liên",
1186
- "Hồng Lâm",
1187
- "Hồng Mai",
1188
- "Hồng Nga",
1189
- "Hồng Ngân",
1190
- "Hồng Ngọc",
1191
- "Hồng Nhung",
1192
- "Hồng Như",
1193
- "Hồng Nhạn",
1194
- "Hồng Oanh",
1195
- "Hồng Phúc",
1196
- "Hồng Phương",
1197
- "Hồng Quế",
1198
- "Hồng Thu",
1199
- "Hồng Thúy",
1200
- "Hồng Thư",
1201
- "Hồng Thảo",
1202
- "Hồng Thắm",
1203
- "Hồng Thủy",
1204
- "Hồng Trúc",
1205
- "Hồng Tâm",
1206
- "Hồng Vân",
1207
- "Hồng Xuân",
1208
- "Hồng Ðiệp",
1209
- "Hồng Ðào",
1210
- "Hồng Đăng",
1211
- "Khiết Linh",
1212
- "Khiết Tâm",
1213
- "Khuê Trung",
1214
- "Khánh Chi",
1215
- "Khánh Giang",
1216
- "Khánh Giao",
1217
- "Khánh Huyền",
1218
- "Khánh Hà",
1219
- "Khánh Hằng",
1220
- "Khánh Linh",
1221
- "Khánh Ly",
1222
- "Khánh Mai",
1223
- "Khánh My",
1224
- "Khánh Ngân",
1225
- "Khánh Ngọc",
1226
- "Khánh Quyên",
1227
- "Khánh Quỳnh",
1228
- "Khánh Thủy",
1229
- "Khánh Trang",
1230
- "Khánh Vi",
1231
- "Khánh Vy",
1232
- "Khánh Vân",
1233
- "Khúc Lan",
1234
- "Khả Khanh",
1235
- "Khả Tú",
1236
- "Khả Ái",
1237
- "Khải Ca",
1238
- "Khải Hà",
1239
- "Khải Tâm",
1240
- "Kim Anh",
1241
- "Kim Chi",
1242
- "Kim Cương",
1243
- "Kim Dung",
1244
- "Kim Duyên",
1245
- "Kim Hoa",
1246
- "Kim Hương",
1247
- "Kim Khanh",
1248
- "Kim Khuyên",
1249
- "Kim Khánh",
1250
- "Kim Lan",
1251
- "Kim Liên",
1252
- "Kim Loan",
1253
- "Kim Ly",
1254
- "Kim Mai",
1255
- "Kim Ngân",
1256
- "Kim Ngọc",
1257
- "Kim Oanh",
1258
- "Kim Phượng",
1259
- "Kim Quyên",
1260
- "Kim Sa",
1261
- "Kim Thanh",
1262
- "Kim Thoa",
1263
- "Kim Thu",
1264
- "Kim Thy",
1265
- "Kim Thông",
1266
- "Kim Thư",
1267
- "Kim Thảo",
1268
- "Kim Thủy",
1269
- "Kim Trang",
1270
- "Kim Tuyến",
1271
- "Kim Tuyết",
1272
- "Kim Tuyền",
1273
- "Kim Xuyến",
1274
- "Kim Xuân",
1275
- "Kim Yến",
1276
- "Kim Ánh",
1277
- "Kim Đan",
1278
- "Kiết Hồng",
1279
- "Kiết Trinh",
1280
- "Kiều Anh",
1281
- "Kiều Diễm",
1282
- "Kiều Dung",
1283
- "Kiều Giang",
1284
- "Kiều Hoa",
1285
- "Kiều Hạnh",
1286
- "Kiều Khanh",
1287
- "Kiều Loan",
1288
- "Kiều Mai",
1289
- "Kiều Minh",
1290
- "Kiều Mỹ",
1291
- "Kiều Nga",
1292
- "Kiều Nguyệt",
1293
- "Kiều Nương",
1294
- "Kiều Thu",
1295
- "Kiều Trang",
1296
- "Kiều Trinh",
1297
- "Kỳ Anh",
1298
- "Kỳ Diệu",
1299
- "Kỳ Duyên",
1300
- "Lam Giang",
1301
- "Lam Hà",
1302
- "Lam Khê",
1303
- "Lam Ngọc",
1304
- "Lam Tuyền",
1305
- "Lan Anh",
1306
- "Lan Chi",
1307
- "Lan Hương",
1308
- "Lan Khuê",
1309
- "Lan Ngọc",
1310
- "Lan Nhi",
1311
- "Lan Phương",
1312
- "Lan Thương",
1313
- "Lan Trúc",
1314
- "Lan Vy",
1315
- "Linh Chi",
1316
- "Linh Châu",
1317
- "Linh Duyên",
1318
- "Linh Giang",
1319
- "Linh Hà",
1320
- "Linh Lan",
1321
- "Linh Nhi",
1322
- "Linh Phương",
1323
- "Linh Phượng",
1324
- "Linh San",
1325
- "Linh Trang",
1326
- "Linh Ðan",
1327
- "Liên Chi",
1328
- "Liên Hoa",
1329
- "Liên Hương",
1330
- "Liên Như",
1331
- "Liên Phương",
1332
- "Liên Trân",
1333
- "Liễu Oanh",
1334
- "Loan Châu",
1335
- "Ly Châu",
1336
- "Lâm Nhi",
1337
- "Lâm Oanh",
1338
- "Lâm Tuyền",
1339
- "Lâm Uyên",
1340
- "Lê Quỳnh",
1341
- "Lưu Ly",
1342
- "Lệ Băng",
1343
- "Lệ Chi",
1344
- "Lệ Giang",
1345
- "Lệ Hoa",
1346
- "Lệ Huyền",
1347
- "Lệ Khanh",
1348
- "Lệ Nga",
1349
- "Lệ Nhi",
1350
- "Lệ Quyên",
1351
- "Lệ Quân",
1352
- "Lệ Thanh",
1353
- "Lệ Thu",
1354
- "Lệ Thủy",
1355
- "Lộc Uyên",
1356
- "Lộc Uyển",
1357
- "Lục Bình",
1358
- "Mai Anh",
1359
- "Mai Chi",
1360
- "Mai Châu",
1361
- "Mai Hiền",
1362
- "Mai Hà",
1363
- "Mai Hương",
1364
- "Mai Hạ",
1365
- "Mai Khanh",
1366
- "Mai Khôi",
1367
- "Mai Lan",
1368
- "Mai Linh",
1369
- "Mai Liên",
1370
- "Mai Loan",
1371
- "Mai Ly",
1372
- "Mai Nhi",
1373
- "Mai Phương",
1374
- "Mai Quyên",
1375
- "Mai Thanh",
1376
- "Mai Thu",
1377
- "Mai Thy",
1378
- "Mai Thảo",
1379
- "Mai Trinh",
1380
- "Mai Tâm",
1381
- "Mai Vy",
1382
- "Minh An",
1383
- "Minh Châu",
1384
- "Minh Duyên",
1385
- "Minh Hiền",
1386
- "Minh Huyền",
1387
- "Minh Huệ",
1388
- "Minh Hà",
1389
- "Minh Hương",
1390
- "Minh Hạnh",
1391
- "Minh Hằng",
1392
- "Minh Hồng",
1393
- "Minh Khai",
1394
- "Minh Khuê",
1395
- "Minh Loan",
1396
- "Minh Minh",
1397
- "Minh Nguyệt",
1398
- "Minh Ngọc",
1399
- "Minh Nhi",
1400
- "Minh Như",
1401
- "Minh Phương",
1402
- "Minh Phượng",
1403
- "Minh Thu",
1404
- "Minh Thúy",
1405
- "Minh Thư",
1406
- "Minh Thương",
1407
- "Minh Thảo",
1408
- "Minh Thủy",
1409
- "Minh Trang",
1410
- "Minh Tuyết",
1411
- "Minh Tuệ",
1412
- "Minh Tâm",
1413
- "Minh Uyên",
1414
- "Minh Vy",
1415
- "Minh Xuân",
1416
- "Minh Yến",
1417
- "Minh Đan",
1418
- "Mậu Xuân",
1419
- "Mộc Miên",
1420
- "Mộng Hoa",
1421
- "Mộng Hương",
1422
- "Mộng Hằng",
1423
- "Mộng Lan",
1424
- "Mộng Liễu",
1425
- "Mộng Nguyệt",
1426
- "Mộng Nhi",
1427
- "Mộng Quỳnh",
1428
- "Mộng Thi",
1429
- "Mộng Thu",
1430
- "Mộng Tuyền",
1431
- "Mộng Vi",
1432
- "Mộng Vy",
1433
- "Mộng Vân",
1434
- "Mộng Ðiệp",
1435
- "Mỹ Anh",
1436
- "Mỹ Diễm",
1437
- "Mỹ Dung",
1438
- "Mỹ Duyên",
1439
- "Mỹ Hiệp",
1440
- "Mỹ Hoàn",
1441
- "Mỹ Huyền",
1442
- "Mỹ Huệ",
1443
- "Mỹ Hường",
1444
- "Mỹ Hạnh",
1445
- "Mỹ Khuyên",
1446
- "Mỹ Kiều",
1447
- "Mỹ Lan",
1448
- "Mỹ Loan",
1449
- "Mỹ Lệ",
1450
- "Mỹ Lợi",
1451
- "Mỹ Nga",
1452
- "Mỹ Ngọc",
1453
- "Mỹ Nhi",
1454
- "Mỹ Nhân",
1455
- "Mỹ Nương",
1456
- "Mỹ Phương",
1457
- "Mỹ Phượng",
1458
- "Mỹ Phụng",
1459
- "Mỹ Thuần",
1460
- "Mỹ Thuận",
1461
- "Mỹ Trang",
1462
- "Mỹ Trâm",
1463
- "Mỹ Tâm",
1464
- "Mỹ Uyên",
1465
- "Mỹ Vân",
1466
- "Mỹ Xuân",
1467
- "Mỹ Yến",
1468
- "Nghi Dung",
1469
- "Nghi Minh",
1470
- "Nghi Xuân",
1471
- "Nguyên Hồng",
1472
- "Nguyên Thảo",
1473
- "Nguyết Ánh",
1474
- "Nguyệt Anh",
1475
- "Nguyệt Cát",
1476
- "Nguyệt Cầm",
1477
- "Nguyệt Hà",
1478
- "Nguyệt Hồng",
1479
- "Nguyệt Lan",
1480
- "Nguyệt Minh",
1481
- "Nguyệt Nga",
1482
- "Nguyệt Quế",
1483
- "Nguyệt Uyển",
1484
- "Nguyệt Ánh",
1485
- "Ngân Anh",
1486
- "Ngân Hà",
1487
- "Ngân Thanh",
1488
- "Ngân Trúc",
1489
- "Ngọc Anh",
1490
- "Ngọc Bích",
1491
- "Ngọc Cầm",
1492
- "Ngọc Diệp",
1493
- "Ngọc Dung",
1494
- "Ngọc Hiền",
1495
- "Ngọc Hoa",
1496
- "Ngọc Hoan",
1497
- "Ngọc Hoàn",
1498
- "Ngọc Huyền",
1499
- "Ngọc Huệ",
1500
- "Ngọc Hà",
1501
- "Ngọc Hân",
1502
- "Ngọc Hạ",
1503
- "Ngọc Hạnh",
1504
- "Ngọc Hằng",
1505
- "Ngọc Khanh",
1506
- "Ngọc Khuê",
1507
- "Ngọc Khánh",
1508
- "Ngọc Lam",
1509
- "Ngọc Lan",
1510
- "Ngọc Linh",
1511
- "Ngọc Liên",
1512
- "Ngọc Loan",
1513
- "Ngọc Ly",
1514
- "Ngọc Lâm",
1515
- "Ngọc Lý",
1516
- "Ngọc Lệ",
1517
- "Ngọc Mai",
1518
- "Ngọc Nhi",
1519
- "Ngọc Nữ",
1520
- "Ngọc Oanh",
1521
- "Ngọc Phụng",
1522
- "Ngọc Quyên",
1523
- "Ngọc Quế",
1524
- "Ngọc Quỳnh",
1525
- "Ngọc San",
1526
- "Ngọc Sương",
1527
- "Ngọc Thi",
1528
- "Ngọc Thy",
1529
- "Ngọc Thơ",
1530
- "Ngọc Trinh",
1531
- "Ngọc Trâm",
1532
- "Ngọc Tuyết",
1533
- "Ngọc Tâm",
1534
- "Ngọc Tú",
1535
- "Ngọc Uyên",
1536
- "Ngọc Uyển",
1537
- "Ngọc Vy",
1538
- "Ngọc Vân",
1539
- "Ngọc Yến",
1540
- "Ngọc Ái",
1541
- "Ngọc Ánh",
1542
- "Ngọc Ðiệp",
1543
- "Ngọc Ðàn",
1544
- "Ngọc Ðào",
1545
- "Nhan Hồng",
1546
- "Nhã Hương",
1547
- "Nhã Hồng",
1548
- "Nhã Khanh",
1549
- "Nhã Lý",
1550
- "Nhã Mai",
1551
- "Nhã Sương",
1552
- "Nhã Thanh",
1553
- "Nhã Trang",
1554
- "Nhã Trúc",
1555
- "Nhã Uyên",
1556
- "Nhã Yến",
1557
- "Nhã Ý",
1558
- "Như Anh",
1559
- "Như Bảo",
1560
- "Như Hoa",
1561
- "Như Hảo",
1562
- "Như Hồng",
1563
- "Như Loan",
1564
- "Như Mai",
1565
- "Như Ngà",
1566
- "Như Ngọc",
1567
- "Như Phương",
1568
- "Như Quân",
1569
- "Như Quỳnh",
1570
- "Như Thảo",
1571
- "Như Trân",
1572
- "Như Tâm",
1573
- "Như Ý",
1574
- "Nhất Thương",
1575
- "Nhật Dạ",
1576
- "Nhật Hà",
1577
- "Nhật Hạ",
1578
- "Nhật Lan",
1579
- "Nhật Linh",
1580
- "Nhật Lệ",
1581
- "Nhật Mai",
1582
- "Nhật Phương",
1583
- "Nhật Ánh",
1584
- "Oanh Thơ",
1585
- "Oanh Vũ",
1586
- "Phi Khanh",
1587
- "Phi Nhung",
1588
- "Phi Nhạn",
1589
- "Phi Phi",
1590
- "Phi Phượng",
1591
- "Phong Lan",
1592
- "Phương An",
1593
- "Phương Anh",
1594
- "Phương Chi",
1595
- "Phương Châu",
1596
- "Phương Diễm",
1597
- "Phương Dung",
1598
- "Phương Giang",
1599
- "Phương Hiền",
1600
- "Phương Hoa",
1601
- "Phương Hạnh",
1602
- "Phương Lan",
1603
- "Phương Linh",
1604
- "Phương Liên",
1605
- "Phương Loan",
1606
- "Phương Mai",
1607
- "Phương Nghi",
1608
- "Phương Ngọc",
1609
- "Phương Nhi",
1610
- "Phương Nhung",
1611
- "Phương Phương",
1612
- "Phương Quyên",
1613
- "Phương Quân",
1614
- "Phương Quế",
1615
- "Phương Quỳnh",
1616
- "Phương Thanh",
1617
- "Phương Thi",
1618
- "Phương Thùy",
1619
- "Phương Thảo",
1620
- "Phương Thủy",
1621
- "Phương Trang",
1622
- "Phương Trinh",
1623
- "Phương Trà",
1624
- "Phương Trâm",
1625
- "Phương Tâm",
1626
- "Phương Uyên",
1627
- "Phương Yến",
1628
- "Phước Bình",
1629
- "Phước Huệ",
1630
- "Phượng Bích",
1631
- "Phượng Liên",
1632
- "Phượng Loan",
1633
- "Phượng Lệ",
1634
- "Phượng Nga",
1635
- "Phượng Nhi",
1636
- "Phượng Tiên",
1637
- "Phượng Uyên",
1638
- "Phượng Vy",
1639
- "Phượng Vũ",
1640
- "Phụng Yến",
1641
- "Quế Anh",
1642
- "Quế Chi",
1643
- "Quế Linh",
1644
- "Quế Lâm",
1645
- "Quế Phương",
1646
- "Quế Thu",
1647
- "Quỳnh Anh",
1648
- "Quỳnh Chi",
1649
- "Quỳnh Dao",
1650
- "Quỳnh Dung",
1651
- "Quỳnh Giang",
1652
- "Quỳnh Giao",
1653
- "Quỳnh Hoa",
1654
- "Quỳnh Hà",
1655
- "Quỳnh Hương",
1656
- "Quỳnh Lam",
1657
- "Quỳnh Liên",
1658
- "Quỳnh Lâm",
1659
- "Quỳnh Nga",
1660
- "Quỳnh Ngân",
1661
- "Quỳnh Nhi",
1662
- "Quỳnh Nhung",
1663
- "Quỳnh Như",
1664
- "Quỳnh Phương",
1665
- "Quỳnh Sa",
1666
- "Quỳnh Thanh",
1667
- "Quỳnh Thơ",
1668
- "Quỳnh Tiên",
1669
- "Quỳnh Trang",
1670
- "Quỳnh Trâm",
1671
- "Quỳnh Vân",
1672
- "Sao Băng",
1673
- "Sao Mai",
1674
- "Song Kê",
1675
- "Song Lam",
1676
- "Song Oanh",
1677
- "Song Thư",
1678
- "Sông Hà",
1679
- "Sông Hương",
1680
- "Sơn Ca",
1681
- "Sơn Tuyền",
1682
- "Sương Sương",
1683
- "Thanh Bình",
1684
- "Thanh Dân",
1685
- "Thanh Giang",
1686
- "Thanh Hiếu",
1687
- "Thanh Hiền",
1688
- "Thanh Hoa",
1689
- "Thanh Huyền",
1690
- "Thanh Hà",
1691
- "Thanh Hương",
1692
- "Thanh Hường",
1693
- "Thanh Hạnh",
1694
- "Thanh Hảo",
1695
- "Thanh Hằng",
1696
- "Thanh Hồng",
1697
- "Thanh Kiều",
1698
- "Thanh Lam",
1699
- "Thanh Lan",
1700
- "Thanh Loan",
1701
- "Thanh Lâm",
1702
- "Thanh Mai",
1703
- "Thanh Mẫn",
1704
- "Thanh Nga",
1705
- "Thanh Nguyên",
1706
- "Thanh Ngân",
1707
- "Thanh Ngọc",
1708
- "Thanh Nhung",
1709
- "Thanh Nhàn",
1710
- "Thanh Nhã",
1711
- "Thanh Phương",
1712
- "Thanh Thanh",
1713
- "Thanh Thiên",
1714
- "Thanh Thu",
1715
- "Thanh Thúy",
1716
- "Thanh Thư",
1717
- "Thanh Thảo",
1718
- "Thanh Thủy",
1719
- "Thanh Trang",
1720
- "Thanh Trúc",
1721
- "Thanh Tuyết",
1722
- "Thanh Tuyền",
1723
- "Thanh Tâm",
1724
- "Thanh Uyên",
1725
- "Thanh Vy",
1726
- "Thanh Vân",
1727
- "Thanh Xuân",
1728
- "Thanh Yến",
1729
- "Thanh Đan",
1730
- "Thi Cầm",
1731
- "Thi Ngôn",
1732
- "Thi Thi",
1733
- "Thi Xuân",
1734
- "Thi Yến",
1735
- "Thiên Di",
1736
- "Thiên Duyên",
1737
- "Thiên Giang",
1738
- "Thiên Hà",
1739
- "Thiên Hương",
1740
- "Thiên Khánh",
1741
- "Thiên Kim",
1742
- "Thiên Lam",
1743
- "Thiên Lan",
1744
- "Thiên Mai",
1745
- "Thiên Mỹ",
1746
- "Thiên Nga",
1747
- "Thiên Nương",
1748
- "Thiên Phương",
1749
- "Thiên Thanh",
1750
- "Thiên Thêu",
1751
- "Thiên Thư",
1752
- "Thiên Thảo",
1753
- "Thiên Trang",
1754
- "Thiên Tuyền",
1755
- "Thiếu Mai",
1756
- "Thiều Ly",
1757
- "Thiện Mỹ",
1758
- "Thiện Tiên",
1759
- "Thu Duyên",
1760
- "Thu Giang",
1761
- "Thu Hiền",
1762
- "Thu Hoài",
1763
- "Thu Huyền",
1764
- "Thu Huệ",
1765
- "Thu Hà",
1766
- "Thu Hậu",
1767
- "Thu Hằng",
1768
- "Thu Hồng",
1769
- "Thu Linh",
1770
- "Thu Liên",
1771
- "Thu Loan",
1772
- "Thu Mai",
1773
- "Thu Minh",
1774
- "Thu Nga",
1775
- "Thu Nguyệt",
1776
- "Thu Ngà",
1777
- "Thu Ngân",
1778
- "Thu Ngọc",
1779
- "Thu Nhiên",
1780
- "Thu Oanh",
1781
- "Thu Phong",
1782
- "Thu Phương",
1783
- "Thu Phượng",
1784
- "Thu Sương",
1785
- "Thu Thuận",
1786
- "Thu Thảo",
1787
- "Thu Thủy",
1788
- "Thu Trang",
1789
- "Thu Việt",
1790
- "Thu Vân",
1791
- "Thu Vọng",
1792
- "Thu Yến",
1793
- "Thuần Hậu",
1794
- "Thy Khanh",
1795
- "Thy Oanh",
1796
- "Thy Trúc",
1797
- "Thy Vân",
1798
- "Thái Chi",
1799
- "Thái Hà",
1800
- "Thái Hồng",
1801
- "Thái Lan",
1802
- "Thái Lâm",
1803
- "Thái Thanh",
1804
- "Thái Thảo",
1805
- "Thái Tâm",
1806
- "Thái Vân",
1807
- "Thùy Anh",
1808
- "Thùy Dung",
1809
- "Thùy Dương",
1810
- "Thùy Giang",
1811
- "Thùy Linh",
1812
- "Thùy Mi",
1813
- "Thùy My",
1814
- "Thùy Nhi",
1815
- "Thùy Như",
1816
- "Thùy Oanh",
1817
- "Thùy Uyên",
1818
- "Thùy Vân",
1819
- "Thúy Anh",
1820
- "Thúy Diễm",
1821
- "Thúy Hiền",
1822
- "Thúy Huyền",
1823
- "Thúy Hà",
1824
- "Thúy Hương",
1825
- "Thúy Hường",
1826
- "Thúy Hạnh",
1827
- "Thúy Hằng",
1828
- "Thúy Kiều",
1829
- "Thúy Liên",
1830
- "Thúy Liễu",
1831
- "Thúy Loan",
1832
- "Thúy Mai",
1833
- "Thúy Minh",
1834
- "Thúy My",
1835
- "Thúy Nga",
1836
- "Thúy Ngà",
1837
- "Thúy Ngân",
1838
- "Thúy Ngọc",
1839
- "Thúy Phượng",
1840
- "Thúy Quỳnh",
1841
- "Thúy Vi",
1842
- "Thúy Vy",
1843
- "Thúy Vân",
1844
- "Thơ Thơ",
1845
- "Thư Lâm",
1846
- "Thư Sương",
1847
- "Thương Huyền",
1848
- "Thương Nga",
1849
- "Thương Thương",
1850
- "Thường Xuân",
1851
- "Thạch Thảo",
1852
- "Thảo Hương",
1853
- "Thảo Hồng",
1854
- "Thảo Linh",
1855
- "Thảo Ly",
1856
- "Thảo Mai",
1857
- "Thảo My",
1858
- "Thảo Nghi",
1859
- "Thảo Nguyên",
1860
- "Thảo Nhi",
1861
- "Thảo Quyên",
1862
- "Thảo Tiên",
1863
- "Thảo Trang",
1864
- "Thảo Uyên",
1865
- "Thảo Vy",
1866
- "Thảo Vân",
1867
- "Thục Anh",
1868
- "Thục Khuê",
1869
- "Thục Nhi",
1870
- "Thục Oanh",
1871
- "Thục Quyên",
1872
- "Thục Trang",
1873
- "Thục Trinh",
1874
- "Thục Tâm",
1875
- "Thục Uyên",
1876
- "Thục Vân",
1877
- "Thục Ðoan",
1878
- "Thục Ðào",
1879
- "Thục Ðình",
1880
- "Thụy Du",
1881
- "Thụy Khanh",
1882
- "Thụy Linh",
1883
- "Thụy Lâm",
1884
- "Thụy Miên",
1885
- "Thụy Nương",
1886
- "Thụy Trinh",
1887
- "Thụy Trâm",
1888
- "Thụy Uyên",
1889
- "Thụy Vân",
1890
- "Thụy Ðào",
1891
- "Thủy Hằng",
1892
- "Thủy Hồng",
1893
- "Thủy Linh",
1894
- "Thủy Minh",
1895
- "Thủy Nguyệt",
1896
- "Thủy Quỳnh",
1897
- "Thủy Tiên",
1898
- "Thủy Trang",
1899
- "Thủy Tâm",
1900
- "Tinh Tú",
1901
- "Tiên Phương",
1902
- "Tiểu Mi",
1903
- "Tiểu My",
1904
- "Tiểu Quỳnh",
1905
- "Trang Anh",
1906
- "Trang Linh",
1907
- "Trang Nhã",
1908
- "Trang Tâm",
1909
- "Trang Ðài",
1910
- "Triều Nguyệt",
1911
- "Triều Thanh",
1912
- "Triệu Mẫn",
1913
- "Trung Anh",
1914
- "Trà Giang",
1915
- "Trà My",
1916
- "Trâm Anh",
1917
- "Trâm Oanh",
1918
- "Trân Châu",
1919
- "Trúc Chi",
1920
- "Trúc Lam",
1921
- "Trúc Lan",
1922
- "Trúc Linh",
1923
- "Trúc Liên",
1924
- "Trúc Loan",
1925
- "Trúc Ly",
1926
- "Trúc Lâm",
1927
- "Trúc Mai",
1928
- "Trúc Phương",
1929
- "Trúc Quân",
1930
- "Trúc Quỳnh",
1931
- "Trúc Vy",
1932
- "Trúc Vân",
1933
- "Trúc Ðào",
1934
- "Trúc Đào",
1935
- "Trầm Hương",
1936
- "Tuyết Anh",
1937
- "Tuyết Băng",
1938
- "Tuyết Chi",
1939
- "Tuyết Hoa",
1940
- "Tuyết Hân",
1941
- "Tuyết Hương",
1942
- "Tuyết Hồng",
1943
- "Tuyết Lan",
1944
- "Tuyết Loan",
1945
- "Tuyết Lâm",
1946
- "Tuyết Mai",
1947
- "Tuyết Nga",
1948
- "Tuyết Nhi",
1949
- "Tuyết Nhung",
1950
- "Tuyết Oanh",
1951
- "Tuyết Thanh",
1952
- "Tuyết Trinh",
1953
- "Tuyết Trầm",
1954
- "Tuyết Tâm",
1955
- "Tuyết Vy",
1956
- "Tuyết Vân",
1957
- "Tuyết Xuân",
1958
- "Tuyền Lâm",
1959
- "Tuệ Lâm",
1960
- "Tuệ Mẫn",
1961
- "Tuệ Nhi",
1962
- "Tâm Hiền",
1963
- "Tâm Hạnh",
1964
- "Tâm Hằng",
1965
- "Tâm Khanh",
1966
- "Tâm Linh",
1967
- "Tâm Nguyên",
1968
- "Tâm Nguyệt",
1969
- "Tâm Nhi",
1970
- "Tâm Như",
1971
- "Tâm Thanh",
1972
- "Tâm Trang",
1973
- "Tâm Ðoan",
1974
- "Tâm Đan",
1975
- "Tùng Linh",
1976
- "Tùng Lâm",
1977
- "Tùng Quân",
1978
- "Tùy Anh",
1979
- "Tùy Linh",
1980
- "Tú Anh",
1981
- "Tú Ly",
1982
- "Tú Nguyệt",
1983
- "Tú Quyên",
1984
- "Tú Quỳnh",
1985
- "Tú Sương",
1986
- "Tú Trinh",
1987
- "Tú Tâm",
1988
- "Tú Uyên",
1989
- "Túy Loan",
1990
- "Tường Chinh",
1991
- "Tường Vi",
1992
- "Tường Vy",
1993
- "Tường Vân",
1994
- "Tịnh Lâm",
1995
- "Tịnh Nhi",
1996
- "Tịnh Như",
1997
- "Tịnh Tâm",
1998
- "Tịnh Yên",
1999
- "Tố Loan",
2000
- "Tố Nga",
2001
- "Tố Nhi",
2002
- "Tố Quyên",
2003
- "Tố Tâm",
2004
- "Tố Uyên",
2005
- "Từ Dung",
2006
- "Từ Ân",
2007
- "Uyên Minh",
2008
- "Uyên My",
2009
- "Uyên Nhi",
2010
- "Uyên Phương",
2011
- "Uyên Thi",
2012
- "Uyên Thy",
2013
- "Uyên Thơ",
2014
- "Uyên Trâm",
2015
- "Uyên Vi",
2016
- "Uyển Khanh",
2017
- "Uyển My",
2018
- "Uyển Nghi",
2019
- "Uyển Nhi",
2020
- "Uyển Nhã",
2021
- "Uyển Như",
2022
- "Vi Quyên",
2023
- "Vinh Diệu",
2024
- "Việt Hà",
2025
- "Việt Hương",
2026
- "Việt Khuê",
2027
- "Việt Mi",
2028
- "Việt Nga",
2029
- "Việt Nhi",
2030
- "Việt Thi",
2031
- "Việt Trinh",
2032
- "Việt Tuyết",
2033
- "Việt Yến",
2034
- "Vy Lam",
2035
- "Vy Lan",
2036
- "Vàng Anh",
2037
- "Vành Khuyên",
2038
- "Vân Anh",
2039
- "Vân Chi",
2040
- "Vân Du",
2041
- "Vân Hà",
2042
- "Vân Hương",
2043
- "Vân Khanh",
2044
- "Vân Khánh",
2045
- "Vân Linh",
2046
- "Vân Ngọc",
2047
- "Vân Nhi",
2048
- "Vân Phi",
2049
- "Vân Phương",
2050
- "Vân Quyên",
2051
- "Vân Quỳnh",
2052
- "Vân Thanh",
2053
- "Vân Thúy",
2054
- "Vân Thường",
2055
- "Vân Tiên",
2056
- "Vân Trang",
2057
- "Vân Trinh",
2058
- "Vũ Hồng",
2059
- "Xuyến Chi",
2060
- "Xuân Bảo",
2061
- "Xuân Dung",
2062
- "Xuân Hiền",
2063
- "Xuân Hoa",
2064
- "Xuân Hân",
2065
- "Xuân Hương",
2066
- "Xuân Hạnh",
2067
- "Xuân Lan",
2068
- "Xuân Linh",
2069
- "Xuân Liễu",
2070
- "Xuân Loan",
2071
- "Xuân Lâm",
2072
- "Xuân Mai",
2073
- "Xuân Nghi",
2074
- "Xuân Ngọc",
2075
- "Xuân Nhi",
2076
- "Xuân Nhiên",
2077
- "Xuân Nương",
2078
- "Xuân Phương",
2079
- "Xuân Phượng",
2080
- "Xuân Thanh",
2081
- "Xuân Thu",
2082
- "Xuân Thảo",
2083
- "Xuân Thủy",
2084
- "Xuân Trang",
2085
- "Xuân Tâm",
2086
- "Xuân Uyên",
2087
- "Xuân Vân",
2088
- "Xuân Yến",
2089
- "Xuân xanh",
2090
- "Yên Bằng",
2091
- "Yên Mai",
2092
- "Yên Nhi",
2093
- "Yên Ðan",
2094
- "Yên Đan",
2095
- "Yến Anh",
2096
- "Yến Hồng",
2097
- "Yến Loan",
2098
- "Yến Mai",
2099
- "Yến My",
2100
- "Yến Nhi",
2101
- "Yến Oanh",
2102
- "Yến Phương",
2103
- "Yến Phượng",
2104
- "Yến Thanh",
2105
- "Yến Thảo",
2106
- "Yến Trang",
2107
- "Yến Trinh",
2108
- "Yến Trâm",
2109
- "Yến Ðan",
2110
- "Ái Hồng",
2111
- "Ái Khanh",
2112
- "Ái Linh",
2113
- "Ái Nhi",
2114
- "Ái Nhân",
2115
- "Ái Thi",
2116
- "Ái Thy",
2117
- "Ái Vân",
2118
- "Ánh Dương",
2119
- "Ánh Hoa",
2120
- "Ánh Hồng",
2121
- "Ánh Linh",
2122
- "Ánh Lệ",
2123
- "Ánh Mai",
2124
- "Ánh Nguyệt",
2125
- "Ánh Ngọc",
2126
- "Ánh Thơ",
2127
- "Ánh Trang",
2128
- "Ánh Tuyết",
2129
- "Ánh Xuân",
2130
- "Ðan Khanh",
2131
- "Ðan Quỳnh",
2132
- "Ðan Thu",
2133
- "Ðinh Hương",
2134
- "Ðoan Thanh",
2135
- "Ðoan Trang",
2136
- "Ðài Trang",
2137
- "Ðông Nghi",
2138
- "Ðông Nhi",
2139
- "Ðông Trà",
2140
- "Ðông Tuyền",
2141
- "Ðông Vy",
2142
- "Ðông Ðào",
2143
- "Ðồng Dao",
2144
- "Ý Bình",
2145
- "Ý Lan",
2146
- "Ý Nhi",
2147
- "Đan Linh",
2148
- "Đan Quỳnh",
2149
- "Đan Thanh",
2150
- "Đan Thu",
2151
- "Đan Thư",
2152
- "Đan Tâm",
2153
- "Đinh Hương",
2154
- "Đoan Thanh",
2155
- "Đoan Trang",
2156
- "Đài Trang",
2157
- "Đông Nghi",
2158
- "Đông Trà",
2159
- "Đông Tuyền",
2160
- "Đông Vy",
2161
- "Đơn Thuần",
2162
- "Đức Hạnh",
2163
- "Ấu Lăng"
2164
- ]
2165
- let OtherName = [".", ",", "/", "%", "&", "*", "-", "+"];
2166
- try {
2167
- var Name;
2168
- if (name == " " || name == null) return "UNKNOWN";
2169
- switch (female_name.some(a => name.includes(a))) {
2170
- case true: {
2171
- if (!OtherName.includes(name)) Name = "FEMALE";
2172
- else Name = ['FEMALE', 'MALE'][Math.floor(Math.random() * 2)]; // just temp 🌚
2173
- }
2174
- break;
2175
- case false: {
2176
- if (female_name.some(a => name.split(' ')[name.split(' ').length - 1] == a)) Name = "FEMALE";
2177
- else if (!OtherName.includes(name) && !female_name.includes(name)) Name = "MALE";
2178
- else Name = ['FEMALE', 'MALE'][Math.floor(Math.random() * 2)]; // just temp 🌚
2179
- }
2180
- break;
2181
- }
2182
- }
2183
- catch (e) {
2184
- return "UNKNOWN";
2185
- }
2186
- return Name || "UNKNOWN";
925
+ function getAdminTextMessageType(type) {
926
+ switch (type) {
927
+ case "change_thread_theme":
928
+ return "log:thread-color";
929
+ case "change_thread_icon":
930
+ case "change_thread_quick_reaction":
931
+ return "log:thread-icon";
932
+ case "change_thread_nickname":
933
+ return "log:user-nickname";
934
+ case "change_thread_admins":
935
+ return "log:thread-admins";
936
+ case "group_poll":
937
+ return "log:thread-poll";
938
+ case "change_thread_approval_mode":
939
+ return "log:thread-approval-mode";
940
+ case "messenger_call_log":
941
+ case "participant_joined_group_call":
942
+ return "log:thread-call";
943
+ default:
944
+ return type;
945
+ }
2187
946
  }
2188
947
 
2189
- /**
2190
- * @param {{ [x: string]: { [x: string]: { [x: string]: any; }; }; class: any; untypedData: any; name: any; addedParticipants: any; leftParticipantFbId: any; messageMetadata: { threadKey: { threadFbId: any; otherUserFbId: any; }; adminText: any; actorFbId: any; }; participants: any; }} m
2191
- */
2192
-
2193
948
  function formatDeltaEvent(m) {
2194
- var logMessageType;
2195
- var logMessageData;
2196
-
2197
- // log:thread-color => {theme_color}
2198
- // log:user-nickname => {participant_id, nickname}
2199
- // log:thread-icon => {thread_icon}
2200
- // log:thread-name => {name}
2201
- // log:subscribe => {addedParticipants - [Array]}
2202
- // log:unsubscribe => {leftParticipantFbId}
2203
- // console.log(m)
2204
- switch (m.class) {
2205
- case "JoinableMode":
2206
- if (m.mode) return;
2207
- logMessageType = "joinable_group_link_reset"
2208
- logMessageData = { link: m.link }
2209
- break;
2210
- case "AdminTextMessage":
2211
- logMessageType = getAdminTextMessageType(m);
2212
- logMessageData = m.untypedData;
2213
- break;
2214
- case "ThreadName":
2215
- logMessageType = "log:thread-name";
2216
- logMessageData = { name: m.name };
2217
- break;
2218
- case "ParticipantsAddedToGroupThread":
2219
- logMessageType = "log:subscribe";
2220
- logMessageData = { addedParticipants: m.addedParticipants };
2221
- break;
2222
- case "ParticipantLeftGroupThread":
2223
- logMessageType = "log:unsubscribe";
2224
- logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
2225
- break;
2226
- }
2227
-
2228
- return {
2229
- type: "event",
2230
- threadID: formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),
2231
- logMessageType: logMessageType,
2232
- logMessageData: logMessageData,
2233
- logMessageBody: m.messageMetadata.adminText,
2234
- author: m.messageMetadata.actorFbId,
2235
- participantIDs: (m.participants || []).map(p => p.toString())
2236
- };
949
+ let logMessageType;
950
+ let logMessageData;
951
+
952
+ // log:thread-color => {theme_color}
953
+ // log:user-nickname => {participant_id, nickname}
954
+ // log:thread-icon => {thread_icon}
955
+ // log:thread-name => {name}
956
+ // log:subscribe => {addedParticipants - [Array]}
957
+ // log:unsubscribe => {leftParticipantFbId}
958
+
959
+ switch (m.class) {
960
+ case "AdminTextMessage":
961
+ logMessageData = m.untypedData;
962
+ logMessageType = getAdminTextMessageType(m.type);
963
+ break;
964
+ case "ThreadName":
965
+ logMessageType = "log:thread-name";
966
+ logMessageData = { name: m.name };
967
+ break;
968
+ case "ParticipantsAddedToGroupThread":
969
+ logMessageType = "log:subscribe";
970
+ logMessageData = { addedParticipants: m.addedParticipants };
971
+ break;
972
+ case "ParticipantLeftGroupThread":
973
+ logMessageType = "log:unsubscribe";
974
+ logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
975
+ break;
976
+ case "ApprovalQueue":
977
+ logMessageType = "log:approval-queue";
978
+ logMessageData = {
979
+ approvalQueue: {
980
+ action: m.action,
981
+ recipientFbId: m.recipientFbId,
982
+ requestSource: m.requestSource,
983
+ ...m.messageMetadata
984
+ }
985
+ };
986
+ }
987
+
988
+ return {
989
+ type: "event",
990
+ threadID: formatID(
991
+ (
992
+ m.messageMetadata.threadKey.threadFbId ||
993
+ m.messageMetadata.threadKey.otherUserFbId
994
+ ).toString()
995
+ ),
996
+ messageID: m.messageMetadata.messageId.toString(),
997
+ logMessageType: logMessageType,
998
+ logMessageData: logMessageData,
999
+ logMessageBody: m.messageMetadata.adminText,
1000
+ timestamp: m.messageMetadata.timestamp,
1001
+ author: m.messageMetadata.actorFbId,
1002
+ participantIDs: (m.participants || []).map(p => p.toString())
1003
+ };
2237
1004
  }
2238
1005
 
2239
- /**
2240
- * @param {{ st: any; from: { toString: () => any; }; to: any; thread_fbid: any; hasOwnProperty: (arg0: string) => any; from_mobile: any; realtime_viewer_fbid: any; }} event
2241
- */
2242
-
2243
1006
  function formatTyp(event) {
2244
- return {
2245
- isTyping: !!event.st,
2246
- from: event.from.toString(),
2247
- threadID: formatID((event.to || event.thread_fbid || event.from).toString()),
2248
- // When receiving typ indication from mobile, `from_mobile` isn't set.
2249
- // If it is, we just use that value.
2250
- fromMobile: event.hasOwnProperty("from_mobile") ? event.from_mobile : true,
2251
- userID: (event.realtime_viewer_fbid || event.from).toString(),
2252
- type: "typ"
2253
- };
1007
+ return {
1008
+ isTyping: !!event.st,
1009
+ from: event.from.toString(),
1010
+ threadID: formatID(
1011
+ (event.to || event.thread_fbid || event.from).toString()
1012
+ ),
1013
+ // When receiving typ indication from mobile, `from_mobile` isn't set.
1014
+ // If it is, we just use that value.
1015
+ fromMobile: event.hasOwnProperty("from_mobile") ? event.from_mobile : true,
1016
+ userID: (event.realtime_viewer_fbid || event.from).toString(),
1017
+ type: "typ"
1018
+ };
2254
1019
  }
2255
1020
 
2256
- /**
2257
- * @param {{ threadKey: { otherUserFbId: any; threadFbId: any; }; actorFbId: any; actionTimestampMs: any; }} delta
2258
- */
2259
-
2260
- // function formatDeltaReadReceipt(delta) {
2261
- // // otherUserFbId seems to be used as both the readerID and the threadID in a 1-1 chat.
2262
- // // In a group chat actorFbId is used for the reader and threadFbId for the thread.
2263
- // return {
2264
- // reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
2265
- // time: delta.actionTimestampMs,
2266
- // threadID: formatID((delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString()),
2267
- // type: "read_receipt"
2268
- // };
2269
- // }
2270
-
2271
- /**
2272
- * @param {{ reader: { toString: () => any; }; time: any; thread_fbid: any; }} event
2273
- */
1021
+ function formatDeltaReadReceipt(delta) {
1022
+ // otherUserFbId seems to be used as both the readerID and the threadID in a 1-1 chat.
1023
+ // In a group chat actorFbId is used for the reader and threadFbId for the thread.
1024
+ return {
1025
+ reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
1026
+ time: delta.actionTimestampMs,
1027
+ threadID: formatID(
1028
+ (delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString()
1029
+ ),
1030
+ type: "read_receipt"
1031
+ };
1032
+ }
2274
1033
 
2275
1034
  function formatReadReceipt(event) {
2276
- return {
2277
- reader: event.reader.toString(),
2278
- time: event.time,
2279
- threadID: formatID((event.thread_fbid || event.reader).toString()),
2280
- type: "read_receipt"
2281
- };
1035
+ return {
1036
+ reader: event.reader.toString(),
1037
+ time: event.time,
1038
+ threadID: formatID((event.thread_fbid || event.reader).toString()),
1039
+ type: "read_receipt"
1040
+ };
2282
1041
  }
2283
1042
 
2284
- /**
2285
- * @param {{ chat_ids: any[]; thread_fbids: any[]; timestamp: any; }} event
2286
- */
2287
-
2288
1043
  function formatRead(event) {
2289
- return {
2290
- threadID: formatID(((event.chat_ids && event.chat_ids[0]) || (event.thread_fbids && event.thread_fbids[0])).toString()),
2291
- time: event.timestamp,
2292
- type: "read"
2293
- };
1044
+ return {
1045
+ threadID: formatID(
1046
+ (
1047
+ (event.chat_ids && event.chat_ids[0]) ||
1048
+ (event.thread_fbids && event.thread_fbids[0])
1049
+ ).toString()
1050
+ ),
1051
+ time: event.timestamp,
1052
+ type: "read"
1053
+ };
2294
1054
  }
2295
1055
 
2296
- /**
2297
- * @param {string} str
2298
- * @param {string | any[]} startToken
2299
- * @param {string} endToken
2300
- */
2301
-
2302
1056
  function getFrom(str, startToken, endToken) {
2303
- var start = str.indexOf(startToken) + startToken.length;
2304
- if (start < startToken.length) return "";
2305
-
2306
- var lastHalf = str.substring(start);
2307
- var end = lastHalf.indexOf(endToken);
2308
- if (end === -1) throw Error("Could not find endTime `" + endToken + "` in the given string.");
2309
- return lastHalf.substring(0, end);
1057
+ const start = str.indexOf(startToken) + startToken.length;
1058
+ if (start < startToken.length) return "";
1059
+
1060
+ const lastHalf = str.substring(start);
1061
+ const end = lastHalf.indexOf(endToken);
1062
+ if (end === -1) {
1063
+ throw new Error(
1064
+ "Could not find endTime `" + endToken + "` in the given string."
1065
+ );
1066
+ }
1067
+ return lastHalf.substring(0, end);
2310
1068
  }
2311
1069
 
2312
- /**
2313
- * @param {string} html
2314
- */
2315
-
2316
1070
  function makeParsable(html) {
2317
- let withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/
2318
- , "");
2319
-
2320
- // (What the fuck FB, why windows style newlines?)
2321
- // So sometimes FB will send us base multiple objects in the same response.
2322
- // They're all valid JSON, one after the other, at the top level. We detect
2323
- // that and make it parse-able by JSON.parse.
2324
- // Ben - July 15th 2017
2325
- //
2326
- // It turns out that Facebook may insert random number of spaces before
2327
- // next object begins (issue #616)
2328
- // rav_kr - 2018-03-19
2329
- let maybeMultipleObjects = withoutForLoop.split(/\}\r\n *\{/);
2330
- if (maybeMultipleObjects.length === 1) return maybeMultipleObjects;
2331
-
2332
- return "[" + maybeMultipleObjects.join("},{") + "]";
1071
+ const withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, "");
1072
+
1073
+ // (What the fuck FB, why windows style newlines?)
1074
+ // So sometimes FB will send us base multiple objects in the same response.
1075
+ // They're all valid JSON, one after the other, at the top level. We detect
1076
+ // that and make it parse-able by JSON.parse.
1077
+ // Ben - July 15th 2017
1078
+ //
1079
+ // It turns out that Facebook may insert random number of spaces before
1080
+ // next object begins (issue #616)
1081
+ // rav_kr - 2018-03-19
1082
+ const maybeMultipleObjects = withoutForLoop.split(/\}\r\n *\{/);
1083
+ if (maybeMultipleObjects.length === 1) return maybeMultipleObjects;
1084
+
1085
+ return "[" + maybeMultipleObjects.join("},{") + "]";
2333
1086
  }
2334
1087
 
2335
- /**
2336
- * @param {any} form
2337
- */
2338
-
2339
1088
  function arrToForm(form) {
2340
- return arrayToObject(form,
2341
- function (/** @type {{ name: any; }} */v) {
2342
- return v.name;
2343
- },
2344
- function (/** @type {{ val: any; }} */v) {
2345
- return v.val;
2346
- }
2347
- );
1089
+ return arrayToObject(
1090
+ form,
1091
+ function (v) {
1092
+ return v.name;
1093
+ },
1094
+ function (v) {
1095
+ return v.val;
1096
+ }
1097
+ );
2348
1098
  }
2349
1099
 
2350
- /**
2351
- * @param {any[]} arr
2352
- * @param {{ (v: any): any; (arg0: any): string | number; }} getKey
2353
- * @param {{ (v: any): any; (arg0: any): any; }} getValue
2354
- */
2355
-
2356
1100
  function arrayToObject(arr, getKey, getValue) {
2357
- return arr.reduce(function (/** @type {{ [x: string]: any; }} */
2358
- acc, /** @type {any} */val) {
2359
- acc[getKey(val)] = getValue(val);
2360
- return acc;
2361
- }, {});
1101
+ return arr.reduce(function (acc, val) {
1102
+ acc[getKey(val)] = getValue(val);
1103
+ return acc;
1104
+ }, {});
2362
1105
  }
2363
1106
 
2364
1107
  function getSignatureID() {
2365
- return Math.floor(Math.random() * 2147483648).toString(16);
1108
+ return Math.floor(Math.random() * 2147483648).toString(16);
2366
1109
  }
2367
1110
 
2368
1111
  function generateTimestampRelative() {
2369
- var d = new Date();
2370
- return d.getHours() + ":" + padZeros(d.getMinutes());
1112
+ const d = new Date();
1113
+ return d.getHours() + ":" + padZeros(d.getMinutes());
2371
1114
  }
2372
1115
 
2373
- /**
2374
- * @param {any} html
2375
- * @param {any} userID
2376
- * @param {{ fb_dtsg: any; ttstamp: any; globalOptions: any; }} ctx
2377
- */
2378
-
2379
1116
  function makeDefaults(html, userID, ctx) {
2380
- var reqCounter = 1;
2381
- var fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
2382
-
2383
- // @Hack Ok we've done hacky things, this is definitely on top 5.
2384
- // We totally assume the object is flat and try parsing until a }.
2385
- // If it works though it's cool because we get a bunch of extra data things.
2386
- //
2387
- // Update: we don't need this. Leaving it in in case we ever do.
2388
- // Ben - July 15th 2017
2389
-
2390
- // var siteData = getFrom(html, "[\"SiteData\",[],", "},");
2391
- // try {
2392
- // siteData = JSON.parse(siteData + "}");
2393
- // } catch(e) {
2394
- // log.warn("makeDefaults", "Couldn't parse SiteData. Won't have access to some variables.");
2395
- // siteData = {};
2396
- // }
2397
-
2398
- var ttstamp = "2";
2399
- for (var i = 0; i < fb_dtsg.length; i++) ttstamp += fb_dtsg.charCodeAt(i);
2400
- var revision = getFrom(html, 'revision":', ",");
2401
-
2402
- /**
2403
- * @param {{ [x: string]: any; hasOwnProperty: (arg0: string) => any; }} obj
2404
- */
2405
-
2406
- function mergeWithDefaults(obj) {
2407
- // @TODO This is missing a key called __dyn.
2408
- // After some investigation it seems like __dyn is some sort of set that FB
2409
- // calls BitMap. It seems like certain responses have a "define" key in the
2410
- // res.jsmods arrays. I think the code iterates over those and calls `set`
2411
- // on the bitmap for each of those keys. Then it calls
2412
- // bitmap.toCompressedString() which returns what __dyn is.
2413
- //
2414
- // So far the API has been working without this.
2415
- //
2416
- // Ben - July 15th 2017
2417
- var newObj = {
2418
- __user: userID,
2419
- __req: (reqCounter++).toString(36),
2420
- __rev: revision,
2421
- __a: 1,
2422
- // __af: siteData.features,
2423
- fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
2424
- jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
2425
- // __spin_r: siteData.__spin_r,
2426
- // __spin_b: siteData.__spin_b,
2427
- // __spin_t: siteData.__spin_t,
2428
- };
2429
-
2430
- // @TODO this is probably not needed.
2431
- // Ben - July 15th 2017
2432
- // if (siteData.be_key) {
2433
- // newObj[siteData.be_key] = siteData.be_mode;
2434
- // }
2435
- // if (siteData.pkg_cohort_key) {
2436
- // newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
2437
- // }
2438
-
2439
- if (!obj) return newObj;
2440
- for (var prop in obj)
2441
- if (obj.hasOwnProperty(prop))
2442
- if (!newObj[prop]) newObj[prop] = obj[prop];
2443
- return newObj;
2444
- }
2445
-
2446
- /**
2447
- * @param {any} url
2448
- * @param {any} jar
2449
- * @param {any} form
2450
- * @param {any} ctxx
2451
- */
2452
-
2453
- function postWithDefaults(url, jar, form, ctxx) {
2454
- return post(url, jar, mergeWithDefaults(form), ctx.globalOptions, ctxx || ctx);
2455
- }
2456
-
2457
- /**
2458
- * @param {any} url
2459
- * @param {any} jar
2460
- * @param {any} qs
2461
- * @param {any} ctxx
2462
- */
2463
-
2464
- function getWithDefaults(url, jar, qs, ctxx) {
2465
- return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
2466
- }
2467
-
2468
- /**
2469
- * @param {any} url
2470
- * @param {any} jar
2471
- * @param {any} form
2472
- * @param {any} qs
2473
- * @param {any} ctxx
2474
- */
2475
-
2476
- function postFormDataWithDefault(url, jar, form, qs, ctxx) {
2477
- return postFormData(url, jar, mergeWithDefaults(form), mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
2478
- }
2479
-
2480
- return {
2481
- get: getWithDefaults,
2482
- post: postWithDefaults,
2483
- postFormData: postFormDataWithDefault
2484
- };
1117
+ let reqCounter = 1;
1118
+ const fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
1119
+
1120
+ // @Hack Ok we've done hacky things, this is definitely on top 5.
1121
+ // We totally assume the object is flat and try parsing until a }.
1122
+ // If it works though it's cool because we get a bunch of extra data things.
1123
+ //
1124
+ // Update: we don't need this. Leaving it in in case we ever do.
1125
+ // Ben - July 15th 2017
1126
+
1127
+ // var siteData = getFrom(html, "[\"SiteData\",[],", "},");
1128
+ // try {
1129
+ // siteData = JSON.parse(siteData + "}");
1130
+ // } catch(e) {
1131
+ // log.warn("makeDefaults", "Couldn't parse SiteData. Won't have access to some variables.");
1132
+ // siteData = {};
1133
+ // }
1134
+
1135
+ let ttstamp = "2";
1136
+ for (let i = 0; i < fb_dtsg.length; i++) {
1137
+ ttstamp += fb_dtsg.charCodeAt(i);
1138
+ }
1139
+ const revision = getFrom(html, 'revision":', ",");
1140
+
1141
+ function mergeWithDefaults(obj) {
1142
+ // @TODO This is missing a key called __dyn.
1143
+ // After some investigation it seems like __dyn is some sort of set that FB
1144
+ // calls BitMap. It seems like certain responses have a "define" key in the
1145
+ // res.jsmods arrays. I think the code iterates over those and calls `set`
1146
+ // on the bitmap for each of those keys. Then it calls
1147
+ // bitmap.toCompressedString() which returns what __dyn is.
1148
+ //
1149
+ // So far the API has been working without this.
1150
+ //
1151
+ // Ben - July 15th 2017
1152
+ const newObj = {
1153
+ __user: userID,
1154
+ __req: (reqCounter++).toString(36),
1155
+ __rev: revision,
1156
+ __a: 1,
1157
+ // __af: siteData.features,
1158
+ fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
1159
+ jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
1160
+ // __spin_r: siteData.__spin_r,
1161
+ // __spin_b: siteData.__spin_b,
1162
+ // __spin_t: siteData.__spin_t,
1163
+ };
1164
+
1165
+ // @TODO this is probably not needed.
1166
+ // Ben - July 15th 2017
1167
+ // if (siteData.be_key) {
1168
+ // newObj[siteData.be_key] = siteData.be_mode;
1169
+ // }
1170
+ // if (siteData.pkg_cohort_key) {
1171
+ // newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
1172
+ // }
1173
+
1174
+ if (!obj) return newObj;
1175
+
1176
+ for (const prop in obj) {
1177
+ if (obj.hasOwnProperty(prop)) {
1178
+ if (!newObj[prop]) {
1179
+ newObj[prop] = obj[prop];
1180
+ }
1181
+ }
1182
+ }
1183
+
1184
+ return newObj;
1185
+ }
1186
+
1187
+ function postWithDefaults(url, jar, form, ctxx, customHeader = {}) {
1188
+ return post(url, jar, mergeWithDefaults(form), ctx.globalOptions, ctxx || ctx, customHeader);
1189
+ }
1190
+
1191
+ function getWithDefaults(url, jar, qs, ctxx, customHeader = {}) {
1192
+ return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx, customHeader);
1193
+ }
1194
+
1195
+ function postFormDataWithDefault(url, jar, form, qs, ctxx) {
1196
+ return postFormData(
1197
+ url,
1198
+ jar,
1199
+ mergeWithDefaults(form),
1200
+ mergeWithDefaults(qs),
1201
+ ctx.globalOptions,
1202
+ ctxx || ctx
1203
+ );
1204
+ }
1205
+
1206
+ return {
1207
+ get: getWithDefaults,
1208
+ post: postWithDefaults,
1209
+ postFormData: postFormDataWithDefault
1210
+ };
2485
1211
  }
2486
1212
 
2487
- /**
2488
- * @param {{ jar: { setCookie: (arg0: string, arg1: string) => void; }; fb_dtsg: string; ttstamp: string; }} ctx
2489
- * @param {{ postFormData: (arg0: string, arg1: any, arg2: any, arg3: {}) => any; post: (arg0: string, arg1: any, arg2: any) => any; get: (arg0: any, arg1: any) => Promise<any>; }} defaultFuncs
2490
- * @param {string | number} [retryCount]
2491
- */
2492
-
2493
- function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
2494
- if (retryCount == undefined) retryCount = 0;
2495
- return function (data) {
2496
- return bluebird.try(function () {
2497
- log.verbose("parseAndCheckLogin", data.body);
2498
- if (data.statusCode >= 500 && data.statusCode < 600) {
2499
- if (retryCount >= 5) {
2500
- throw {
2501
- error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
2502
- statusCode: data.statusCode,
2503
- res: data.body
2504
- };
2505
- }
2506
- retryCount++;
2507
- var retryTime = Math.floor(Math.random() * 5000);
2508
- log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
2509
- var url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
2510
- if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {})).then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
2511
- else return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData)).then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
2512
- }
2513
- if (data.statusCode !== 200) throw new Error("parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.");
2514
-
2515
- var res = null;
2516
- try {
2517
- res = JSON.parse(makeParsable(data.body));
2518
- }
2519
- catch (e) {
2520
- throw {
2521
- error: "JSON.parse error. Check the `detail` property on this error.",
2522
- detail: e,
2523
- res: data.body
2524
- };
2525
- }
2526
-
2527
- // In some cases the response contains only a redirect URL which should be followed
2528
- if (res.redirect && data.request.method === "GET") return defaultFuncs.get(res.redirect, ctx.jar).then(parseAndCheckLogin(ctx, defaultFuncs));
2529
-
2530
- // TODO: handle multiple cookies?
2531
- if (res.jsmods && res.jsmods.require && Array.isArray(res.jsmods.require[0]) && res.jsmods.require[0][0] === "Cookie") {
2532
- res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace("_js_", "");
2533
- var cookie = formatCookie(res.jsmods.require[0][3], "facebook");
2534
- var cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
2535
- ctx.jar.setCookie(cookie, "https://www.facebook.com");
2536
- ctx.jar.setCookie(cookie2, "https://www.messenger.com");
2537
- }
2538
-
2539
- // On every request we check if we got a DTSG and we mutate the context so that we use the latest
2540
- // one for the next requests.
2541
- if (res.jsmods && Array.isArray(res.jsmods.require)) {
2542
- var arr = res.jsmods.require;
2543
- for (var i in arr) {
2544
- if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
2545
- ctx.fb_dtsg = arr[i][3][0];
2546
-
2547
- // Update ttstamp since that depends on fb_dtsg
2548
- ctx.ttstamp = "2";
2549
- for (var j = 0; j < ctx.fb_dtsg.length; j++) ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
2550
- }
2551
- }
2552
- }
2553
-
2554
- if (res.error === 1357001) throw { error: "Not logged in." };
2555
- return res;
2556
- });
2557
- };
1213
+ function parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall) {
1214
+ if (retryCount == undefined) {
1215
+ retryCount = 0;
1216
+ }
1217
+ if (sourceCall == undefined) {
1218
+ try {
1219
+ throw new Error();
1220
+ }
1221
+ catch (e) {
1222
+ sourceCall = e;
1223
+ }
1224
+ }
1225
+ return function (data) {
1226
+ return tryPromise(function () {
1227
+ log.verbose("parseAndCheckLogin", data.body);
1228
+ if (data.statusCode >= 500 && data.statusCode < 600) {
1229
+ if (retryCount >= 5) {
1230
+ throw new CustomError({
1231
+ message: "Request retry failed. Check the `res` and `statusCode` property on this error.",
1232
+ statusCode: data.statusCode,
1233
+ res: data.body,
1234
+ error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
1235
+ sourceCall: sourceCall
1236
+ });
1237
+ }
1238
+ retryCount++;
1239
+ const retryTime = Math.floor(Math.random() * 5000);
1240
+ log.warn(
1241
+ "parseAndCheckLogin",
1242
+ "Got status code " +
1243
+ data.statusCode +
1244
+ " - " +
1245
+ retryCount +
1246
+ ". attempt to retry in " +
1247
+ retryTime +
1248
+ " milliseconds..."
1249
+ );
1250
+ const url =
1251
+ data.request.uri.protocol +
1252
+ "//" +
1253
+ data.request.uri.hostname +
1254
+ data.request.uri.pathname;
1255
+ if (
1256
+ data.request.headers["Content-Type"].split(";")[0] ===
1257
+ "multipart/form-data"
1258
+ ) {
1259
+ return delay(retryTime)
1260
+ .then(function () {
1261
+ return defaultFuncs.postFormData(
1262
+ url,
1263
+ ctx.jar,
1264
+ data.request.formData,
1265
+ {}
1266
+ );
1267
+ })
1268
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall));
1269
+ }
1270
+ else {
1271
+ return delay(retryTime)
1272
+ .then(function () {
1273
+ return defaultFuncs.post(url, ctx.jar, data.request.formData);
1274
+ })
1275
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall));
1276
+ }
1277
+ }
1278
+ if (data.statusCode !== 200)
1279
+ throw new CustomError({
1280
+ message: "parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.",
1281
+ statusCode: data.statusCode,
1282
+ res: data.body,
1283
+ error: "parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.",
1284
+ sourceCall: sourceCall
1285
+ });
1286
+
1287
+ let res = null;
1288
+ try {
1289
+ res = JSON.parse(makeParsable(data.body));
1290
+ } catch (e) {
1291
+ throw new CustomError({
1292
+ message: "JSON.parse error. Check the `detail` property on this error.",
1293
+ detail: e,
1294
+ res: data.body,
1295
+ error: "JSON.parse error. Check the `detail` property on this error.",
1296
+ sourceCall: sourceCall
1297
+ });
1298
+ }
1299
+
1300
+ // In some cases the response contains only a redirect URL which should be followed
1301
+ if (res.redirect && data.request.method === "GET") {
1302
+ return defaultFuncs
1303
+ .get(res.redirect, ctx.jar)
1304
+ .then(parseAndCheckLogin(ctx, defaultFuncs, undefined, sourceCall));
1305
+ }
1306
+
1307
+ // TODO: handle multiple cookies?
1308
+ if (
1309
+ res.jsmods &&
1310
+ res.jsmods.require &&
1311
+ Array.isArray(res.jsmods.require[0]) &&
1312
+ res.jsmods.require[0][0] === "Cookie"
1313
+ ) {
1314
+ res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace(
1315
+ "_js_",
1316
+ ""
1317
+ );
1318
+ const cookie = formatCookie(res.jsmods.require[0][3], "facebook");
1319
+ const cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
1320
+ ctx.jar.setCookie(cookie, "https://www.facebook.com");
1321
+ ctx.jar.setCookie(cookie2, "https://www.messenger.com");
1322
+ }
1323
+
1324
+ // On every request we check if we got a DTSG and we mutate the context so that we use the latest
1325
+ // one for the next requests.
1326
+ if (res.jsmods && Array.isArray(res.jsmods.require)) {
1327
+ const arr = res.jsmods.require;
1328
+ for (const i in arr) {
1329
+ if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
1330
+ ctx.fb_dtsg = arr[i][3][0];
1331
+
1332
+ // Update ttstamp since that depends on fb_dtsg
1333
+ ctx.ttstamp = "2";
1334
+ for (let j = 0; j < ctx.fb_dtsg.length; j++) {
1335
+ ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
1336
+ }
1337
+ }
1338
+ }
1339
+ }
1340
+
1341
+ if (res.error === 1357001) {
1342
+ throw new CustomError({
1343
+ message: "Facebook blocked login. Please visit https://facebook.com and check your account.",
1344
+ error: "Not logged in.",
1345
+ res: res,
1346
+ statusCode: data.statusCode,
1347
+ sourceCall: sourceCall
1348
+ });
1349
+ }
1350
+ return res;
1351
+ });
1352
+ };
2558
1353
  }
2559
1354
 
2560
- /**
2561
- * @param {{ setCookie: (arg0: any, arg1: string) => void; }} jar
2562
- */
1355
+ function checkLiveCookie(ctx, defaultFuncs) {
1356
+ return defaultFuncs
1357
+ .get("https://m.facebook.com/me", ctx.jar)
1358
+ .then(function (res) {
1359
+ if (res.body.indexOf(ctx.i_userID || ctx.userID) === -1) {
1360
+ throw new CustomError({
1361
+ message: "Not logged in.",
1362
+ error: "Not logged in."
1363
+ });
1364
+ }
1365
+ return true;
1366
+ });
1367
+ }
2563
1368
 
2564
1369
  function saveCookies(jar) {
2565
- return function (/** @type {{ headers: { [x: string]: any[]; }; }} */res) {
2566
- var cookies = res.headers["set-cookie"] || [];
2567
- cookies.forEach(function (/** @type {string} */c) {
2568
- if (c.indexOf(".facebook.com") > -1) { // yo wtf is this?
2569
- jar.setCookie(c, "https://www.facebook.com");
2570
- jar.setCookie(c.replace(/domain=\.facebook\.com/, "domain=.messenger.com"), "https://www.messenger.com");
2571
- }
2572
- });
2573
- return res;
2574
- };
1370
+ return function (res) {
1371
+ const cookies = res.headers["set-cookie"] || [];
1372
+ cookies.forEach(function (c) {
1373
+ if (c.indexOf(".facebook.com") > -1) {
1374
+ jar.setCookie(c, "https://www.facebook.com");
1375
+ }
1376
+ const c2 = c.replace(/domain=\.facebook\.com/, "domain=.messenger.com");
1377
+ jar.setCookie(c2, "https://www.messenger.com");
1378
+ });
1379
+ return res;
1380
+ };
2575
1381
  }
2576
1382
 
2577
- var NUM_TO_MONTH = [
2578
- "Jan",
2579
- "Feb",
2580
- "Mar",
2581
- "Apr",
2582
- "May",
2583
- "Jun",
2584
- "Jul",
2585
- "Aug",
2586
- "Sep",
2587
- "Oct",
2588
- "Nov",
2589
- "Dec"
1383
+ const NUM_TO_MONTH = [
1384
+ "Jan",
1385
+ "Feb",
1386
+ "Mar",
1387
+ "Apr",
1388
+ "May",
1389
+ "Jun",
1390
+ "Jul",
1391
+ "Aug",
1392
+ "Sep",
1393
+ "Oct",
1394
+ "Nov",
1395
+ "Dec"
2590
1396
  ];
2591
- var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
2592
-
2593
- /**
2594
- * @param {{ getUTCDate: () => any; getUTCHours: () => any; getUTCMinutes: () => any; getUTCSeconds: () => any; getUTCDay: () => string | number; getUTCMonth: () => string | number; getUTCFullYear: () => string; }} date
2595
- */
2596
-
1397
+ const NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
2597
1398
  function formatDate(date) {
2598
- var d = date.getUTCDate();
2599
- d = d >= 10 ? d : "0" + d;
2600
- var h = date.getUTCHours();
2601
- h = h >= 10 ? h : "0" + h;
2602
- var m = date.getUTCMinutes();
2603
- m = m >= 10 ? m : "0" + m;
2604
- var s = date.getUTCSeconds();
2605
- s = s >= 10 ? s : "0" + s;
2606
- return (NUM_TO_DAY[date.getUTCDay()] + ", " + d + " " + NUM_TO_MONTH[date.getUTCMonth()] + " " + date.getUTCFullYear() + " " + h + ":" + m + ":" + s + " GMT");
1399
+ let d = date.getUTCDate();
1400
+ d = d >= 10 ? d : "0" + d;
1401
+ let h = date.getUTCHours();
1402
+ h = h >= 10 ? h : "0" + h;
1403
+ let m = date.getUTCMinutes();
1404
+ m = m >= 10 ? m : "0" + m;
1405
+ let s = date.getUTCSeconds();
1406
+ s = s >= 10 ? s : "0" + s;
1407
+ return (
1408
+ NUM_TO_DAY[date.getUTCDay()] +
1409
+ ", " +
1410
+ d +
1411
+ " " +
1412
+ NUM_TO_MONTH[date.getUTCMonth()] +
1413
+ " " +
1414
+ date.getUTCFullYear() +
1415
+ " " +
1416
+ h +
1417
+ ":" +
1418
+ m +
1419
+ ":" +
1420
+ s +
1421
+ " GMT"
1422
+ );
2607
1423
  }
2608
1424
 
2609
- /**
2610
- * @param {string[]} arr
2611
- * @param {string} url
2612
- */
2613
-
2614
1425
  function formatCookie(arr, url) {
2615
- return arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com";
1426
+ return (
1427
+ arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com"
1428
+ );
2616
1429
  }
2617
1430
 
2618
- /**
2619
- * @param {{ thread_fbid: { toString: () => any; }; participants: any[]; name: any; custom_nickname: any; snippet: any; snippet_attachments: any; snippet_sender: any; unread_count: any; message_count: any; image_src: any; timestamp: any; mute_until: any; is_canonical_user: any; is_canonical: any; is_subscribed: any; folder: any; is_archived: any; recipients_loadable: any; has_email_participant: any; read_only: any; can_reply: any; cannot_reply_reason: any; last_message_timestamp: any; last_read_timestamp: any; last_message_type: any; custom_like_icon: any; custom_color: any; admin_ids: any; thread_type: any; }} data
2620
- */
2621
-
2622
1431
  function formatThread(data) {
2623
- return {
2624
- threadID: formatID(data.thread_fbid.toString()),
2625
- participants: data.participants.map(formatID),
2626
- participantIDs: data.participants.map(formatID),
2627
- name: data.name,
2628
- nicknames: data.custom_nickname,
2629
- snippet: data.snippet,
2630
- snippetAttachments: data.snippet_attachments,
2631
- snippetSender: formatID((data.snippet_sender || "").toString()),
2632
- unreadCount: data.unread_count,
2633
- messageCount: data.message_count,
2634
- imageSrc: data.image_src,
2635
- timestamp: data.timestamp,
2636
- muteUntil: data.mute_until,
2637
- isCanonicalUser: data.is_canonical_user,
2638
- isCanonical: data.is_canonical,
2639
- isSubscribed: data.is_subscribed,
2640
- folder: data.folder,
2641
- isArchived: data.is_archived,
2642
- recipientsLoadable: data.recipients_loadable,
2643
- hasEmailParticipant: data.has_email_participant,
2644
- readOnly: data.read_only,
2645
- canReply: data.can_reply,
2646
- cannotReplyReason: data.cannot_reply_reason,
2647
- lastMessageTimestamp: data.last_message_timestamp,
2648
- lastReadTimestamp: data.last_read_timestamp,
2649
- lastMessageType: data.last_message_type,
2650
- emoji: data.custom_like_icon,
2651
- color: data.custom_color,
2652
- adminIDs: data.admin_ids,
2653
- threadType: data.thread_type
2654
- };
1432
+ return {
1433
+ threadID: formatID(data.thread_fbid.toString()),
1434
+ participants: data.participants.map(formatID),
1435
+ participantIDs: data.participants.map(formatID),
1436
+ name: data.name,
1437
+ nicknames: data.custom_nickname,
1438
+ snippet: data.snippet,
1439
+ snippetAttachments: data.snippet_attachments,
1440
+ snippetSender: formatID((data.snippet_sender || "").toString()),
1441
+ unreadCount: data.unread_count,
1442
+ messageCount: data.message_count,
1443
+ imageSrc: data.image_src,
1444
+ timestamp: data.timestamp,
1445
+ serverTimestamp: data.server_timestamp, // what is this?
1446
+ muteUntil: data.mute_until,
1447
+ isCanonicalUser: data.is_canonical_user,
1448
+ isCanonical: data.is_canonical,
1449
+ isSubscribed: data.is_subscribed,
1450
+ folder: data.folder,
1451
+ isArchived: data.is_archived,
1452
+ recipientsLoadable: data.recipients_loadable,
1453
+ hasEmailParticipant: data.has_email_participant,
1454
+ readOnly: data.read_only,
1455
+ canReply: data.can_reply,
1456
+ cannotReplyReason: data.cannot_reply_reason,
1457
+ lastMessageTimestamp: data.last_message_timestamp,
1458
+ lastReadTimestamp: data.last_read_timestamp,
1459
+ lastMessageType: data.last_message_type,
1460
+ emoji: data.custom_like_icon,
1461
+ color: data.custom_color,
1462
+ adminIDs: data.admin_ids,
1463
+ threadType: data.thread_type
1464
+ };
2655
1465
  }
2656
1466
 
2657
- /**
2658
- * @param {any} obj
2659
- */
2660
-
2661
1467
  function getType(obj) {
2662
- return Object.prototype.toString.call(obj).slice(8, -1);
1468
+ return Object.prototype.toString.call(obj).slice(8, -1);
2663
1469
  }
2664
1470
 
2665
- /**
2666
- * @param {{ lat: number; p: any; }} presence
2667
- * @param {any} userID
2668
- */
2669
-
2670
1471
  function formatProxyPresence(presence, userID) {
2671
- if (presence.lat === undefined || presence.p === undefined) return null;
2672
- return {
2673
- type: "presence",
2674
- timestamp: presence.lat * 1000,
2675
- userID: userID || '',
2676
- statuses: presence.p
2677
- };
1472
+ if (presence.lat === undefined || presence.p === undefined) return null;
1473
+ return {
1474
+ type: "presence",
1475
+ timestamp: presence.lat * 1000,
1476
+ userID: userID,
1477
+ statuses: presence.p
1478
+ };
2678
1479
  }
2679
1480
 
2680
- /**
2681
- * @param {{ la: number; a: any; }} presence
2682
- * @param {any} userID
2683
- */
2684
-
2685
1481
  function formatPresence(presence, userID) {
2686
- return {
2687
- type: "presence",
2688
- timestamp: presence.la * 1000,
2689
- userID: userID || '',
2690
- statuses: presence.a
2691
- };
1482
+ return {
1483
+ type: "presence",
1484
+ timestamp: presence.la * 1000,
1485
+ userID: userID,
1486
+ statuses: presence.a
1487
+ };
2692
1488
  }
2693
1489
 
2694
- /**
2695
- * @param {any} payload
2696
- */
2697
-
2698
1490
  function decodeClientPayload(payload) {
2699
- /*
2700
- Special function which Client using to "encode" clients JSON payload
2701
- */
2702
-
2703
- /**
2704
- * @param {string | any[]} array
2705
- */
2706
-
2707
- function Utf8ArrayToStr(array) {
2708
- var out, i, len, c;
2709
- var char2, char3;
2710
- out = "";
2711
- len = array.length;
2712
- i = 0;
2713
- while (i < len) {
2714
- c = array[i++];
2715
- switch (c >> 4) {
2716
- case 0:
2717
- case 1:
2718
- case 2:
2719
- case 3:
2720
- case 4:
2721
- case 5:
2722
- case 6:
2723
- case 7:
2724
- out += String.fromCharCode(c);
2725
- break;
2726
- case 12:
2727
- case 13:
2728
- char2 = array[i++];
2729
- out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
2730
- break;
2731
- case 14:
2732
- char2 = array[i++];
2733
- char3 = array[i++];
2734
- out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
2735
- break;
2736
- }
2737
- }
2738
- return out;
2739
- }
2740
- return JSON.parse(Utf8ArrayToStr(payload));
1491
+ /*
1492
+ Special function which Client using to "encode" clients JSON payload
1493
+ */
1494
+ return JSON.parse(String.fromCharCode.apply(null, payload));
2741
1495
  }
2742
1496
 
2743
- /**
2744
- * @param {{ getCookies: (arg0: string) => string | any[]; }} jar
2745
- */
2746
-
2747
1497
  function getAppState(jar) {
2748
- return jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
2749
- }
2750
-
2751
- function getData_Path(Obj, Arr, Stt) {
2752
- //default stt = 0
2753
- if (Arr.length === 0 && Obj != undefined) {
2754
- return Obj; //object
2755
- }
2756
- else if (Obj == undefined) {
2757
- return Stt;
2758
- }
2759
- const head = Arr[0];
2760
- if (head == undefined) {
2761
- return Stt;
2762
- }
2763
- const tail = Arr.slice(1);
2764
- return getData_Path(Obj[head], tail, Stt++);
2765
- }
2766
-
2767
-
2768
- function setData_Path(obj, path, value) {
2769
- if (!path.length) {
2770
- return obj;
2771
- }
2772
- const currentKey = path[0];
2773
- let currentObj = obj[currentKey];
2774
-
2775
- if (!currentObj) {
2776
- obj[currentKey] = value;
2777
- currentObj = obj[currentKey];
2778
- }
2779
- path.shift();
2780
- if (!path.length) {
2781
- currentObj = value;
2782
- } else {
2783
- currentObj = setData_Path(currentObj, path, value);
2784
- }
2785
-
2786
- return obj;
2787
- }
2788
-
2789
- function getPaths(obj, parentPath = []) {
2790
- let paths = [];
2791
- for (let prop in obj) {
2792
- if (typeof obj[prop] === "object") {
2793
- paths = paths.concat(getPaths(obj[prop], [...parentPath, prop]));
2794
- } else {
2795
- paths.push([...parentPath, prop]);
2796
- }
2797
- }
2798
- return paths;
2799
- }
2800
-
2801
- function cleanHTML(text) {
2802
- text = text.replace(/(<br>)|(<\/?i>)|(<\/?em>)|(<\/?b>)|(!?~)|(&amp;)|(&#039;)|(&lt;)|(&gt;)|(&quot;)/g, (match) => {
2803
- switch (match) {
2804
- case "<br>":
2805
- return "\n";
2806
- case "<i>":
2807
- case "<em>":
2808
- case "</i>":
2809
- case "</em>":
2810
- return "*";
2811
- case "<b>":
2812
- case "</b>":
2813
- return "**";
2814
- case "~!":
2815
- case "!~":
2816
- return "||";
2817
- case "&amp;":
2818
- return "&";
2819
- case "&#039;":
2820
- return "'";
2821
- case "&lt;":
2822
- return "<";
2823
- case "&gt;":
2824
- return ">";
2825
- case "&quot;":
2826
- return '"';
2827
- }
2828
- });
2829
- return text;
1498
+ return jar
1499
+ .getCookies("https://www.facebook.com")
1500
+ .concat(jar.getCookies("https://facebook.com"))
1501
+ .concat(jar.getCookies("https://www.messenger.com"));
2830
1502
  }
2831
-
2832
1503
  module.exports = {
2833
- cleanHTML,
2834
- isReadableStream: isReadableStream,
2835
- get: get,
2836
- post: post,
2837
- postFormData: postFormData,
2838
- generateThreadingID: generateThreadingID,
2839
- generateOfflineThreadingID: generateOfflineThreadingID,
2840
- getGUID: getGUID,
2841
- getFrom: getFrom,
2842
- makeParsable: makeParsable,
2843
- arrToForm: arrToForm,
2844
- getSignatureID: getSignatureID,
2845
- getJar: request.jar,
2846
- generateTimestampRelative: generateTimestampRelative,
2847
- makeDefaults: makeDefaults,
2848
- parseAndCheckLogin: parseAndCheckLogin,
2849
- getGender: getGenderByPhysicalMethod,
2850
- getData_Path,
2851
- setData_Path,
2852
- getPaths,
2853
- saveCookies,
2854
- getType,
2855
- _formatAttachment,
2856
- formatHistoryMessage,
2857
- formatID,
2858
- formatMessage,
2859
- formatDeltaEvent,
2860
- formatDeltaMessage,
2861
- formatProxyPresence,
2862
- formatPresence,
2863
- formatTyp,
2864
- // formatDeltaReadReceipt,
2865
- formatCookie,
2866
- formatThread,
2867
- formatReadReceipt,
2868
- formatRead,
2869
- generatePresence,
2870
- generateAccessiblityCookie,
2871
- formatDate,
2872
- decodeClientPayload,
2873
- getAppState,
2874
- getAdminTextMessageType,
2875
- setProxy
2876
- };
1504
+ CustomError,
1505
+ isReadableStream,
1506
+ get,
1507
+ post,
1508
+ postFormData,
1509
+ generateThreadingID,
1510
+ generateOfflineThreadingID,
1511
+ getGUID,
1512
+ getFrom,
1513
+ makeParsable,
1514
+ arrToForm,
1515
+ getSignatureID,
1516
+ getJar: request.jar,
1517
+ generateTimestampRelative,
1518
+ makeDefaults,
1519
+ parseAndCheckLogin,
1520
+ saveCookies,
1521
+ getType,
1522
+ _formatAttachment,
1523
+ formatHistoryMessage,
1524
+ formatID,
1525
+ formatMessage,
1526
+ formatDeltaEvent,
1527
+ formatDeltaMessage,
1528
+ formatProxyPresence,
1529
+ formatPresence,
1530
+ formatTyp,
1531
+ formatDeltaReadReceipt,
1532
+ formatCookie,
1533
+ formatThread,
1534
+ formatReadReceipt,
1535
+ formatRead,
1536
+ generatePresence,
1537
+ generateAccessiblityCookie,
1538
+ formatDate,
1539
+ decodeClientPayload,
1540
+ getAppState,
1541
+ getAdminTextMessageType,
1542
+ setProxy,
1543
+ checkLiveCookie
1544
+ };
1545
+