fca-dragon 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.gitattributes +2 -0
- package/Extra/Bypass/956/index.js +234 -0
- package/Extra/Bypass/test/aaaa.json +170 -0
- package/Extra/Bypass/test/index.js +188 -0
- package/Extra/Database/index.js +469 -0
- package/Extra/ExtraAddons.js +82 -0
- package/Extra/ExtraFindUID.js +62 -0
- package/Extra/ExtraGetThread.js +365 -0
- package/Extra/ExtraScreenShot.js +430 -0
- package/Extra/ExtraUptimeRobot.js +38 -0
- package/Extra/Html/Classic/script.js +119 -0
- package/Extra/Html/Classic/style.css +8 -0
- package/Extra/Security/AES_256_GCM/index.js +0 -0
- package/Extra/Security/Base/Step_1.js +6 -0
- package/Extra/Security/Base/Step_2.js +22 -0
- package/Extra/Security/Base/Step_3.js +22 -0
- package/Extra/Security/Base/index.js +191 -0
- package/Extra/Security/Index.js +5 -0
- package/Extra/Security/Step_1.js +6 -0
- package/Extra/Security/Step_2.js +22 -0
- package/Extra/Security/Step_3.js +22 -0
- package/Extra/Src/Change_Environment.js +24 -0
- package/Extra/Src/Check_Update.js +67 -0
- package/Extra/Src/History.js +115 -0
- package/Extra/Src/Instant_Update.js +65 -0
- package/Extra/Src/Last-Run.js +65 -0
- package/Extra/Src/Premium.js +81 -0
- package/Extra/Src/Release_Memory.js +160 -0
- package/Extra/Src/Websocket.js +213 -0
- package/Extra/Src/image/checkmate.jpg +0 -0
- package/Extra/Src/test.js +28 -0
- package/Extra/Src/uuid.js +137 -0
- package/FastConfigFca.json +56 -0
- package/Func/AcceptAgreement.js +31 -0
- package/Func/ClearCache.js +64 -0
- package/Func/ReportV1.js +54 -0
- package/LICENSE +21 -0
- package/Language/index.json +220 -0
- package/Main.js +1062 -0
- package/README.md +128 -0
- package/SECURITY.md +18 -0
- package/broadcast.js +44 -0
- package/index.js +428 -0
- package/logger.js +66 -0
- package/package.json +93 -0
- package/src/Dev_Horizon_Data.js +125 -0
- package/src/Dev_shareTest2.js +68 -0
- package/src/Dev_shareTest3.js +71 -0
- package/src/Premium.js +25 -0
- package/src/Screenshot.js +83 -0
- package/src/addExternalModule.js +16 -0
- package/src/addUserToGroup.js +79 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +41 -0
- package/src/changeAvt.js +85 -0
- package/src/changeBio.js +65 -0
- package/src/changeBlockedStatus.js +36 -0
- package/src/changeGroupImage.js +106 -0
- package/src/changeNickname.js +45 -0
- package/src/changeThreadColor.js +62 -0
- package/src/changeThreadEmoji.js +42 -0
- package/src/createNewGroup.js +70 -0
- package/src/createPoll.js +60 -0
- package/src/deleteMessage.js +45 -0
- package/src/deleteThread.js +43 -0
- package/src/editMessage.js +53 -0
- package/src/forwardAttachment.js +48 -0
- package/src/getAccessToken.js +28 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +27 -0
- package/src/getFriendsList.js +73 -0
- package/src/getMessage.js +103 -0
- package/src/getThreadHistory.js +537 -0
- package/src/getThreadInfo.js +415 -0
- package/src/getThreadInfoOLD.js +422 -0
- package/src/getThreadList.js +213 -0
- package/src/getThreadMain.js +220 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getUID.js +59 -0
- package/src/getUserID.js +62 -0
- package/src/getUserInfo.js +113 -0
- package/src/getUserInfoMain.js +65 -0
- package/src/getUserInfoV2.js +32 -0
- package/src/getUserInfoV3.js +63 -0
- package/src/getUserInfoV4.js +55 -0
- package/src/getUserInfoV5.js +61 -0
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +49 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/httpPostFormData.js +41 -0
- package/src/listenMqtt.js +929 -0
- package/src/listenMqttV1.js +846 -0
- package/src/logout.js +68 -0
- package/src/markAsDelivered.js +48 -0
- package/src/markAsRead.js +70 -0
- package/src/markAsReadAll.js +43 -0
- package/src/markAsSeen.js +51 -0
- package/src/muteThread.js +47 -0
- package/src/removeUserFromGroup.js +49 -0
- package/src/resolvePhotoUrl.js +37 -0
- package/src/searchForThread.js +43 -0
- package/src/sendMessage.js +386 -0
- package/src/sendMqttMessage.js +71 -0
- package/src/sendTypingIndicator.js +80 -0
- package/src/setMessageReaction.js +109 -0
- package/src/setPostReaction.js +102 -0
- package/src/setTitle.js +74 -0
- package/src/shareContact.js +55 -0
- package/src/shareLink.js +58 -0
- package/src/threadColors.js +39 -0
- package/src/unfriend.js +43 -0
- package/src/unsendMessage.js +40 -0
- package/test/Database_Test.js +4 -0
- package/test/Db2.js +530 -0
- package/test/Horizon_Database/A_README.md +1 -0
- package/test/Horizon_Database/Database.db +0 -0
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +7 -0
- package/test/env/.env +0 -0
- package/test/example-config.json +18 -0
- package/test/example-db.db +0 -0
- package/test/memoryleak.js +18 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/test/testname.js +1342 -0
- package/test/testv2.js +3 -0
- package/utils.js +3006 -0
@@ -0,0 +1,929 @@
|
|
1
|
+
/* eslint-disable linebreak-style */
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
const utils = require('../utils');
|
5
|
+
const log = require('npmlog');
|
6
|
+
const mqtt = require('mqtt');
|
7
|
+
const WebSocket = require('ws');
|
8
|
+
const HttpsProxyAgent = require('https-proxy-agent');
|
9
|
+
const EventEmitter = require('events');
|
10
|
+
const Duplexify = require('duplexify');
|
11
|
+
const {
|
12
|
+
Transform
|
13
|
+
} = require('stream');
|
14
|
+
var identity = function() {};
|
15
|
+
var form = {};
|
16
|
+
var getSeqID = function() {};
|
17
|
+
global.Fca.Data.MsgCount = new Map();
|
18
|
+
global.Fca.Data.event = new Map();
|
19
|
+
|
20
|
+
const topics = ['/ls_req', '/ls_resp', '/legacy_web', '/webrtc', '/rtc_multi', '/onevc', '/br_sr', '/sr_res', '/t_ms', '/thread_typing', '/orca_typing_notifications', '/notify_disconnect', '/orca_presence', '/inbox', '/mercury', '/messaging_events', '/orca_message_notifications', '/pp', '/webrtc_response'];
|
21
|
+
|
22
|
+
let WebSocket_Global;
|
23
|
+
|
24
|
+
function buildProxy() {
|
25
|
+
const Proxy = new Transform({
|
26
|
+
objectMode: false,
|
27
|
+
transform(chunk, enc, next) {
|
28
|
+
if (WebSocket_Global.readyState !== WebSocket_Global.OPEN) {
|
29
|
+
return next();
|
30
|
+
}
|
31
|
+
|
32
|
+
let data;
|
33
|
+
if (typeof chunk === 'string') {
|
34
|
+
data = Buffer.from(chunk, 'utf8');
|
35
|
+
} else {
|
36
|
+
data = chunk;
|
37
|
+
}
|
38
|
+
|
39
|
+
WebSocket_Global.send(data);
|
40
|
+
next();
|
41
|
+
},
|
42
|
+
flush(done) {
|
43
|
+
WebSocket_Global.close();
|
44
|
+
done();
|
45
|
+
},
|
46
|
+
writev(chunks, cb) {
|
47
|
+
const buffers = chunks.map(({ chunk }) => {
|
48
|
+
if (typeof chunk === 'string') {
|
49
|
+
return Buffer.from(chunk, 'utf8');
|
50
|
+
}
|
51
|
+
return chunk;
|
52
|
+
});
|
53
|
+
this._write(Buffer.concat(buffers), 'binary', cb);
|
54
|
+
},
|
55
|
+
});
|
56
|
+
return Proxy;
|
57
|
+
}
|
58
|
+
|
59
|
+
function buildStream(options, WebSocket, Proxy) {
|
60
|
+
const Stream = Duplexify(undefined, undefined, options);
|
61
|
+
Stream.socket = WebSocket;
|
62
|
+
|
63
|
+
WebSocket.onclose = () => {
|
64
|
+
Stream.end();
|
65
|
+
Stream.destroy();
|
66
|
+
};
|
67
|
+
|
68
|
+
WebSocket.onerror = (err) => {
|
69
|
+
Stream.destroy(err);
|
70
|
+
};
|
71
|
+
|
72
|
+
WebSocket.onmessage = (event) => {
|
73
|
+
const data = event.data instanceof ArrayBuffer ? Buffer.from(event.data) : Buffer.from(event.data, 'utf8');
|
74
|
+
Stream.push(data);
|
75
|
+
};
|
76
|
+
|
77
|
+
WebSocket.onopen = () => {
|
78
|
+
Stream.setReadable(Proxy);
|
79
|
+
Stream.setWritable(Proxy);
|
80
|
+
Stream.emit('connect');
|
81
|
+
};
|
82
|
+
|
83
|
+
WebSocket_Global = WebSocket;
|
84
|
+
Proxy.on('close', () => WebSocket.close());
|
85
|
+
|
86
|
+
return Stream;
|
87
|
+
}
|
88
|
+
|
89
|
+
function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
|
90
|
+
const chatOn = ctx.globalOptions.online;
|
91
|
+
const foreground = false;
|
92
|
+
|
93
|
+
const sessionID = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1;
|
94
|
+
const username = {
|
95
|
+
u: ctx.userID,
|
96
|
+
s: sessionID,
|
97
|
+
chat_on: chatOn,
|
98
|
+
fg: foreground,
|
99
|
+
d: utils.getGUID(),
|
100
|
+
ct: 'websocket',
|
101
|
+
aid: '219994525426954',
|
102
|
+
aids: null,
|
103
|
+
mqtt_sid: '',
|
104
|
+
cp: 3,
|
105
|
+
ecp: 10,
|
106
|
+
st: [],
|
107
|
+
pm: [],
|
108
|
+
dc: '',
|
109
|
+
no_auto_fg: true,
|
110
|
+
gas: null,
|
111
|
+
pack: [],
|
112
|
+
p: null,
|
113
|
+
php_override: ""
|
114
|
+
};
|
115
|
+
|
116
|
+
const cookies = ctx.jar.getCookies('https://www.facebook.com').join('; ');
|
117
|
+
|
118
|
+
let host;
|
119
|
+
if (ctx.mqttEndpoint) {
|
120
|
+
host = `${ctx.mqttEndpoint}&sid=${sessionID}`;
|
121
|
+
} else if (ctx.region) {
|
122
|
+
host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLowerCase()}&sid=${sessionID}`;
|
123
|
+
} else {
|
124
|
+
host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}`;
|
125
|
+
}
|
126
|
+
|
127
|
+
const options = {
|
128
|
+
clientId: 'mqttwsclient',
|
129
|
+
protocolId: 'MQIsdp',
|
130
|
+
protocolVersion: 3,
|
131
|
+
username: JSON.stringify(username),
|
132
|
+
clean: true,
|
133
|
+
wsOptions: {
|
134
|
+
headers: {
|
135
|
+
Cookie: cookies,
|
136
|
+
Origin: 'https://www.facebook.com',
|
137
|
+
'User-Agent': ctx.globalOptions.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36',
|
138
|
+
Referer: 'https://www.facebook.com/',
|
139
|
+
Host: new URL(host).hostname,
|
140
|
+
},
|
141
|
+
origin: 'https://www.facebook.com',
|
142
|
+
protocolVersion: 13,
|
143
|
+
binaryType: 'arraybuffer',
|
144
|
+
},
|
145
|
+
keepalive: 60,
|
146
|
+
reschedulePings: true,
|
147
|
+
reconnectPeriod: 3,
|
148
|
+
};
|
149
|
+
|
150
|
+
if (ctx.globalOptions.proxy !== undefined) {
|
151
|
+
const agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
|
152
|
+
options.wsOptions.agent = agent;
|
153
|
+
}
|
154
|
+
|
155
|
+
ctx.mqttClient = new mqtt.Client(() => buildStream(options, new WebSocket(host, options.wsOptions), buildProxy()), options);
|
156
|
+
global.mqttClient = ctx.mqttClient;
|
157
|
+
|
158
|
+
global.mqttClient.on('error', (err) => {
|
159
|
+
log.error('listenMqtt', err);
|
160
|
+
global.mqttClient.end();
|
161
|
+
|
162
|
+
if (ctx.globalOptions.autoReconnect) {
|
163
|
+
getSeqID();
|
164
|
+
} else {
|
165
|
+
globalCallback({
|
166
|
+
type: 'stop_listen',
|
167
|
+
error: 'Server Đã Sập - Auto Restart'
|
168
|
+
}, null);
|
169
|
+
return process.exit(1);
|
170
|
+
}
|
171
|
+
});
|
172
|
+
|
173
|
+
global.mqttClient.on('connect', () => {
|
174
|
+
if (!global.Fca.Data.Setup || global.Fca.Data.Setup === undefined) {
|
175
|
+
if (global.Fca.Require.FastConfig.RestartMQTT_Minutes !== 0 && global.Fca.Data.StopListening !== true) {
|
176
|
+
global.Fca.Data.Setup = true;
|
177
|
+
setTimeout(() => {
|
178
|
+
global.Fca.Require.logger.Warning('Closing MQTT Client...');
|
179
|
+
ctx.mqttClient.end();
|
180
|
+
global.Fca.Require.logger.Warning('Reconnecting MQTT Client...');
|
181
|
+
global.Fca.Data.Setup = false;
|
182
|
+
getSeqID();
|
183
|
+
}, Number(global.Fca.Require.FastConfig.RestartMQTT_Minutes) * 60 * 1000);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
if (process.env.OnStatus === undefined) {
|
188
|
+
global.Fca.Require.logger.Normal('Bạn Đang Sài Phiên Bản: Premium Access');
|
189
|
+
|
190
|
+
if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) === 0) {
|
191
|
+
// something
|
192
|
+
} else if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) < 10) {
|
193
|
+
log.warn('AutoRestartMinutes', 'The number of minutes to automatically restart must be more than 10 minutes');
|
194
|
+
} else if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) < 0) {
|
195
|
+
log.warn('AutoRestartMinutes', 'Invalid auto-restart minutes!');
|
196
|
+
} else {
|
197
|
+
global.Fca.Require.logger.Normal(global.Fca.getText(global.Fca.Require.Language.Src.AutoRestart, global.Fca.Require.FastConfig.AutoRestartMinutes));
|
198
|
+
global.Fca.Require.logger.Normal(`Auto Restart MQTT Client After: ${global.Fca.Require.FastConfig.RestartMQTT_Minutes} Minutes`);
|
199
|
+
setTimeout(() => {
|
200
|
+
global.Fca.Require.logger.Normal(global.Fca.Require.Language.Src.OnRestart);
|
201
|
+
process.exit(1);
|
202
|
+
}, Number(global.Fca.Require.FastConfig.AutoRestartMinutes) * 60000);
|
203
|
+
}
|
204
|
+
require('../broadcast').startBroadcasting();
|
205
|
+
const MemoryManager = require('../Extra/Src/Release_Memory');
|
206
|
+
const path = require('path');
|
207
|
+
|
208
|
+
const SettingMemoryManager = {
|
209
|
+
warningThreshold: 0.7,
|
210
|
+
releaseThreshold: 0.8,
|
211
|
+
maxThreshold: 0.9,
|
212
|
+
interval: 60 * 1000,
|
213
|
+
logLevel: 'warn',
|
214
|
+
logFile: path.join(process.cwd(), 'Horizon_Database' ,'memory.log'),
|
215
|
+
smartReleaseEnabled: true,
|
216
|
+
allowLog: (global.Fca.Require.FastConfig.AntiStuckAndMemoryLeak.LogFile.Use || false)
|
217
|
+
};
|
218
|
+
|
219
|
+
const memoryManager = new MemoryManager(SettingMemoryManager);
|
220
|
+
|
221
|
+
memoryManager.autoStart(60 * 60 * 1000);
|
222
|
+
|
223
|
+
if (global.Fca.Require.FastConfig.AntiStuckAndMemoryLeak.AutoRestart.Use) {
|
224
|
+
memoryManager.onMaxMemory(function() {
|
225
|
+
global.Fca.Require.logger.Warning('Memory Usage >= 90% - Auto Restart Avoid Crash');
|
226
|
+
process.exit(1);
|
227
|
+
});
|
228
|
+
}
|
229
|
+
process.env.OnStatus = true;
|
230
|
+
}
|
231
|
+
|
232
|
+
topics.forEach((topicsub) => global.mqttClient.subscribe(topicsub));
|
233
|
+
|
234
|
+
|
235
|
+
let topic;
|
236
|
+
const queue = {
|
237
|
+
sync_api_version: 11,
|
238
|
+
max_deltas_able_to_process: 100,
|
239
|
+
delta_batch_size: 500,
|
240
|
+
encoding: 'JSON',
|
241
|
+
entity_fbid: ctx.userID,
|
242
|
+
};
|
243
|
+
|
244
|
+
topic = "/messenger_sync_create_queue";
|
245
|
+
queue.initial_titan_sequence_id = ctx.lastSeqId;
|
246
|
+
queue.device_params = null;
|
247
|
+
|
248
|
+
global.mqttClient.publish(topic, JSON.stringify(queue), {
|
249
|
+
qos: 1,
|
250
|
+
retain: false
|
251
|
+
});
|
252
|
+
|
253
|
+
var rTimeout = setTimeout(function() {
|
254
|
+
global.mqttClient.end();
|
255
|
+
getSeqID();
|
256
|
+
}, 3000);
|
257
|
+
|
258
|
+
ctx.tmsWait = function() {
|
259
|
+
clearTimeout(rTimeout);
|
260
|
+
ctx.globalOptions.emitReady ? globalCallback({
|
261
|
+
type: "ready",
|
262
|
+
error: null
|
263
|
+
}) : '';
|
264
|
+
delete ctx.tmsWait;
|
265
|
+
};
|
266
|
+
});
|
267
|
+
|
268
|
+
const HandleMessage = function(topic, message, _packet) {
|
269
|
+
const jsonMessage = JSON.parse(message.toString());
|
270
|
+
if (topic === "/t_ms") {
|
271
|
+
if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
|
272
|
+
|
273
|
+
if (jsonMessage.firstDeltaSeqId && jsonMessage.syncToken) {
|
274
|
+
ctx.lastSeqId = jsonMessage.firstDeltaSeqId;
|
275
|
+
ctx.syncToken = jsonMessage.syncToken;
|
276
|
+
}
|
277
|
+
|
278
|
+
if (jsonMessage.lastIssuedSeqId) ctx.lastSeqId = parseInt(jsonMessage.lastIssuedSeqId);
|
279
|
+
//If it contains more than 1 delta
|
280
|
+
for (var i in jsonMessage.deltas) {
|
281
|
+
var delta = jsonMessage.deltas[i];
|
282
|
+
parseDelta(defaultFuncs, api, ctx, globalCallback, {
|
283
|
+
"delta": delta
|
284
|
+
});
|
285
|
+
}
|
286
|
+
} else if (topic === "/ls_resp") {
|
287
|
+
const payload = JSON.parse(jsonMessage.payload); //'{"name":null,"step":[1,[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"replaceOptimsiticMessage","7192532113093667880","mid.$gABfX5li9LA6VdUymnWPRAdlkiawo"]]]],[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"mailboxTaskCompletionApiOnTaskCompletion",[19,"415"],true]]]],[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"removeTask",[19,"415"],[9]]]]]]}'
|
288
|
+
const request_ID = jsonMessage.request_id;
|
289
|
+
|
290
|
+
if (ctx.callback_Task[request_ID] != undefined && ctx.callback_Task[request_ID].type != undefined) {
|
291
|
+
const {
|
292
|
+
callback,
|
293
|
+
type
|
294
|
+
} = ctx.callback_Task[request_ID];
|
295
|
+
const Data = new getRespData(type, payload);
|
296
|
+
if (!callback) {
|
297
|
+
return;
|
298
|
+
}
|
299
|
+
else if (!Data) {
|
300
|
+
callback("Something went wrong 🐳", null);
|
301
|
+
} else {
|
302
|
+
callback(null, Data);
|
303
|
+
}
|
304
|
+
}
|
305
|
+
} else if (topic === "/thread_typing" || topic === "/orca_typing_notifications") {
|
306
|
+
var typ = {
|
307
|
+
type: "typ",
|
308
|
+
isTyping: !!jsonMessage.state,
|
309
|
+
from: jsonMessage.sender_fbid.toString(),
|
310
|
+
threadID: utils.formatID((jsonMessage.thread || jsonMessage.sender_fbid).toString())
|
311
|
+
};
|
312
|
+
(function() {
|
313
|
+
globalCallback(null, typ);
|
314
|
+
})();
|
315
|
+
} else if (topic === "/orca_presence") {
|
316
|
+
if (!ctx.globalOptions.updatePresence) {
|
317
|
+
for (var i in jsonMessage.list) {
|
318
|
+
var data = jsonMessage.list[i];
|
319
|
+
var userID = data["u"];
|
320
|
+
|
321
|
+
var presence = {
|
322
|
+
type: "presence",
|
323
|
+
userID: userID.toString(),
|
324
|
+
//Convert to ms
|
325
|
+
timestamp: data["l"] * 1000,
|
326
|
+
statuses: data["p"]
|
327
|
+
};
|
328
|
+
(function() {
|
329
|
+
globalCallback(null, presence);
|
330
|
+
})();
|
331
|
+
}
|
332
|
+
}
|
333
|
+
}
|
334
|
+
|
335
|
+
};
|
336
|
+
|
337
|
+
global.mqttClient.on('message', HandleMessage);
|
338
|
+
|
339
|
+
process.on('SIGINT', () => {
|
340
|
+
LogUptime();
|
341
|
+
process.kill(process.pid);
|
342
|
+
});
|
343
|
+
|
344
|
+
process.on('exit', LogUptime);
|
345
|
+
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
function getRespData(Type, payload) {
|
350
|
+
try {
|
351
|
+
switch (Type) {
|
352
|
+
case "sendMqttMessage": {
|
353
|
+
return {
|
354
|
+
type: Type,
|
355
|
+
threadID: payload.step[1][2][2][1][2], //this is sick bro
|
356
|
+
messageID: payload.step[1][2][2][1][3],
|
357
|
+
payload: payload.step[1][2]
|
358
|
+
};
|
359
|
+
}
|
360
|
+
default: { //!very LAZY :> cook yourself
|
361
|
+
return {
|
362
|
+
Data: payload.step[1][2][2][1],
|
363
|
+
type: Type,
|
364
|
+
payload: payload.step[1][2]
|
365
|
+
};
|
366
|
+
}
|
367
|
+
}
|
368
|
+
} catch (e) {
|
369
|
+
return null;
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
function LogUptime() {
|
374
|
+
const uptime = process.uptime();
|
375
|
+
const {
|
376
|
+
join
|
377
|
+
} = require('path');
|
378
|
+
const filePath = join(__dirname, '../CountTime.json');
|
379
|
+
|
380
|
+
let time1;
|
381
|
+
if (global.Fca.Require.fs.existsSync(filePath)) {
|
382
|
+
time1 = Number(global.Fca.Require.fs.readFileSync(filePath, 'utf8')) || 0;
|
383
|
+
} else {
|
384
|
+
time1 = 0;
|
385
|
+
}
|
386
|
+
|
387
|
+
global.Fca.Require.fs.writeFileSync(filePath, String(Number(uptime) + time1), 'utf8');
|
388
|
+
}
|
389
|
+
|
390
|
+
if (global.Fca.Require.FastConfig.AntiGetInfo.AntiGetThreadInfo) {
|
391
|
+
setInterval(() => {
|
392
|
+
try {
|
393
|
+
const { updateMessageCount, getData, hasData } = require('../Extra/ExtraGetThread');
|
394
|
+
const Data = global.Fca.Data.MsgCount;
|
395
|
+
const Arr = Array.from(Data.keys());
|
396
|
+
for (let i of Arr) {
|
397
|
+
const Count = parseInt(Data.get(i));
|
398
|
+
if (hasData(i)) {
|
399
|
+
let x = getData(i);
|
400
|
+
x.messageCount += Count;
|
401
|
+
updateMessageCount(i, x);
|
402
|
+
Data.delete(i);
|
403
|
+
}
|
404
|
+
}
|
405
|
+
|
406
|
+
} catch (e) {
|
407
|
+
console.log(e);
|
408
|
+
}
|
409
|
+
}, 30 * 1000);
|
410
|
+
}
|
411
|
+
|
412
|
+
function parseDelta(defaultFuncs, api, ctx, globalCallback, {
|
413
|
+
delta
|
414
|
+
}) {
|
415
|
+
if (delta.class === 'NewMessage') {
|
416
|
+
if (ctx.globalOptions.pageID && ctx.globalOptions.pageID !== delta.queue) return;
|
417
|
+
|
418
|
+
const resolveAttachmentUrl = (i) => {
|
419
|
+
if (!delta.attachments || i === delta.attachments.length || utils.getType(delta.attachments) !== 'Array') {
|
420
|
+
let fmtMsg;
|
421
|
+
try {
|
422
|
+
fmtMsg = utils.formatDeltaMessage(delta);
|
423
|
+
} catch (err) {
|
424
|
+
return log.error('Lỗi Nhẹ', err);
|
425
|
+
}
|
426
|
+
|
427
|
+
if (fmtMsg) {
|
428
|
+
const isGroup = fmtMsg.isGroup;
|
429
|
+
const threadID = fmtMsg.threadID;
|
430
|
+
const messageID = fmtMsg.messageID;
|
431
|
+
|
432
|
+
global.Fca.Data.event.set("Data", {
|
433
|
+
isGroup,
|
434
|
+
threadID,
|
435
|
+
messageID
|
436
|
+
});
|
437
|
+
|
438
|
+
if (global.Fca.Require.FastConfig.AntiGetInfo.AntiGetThreadInfo) {
|
439
|
+
global.Fca.Data.MsgCount.set(fmtMsg.threadID, ((global.Fca.Data.MsgCount.get(fmtMsg.threadID)) + 1 || 1));
|
440
|
+
}
|
441
|
+
|
442
|
+
if (ctx.globalOptions.autoMarkDelivery) {
|
443
|
+
markDelivery(ctx, api, fmtMsg.threadID, fmtMsg.messageID);
|
444
|
+
}
|
445
|
+
|
446
|
+
if (!ctx.globalOptions.selfListen && fmtMsg.senderID === ctx.userID) return;
|
447
|
+
globalCallback(null, fmtMsg);
|
448
|
+
}
|
449
|
+
} else {
|
450
|
+
const attachment = delta.attachments[i];
|
451
|
+
if (attachment.mercury.attach_type === 'photo') {
|
452
|
+
api.resolvePhotoUrl(attachment.fbid, (err, url) => {
|
453
|
+
if (!err) attachment.mercury.metadata.url = url;
|
454
|
+
resolveAttachmentUrl(i + 1);
|
455
|
+
});
|
456
|
+
} else {
|
457
|
+
resolveAttachmentUrl(i + 1);
|
458
|
+
}
|
459
|
+
}
|
460
|
+
};
|
461
|
+
|
462
|
+
resolveAttachmentUrl(0);
|
463
|
+
} else if (delta.class === 'ClientPayload') {
|
464
|
+
const clientPayload = utils.decodeClientPayload(delta.payload);
|
465
|
+
if (clientPayload && clientPayload.deltas) {
|
466
|
+
for (const delta of clientPayload.deltas) {
|
467
|
+
if (delta.deltaMessageReaction && !!ctx.globalOptions.listenEvents) {
|
468
|
+
const messageReaction = {
|
469
|
+
type: 'message_reaction',
|
470
|
+
threadID: (delta.deltaMessageReaction.threadKey.threadFbId ? delta.deltaMessageReaction.threadKey.threadFbId : delta.deltaMessageReaction.threadKey.otherUserFbId).toString(),
|
471
|
+
messageID: delta.deltaMessageReaction.messageId,
|
472
|
+
reaction: delta.deltaMessageReaction.reaction,
|
473
|
+
senderID: delta.deltaMessageReaction.senderId.toString(),
|
474
|
+
userID: delta.deltaMessageReaction.userId.toString(),
|
475
|
+
};
|
476
|
+
globalCallback(null, messageReaction);
|
477
|
+
} else if (delta.deltaRecallMessageData && !!ctx.globalOptions.listenEvents) {
|
478
|
+
const messageUnsend = {
|
479
|
+
type: 'message_unsend',
|
480
|
+
threadID: (delta.deltaRecallMessageData.threadKey.threadFbId ? delta.deltaRecallMessageData.threadKey.threadFbId : delta.deltaRecallMessageData.threadKey.otherUserFbId).toString(),
|
481
|
+
messageID: delta.deltaRecallMessageData.messageID,
|
482
|
+
senderID: delta.deltaRecallMessageData.senderID.toString(),
|
483
|
+
deletionTimestamp: delta.deltaRecallMessageData.deletionTimestamp,
|
484
|
+
timestamp: delta.deltaRecallMessageData.timestamp,
|
485
|
+
};
|
486
|
+
globalCallback(null, messageUnsend);
|
487
|
+
} else if (delta.deltaMessageReply) {
|
488
|
+
const mdata =
|
489
|
+
delta.deltaMessageReply.message === undefined ?
|
490
|
+
[] :
|
491
|
+
delta.deltaMessageReply.message.data === undefined ?
|
492
|
+
[] :
|
493
|
+
delta.deltaMessageReply.message.data.prng === undefined ?
|
494
|
+
[] :
|
495
|
+
JSON.parse(delta.deltaMessageReply.message.data.prng);
|
496
|
+
|
497
|
+
const m_id = mdata.map((u) => u.i);
|
498
|
+
const m_offset = mdata.map((u) => u.o);
|
499
|
+
const m_length = mdata.map((u) => u.l);
|
500
|
+
|
501
|
+
const mentions = {};
|
502
|
+
for (let i = 0; i < m_id.length; i++) {
|
503
|
+
mentions[m_id[i]] = (delta.deltaMessageReply.message.body || '').substring(m_offset[i], m_offset[i] + m_length[i]);
|
504
|
+
}
|
505
|
+
|
506
|
+
const callbackToReturn = {
|
507
|
+
type: 'message_reply',
|
508
|
+
threadID: (delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.message.messageMetadata.threadKey.otherUserFbId).toString(),
|
509
|
+
messageID: delta.deltaMessageReply.message.messageMetadata.messageId,
|
510
|
+
senderID: delta.deltaMessageReply.message.messageMetadata.actorFbId.toString(),
|
511
|
+
attachments: ( delta.deltaMessageReply.message.attachments || [] )
|
512
|
+
.map((att) => {
|
513
|
+
const mercury = JSON.parse(att.mercuryJSON);
|
514
|
+
Object.assign(att, mercury);
|
515
|
+
return att;
|
516
|
+
})
|
517
|
+
.map((att) => {
|
518
|
+
let x;
|
519
|
+
try {
|
520
|
+
x = utils._formatAttachment(att);
|
521
|
+
} catch (ex) {
|
522
|
+
x = att;
|
523
|
+
x.error = ex;
|
524
|
+
x.type = 'unknown';
|
525
|
+
}
|
526
|
+
return x;
|
527
|
+
}),
|
528
|
+
args: (delta.deltaMessageReply.message.body || '').trim().split(/\s+/),
|
529
|
+
body: delta.deltaMessageReply.message.body || '',
|
530
|
+
isGroup: !!delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId,
|
531
|
+
mentions,
|
532
|
+
timestamp: parseInt(delta.deltaMessageReply.message.messageMetadata.timestamp),
|
533
|
+
participantIDs: (delta.deltaMessageReply.message.participants || []).map((e) => e.toString()),
|
534
|
+
};
|
535
|
+
|
536
|
+
if (delta.deltaMessageReply.repliedToMessage) {
|
537
|
+
const mdata =
|
538
|
+
delta.deltaMessageReply.repliedToMessage === undefined ?
|
539
|
+
[] :
|
540
|
+
delta.deltaMessageReply.repliedToMessage.data === undefined ?
|
541
|
+
[] :
|
542
|
+
delta.deltaMessageReply.repliedToMessage.data.prng === undefined ?
|
543
|
+
[] :
|
544
|
+
JSON.parse(delta.deltaMessageReply.repliedToMessage.data.prng);
|
545
|
+
|
546
|
+
const m_id = mdata.map((u) => u.i);
|
547
|
+
const m_offset = mdata.map((u) => u.o);
|
548
|
+
const m_length = mdata.map((u) => u.l);
|
549
|
+
|
550
|
+
const rmentions = {};
|
551
|
+
for (let i = 0; i < m_id.length; i++) {
|
552
|
+
rmentions[m_id[i]] = (delta.deltaMessageReply.repliedToMessage.body || '').substring(m_offset[i], m_offset[i] + m_length[i]);
|
553
|
+
}
|
554
|
+
|
555
|
+
callbackToReturn.messageReply = {
|
556
|
+
threadID: (delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.otherUserFbId).toString(),
|
557
|
+
messageID: delta.deltaMessageReply.repliedToMessage.messageMetadata.messageId,
|
558
|
+
senderID: delta.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),
|
559
|
+
attachments: delta.deltaMessageReply.repliedToMessage.attachments
|
560
|
+
.map((att) => {
|
561
|
+
const mercury = JSON.parse(att.mercuryJSON);
|
562
|
+
Object.assign(att, mercury);
|
563
|
+
return att;
|
564
|
+
})
|
565
|
+
.map((att) => {
|
566
|
+
let x;
|
567
|
+
try {
|
568
|
+
x = utils._formatAttachment(att);
|
569
|
+
} catch (ex) {
|
570
|
+
x = att;
|
571
|
+
x.error = ex;
|
572
|
+
x.type = 'unknown';
|
573
|
+
}
|
574
|
+
return x;
|
575
|
+
}),
|
576
|
+
args: (delta.deltaMessageReply.repliedToMessage.body || '').trim().split(/\s+/),
|
577
|
+
body: delta.deltaMessageReply.repliedToMessage.body || '',
|
578
|
+
isGroup: !!delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId,
|
579
|
+
mentions: rmentions,
|
580
|
+
timestamp: parseInt(delta.deltaMessageReply.repliedToMessage.messageMetadata.timestamp),
|
581
|
+
participantIDs: (delta.deltaMessageReply.repliedToMessage.participants || []).map((e) => e.toString()),
|
582
|
+
};
|
583
|
+
} else if (delta.deltaMessageReply.replyToMessageId) {
|
584
|
+
return defaultFuncs
|
585
|
+
.post('https://www.facebook.com/api/graphqlbatch/', ctx.jar, {
|
586
|
+
av: ctx.globalOptions.pageID,
|
587
|
+
queries: JSON.stringify({
|
588
|
+
o0: {
|
589
|
+
doc_id: '2848441488556444',
|
590
|
+
query_params: {
|
591
|
+
thread_and_message_id: {
|
592
|
+
thread_id: callbackToReturn.threadID,
|
593
|
+
message_id: delta.deltaMessageReply.replyToMessageId.id,
|
594
|
+
},
|
595
|
+
},
|
596
|
+
},
|
597
|
+
}),
|
598
|
+
})
|
599
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
600
|
+
.then((resData) => {
|
601
|
+
if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
602
|
+
if (resData[resData.length - 1].successful_results === 0) throw {
|
603
|
+
error: 'forcedFetch: there was no successful_results',
|
604
|
+
res: resData
|
605
|
+
};
|
606
|
+
const fetchData = resData[0].o0.data.message;
|
607
|
+
const mobj = {};
|
608
|
+
|
609
|
+
for (const n in fetchData.message.ranges) {
|
610
|
+
mobj[fetchData.message.ranges[n].entity.id] = (fetchData.message.text || '').substr(fetchData.message.ranges[n].offset, fetchData.message.ranges[n].length);
|
611
|
+
}
|
612
|
+
callbackToReturn.messageReply = {
|
613
|
+
type: 'Message',
|
614
|
+
threadID: callbackToReturn.threadID,
|
615
|
+
messageID: fetchData.message_id,
|
616
|
+
senderID: fetchData.message_sender.id.toString(),
|
617
|
+
attachments: fetchData.message.blob_attachment.map((att) => utils._formatAttachment({
|
618
|
+
blob_attachment: att
|
619
|
+
})),
|
620
|
+
args: (fetchData.message.text || '').trim().split(/\s+/) || [],
|
621
|
+
body: fetchData.message.text || '',
|
622
|
+
isGroup: callbackToReturn.isGroup,
|
623
|
+
mentions: mobj,
|
624
|
+
timestamp: parseInt(fetchData.timestamp_precise),
|
625
|
+
};
|
626
|
+
})
|
627
|
+
|
628
|
+
.catch((err) => log.error('forcedFetch', err))
|
629
|
+
.finally(() => {
|
630
|
+
if (ctx.globalOptions.autoMarkDelivery) {
|
631
|
+
markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
|
632
|
+
}
|
633
|
+
|
634
|
+
if (!ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID) return;
|
635
|
+
globalCallback(null, callbackToReturn);
|
636
|
+
});
|
637
|
+
} else {
|
638
|
+
callbackToReturn.delta = delta;
|
639
|
+
}
|
640
|
+
if (ctx.globalOptions.autoMarkDelivery) {
|
641
|
+
markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
|
642
|
+
}
|
643
|
+
|
644
|
+
if (!ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID) return;
|
645
|
+
globalCallback(null, callbackToReturn);
|
646
|
+
}
|
647
|
+
}
|
648
|
+
|
649
|
+
return;
|
650
|
+
}
|
651
|
+
}
|
652
|
+
switch (delta.class) {
|
653
|
+
case 'ReadReceipt': {
|
654
|
+
let fmtMsg;
|
655
|
+
try {
|
656
|
+
fmtMsg = utils.formatDeltaReadReceipt(delta);
|
657
|
+
} catch (err) {
|
658
|
+
return log.error('Lỗi Nhẹ', err);
|
659
|
+
}
|
660
|
+
globalCallback(null, fmtMsg);
|
661
|
+
break;
|
662
|
+
}
|
663
|
+
case 'AdminTextMessage': {
|
664
|
+
switch (delta.type) {
|
665
|
+
case 'joinable_group_link_mode_change':
|
666
|
+
case 'magic_words':
|
667
|
+
case 'pin_messages_v2':
|
668
|
+
case 'change_thread_theme':
|
669
|
+
case 'change_thread_icon':
|
670
|
+
case 'change_thread_nickname':
|
671
|
+
case 'change_thread_admins':
|
672
|
+
case 'change_thread_approval_mode':
|
673
|
+
case 'group_poll':
|
674
|
+
case 'messenger_call_log':
|
675
|
+
case 'participant_joined_group_call': {
|
676
|
+
let fmtMsg;
|
677
|
+
try {
|
678
|
+
fmtMsg = utils.formatDeltaEvent(delta);
|
679
|
+
} catch (err) {
|
680
|
+
console.log(delta);
|
681
|
+
return log.error('Lỗi Nhẹ', err);
|
682
|
+
}
|
683
|
+
globalCallback(null, fmtMsg);
|
684
|
+
break;
|
685
|
+
}
|
686
|
+
}
|
687
|
+
break;
|
688
|
+
}
|
689
|
+
|
690
|
+
//For group images
|
691
|
+
case 'ForcedFetch': {
|
692
|
+
if (!delta.threadKey) return;
|
693
|
+
const mid = delta.messageId;
|
694
|
+
const tid = delta.threadKey.threadFbId;
|
695
|
+
|
696
|
+
if (mid && tid) {
|
697
|
+
const form = {
|
698
|
+
av: ctx.globalOptions.pageID,
|
699
|
+
queries: JSON.stringify({
|
700
|
+
o0: {
|
701
|
+
doc_id: '2848441488556444',
|
702
|
+
query_params: {
|
703
|
+
thread_and_message_id: {
|
704
|
+
thread_id: tid.toString(),
|
705
|
+
message_id: mid,
|
706
|
+
},
|
707
|
+
},
|
708
|
+
},
|
709
|
+
}),
|
710
|
+
};
|
711
|
+
defaultFuncs
|
712
|
+
.post('https://www.facebook.com/api/graphqlbatch/', ctx.jar, form)
|
713
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
714
|
+
.then((resData) => {
|
715
|
+
if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
716
|
+
|
717
|
+
if (resData[resData.length - 1].successful_results === 0) throw {
|
718
|
+
error: 'forcedFetch: there was no successful_results',
|
719
|
+
res: resData
|
720
|
+
};
|
721
|
+
|
722
|
+
const fetchData = resData[0].o0.data.message;
|
723
|
+
|
724
|
+
if (utils.getType(fetchData) === 'Object') {
|
725
|
+
log.info('forcedFetch', fetchData);
|
726
|
+
switch (fetchData.__typename) {
|
727
|
+
case 'ThreadImageMessage':
|
728
|
+
if (!ctx.globalOptions.selfListen && fetchData.message_sender.id.toString() === ctx.userID) return;
|
729
|
+
if (!ctx.loggedIn) return;
|
730
|
+
|
731
|
+
globalCallback(null, {
|
732
|
+
type: 'change_thread_image',
|
733
|
+
threadID: utils.formatID(tid.toString()),
|
734
|
+
snippet: fetchData.snippet,
|
735
|
+
timestamp: fetchData.timestamp_precise,
|
736
|
+
author: fetchData.message_sender.id,
|
737
|
+
image: {
|
738
|
+
attachmentID: fetchData.image_with_metadata && fetchData.image_with_metadata.legacy_attachment_id,
|
739
|
+
width: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.x,
|
740
|
+
height: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.y,
|
741
|
+
url: fetchData.image_with_metadata && fetchData.image_with_metadata.preview.uri,
|
742
|
+
},
|
743
|
+
});
|
744
|
+
break;
|
745
|
+
case 'UserMessage': {
|
746
|
+
const event = {
|
747
|
+
type: 'message',
|
748
|
+
senderID: utils.formatID(fetchData.message_sender.id),
|
749
|
+
body: fetchData.message.text || '',
|
750
|
+
threadID: utils.formatID(tid.toString()),
|
751
|
+
messageID: fetchData.message_id,
|
752
|
+
attachments: [{
|
753
|
+
type: 'share',
|
754
|
+
ID: fetchData.extensible_attachment.legacy_attachment_id,
|
755
|
+
url: fetchData.extensible_attachment.story_attachment.url,
|
756
|
+
title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
|
757
|
+
description: fetchData.extensible_attachment.story_attachment.description.text,
|
758
|
+
source: fetchData.extensible_attachment.story_attachment.source,
|
759
|
+
image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
|
760
|
+
width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
|
761
|
+
height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
|
762
|
+
playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
|
763
|
+
duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
|
764
|
+
subattachments: fetchData.extensible_attachment.subattachments,
|
765
|
+
properties: fetchData.extensible_attachment.story_attachment.properties,
|
766
|
+
}],
|
767
|
+
mentions: {},
|
768
|
+
timestamp: parseInt(fetchData.timestamp_precise),
|
769
|
+
isGroup: (fetchData.message_sender.id !== tid.toString()),
|
770
|
+
};
|
771
|
+
|
772
|
+
log.info('ff-Return', event);
|
773
|
+
globalCallback(null, event);
|
774
|
+
break;
|
775
|
+
}
|
776
|
+
default:
|
777
|
+
log.error('forcedFetch', fetchData);
|
778
|
+
}
|
779
|
+
} else {
|
780
|
+
log.error('forcedFetch', fetchData);
|
781
|
+
}
|
782
|
+
})
|
783
|
+
.catch((err) => log.error('forcedFetch', err));
|
784
|
+
}
|
785
|
+
break;
|
786
|
+
}
|
787
|
+
case 'ThreadName':
|
788
|
+
case 'ParticipantsAddedToGroupThread':
|
789
|
+
case 'ParticipantLeftGroupThread': {
|
790
|
+
let formattedEvent;
|
791
|
+
try {
|
792
|
+
formattedEvent = utils.formatDeltaEvent(delta);
|
793
|
+
} catch (err) {
|
794
|
+
console.log(err);
|
795
|
+
return log.error('Lỗi Nhẹ', err);
|
796
|
+
}
|
797
|
+
|
798
|
+
if (!ctx.globalOptions.selfListen && formattedEvent.author.toString() === ctx.userID) return;
|
799
|
+
if (!ctx.loggedIn) return;
|
800
|
+
globalCallback(null, formattedEvent);
|
801
|
+
break;
|
802
|
+
}
|
803
|
+
case 'NewMessage': {
|
804
|
+
if (delta.attachments !== undefined && delta.attachments.length === 1 && delta.attachments[0].mercury.extensible_attachment !== undefined && delta.attachments[0].mercury.extensible_attachment.story_attachment.style_list != null && delta.attachments[0].mercury.extensible_attachment.story_attachment.style_list.includes('message_live_location')) {
|
805
|
+
delta.class = 'UserLocation';
|
806
|
+
let fmtMsg;
|
807
|
+
try {
|
808
|
+
fmtMsg = utils.formatDeltaEvent(delta);
|
809
|
+
} catch (err) {
|
810
|
+
console.log(delta);
|
811
|
+
return log.error('Lỗi Nhẹ', err);
|
812
|
+
}
|
813
|
+
globalCallback(null, fmtMsg);
|
814
|
+
}
|
815
|
+
break;
|
816
|
+
}
|
817
|
+
}
|
818
|
+
}
|
819
|
+
|
820
|
+
function markDelivery(ctx, api, threadID, messageID) {
|
821
|
+
if (threadID && messageID) {
|
822
|
+
api.markAsDelivered(threadID, messageID, (err) => {
|
823
|
+
if (err) log.error('markAsDelivered', err);
|
824
|
+
else {
|
825
|
+
if (ctx.globalOptions.autoMarkRead) {
|
826
|
+
api.markAsRead(threadID, (err) => {
|
827
|
+
if (err) log.error('markAsDelivered', err);
|
828
|
+
});
|
829
|
+
}
|
830
|
+
}
|
831
|
+
});
|
832
|
+
}
|
833
|
+
}
|
834
|
+
|
835
|
+
|
836
|
+
|
837
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
838
|
+
var globalCallback = identity;
|
839
|
+
getSeqID = function getSeqID() {
|
840
|
+
ctx.t_mqttCalled = false;
|
841
|
+
defaultFuncs
|
842
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
843
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
844
|
+
.then((resData) => {
|
845
|
+
if (utils.getType(resData) != "Array") {
|
846
|
+
if (global.Fca.Require.FastConfig.AutoLogin) {
|
847
|
+
return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
|
848
|
+
return global.Fca.Action('AutoLogin');
|
849
|
+
});
|
850
|
+
} else if (!global.Fca.Require.FastConfig.AutoLogin) {
|
851
|
+
return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
|
852
|
+
}
|
853
|
+
return;
|
854
|
+
} else {
|
855
|
+
if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
856
|
+
if (resData[resData.length - 1].successful_results === 0) throw {
|
857
|
+
error: "getSeqId: there was no successful_results",
|
858
|
+
res: resData
|
859
|
+
};
|
860
|
+
if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
|
861
|
+
ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
|
862
|
+
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
863
|
+
} else throw {
|
864
|
+
error: "getSeqId: no sync_sequence_id found.",
|
865
|
+
res: resData
|
866
|
+
};
|
867
|
+
}
|
868
|
+
})
|
869
|
+
.catch((err) => {
|
870
|
+
log.error("getSeqId", err);
|
871
|
+
if (utils.getType(err) == "Object" && err.error === global.Fca.Require.Language.Index.ErrAppState) ctx.loggedIn = false;
|
872
|
+
return globalCallback(err);
|
873
|
+
});
|
874
|
+
};
|
875
|
+
|
876
|
+
return function(callback) {
|
877
|
+
class MessageEmitter extends EventEmitter {
|
878
|
+
stopListening(callback) {
|
879
|
+
callback = callback || (() => {});
|
880
|
+
globalCallback = identity;
|
881
|
+
if (ctx.mqttClient) {
|
882
|
+
ctx.mqttClient.unsubscribe("/webrtc");
|
883
|
+
ctx.mqttClient.unsubscribe("/rtc_multi");
|
884
|
+
ctx.mqttClient.unsubscribe("/onevc");
|
885
|
+
ctx.mqttClient.publish("/browser_close", "{}");
|
886
|
+
ctx.mqttClient.end(false, function(...data) {
|
887
|
+
ctx.mqttClient = undefined;
|
888
|
+
});
|
889
|
+
}
|
890
|
+
global.Fca.Data.StopListening = true;
|
891
|
+
}
|
892
|
+
}
|
893
|
+
|
894
|
+
var msgEmitter = new MessageEmitter();
|
895
|
+
globalCallback = (callback || function(error, message) {
|
896
|
+
if (error) return msgEmitter.emit("error", error);
|
897
|
+
msgEmitter.emit("message", message);
|
898
|
+
});
|
899
|
+
|
900
|
+
//Reset some stuff
|
901
|
+
if (!ctx.firstListen) ctx.lastSeqId = null;
|
902
|
+
ctx.syncToken = undefined;
|
903
|
+
ctx.t_mqttCalled = false;
|
904
|
+
|
905
|
+
//Same request as getThreadList
|
906
|
+
form = {
|
907
|
+
av: ctx.globalOptions.pageID,
|
908
|
+
queries: JSON.stringify({
|
909
|
+
o0: {
|
910
|
+
doc_id: '3336396659757871',
|
911
|
+
query_params: {
|
912
|
+
limit: 1,
|
913
|
+
before: null,
|
914
|
+
tags: ['INBOX'],
|
915
|
+
includeDeliveryReceipts: false,
|
916
|
+
includeSeqID: true,
|
917
|
+
},
|
918
|
+
},
|
919
|
+
}),
|
920
|
+
};
|
921
|
+
|
922
|
+
|
923
|
+
if (!ctx.firstListen || !ctx.lastSeqId) getSeqID();
|
924
|
+
else listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
925
|
+
ctx.firstListen = false;
|
926
|
+
|
927
|
+
return msgEmitter;
|
928
|
+
};
|
929
|
+
};
|