fca-nx 6.6.6 → 6.6.8
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.
- package/package.json +1 -1
- package/src/api/action/addfriend.js +109 -0
- package/src/api/action/changeCover.js +106 -221
- package/src/api/http/httpGet.js +33 -13
- package/src/api/http/httpPost.js +32 -14
- package/src/api/messaging/editMessage.js +50 -34
- package/src/api/messaging/sendMessage.js +19 -8
- package/src/api/socket/listenMqtt.js +52 -33
- package/src/api/users/getUserInfoV2.js +145 -786
- package/src/app/createFcaClient.js +0 -1
- package/src/api/action/addFriend.js +0 -145
- /package/{LICENCE → LICENSE} +0 -0
|
@@ -8,32 +8,37 @@ function generateOfflineThreadingId() {
|
|
|
8
8
|
|
|
9
9
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
10
10
|
return function editMessage(text, messageID, callback) {
|
|
11
|
-
let resolveFunc
|
|
12
|
-
let rejectFunc
|
|
11
|
+
let resolveFunc;
|
|
12
|
+
let rejectFunc;
|
|
13
|
+
|
|
13
14
|
const returnPromise = new Promise((resolve, reject) => {
|
|
14
15
|
resolveFunc = resolve;
|
|
15
16
|
rejectFunc = reject;
|
|
16
17
|
});
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
callback
|
|
20
|
-
|
|
19
|
+
const handleCallback = (err, data) => {
|
|
20
|
+
if (typeof callback === "function") {
|
|
21
|
+
callback(err, data);
|
|
22
|
+
}
|
|
23
|
+
if (err) {
|
|
24
|
+
rejectFunc(err);
|
|
25
|
+
} else {
|
|
21
26
|
resolveFunc(data);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
24
29
|
|
|
25
30
|
if (!ctx.mqttClient) {
|
|
26
|
-
|
|
31
|
+
handleCallback({ error: "Not connected to MQTT" });
|
|
27
32
|
return returnPromise;
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
if (!messageID || !text) {
|
|
31
|
-
|
|
36
|
+
handleCallback({ error: "messageID and text are required." });
|
|
32
37
|
return returnPromise;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
ctx.wsReqNumber
|
|
36
|
-
ctx.wsTaskNumber
|
|
40
|
+
ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
|
|
41
|
+
ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
|
|
37
42
|
|
|
38
43
|
const reqID = ctx.wsReqNumber;
|
|
39
44
|
|
|
@@ -42,49 +47,60 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
42
47
|
payload: JSON.stringify({
|
|
43
48
|
data_trace_id: null,
|
|
44
49
|
epoch_id: parseInt(generateOfflineThreadingId()),
|
|
45
|
-
tasks: [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
tasks: [
|
|
51
|
+
{
|
|
52
|
+
failure_count: null,
|
|
53
|
+
label: "742",
|
|
54
|
+
payload: JSON.stringify({
|
|
55
|
+
message_id: messageID,
|
|
56
|
+
text: text,
|
|
57
|
+
}),
|
|
58
|
+
queue_name: "edit_message",
|
|
59
|
+
task_id: ctx.wsTaskNumber,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
55
62
|
version_id: "6903494529735864",
|
|
56
63
|
}),
|
|
57
64
|
request_id: reqID,
|
|
58
|
-
type: 3
|
|
65
|
+
type: 3,
|
|
59
66
|
};
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}, 5000);
|
|
68
|
+
const cleanup = () => {
|
|
69
|
+
if (ctx.mqttClient) {
|
|
70
|
+
ctx.mqttClient.removeListener("message", handleRes);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
67
73
|
|
|
68
74
|
const handleRes = (topic, message) => {
|
|
69
75
|
if (topic !== "/ls_resp") return;
|
|
70
76
|
try {
|
|
71
77
|
let jsonMsg = JSON.parse(message.toString());
|
|
72
78
|
if (!jsonMsg.payload) return;
|
|
73
|
-
|
|
79
|
+
|
|
80
|
+
if (typeof jsonMsg.payload === "string") {
|
|
81
|
+
jsonMsg.payload = JSON.parse(jsonMsg.payload);
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
if (jsonMsg.request_id != reqID) return;
|
|
75
85
|
|
|
76
86
|
clearTimeout(timeout);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
callback(undefined, { messageID, body: text });
|
|
87
|
+
cleanup();
|
|
88
|
+
handleCallback(null, { messageID, body: text });
|
|
80
89
|
} catch (e) {
|
|
81
90
|
clearTimeout(timeout);
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
cleanup();
|
|
92
|
+
handleCallback(null, { messageID, body: text });
|
|
84
93
|
}
|
|
85
94
|
};
|
|
86
95
|
|
|
96
|
+
const timeout = setTimeout(() => {
|
|
97
|
+
cleanup();
|
|
98
|
+
handleCallback(null, { messageID, body: text });
|
|
99
|
+
}, 5000);
|
|
100
|
+
|
|
87
101
|
ctx.mqttClient.on("message", handleRes);
|
|
102
|
+
ctx.mqttClient.publish("/ls_req", JSON.stringify(context), { qos: 1, retain: false });
|
|
103
|
+
|
|
88
104
|
return returnPromise;
|
|
89
105
|
};
|
|
90
106
|
};
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Modified by MueidMursalinRifat
|
|
4
|
-
* Don't change credit
|
|
2
|
+
* Created by Donix-VN (DongDev)
|
|
3
|
+
* Modified by MueidMursalinRifat & Xalman
|
|
5
4
|
* Send a message using MQTT.
|
|
6
|
-
* @param {string}
|
|
5
|
+
* @param {string|object} msg - The message object or text to send.
|
|
7
6
|
* @param {string} threadID - The ID of the thread to send the message to.
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
10
|
-
* @
|
|
11
|
-
* @returns {Promise<object>} A promise that resolves with the bodies of the sent message.
|
|
7
|
+
* @param {function} [callback] - Optional. The callback function.
|
|
8
|
+
* @param {string} [replyToMessage] - Optional. Message ID to reply to.
|
|
9
|
+
* @returns {Promise<object>} A promise that resolves with the sent message metadata.
|
|
12
10
|
*/
|
|
13
11
|
|
|
14
12
|
"use strict";
|
|
@@ -173,6 +171,19 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
173
171
|
metadata_dataclass: JSON.stringify({ media_accessibility_metadata: { alt_text: null } })
|
|
174
172
|
};
|
|
175
173
|
|
|
174
|
+
// --- TEXT EFFECTS SUPPORT FOR MQTT ---
|
|
175
|
+
if (m.text_effect_ids) {
|
|
176
|
+
let effectArray = [];
|
|
177
|
+
if (Array.isArray(m.text_effect_ids)) {
|
|
178
|
+
effectArray = m.text_effect_ids;
|
|
179
|
+
} else if (typeof m.text_effect_ids === "string" || typeof m.text_effect_ids === "number") {
|
|
180
|
+
effectArray = [m.text_effect_ids];
|
|
181
|
+
}
|
|
182
|
+
if (effectArray.length > 0) {
|
|
183
|
+
payload0.text_effect_ids = effectArray.map(id => String(id));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
176
187
|
const mentionData = buildMentionData(m, baseBody);
|
|
177
188
|
if (mentionData) payload0.mention_data = mentionData;
|
|
178
189
|
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modified by Xalman
|
|
3
|
+
* Fixed Auto-Logout, MQTT Heartbeat Leak, and Loop Reconnection Bugs.
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
"use strict";
|
|
2
7
|
|
|
3
8
|
const mqtt = require("mqtt");
|
|
@@ -19,7 +24,7 @@ const CYCLE_MS_DEFAULT = 60 * 60 * 1000;
|
|
|
19
24
|
const RECONNECT_DELAY_MS_DEFAULT = 3000;
|
|
20
25
|
const UNSUB_ALL_TIMEOUT_MS = 5000;
|
|
21
26
|
const MAX_MQTT_RECONNECT_DELAY_MS = 60000;
|
|
22
|
-
const MAX_MQTT_RECONNECT_ATTEMPTS =
|
|
27
|
+
const MAX_MQTT_RECONNECT_ATTEMPTS = 15;
|
|
23
28
|
const HEARTBEAT_INTERVAL_MS = 30000;
|
|
24
29
|
const HEARTBEAT_TIMEOUT_MS = 10000;
|
|
25
30
|
|
|
@@ -76,12 +81,13 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
76
81
|
function postSafe(...args) {
|
|
77
82
|
return rawPost(...args).catch(err => {
|
|
78
83
|
const msg = (err && err.error) || (err && err.message) || String(err || "");
|
|
79
|
-
|
|
84
|
+
// Handle Auto-Logout and Checkpoint Auth triggers
|
|
85
|
+
if (/Not logged in|blocked the login|Checkpoint|Login approved/i.test(msg)) {
|
|
80
86
|
emitAuth(
|
|
81
87
|
ctx,
|
|
82
88
|
api,
|
|
83
89
|
globalCallback,
|
|
84
|
-
/blocked/i.test(msg) ? "login_blocked" : "not_logged_in",
|
|
90
|
+
/blocked|checkpoint/i.test(msg) ? "login_blocked" : "not_logged_in",
|
|
85
91
|
msg
|
|
86
92
|
);
|
|
87
93
|
}
|
|
@@ -110,11 +116,12 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
110
116
|
return Promise.resolve();
|
|
111
117
|
}
|
|
112
118
|
|
|
119
|
+
// Updated Doc ID to modern Facebook GraphQL Thread Query Endpoint to avoid logouts
|
|
113
120
|
const form = {
|
|
114
121
|
av: ctx.globalOptions.pageID || ctx.userID,
|
|
115
122
|
queries: JSON.stringify({
|
|
116
123
|
o0: {
|
|
117
|
-
doc_id: "
|
|
124
|
+
doc_id: "6007624976008514",
|
|
118
125
|
query_params: {
|
|
119
126
|
limit: 1,
|
|
120
127
|
before: null,
|
|
@@ -178,6 +185,8 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
178
185
|
stopHeartbeat();
|
|
179
186
|
if (!isConnected()) return;
|
|
180
187
|
|
|
188
|
+
lastPongTime = Date.now();
|
|
189
|
+
|
|
181
190
|
heartbeatTimer = setInterval(() => {
|
|
182
191
|
if (!isConnected()) {
|
|
183
192
|
stopHeartbeat();
|
|
@@ -192,7 +201,8 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
192
201
|
}
|
|
193
202
|
|
|
194
203
|
try {
|
|
195
|
-
|
|
204
|
+
// Send standard MQTT ping timestamp packet to keep Facebook connection alive
|
|
205
|
+
ctx.mqttClient.publish("/ping", JSON.stringify({ timestamp: Date.now() }), { qos: 0 });
|
|
196
206
|
logger("mqtt heartbeat sent", "debug");
|
|
197
207
|
} catch (err) {
|
|
198
208
|
logger(`mqtt heartbeat error: ${err.message}`, "warn");
|
|
@@ -381,6 +391,41 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
381
391
|
}
|
|
382
392
|
}
|
|
383
393
|
|
|
394
|
+
function attachClientListeners() {
|
|
395
|
+
if (!ctx.mqttClient) return;
|
|
396
|
+
|
|
397
|
+
// Clean up prior event listeners to prevent memory leak & double-triggering
|
|
398
|
+
ctx.mqttClient.removeAllListeners("pong");
|
|
399
|
+
ctx.mqttClient.removeAllListeners("close");
|
|
400
|
+
ctx.mqttClient.removeAllListeners("error");
|
|
401
|
+
|
|
402
|
+
ctx.mqttClient.on("pong", () => {
|
|
403
|
+
lastPongTime = Date.now();
|
|
404
|
+
logger("mqtt pong received", "debug");
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
ctx.mqttClient.once("close", () => {
|
|
408
|
+
logger("mqtt connection closed", "warn");
|
|
409
|
+
stopHeartbeat();
|
|
410
|
+
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
|
|
411
|
+
if (!isReconnecting) {
|
|
412
|
+
isReconnecting = true;
|
|
413
|
+
delayedReconnect();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
ctx.mqttClient.once("error", (err) => {
|
|
419
|
+
logger(`mqtt error: ${err.message}`, "error");
|
|
420
|
+
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
|
|
421
|
+
if (!isReconnecting) {
|
|
422
|
+
isReconnecting = true;
|
|
423
|
+
forceCycle();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
384
429
|
return function (callback) {
|
|
385
430
|
class MessageEmitter extends EventEmitter {
|
|
386
431
|
stopListening(callback2) {
|
|
@@ -464,34 +509,8 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
464
509
|
} else {
|
|
465
510
|
logger("mqtt starting listenMqtt", "info");
|
|
466
511
|
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
startHeartbeat();
|
|
470
|
-
|
|
471
|
-
ctx.mqttClient.on("pong", () => {
|
|
472
|
-
lastPongTime = Date.now();
|
|
473
|
-
logger("mqtt pong received", "debug");
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
ctx.mqttClient.on("close", () => {
|
|
477
|
-
logger("mqtt connection closed", "warn");
|
|
478
|
-
stopHeartbeat();
|
|
479
|
-
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
|
|
480
|
-
isReconnecting = true;
|
|
481
|
-
delayedReconnect();
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
ctx.mqttClient.on("error", (err) => {
|
|
486
|
-
logger(`mqtt error: ${err.message}`, "error");
|
|
487
|
-
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
|
|
488
|
-
if (!isReconnecting) {
|
|
489
|
-
isReconnecting = true;
|
|
490
|
-
forceCycle();
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
}
|
|
512
|
+
attachClientListeners();
|
|
513
|
+
startHeartbeat();
|
|
495
514
|
}
|
|
496
515
|
|
|
497
516
|
api.stopListening = msgEmitter.stopListening;
|