thinhdev-meta-api 1.5.2 → 1.5.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/getThreadInfo.js +49 -282
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thinhdev-meta-api",
3
- "version": "1.5.2",
3
+ "version": "1.5.5",
4
4
  "description": "Facebook-chat-api protect and deploy by Kanzu and HZI Team",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,8 +1,8 @@
1
- /* eslint-disable linebreak-style */
2
1
  "use strict";
3
2
 
4
3
  var utils = require("../utils");
5
- // tương lai đi rồi fix ahahha
4
+ var log = require("npmlog");
5
+
6
6
  function formatEventReminders(reminder) {
7
7
  return {
8
8
  reminderID: reminder.id,
@@ -21,7 +21,7 @@ function formatEventReminders(reminder) {
21
21
  secondsToNotifyBefore: reminder.seconds_to_notify_before,
22
22
  allowsRsvp: reminder.allows_rsvp,
23
23
  relatedEvent: reminder.related_event,
24
- members: reminder.event_reminder_members.edges.map(function(member) {
24
+ members: reminder.event_reminder_members.edges.map(function (member) {
25
25
  return {
26
26
  memberID: member.node.id,
27
27
  state: member.guest_list_state.toLowerCase()
@@ -31,33 +31,15 @@ function formatEventReminders(reminder) {
31
31
  }
32
32
 
33
33
  function formatThreadGraphQLResponse(data) {
34
- try{
35
- var messageThread = data.message_thread;
36
- } catch (err){
37
- console.error("GetThreadInfoGraphQL", "Can't get this thread info!");
38
- return {err: err};
39
- }
40
- var threadID = messageThread.thread_key.thread_fbid
41
- ? messageThread.thread_key.thread_fbid
42
- : messageThread.thread_key.other_user_id;
34
+ var messageThread = data.o0.data.message_thread;
35
+ var threadID = messageThread.thread_key.thread_fbid ? messageThread.thread_key.thread_fbid : messageThread.thread_key.other_user_id;
43
36
 
44
37
  // Remove me
45
38
  var lastM = messageThread.last_message;
46
- var snippetID =
47
- lastM &&
48
- lastM.nodes &&
49
- lastM.nodes[0] &&
50
- lastM.nodes[0].message_sender &&
51
- lastM.nodes[0].message_sender.messaging_actor
52
- ? lastM.nodes[0].message_sender.messaging_actor.id
53
- : null;
54
- var snippetText =
55
- lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
39
+ var snippetID = lastM && lastM.nodes && lastM.nodes[0] && lastM.nodes[0].message_sender && lastM.nodes[0].message_sender.messaging_actor ? lastM.nodes[0].message_sender.messaging_actor.id : null;
40
+ var snippetText = lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
56
41
  var lastR = messageThread.last_read_receipt;
57
- var lastReadTimestamp =
58
- lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise
59
- ? lastR.nodes[0].timestamp_precise
60
- : null;
42
+ var lastReadTimestamp = lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise ? lastR.nodes[0].timestamp_precise : null;
61
43
 
62
44
  return {
63
45
  threadID: threadID,
@@ -84,27 +66,16 @@ function formatThreadGraphQLResponse(data) {
84
66
  isArchived: messageThread.has_viewer_archived,
85
67
  folder: messageThread.folder,
86
68
  cannotReplyReason: messageThread.cannot_reply_reason,
87
- eventReminders: messageThread.event_reminders
88
- ? messageThread.event_reminders.nodes.map(formatEventReminders)
89
- : null,
90
- emoji: messageThread.customization_info
91
- ? messageThread.customization_info.emoji
92
- : null,
93
- color:
94
- messageThread.customization_info &&
95
- messageThread.customization_info.outgoing_bubble_color
96
- ? messageThread.customization_info.outgoing_bubble_color.slice(2)
97
- : null,
69
+ eventReminders: messageThread.event_reminders ? messageThread.event_reminders.nodes.map(formatEventReminders) : null,
70
+ emoji: messageThread.customization_info ? messageThread.customization_info.emoji : null,
71
+ color: messageThread.customization_info && messageThread.customization_info.outgoing_bubble_color ? messageThread.customization_info.outgoing_bubble_color.slice(2) : null,
98
72
  nicknames:
99
73
  messageThread.customization_info &&
100
- messageThread.customization_info.participant_customizations
101
- ? messageThread.customization_info.participant_customizations.reduce(
102
- function(res, val) {
103
- if (val.nickname) res[val.participant_id] = val.nickname;
104
- return res;
105
- },
106
- {}
107
- )
74
+ messageThread.customization_info.participant_customizations
75
+ ? messageThread.customization_info.participant_customizations.reduce(function (res, val) {
76
+ if (val.nickname) res[val.participant_id] = val.nickname;
77
+ return res;
78
+ }, {})
108
79
  : {},
109
80
  adminIDs: messageThread.thread_admins,
110
81
  approvalMode: Boolean(messageThread.approval_mode),
@@ -134,27 +105,17 @@ function formatThreadGraphQLResponse(data) {
134
105
  hasEmailParticipant: false,
135
106
  readOnly: false,
136
107
  canReply: messageThread.cannot_reply_reason == null,
137
- lastMessageTimestamp: messageThread.last_message
138
- ? messageThread.last_message.timestamp_precise
139
- : null,
108
+ lastMessageTimestamp: messageThread.last_message ? messageThread.last_message.timestamp_precise : null,
140
109
  lastMessageType: "message",
141
110
  lastReadTimestamp: lastReadTimestamp,
142
- threadType: messageThread.thread_type == "GROUP" ? 2 : 1,
143
- TimeCreate: Date.now(),
144
- TimeUpdate: Date.now()
111
+ threadType: messageThread.thread_type == "GROUP" ? 2 : 1
145
112
  };
146
113
  }
147
114
 
148
- module.exports = function(defaultFuncs, api, ctx) {
149
-
150
- var { createData,getData,hasData,setLastRun,updateData, getAll } = require('../Extra/ExtraGetThread');
151
- var { capture } = require('../Extra/Src/Last-Run');
152
- var Database = require('../Extra/Database');
153
- global.Fca.Data.Userinfo = [];
154
-
155
- return async function getThreadInfoGraphQL(threadID, callback) {
156
- var resolveFunc = function(){};
157
- var rejectFunc = function(){};
115
+ module.exports = function (defaultFuncs, api, ctx) {
116
+ return function getThreadInfoGraphQL(threadID, callback) {
117
+ var resolveFunc = function () { };
118
+ var rejectFunc = function () { };
158
119
  var returnPromise = new Promise(function (resolve, reject) {
159
120
  resolveFunc = resolve;
160
121
  rejectFunc = reject;
@@ -162,243 +123,49 @@ module.exports = function(defaultFuncs, api, ctx) {
162
123
 
163
124
  if (utils.getType(callback) != "Function" && utils.getType(callback) != "AsyncFunction") {
164
125
  callback = function (err, data) {
165
- if (err) {
166
- return rejectFunc(err);
167
- }
126
+ if (err) return rejectFunc(err);
168
127
  resolveFunc(data);
169
128
  };
170
129
  }
171
130
 
172
- // được tìm thấy vào giữa tháng 8/2022 bởi @KanzuWakazaki - đã được chia sẻ cho @D-Jukie và Horizon Team Public group 🤴
173
- // những code tương tự muliti thread như này đều thể copy idea 🐧
174
- // đã áp dụng vào fca mới(cloud - fca(private)) vào cuối tháng 8/2022 bởi @IteralingCode(Hidden Member( always :) )) - Synthetic 4 - @Horizon Team
175
- //cập nhật dự án bị bỏ rơi này vào ngày 19/11/2022 bởi @KanzuWakazaki(Owner) - Synthetic 1 - @Horizon Team nhằm đáp ứng nhu cầu của client !
176
-
177
- if (utils.getType(threadID) !== "Array") threadID = [threadID];
178
-
179
-
180
- var SpecialMethod = function(TID) {
181
- const All = getAll();
182
- const Real = [];
183
- const Average = [];
184
- for (let i of All) {
185
- if (i.data.threadID != undefined) {
186
- if (i.data.TimeCreate + 900 * 1000 <= Date.now()) {
187
- Real.push(i.data.threadID);
188
- }
189
- else {
190
- Average.push({
191
- threadID: i.data.threadID,
192
- TimeCreate: i.data.TimeCreate
193
- });
194
- continue;
195
- }
196
- } else continue;
197
- }
198
- const AllofThread = [];
199
- if (Average.length > 0) {
200
- var Time = 0;
201
- for (let i of Average) {
202
- Time += i.TimeCreate;
203
- }
204
- Time = Time / Average.length;
205
- if (Time + 900 * 1000 <= Date.now()) {
206
- for (let i of Average) {
207
- Real.push(i.threadID);
208
- }
209
- } //can't =))
210
- else {
211
- setTimeout(function () {
212
- SpecialMethod(TID);
213
- }, Time + 900 * 1000 - Date.now());
214
- }
215
- }
216
- else {
217
- setTimeout(function () {
218
- SpecialMethod(TID);
219
- }, 900 * 1000);
220
- }
221
- if (Real.length == 0) return;
222
- else if (Real.length == 1) {
223
- return DefaultMethod(TID);
224
- }
225
- else if (All.length > 1) {
226
- for (let i of All) {
227
- if (i.data.threadID !== undefined) AllofThread.push(i.data.threadID);
228
- }
229
-
230
- const processChunk = (chunk) => {
231
- const Form = {};
232
- const ThreadInfo = new Map();
233
-
234
- for (let y = 0; y < chunk.length; y++) {
235
- const x = chunk[y];
236
- Form["o" + y] = {
237
- doc_id: "3449967031715030",
238
- query_params: { id: x, message_limit: 0, load_messages: false, load_read_receipts: false, before: null }
239
- };
240
- }
241
-
242
- const form = { queries: JSON.stringify(Form), batch_name: "MessengerGraphQLThreadFetcher" };
243
-
244
- defaultFuncs
245
- .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
246
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
247
- .then(resData => {
248
- if (resData.error || resData[resData.length - 1].error_results !== 0) throw "Lỗi: getThreadInfoGraphQL Có Thể Do Bạn Spam Quá Nhiều";
249
- for (let i = 0, len = resData.length - 1; i < len; i++) {
250
- const x = resData[i];
251
- const key = Object.keys(x)[0];
252
- ThreadInfo.set(x[key].data.threadID, formatThreadGraphQLResponse(x[key].data));
253
- }
254
- try {
255
- for (const [threadID, threadInfo] of ThreadInfo) {
256
- updateData(threadID, threadInfo);
257
- if (utils.getType(threadInfo.userInfo) === "Array") {
258
- for (const user of threadInfo.userInfo) {
259
- if (global.Fca.Data.Userinfo.some(u => u.id === user.id)) {
260
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(u => u.id === user.id), 1);
261
- }
262
- global.Fca.Data.Userinfo.push(user);
263
- }
264
- }
265
- }
266
- } catch (e) {
267
- console.log(e);
268
- }
269
- })
270
- .catch(() => { throw "Lỗi: getThreadInfoGraphQL Có Thể Do Bạn Spam Quá Nhiều"; });
271
-
272
- };
273
- for (const chunk of chunkArray(AllofThread, 5)) {
274
- processChunk(chunk);
275
- }
276
- }
277
- };
278
- function* chunkArray(arr, size) {
279
- for (let i = 0; i < arr.length; i += size) {
280
- yield arr.slice(i, i + size);
281
- }
282
- }
283
-
284
- var DefaultMethod = function(TID) {
285
- var ThreadInfo = [];
286
- for (let i of TID) {
287
- ThreadInfo.push(getData(i));
288
- }
289
- if (ThreadInfo.length == 1) {
290
- callback(null,ThreadInfo[0]);
291
- if (utils.getType(ThreadInfo[0].userInfo) == "Array") {
292
- for (let i of ThreadInfo[0].userInfo) {
293
- if (global.Fca.Data.Userinfo.some(ii => ii.id == i.id)) {
294
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(ii => ii.id == i.id), 1);
295
- }
296
- global.Fca.Data.Userinfo.push(i);
297
- }
298
- } else {
299
- for (let i of ThreadInfo) {
300
- if (utils.getType(i.userInfo) == "Array") {
301
- for (let ii of i.userInfo) {
302
- if (global.Fca.Data.Userinfo.some(iii => iii.id == ii.id)) {
303
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(iii => iii.id == ii.id), 1);
304
- }
305
- global.Fca.Data.Userinfo.push(ii);
306
- }
307
- }
308
- }
309
- callback(null,ThreadInfo);
310
- }
311
- }
312
- };
313
- var CreateMethod = function(TID) {
314
- var Form = {};
315
- var ThreadInfo = [];
316
-
317
- TID.map(function (x,y) {
318
- Form["o" + y] = {
131
+ // `queries` has to be a string. I couldn't tell from the dev console. This
132
+ // took me a really long time to figure out. I deserve a cookie for this.
133
+ var form = {
134
+ queries: JSON.stringify({
135
+ o0: {
136
+ // This doc_id is valid as of July 20th, 2020
319
137
  doc_id: "3449967031715030",
320
138
  query_params: {
321
- id: x,
139
+ id: threadID,
322
140
  message_limit: 0,
323
141
  load_messages: false,
324
142
  load_read_receipts: false,
325
143
  before: null
326
144
  }
327
- };
328
- });
145
+ }
146
+ }),
147
+ batch_name: "MessengerGraphQLThreadFetcher"
148
+ };
329
149
 
330
- var form = {
331
- queries: JSON.stringify(Form),
332
- batch_name: "MessengerGraphQLThreadFetcher"
333
- };
334
- defaultFuncs
150
+ defaultFuncs
335
151
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
336
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
337
- .then(function(resData) {
338
- if (resData.error) {
339
- throw resData.error;
340
- }
152
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
153
+ .then(function (resData) {
154
+ if (resData.error) throw resData;
155
+ // This returns us an array of things. The last one is the success /
156
+ // failure one.
157
+ // @TODO What do we do in this case?
341
158
  if (resData[resData.length - 1].error_results !== 0) {
342
- throw resData.error;
343
- }
344
- resData = resData.splice(0, resData.length - 1);
345
- resData.sort((a, b) => { return Object.keys(a)[0].localeCompare(Object.keys(b)[0]); });
346
- resData.map(function (x,y) {
347
- ThreadInfo.push(formatThreadGraphQLResponse(x["o"+y].data));
348
- });
349
- if (Object.keys(resData).length == 1) {
350
- createData(threadID,ThreadInfo[0]);
351
- callback(null, ThreadInfo[0]);
352
- capture(callback);
353
- setLastRun('LastUpdate', callback);
354
- if (global.Fca.Data.Userinfo == undefined) global.Fca.Data.Userinfo = [];
355
- if (utils.getType(ThreadInfo[0].userInfo) == "Array") {
356
- for (let i of ThreadInfo[0].userInfo) {
357
- if (global.Fca.Data.Userinfo.some(ii => ii.id == i.id)) {
358
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(ii => ii.id == i.id), 1);
359
- }
360
- global.Fca.Data.Userinfo.push(i);
361
- }
362
- }
363
- } else {
364
- // api.Horizon_Data([ThreadInfo], "Threads", "Post");
365
- for (let i of ThreadInfo) {
366
- createData(i.threadID,i);
367
- if (utils.getType(i.userInfo) == "Array") {
368
- for (let ii of i.userInfo) {
369
- if (global.Fca.Data.Userinfo.some(iii => iii.id == ii.id)) {
370
- global.Fca.Data.Userinfo.splice(global.Fca.Data.Userinfo.findIndex(iii => iii.id == ii.id), 1);
371
- }
372
- global.Fca.Data.Userinfo.push(ii);
373
- }
374
- }
375
- }
376
- callback(null, ThreadInfo);
159
+ console.log(resData); //Log more info
160
+ throw new Error("well darn there was an error_result");
377
161
  }
162
+ callback(null, formatThreadGraphQLResponse(resData[0]));
378
163
  })
379
- .catch(function(err){
380
- throw err;
164
+ .catch(function (err) {
165
+ log.error("getThreadInfoGraphQL", err);
166
+ return callback(err);
381
167
  });
382
- };
383
- if (global.Fca.Data.Already != true) { SpecialMethod(threadID); global.Fca.Data.Already = true; setInterval(function(){Database(true).set('UserInfo', global.Fca.Data.Userinfo); delete global.Fca.Data.Userinfo; global.Fca.Data.Userinfo = []; }, 900 * 1000); }
384
-
385
- try {
386
- for (let i of threadID) {
387
- switch (hasData(i)) {
388
- case true: {
389
- DefaultMethod(threadID);
390
- break;
391
- }
392
- case false: {
393
- CreateMethod(threadID);
394
- break;
395
- }
396
- }
397
- }
398
- }
399
- catch (err) {
400
- console.log(err);
401
- }
168
+
402
169
  return returnPromise;
403
170
  };
404
- };
171
+ };