vtuanhihi 0.0.1-security → 2.0.6

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

Potentially problematic release.


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

Files changed (113) hide show
  1. package/.editorconfig +12 -0
  2. package/.gitattributes +2 -0
  3. package/Extra/Database/index.js +469 -0
  4. package/Extra/ExtraAddons.js +82 -0
  5. package/Extra/ExtraFindUID.js +62 -0
  6. package/Extra/ExtraGetThread.js +340 -0
  7. package/Extra/ExtraScreenShot.js +430 -0
  8. package/Extra/ExtraUptimeRobot.js +38 -0
  9. package/Extra/Html/Classic/script.js +119 -0
  10. package/Extra/Html/Classic/style.css +8 -0
  11. package/Extra/Security/Index.js +173 -0
  12. package/Extra/Security/Step_1.js +6 -0
  13. package/Extra/Security/Step_2.js +22 -0
  14. package/Extra/Security/Step_3.js +22 -0
  15. package/Extra/Src/Change_Environment.js +24 -0
  16. package/Extra/Src/Check_Update.js +67 -0
  17. package/Extra/Src/History.js +115 -0
  18. package/Extra/Src/Instant_Update.js +65 -0
  19. package/Extra/Src/Last-Run.js +65 -0
  20. package/Extra/Src/Premium.js +81 -0
  21. package/Extra/Src/Release_Memory.js +41 -0
  22. package/Extra/Src/Websocket.js +213 -0
  23. package/Extra/Src/image/checkmate.jpg +0 -0
  24. package/Extra/Src/uuid.js +137 -0
  25. package/FastConfigFca.json +39 -0
  26. package/Func/AcceptAgreement.js +31 -0
  27. package/Func/ClearCache.js +64 -0
  28. package/Func/ReportV1.js +54 -0
  29. package/LICENSE +21 -0
  30. package/Language/index.json +218 -0
  31. package/Main.js +1192 -0
  32. package/README.md +140 -5
  33. package/SECURITY.md +18 -0
  34. package/broadcast.js +40 -0
  35. package/index.js +383 -0
  36. package/logger.js +66 -0
  37. package/package.json +95 -3
  38. package/src/Dev_Horizon_Data.js +125 -0
  39. package/src/Premium.js +25 -0
  40. package/src/Screenshot.js +83 -0
  41. package/src/addExternalModule.js +16 -0
  42. package/src/addUserToGroup.js +79 -0
  43. package/src/changeAdminStatus.js +79 -0
  44. package/src/changeArchivedStatus.js +41 -0
  45. package/src/changeAvt.js +85 -0
  46. package/src/changeBio.js +65 -0
  47. package/src/changeBlockedStatus.js +36 -0
  48. package/src/changeGroupImage.js +106 -0
  49. package/src/changeNickname.js +45 -0
  50. package/src/changeThreadColor.js +62 -0
  51. package/src/changeThreadEmoji.js +42 -0
  52. package/src/createNewGroup.js +70 -0
  53. package/src/createPoll.js +60 -0
  54. package/src/deleteMessage.js +45 -0
  55. package/src/deleteThread.js +43 -0
  56. package/src/forwardAttachment.js +48 -0
  57. package/src/getAccessToken.js +28 -0
  58. package/src/getCurrentUserID.js +7 -0
  59. package/src/getEmojiUrl.js +27 -0
  60. package/src/getFriendsList.js +73 -0
  61. package/src/getMessage.js +80 -0
  62. package/src/getThreadHistory.js +537 -0
  63. package/src/getThreadInfo.js +425 -0
  64. package/src/getThreadList.js +213 -0
  65. package/src/getThreadMain.js +220 -0
  66. package/src/getThreadPictures.js +59 -0
  67. package/src/getUID.js +59 -0
  68. package/src/getUserID.js +62 -0
  69. package/src/getUserInfo.js +113 -0
  70. package/src/getUserInfoMain.js +65 -0
  71. package/src/getUserInfoV2.js +32 -0
  72. package/src/getUserInfoV3.js +63 -0
  73. package/src/getUserInfoV4.js +55 -0
  74. package/src/getUserInfoV5.js +61 -0
  75. package/src/handleFriendRequest.js +46 -0
  76. package/src/handleMessageRequest.js +49 -0
  77. package/src/httpGet.js +49 -0
  78. package/src/httpPost.js +48 -0
  79. package/src/httpPostFormData.js +41 -0
  80. package/src/listenMqtt.js +787 -0
  81. package/src/logout.js +68 -0
  82. package/src/markAsDelivered.js +48 -0
  83. package/src/markAsRead.js +70 -0
  84. package/src/markAsReadAll.js +43 -0
  85. package/src/markAsSeen.js +51 -0
  86. package/src/muteThread.js +47 -0
  87. package/src/removeUserFromGroup.js +49 -0
  88. package/src/resolvePhotoUrl.js +37 -0
  89. package/src/searchForThread.js +43 -0
  90. package/src/sendMessage.js +379 -0
  91. package/src/sendTypingIndicator.js +80 -0
  92. package/src/setMessageReaction.js +109 -0
  93. package/src/setPostReaction.js +102 -0
  94. package/src/setTitle.js +74 -0
  95. package/src/threadColors.js +39 -0
  96. package/src/unfriend.js +43 -0
  97. package/src/unsendMessage.js +40 -0
  98. package/test/Data_/A_README.md +1 -0
  99. package/test/Data_/Database.db +0 -0
  100. package/test/Database_Test.js +4 -0
  101. package/test/Db2.js +530 -0
  102. package/test/data/shareAttach.js +146 -0
  103. package/test/data/something.mov +0 -0
  104. package/test/data/test.png +0 -0
  105. package/test/data/test.txt +7 -0
  106. package/test/env/.env +0 -0
  107. package/test/example-config.json +18 -0
  108. package/test/example-db.db +0 -0
  109. package/test/memoryleak.js +18 -0
  110. package/test/test-page.js +140 -0
  111. package/test/test.js +385 -0
  112. package/test/testv2.js +18 -0
  113. package/utils.js +1684 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ //var cheerio = require("cheerio");
4
+ var utils = require("../utils");
5
+ var log = require("npmlog");
6
+
7
+ // [almost] copy pasted from one of FB's minified file (GenderConst)
8
+ var GENDERS = {
9
+ 0: "unknown",
10
+ 1: "female_singular",
11
+ 2: "male_singular",
12
+ 3: "female_singular_guess",
13
+ 4: "male_singular_guess",
14
+ 5: "mixed",
15
+ 6: "neuter_singular",
16
+ 7: "unknown_singular",
17
+ 8: "female_plural",
18
+ 9: "male_plural",
19
+ 10: "neuter_plural",
20
+ 11: "unknown_plural"
21
+ };
22
+
23
+ function formatData(obj) {
24
+ return Object.keys(obj).map(function (key) {
25
+ var user = obj[key];
26
+ return {
27
+ alternateName: user.alternateName,
28
+ firstName: user.firstName,
29
+ gender: GENDERS[user.gender],
30
+ userID: utils.formatID(user.id.toString()),
31
+ isFriend: user.is_friend != null && user.is_friend ? true : false,
32
+ fullName: user.name,
33
+ profilePicture: user.thumbSrc,
34
+ type: user.type,
35
+ profileUrl: user.uri,
36
+ vanity: user.vanity,
37
+ isBirthday: !!user.is_birthday
38
+ };
39
+ });
40
+ }
41
+
42
+ module.exports = function (defaultFuncs, api, ctx) {
43
+ return function getFriendsList(callback) {
44
+ var resolveFunc = function () { };
45
+ var rejectFunc = function () { };
46
+ var returnPromise = new Promise(function (resolve, reject) {
47
+ resolveFunc = resolve;
48
+ rejectFunc = reject;
49
+ });
50
+
51
+ if (!callback) {
52
+ callback = function (err, friendList) {
53
+ if (err) return rejectFunc(err);
54
+ resolveFunc(friendList);
55
+ };
56
+ }
57
+
58
+ defaultFuncs
59
+ .postFormData("https://www.facebook.com/chat/user_info_all", ctx.jar, {}, { viewer: ctx.userID })
60
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
61
+ .then(function (resData) {
62
+ if (!resData) throw { error: "getFriendsList returned empty object." };
63
+ if (resData.error) throw resData;
64
+ callback(null, formatData(resData.payload));
65
+ })
66
+ .catch(function (err) {
67
+ log.error("getFriendsList", "Lỗi getFriendsList Có Thể Do Bạn Spam Quá Nhiều ! Hãy Hạn Chế !");
68
+ return callback(err);
69
+ });
70
+
71
+ return returnPromise;
72
+ };
73
+ };
@@ -0,0 +1,80 @@
1
+ /* eslint-disable linebreak-style */
2
+ "use strict";
3
+
4
+ var utils = require("../utils");
5
+ var log = require("npmlog");
6
+
7
+ module.exports = function(defaultFuncs, api, ctx) {
8
+ return function getMessage(threadID, messageID, callback) {
9
+ if (!callback) {
10
+ return callback({ error: "getMessage: need callback" });
11
+ }
12
+
13
+ if (!threadID || !messageID) {
14
+ return callback({ error: "getMessage: need threadID and messageID" });
15
+ }
16
+
17
+ const form = {
18
+ "av": ctx.globalOptions.pageID,
19
+ "queries": JSON.stringify({
20
+ "o0": {
21
+ //This doc_id is valid as of ? (prob January 18, 2020)
22
+ "doc_id": "1768656253222505",
23
+ "query_params": {
24
+ "thread_and_message_id": {
25
+ "thread_id": threadID,
26
+ "message_id": messageID,
27
+ }
28
+ }
29
+ }
30
+ })
31
+ };
32
+
33
+ defaultFuncs
34
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
35
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
+ .then((resData) => {
37
+ if (resData[resData.length - 1].error_results > 0) {
38
+ throw resData[0].o0.errors;
39
+ }
40
+
41
+ if (resData[resData.length - 1].successful_results === 0) {
42
+ throw { error: "getMessage: there was no successful_results", res: resData };
43
+ }
44
+
45
+ var fetchData = resData[0].o0.data.message;
46
+ if (fetchData) {
47
+ (!ctx.globalOptions.selfListen &&
48
+ fetchData.message_sender.id.toString() === ctx.userID) ||
49
+ !ctx.loggedIn ?
50
+ undefined :
51
+ (function () { callback(null, {
52
+ threadID: threadID,
53
+ messageID: fetchData.message_id,
54
+ senderID: fetchData.message_sender.id,
55
+ attachments: fetchData.blob_attachments.map(att => {
56
+ var x;
57
+ try {
58
+ x = utils._formatAttachment(att);
59
+ } catch (ex) {
60
+ x = att;
61
+ x.error = ex;
62
+ x.type = "unknown";
63
+ }
64
+ return x;
65
+ }),
66
+ body: fetchData.message.text,
67
+ mentions: fetchData.message.ranges,
68
+ timestamp: fetchData.timestamp_precise,
69
+ messageReply: fetchData.replied_to_message,
70
+ raw: fetchData,
71
+ }); })();
72
+ }
73
+ })
74
+ .catch((err) => {
75
+ log.error("getMessage", err);
76
+ callback(err);
77
+ });
78
+
79
+ };
80
+ };
@@ -0,0 +1,537 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ function formatAttachmentsGraphQLResponse(attachment) {
7
+ switch (attachment.__typename) {
8
+ case "MessageImage":
9
+ return {
10
+ type: "photo",
11
+ ID: attachment.legacy_attachment_id,
12
+ filename: attachment.filename,
13
+ thumbnailUrl: attachment.thumbnail.uri,
14
+
15
+ previewUrl: attachment.preview.uri,
16
+ previewWidth: attachment.preview.width,
17
+ previewHeight: attachment.preview.height,
18
+
19
+ largePreviewUrl: attachment.large_preview.uri,
20
+ largePreviewHeight: attachment.large_preview.height,
21
+ largePreviewWidth: attachment.large_preview.width,
22
+
23
+ // You have to query for the real image. See below.
24
+ url: attachment.large_preview.uri, // @Legacy
25
+ width: attachment.large_preview.width, // @Legacy
26
+ height: attachment.large_preview.height, // @Legacy
27
+ name: attachment.filename, // @Legacy
28
+
29
+ // @Undocumented
30
+ attributionApp: attachment.attribution_app
31
+ ? {
32
+ attributionAppID: attachment.attribution_app.id,
33
+ name: attachment.attribution_app.name,
34
+ logo: attachment.attribution_app.square_logo
35
+ }
36
+ : null
37
+
38
+ // @TODO No idea what this is, should we expose it?
39
+ // Ben - July 15th 2017
40
+ // renderAsSticker: attachment.render_as_sticker,
41
+
42
+ // This is _not_ the real URI, this is still just a large preview.
43
+ // To get the URL we'll need to support a POST query to
44
+ //
45
+ // https://www.facebook.com/webgraphql/query/
46
+ //
47
+ // With the following query params:
48
+ //
49
+ // query_id:728987990612546
50
+ // variables:{"id":"100009069356507","photoID":"10213724771692996"}
51
+ // dpr:1
52
+ //
53
+ // No special form though.
54
+ };
55
+ case "MessageAnimatedImage":
56
+ return {
57
+ type: "animated_image",
58
+ ID: attachment.legacy_attachment_id,
59
+ filename: attachment.filename,
60
+
61
+ previewUrl: attachment.preview_image.uri,
62
+ previewWidth: attachment.preview_image.width,
63
+ previewHeight: attachment.preview_image.height,
64
+
65
+ url: attachment.animated_image.uri,
66
+ width: attachment.animated_image.width,
67
+ height: attachment.animated_image.height,
68
+
69
+ thumbnailUrl: attachment.preview_image.uri, // @Legacy
70
+ name: attachment.filename, // @Legacy
71
+ facebookUrl: attachment.animated_image.uri, // @Legacy
72
+ rawGifImage: attachment.animated_image.uri, // @Legacy
73
+ animatedGifUrl: attachment.animated_image.uri, // @Legacy
74
+ animatedGifPreviewUrl: attachment.preview_image.uri, // @Legacy
75
+ animatedWebpUrl: attachment.animated_image.uri, // @Legacy
76
+ animatedWebpPreviewUrl: attachment.preview_image.uri, // @Legacy
77
+
78
+ // @Undocumented
79
+ attributionApp: attachment.attribution_app
80
+ ? {
81
+ attributionAppID: attachment.attribution_app.id,
82
+ name: attachment.attribution_app.name,
83
+ logo: attachment.attribution_app.square_logo
84
+ }
85
+ : null
86
+ };
87
+ case "MessageVideo":
88
+ return {
89
+ type: "video",
90
+ filename: attachment.filename,
91
+ ID: attachment.legacy_attachment_id,
92
+
93
+ thumbnailUrl: attachment.large_image.uri, // @Legacy
94
+
95
+ previewUrl: attachment.large_image.uri,
96
+ previewWidth: attachment.large_image.width,
97
+ previewHeight: attachment.large_image.height,
98
+
99
+ url: attachment.playable_url,
100
+ width: attachment.original_dimensions.x,
101
+ height: attachment.original_dimensions.y,
102
+
103
+ duration: attachment.playable_duration_in_ms,
104
+ videoType: attachment.video_type.toLowerCase()
105
+ };
106
+ case "MessageFile":
107
+ return {
108
+ type: "file",
109
+ filename: attachment.filename,
110
+ ID: attachment.message_file_fbid,
111
+
112
+ url: attachment.url,
113
+ isMalicious: attachment.is_malicious,
114
+ contentType: attachment.content_type,
115
+
116
+ name: attachment.filename, // @Legacy
117
+ mimeType: "", // @Legacy
118
+ fileSize: -1 // @Legacy
119
+ };
120
+ case "MessageAudio":
121
+ return {
122
+ type: "audio",
123
+ filename: attachment.filename,
124
+ ID: attachment.url_shimhash, // Not fowardable
125
+
126
+ audioType: attachment.audio_type,
127
+ duration: attachment.playable_duration_in_ms,
128
+ url: attachment.playable_url,
129
+
130
+ isVoiceMail: attachment.is_voicemail
131
+ };
132
+ default:
133
+ return {
134
+ error: "Don't know about attachment type " + attachment.__typename
135
+ };
136
+ }
137
+ }
138
+
139
+ function formatExtensibleAttachment(attachment) {
140
+ if (attachment.story_attachment) {
141
+ return {
142
+ type: "share",
143
+ ID: attachment.legacy_attachment_id,
144
+ url: attachment.story_attachment.url,
145
+
146
+ title: attachment.story_attachment.title_with_entities.text,
147
+ description: attachment.story_attachment.description && attachment.story_attachment.description.text,
148
+ source: attachment.story_attachment.source == null ? null : attachment.story_attachment.source.text,
149
+
150
+ image: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).uri,
151
+ width: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).width,
152
+ height: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).height,
153
+ playable: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.is_playable,
154
+ duration: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.playable_duration_in_ms,
155
+ playableUrl: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.playable_url,
156
+
157
+ subattachments: attachment.story_attachment.subattachments,
158
+
159
+ // Format example:
160
+ //
161
+ // [{
162
+ // key: "width",
163
+ // value: { text: "1280" }
164
+ // }]
165
+ //
166
+ // That we turn into:
167
+ //
168
+ // {
169
+ // width: "1280"
170
+ // }
171
+ //
172
+ properties: attachment.story_attachment.properties.reduce(function (obj, cur) {
173
+ obj[cur.key] = cur.value.text;
174
+ return obj;
175
+ }, {}),
176
+
177
+ // Deprecated fields
178
+ animatedImageSize: "", // @Legacy
179
+ facebookUrl: "", // @Legacy
180
+ styleList: "", // @Legacy
181
+ target: "", // @Legacy
182
+ thumbnailUrl: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).uri, // @Legacy
183
+ thumbnailWidth: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).width, // @Legacy
184
+ thumbnailHeight: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).height // @Legacy
185
+ };
186
+ }
187
+ else return { error: "Don't know what to do with extensible_attachment." };
188
+ }
189
+
190
+ function formatReactionsGraphQL(reaction) {
191
+ return {
192
+ reaction: reaction.reaction,
193
+ userID: reaction.user.id
194
+ };
195
+ }
196
+
197
+ function formatEventData(event) {
198
+ if (event == null) return {};
199
+
200
+ switch (event.__typename) {
201
+ case "ThemeColorExtensibleMessageAdminText":
202
+ return { color: event.theme_color };
203
+ case "ThreadNicknameExtensibleMessageAdminText":
204
+ return {
205
+ nickname: event.nickname,
206
+ participantID: event.participant_id
207
+ };
208
+ case "ThreadIconExtensibleMessageAdminText":
209
+ return { threadIcon: event.thread_icon };
210
+ case "InstantGameUpdateExtensibleMessageAdminText":
211
+ return {
212
+ gameID: (event.game == null ? null : event.game.id),
213
+ update_type: event.update_type,
214
+ collapsed_text: event.collapsed_text,
215
+ expanded_text: event.expanded_text,
216
+ instant_game_update_data: event.instant_game_update_data
217
+ };
218
+ case "GameScoreExtensibleMessageAdminText":
219
+ return { game_type: event.game_type };
220
+ case "RtcCallLogExtensibleMessageAdminText":
221
+ return {
222
+ event: event.event,
223
+ is_video_call: event.is_video_call,
224
+ server_info_data: event.server_info_data
225
+ };
226
+ case "GroupPollExtensibleMessageAdminText":
227
+ return {
228
+ event_type: event.event_type,
229
+ total_count: event.total_count,
230
+ question: event.question
231
+ };
232
+ case "AcceptPendingThreadExtensibleMessageAdminText":
233
+ return {
234
+ accepter_id: event.accepter_id,
235
+ requester_id: event.requester_id
236
+ };
237
+ case "ConfirmFriendRequestExtensibleMessageAdminText":
238
+ return {
239
+ friend_request_recipient: event.friend_request_recipient,
240
+ friend_request_sender: event.friend_request_sender
241
+ };
242
+ case "AddContactExtensibleMessageAdminText":
243
+ return {
244
+ contact_added_id: event.contact_added_id,
245
+ contact_adder_id: event.contact_adder_id
246
+ };
247
+ case "AdExtensibleMessageAdminText":
248
+ return {
249
+ ad_client_token: event.ad_client_token,
250
+ ad_id: event.ad_id,
251
+ ad_preferences_link: event.ad_preferences_link,
252
+ ad_properties: event.ad_properties
253
+ };
254
+ // never data
255
+ case "ParticipantJoinedGroupCallExtensibleMessageAdminText":
256
+ case "ThreadEphemeralTtlModeExtensibleMessageAdminText":
257
+ case "StartedSharingVideoExtensibleMessageAdminText":
258
+ case "LightweightEventCreateExtensibleMessageAdminText":
259
+ case "LightweightEventNotifyExtensibleMessageAdminText":
260
+ case "LightweightEventNotifyBeforeEventExtensibleMessageAdminText":
261
+ case "LightweightEventUpdateTitleExtensibleMessageAdminText":
262
+ case "LightweightEventUpdateTimeExtensibleMessageAdminText":
263
+ case "LightweightEventUpdateLocationExtensibleMessageAdminText":
264
+ case "LightweightEventDeleteExtensibleMessageAdminText":
265
+ return {};
266
+ default:
267
+ return { error: "Don't know what to with event data type " + event.__typename };
268
+ }
269
+ }
270
+
271
+ function formatMessagesGraphQLResponse(data) {
272
+ var messageThread = data.o0.data.message_thread;
273
+ var threadID = messageThread.thread_key.thread_fbid ? messageThread.thread_key.thread_fbid : messageThread.thread_key.other_user_id;
274
+
275
+ var messages = messageThread.messages.nodes.map(function (d) {
276
+ switch (d.__typename) {
277
+ case "UserMessage":
278
+ // Give priority to stickers. They're seen as normal messages but we've
279
+ // been considering them as attachments.
280
+ var maybeStickerAttachment;
281
+ if (d.sticker) {
282
+ maybeStickerAttachment = [
283
+ {
284
+ type: "sticker",
285
+ ID: d.sticker.id,
286
+ url: d.sticker.url,
287
+
288
+ packID: d.sticker.pack.id,
289
+ spriteUrl: d.sticker.sprite_image,
290
+ spriteUrl2x: d.sticker.sprite_image_2x,
291
+ width: d.sticker.width,
292
+ height: d.sticker.height,
293
+
294
+ caption: d.snippet, // Not sure what the heck caption was.
295
+ description: d.sticker.label, // Not sure about this one either.
296
+
297
+ frameCount: d.sticker.frame_count,
298
+ frameRate: d.sticker.frame_rate,
299
+ framesPerRow: d.sticker.frames_per_row,
300
+ framesPerCol: d.sticker.frames_per_col,
301
+
302
+ stickerID: d.sticker.id, // @Legacy
303
+ spriteURI: d.sticker.sprite_image, // @Legacy
304
+ spriteURI2x: d.sticker.sprite_image_2x // @Legacy
305
+ }
306
+ ];
307
+ }
308
+
309
+ var mentionsObj = {};
310
+ if (d.message !== null) {
311
+ d.message.ranges.forEach(e => mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length));
312
+ }
313
+
314
+ return {
315
+ type: "message",
316
+ attachments: maybeStickerAttachment
317
+ ? maybeStickerAttachment
318
+ : d.blob_attachments && d.blob_attachments.length > 0
319
+ ? d.blob_attachments.map(formatAttachmentsGraphQLResponse)
320
+ : d.extensible_attachment
321
+ ? [formatExtensibleAttachment(d.extensible_attachment)]
322
+ : [],
323
+ body: d.message !== null ? d.message.text : '',
324
+ isGroup: messageThread.thread_type === "GROUP",
325
+ messageID: d.message_id,
326
+ senderID: d.message_sender.id,
327
+ threadID: threadID,
328
+ timestamp: d.timestamp_precise,
329
+
330
+ mentions: mentionsObj,
331
+ isUnread: d.unread,
332
+
333
+ // New
334
+ messageReactions: d.message_reactions ? d.message_reactions.map(formatReactionsGraphQL) : null,
335
+ isSponsored: d.is_sponsored,
336
+ snippet: d.snippet
337
+ };
338
+ case "ThreadNameMessage":
339
+ return {
340
+ type: "event",
341
+ messageID: d.message_id,
342
+ threadID: threadID,
343
+ isGroup: messageThread.thread_type === "GROUP",
344
+ senderID: d.message_sender.id,
345
+ timestamp: d.timestamp_precise,
346
+ eventType: "change_thread_name",
347
+ snippet: d.snippet,
348
+ eventData: { threadName: d.thread_name },
349
+
350
+ // @Legacy
351
+ author: d.message_sender.id,
352
+ logMessageType: "log:thread-name",
353
+ logMessageData: { name: d.thread_name }
354
+ };
355
+ case "ThreadImageMessage":
356
+ return {
357
+ type: "event",
358
+ messageID: d.message_id,
359
+ threadID: threadID,
360
+ isGroup: messageThread.thread_type === "GROUP",
361
+ senderID: d.message_sender.id,
362
+ timestamp: d.timestamp_precise,
363
+ eventType: "change_thread_image",
364
+ snippet: d.snippet,
365
+ eventData: d.image_with_metadata == null
366
+ ? {} /* removed image */
367
+ : {
368
+ /* image added */
369
+ threadImage: {
370
+ attachmentID: d.image_with_metadata.legacy_attachment_id,
371
+ width: d.image_with_metadata.original_dimensions.x,
372
+ height: d.image_with_metadata.original_dimensions.y,
373
+ url: d.image_with_metadata.preview.uri
374
+ }
375
+ },
376
+
377
+ // @Legacy
378
+ logMessageType: "log:thread-icon",
379
+ logMessageData: { thread_icon: d.image_with_metadata ? d.image_with_metadata.preview.uri : null }
380
+ };
381
+ case "ParticipantLeftMessage":
382
+ return {
383
+ type: "event",
384
+ messageID: d.message_id,
385
+ threadID: threadID,
386
+ isGroup: messageThread.thread_type === "GROUP",
387
+ senderID: d.message_sender.id,
388
+ timestamp: d.timestamp_precise,
389
+ eventType: "remove_participants",
390
+ snippet: d.snippet,
391
+ eventData: {
392
+ // Array of IDs.
393
+ participantsRemoved: d.participants_removed.map(function (p) {
394
+ return p.id;
395
+ })
396
+ },
397
+
398
+ // @Legacy
399
+ logMessageType: "log:unsubscribe",
400
+ logMessageData: {
401
+ leftParticipantFbId: d.participants_removed.map(function (p) {
402
+ return p.id;
403
+ })
404
+ }
405
+ };
406
+ case "ParticipantsAddedMessage":
407
+ return {
408
+ type: "event",
409
+ messageID: d.message_id,
410
+ threadID: threadID,
411
+ isGroup: messageThread.thread_type === "GROUP",
412
+ senderID: d.message_sender.id,
413
+ timestamp: d.timestamp_precise,
414
+ eventType: "add_participants",
415
+ snippet: d.snippet,
416
+ eventData: {
417
+ // Array of IDs.
418
+ participantsAdded: d.participants_added.map(function (p) {
419
+ return p.id;
420
+ })
421
+ },
422
+
423
+ // @Legacy
424
+ logMessageType: "log:subscribe",
425
+ logMessageData: {
426
+ addedParticipants: d.participants_added.map(function (p) {
427
+ return p.id;
428
+ })
429
+ }
430
+ };
431
+ case "VideoCallMessage":
432
+ return {
433
+ type: "event",
434
+ messageID: d.message_id,
435
+ threadID: threadID,
436
+ isGroup: messageThread.thread_type === "GROUP",
437
+ senderID: d.message_sender.id,
438
+ timestamp: d.timestamp_precise,
439
+ eventType: "video_call",
440
+ snippet: d.snippet,
441
+
442
+ // @Legacy
443
+ logMessageType: "other"
444
+ };
445
+ case "VoiceCallMessage":
446
+ return {
447
+ type: "event",
448
+ messageID: d.message_id,
449
+ threadID: threadID,
450
+ isGroup: messageThread.thread_type === "GROUP",
451
+ senderID: d.message_sender.id,
452
+ timestamp: d.timestamp_precise,
453
+ eventType: "voice_call",
454
+ snippet: d.snippet,
455
+
456
+ // @Legacy
457
+ logMessageType: "other"
458
+ };
459
+ case "GenericAdminTextMessage":
460
+ return {
461
+ type: "event",
462
+ messageID: d.message_id,
463
+ threadID: threadID,
464
+ isGroup: messageThread.thread_type === "GROUP",
465
+ senderID: d.message_sender.id,
466
+ timestamp: d.timestamp_precise,
467
+ snippet: d.snippet,
468
+ eventType: d.extensible_message_admin_text_type.toLowerCase(),
469
+ eventData: formatEventData(d.extensible_message_admin_text),
470
+
471
+ // @Legacy
472
+ logMessageType: utils.getAdminTextMessageType(
473
+ d.extensible_message_admin_text_type
474
+ ),
475
+ logMessageData: d.extensible_message_admin_text // Maybe different?
476
+ };
477
+ default:
478
+ return { error: "Don't know about message type " + d.__typename };
479
+ }
480
+ });
481
+ return messages;
482
+ }
483
+
484
+ module.exports = function (defaultFuncs, api, ctx) {
485
+ return function getThreadHistoryGraphQL(threadID, amount, timestamp, callback) {
486
+ var resolveFunc = function () { };
487
+ var rejectFunc = function () { };
488
+ var returnPromise = new Promise(function (resolve, reject) {
489
+ resolveFunc = resolve;
490
+ rejectFunc = reject;
491
+ });
492
+
493
+ if (!callback) {
494
+ callback = function (err, data) {
495
+ if (err) return rejectFunc(err);
496
+ resolveFunc(data);
497
+ };
498
+ }
499
+
500
+ // `queries` has to be a string. I couldn't tell from the dev console. This
501
+ // took me a really long time to figure out. I deserve a cookie for this.
502
+ var form = {
503
+ "av": ctx.globalOptions.pageID,
504
+ queries: JSON.stringify({
505
+ o0: {
506
+ // This doc_id was valid on February 2nd 2017.
507
+ doc_id: "1498317363570230",
508
+ query_params: {
509
+ id: threadID,
510
+ message_limit: amount,
511
+ load_messages: 1,
512
+ load_read_receipts: false,
513
+ before: timestamp
514
+ }
515
+ }
516
+ })
517
+ };
518
+
519
+ defaultFuncs
520
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
521
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
522
+ .then(function (resData) {
523
+ if (resData.error) throw resData;
524
+ // This returns us an array of things. The last one is the success /
525
+ // failure one.
526
+ // @TODO What do we do in this case?
527
+ if (resData[resData.length - 1].error_results !== 0) throw new Error("There was an error_result.");
528
+ callback(null, formatMessagesGraphQLResponse(resData[0]));
529
+ })
530
+ .catch(function (err) {
531
+ log.error("getThreadHistoryGraphQL", "Lỗi getThreadHistoryGraphQL Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !");
532
+ return callback(err);
533
+ });
534
+
535
+ return returnPromise;
536
+ };
537
+ };