fca-nx 7.0.0 → 7.0.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.
- package/module/config.js +1 -0
- package/module/loginHelper.js +24 -46
- package/package.json +2 -2
- package/src/api/messaging/getThemePictures.js +21 -35
- package/src/api/socket/core/getSeqID.js +25 -29
- package/src/api/socket/e2ee/index.js +22 -84
- package/src/api/socket/e2ee/protocol.js +9 -32
- package/src/api/socket/e2ee/ratchet.js +1 -29
- package/src/api/socket/e2ee/store.js +42 -140
- package/src/api/socket/e2ee/vendor/fb-e2ee.cjs +18 -140
- package/src/api/socket/listenE2EE.js +1 -14
- package/src/api/socket/sendMessage.js +77 -186
- package/src/api/users/getUserInfoV2.js +61 -61
- package/src/utils/textEffects.js +1 -8
- package/src/utils/sendThrottle.js +0 -64
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* fca-nx sendMessage — MQTT primary, OldMessage fallback, E2EE for encrypted DMs.
|
|
5
|
-
* Hardened6: soft MQTT wait, E2EE→MQTT→HTTP cascade, ack retry, paced sends.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
3
|
var utils = require("../../utils/utils");
|
|
9
4
|
var logger = require("../../utils/logger");
|
|
10
|
-
var {
|
|
5
|
+
var { getTextEffectId, getTextEffectIds } = require("../../utils/textEffects");
|
|
11
6
|
|
|
12
7
|
var ALLOWED = {
|
|
13
8
|
attachment: true, url: true, sticker: true, emoji: true,
|
|
14
9
|
emojiSize: true, body: true, mentions: true, location: true,
|
|
15
|
-
replyToMessage: true, forwardAttachmentIds: true
|
|
10
|
+
replyToMessage: true, forwardAttachmentIds: true, text_effect_ids: true,
|
|
11
|
+
textEffect: true, text_effect: true, text_effect_id: true,
|
|
12
|
+
textEffectId: true, textEffectID: true, effect: true, effect_id: true,
|
|
13
|
+
effectID: true, text_effect_name: true, effectName: true, effect_name: true
|
|
16
14
|
};
|
|
17
15
|
|
|
18
16
|
var EMOJI_SIZES = { small: 1, medium: 2, large: 3 };
|
|
@@ -32,15 +30,19 @@ function buildMentionData(msg, baseBody) {
|
|
|
32
30
|
var ids = [], offsets = [], lengths = [], types = [];
|
|
33
31
|
for (var i = 0; i < msg.mentions.length; i++) {
|
|
34
32
|
var mention = msg.mentions[i];
|
|
33
|
+
// Ensure tag always has @ prefix — Facebook counts @ in both offset and length
|
|
35
34
|
var tag = String(mention.tag || "");
|
|
36
35
|
if (tag && !tag.startsWith("@")) tag = "@" + tag;
|
|
37
36
|
var fromIndex = Number.isInteger(mention.fromIndex) ? mention.fromIndex : 0;
|
|
38
37
|
var offset = baseBody.indexOf(tag, fromIndex);
|
|
39
|
-
if (offset === -1)
|
|
38
|
+
if (offset === -1) {
|
|
39
|
+
// Fallback: search for bare name without @
|
|
40
|
+
offset = baseBody.indexOf(tag.slice(1), fromIndex);
|
|
41
|
+
}
|
|
40
42
|
if (offset < 0) offset = 0;
|
|
41
43
|
ids.push(String(mention.id || 0));
|
|
42
44
|
offsets.push(offset);
|
|
43
|
-
lengths.push(tag.length);
|
|
45
|
+
lengths.push(tag.length); // includes @ — matches Facebook's expectation
|
|
44
46
|
types.push("p");
|
|
45
47
|
}
|
|
46
48
|
return {
|
|
@@ -69,87 +71,52 @@ function extractIdsFromPayload(payload) {
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
function publishLsRequestWithAck(mqttClient, content, requestId, timeout) {
|
|
72
|
-
timeout = timeout ||
|
|
73
|
-
return new Promise(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var settled = false;
|
|
79
|
-
function done(err, val) {
|
|
80
|
-
if (settled) return;
|
|
81
|
-
settled = true;
|
|
82
|
-
try { clearTimeout(timer); } catch (_) { }
|
|
83
|
-
try { mqttClient.removeListener("message", onMessage); } catch (_) { }
|
|
84
|
-
if (err) reject(err);
|
|
85
|
-
else resolve(val);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
var timer = setTimeout(function () {
|
|
89
|
-
done(new Error("MQTT sendMessage timed out after " + timeout + "ms"));
|
|
74
|
+
timeout = timeout || 15000;
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
var timer = setTimeout(() => {
|
|
77
|
+
mqttClient.removeListener('message', onMessage);
|
|
78
|
+
reject(new Error('MQTT sendMessage timed out after ' + timeout + 'ms'));
|
|
90
79
|
}, timeout);
|
|
91
80
|
|
|
92
81
|
function onMessage(topic, message) {
|
|
93
|
-
if (topic !==
|
|
82
|
+
if (topic !== '/ls_resp') return;
|
|
94
83
|
try {
|
|
95
84
|
var data = JSON.parse(message.toString());
|
|
96
|
-
if (String(data.request_id)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
messageID: extracted.messageID
|
|
101
|
-
}
|
|
85
|
+
if (String(data.request_id) === String(requestId)) {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
mqttClient.removeListener('message', onMessage);
|
|
88
|
+
var extracted = extractIdsFromPayload(data.payload ? JSON.parse(data.payload) : {});
|
|
89
|
+
resolve({ threadID: extracted.threadID, messageID: extracted.messageID });
|
|
90
|
+
}
|
|
102
91
|
} catch (_) { }
|
|
103
92
|
}
|
|
104
93
|
|
|
105
|
-
mqttClient.on(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
done(pubErr);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Wait briefly for MQTT to become ready (reconnect in progress). */
|
|
117
|
-
function waitForMqtt(ctx, maxMs) {
|
|
118
|
-
maxMs = maxMs || 4000;
|
|
119
|
-
return new Promise(function (resolve) {
|
|
120
|
-
var client = ctx.mqttClient || global.mqttClient;
|
|
121
|
-
if (client && client.connected) return resolve(client);
|
|
122
|
-
var start = Date.now();
|
|
123
|
-
var iv = setInterval(function () {
|
|
124
|
-
var c = ctx.mqttClient || global.mqttClient;
|
|
125
|
-
if (c && c.connected) {
|
|
126
|
-
clearInterval(iv);
|
|
127
|
-
return resolve(c);
|
|
128
|
-
}
|
|
129
|
-
if (Date.now() - start >= maxMs) {
|
|
130
|
-
clearInterval(iv);
|
|
131
|
-
return resolve(c || null);
|
|
94
|
+
mqttClient.on('message', onMessage);
|
|
95
|
+
mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1 }, err => {
|
|
96
|
+
if (err) {
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
mqttClient.removeListener('message', onMessage);
|
|
99
|
+
reject(err);
|
|
132
100
|
}
|
|
133
|
-
}
|
|
101
|
+
});
|
|
134
102
|
});
|
|
135
103
|
}
|
|
136
104
|
|
|
137
105
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
138
|
-
var uploadAttachmentFn = require(
|
|
106
|
+
var uploadAttachmentFn = require('../messaging/uploadAttachment')(defaultFuncs, api, ctx);
|
|
139
107
|
|
|
140
108
|
async function uploadAttachments(attachments) {
|
|
141
109
|
if (!Array.isArray(attachments)) attachments = [attachments];
|
|
142
110
|
return uploadAttachmentFn(attachments);
|
|
143
111
|
}
|
|
144
112
|
|
|
145
|
-
async function sendViaMqtt(msg, threadID, replyToMessage
|
|
146
|
-
var mqttClient =
|
|
147
|
-
if (!mqttClient
|
|
148
|
-
throw new Error("MQTT client not available");
|
|
149
|
-
}
|
|
113
|
+
async function sendViaMqtt(msg, threadID, replyToMessage) {
|
|
114
|
+
var mqttClient = ctx.mqttClient || global.mqttClient;
|
|
115
|
+
if (!mqttClient) throw new Error('MQTT client not available');
|
|
150
116
|
|
|
151
117
|
var baseBody = msg.body != null ? String(msg.body) : "";
|
|
152
118
|
var requestId = Math.floor(100 + Math.random() * 900);
|
|
119
|
+
var epoch = (BigInt(Date.now()) << 22n).toString();
|
|
153
120
|
|
|
154
121
|
var payload0 = {
|
|
155
122
|
thread_id: String(threadID),
|
|
@@ -169,23 +136,18 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
169
136
|
var mentionData = buildMentionData(msg, baseBody);
|
|
170
137
|
if (mentionData) payload0.mention_data = mentionData;
|
|
171
138
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
payload0.hot_emoji_size = toEmojiSize(msg.emojiSize);
|
|
180
|
-
}
|
|
139
|
+
var textEffectId = getTextEffectId(msg);
|
|
140
|
+
if (textEffectId) payload0.text_effect_id = textEffectId;
|
|
141
|
+
var effectArray = getTextEffectIds(msg);
|
|
142
|
+
if (effectArray.length) payload0.text_effect_ids = effectArray;
|
|
143
|
+
|
|
144
|
+
if (msg.sticker) { payload0.send_type = 2; payload0.sticker_id = msg.sticker; }
|
|
145
|
+
if (msg.emoji) { payload0.send_type = 1; payload0.text = msg.emoji; payload0.hot_emoji_size = toEmojiSize(msg.emojiSize); }
|
|
181
146
|
|
|
182
147
|
if (msg.location && msg.location.latitude != null && msg.location.longitude != null) {
|
|
183
148
|
payload0.send_type = 1;
|
|
184
149
|
payload0.location_data = {
|
|
185
|
-
coordinates: {
|
|
186
|
-
latitude: msg.location.latitude,
|
|
187
|
-
longitude: msg.location.longitude
|
|
188
|
-
},
|
|
150
|
+
coordinates: { latitude: msg.location.latitude, longitude: msg.location.longitude },
|
|
189
151
|
is_current_location: Boolean(msg.location.current),
|
|
190
152
|
is_live_location: Boolean(msg.location.live)
|
|
191
153
|
};
|
|
@@ -217,15 +179,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
217
179
|
if (msg.forwardAttachmentIds && msg.forwardAttachmentIds.length) {
|
|
218
180
|
payload0.attachment_fbids = payload0.attachment_fbids.concat(msg.forwardAttachmentIds.map(String));
|
|
219
181
|
}
|
|
182
|
+
|
|
220
183
|
if (toUpload.length) {
|
|
221
184
|
var uploaded = await uploadAttachments(toUpload);
|
|
222
185
|
for (var u of uploaded) {
|
|
223
186
|
if (!u) continue;
|
|
224
187
|
var fbid = u.image_id || u.video_id || u.audio_id || u.file_id || u.sticker_id || u.gif_id;
|
|
225
188
|
if (!fbid) {
|
|
226
|
-
var firstKey = Object.keys(u).find(function (k)
|
|
227
|
-
return u[k] && /^\d+$/.test(String(u[k]));
|
|
228
|
-
});
|
|
189
|
+
var firstKey = Object.keys(u).find(function(k) { return u[k] && /^\d+$/.test(String(u[k])); });
|
|
229
190
|
if (firstKey) fbid = u[firstKey];
|
|
230
191
|
}
|
|
231
192
|
if (fbid) payload0.attachment_fbids.push(String(fbid));
|
|
@@ -236,14 +197,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
236
197
|
|
|
237
198
|
var tasks = [
|
|
238
199
|
{
|
|
239
|
-
label:
|
|
200
|
+
label: '46',
|
|
240
201
|
payload: JSON.stringify(payload0),
|
|
241
202
|
queue_name: String(threadID),
|
|
242
203
|
task_id: 400,
|
|
243
204
|
failure_count: null
|
|
244
205
|
},
|
|
245
206
|
{
|
|
246
|
-
label:
|
|
207
|
+
label: '21',
|
|
247
208
|
payload: JSON.stringify({
|
|
248
209
|
thread_id: String(threadID),
|
|
249
210
|
last_read_watermark_ts: Date.now(),
|
|
@@ -256,102 +217,57 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
256
217
|
];
|
|
257
218
|
|
|
258
219
|
var content = {
|
|
259
|
-
app_id:
|
|
220
|
+
app_id: '2220391788200892',
|
|
260
221
|
payload: JSON.stringify({
|
|
261
222
|
tasks: tasks,
|
|
262
|
-
epoch_id:
|
|
263
|
-
version_id:
|
|
223
|
+
epoch_id: epoch,
|
|
224
|
+
version_id: '24804310205905615',
|
|
225
|
+
data_trace_id: '#' + Buffer.from(String(Math.random())).toString('base64').replace(/=+$/, '')
|
|
264
226
|
}),
|
|
265
227
|
request_id: requestId,
|
|
266
228
|
type: 3
|
|
267
229
|
};
|
|
268
230
|
|
|
269
|
-
|
|
270
|
-
var timeout = ackTimeout || 18000;
|
|
271
|
-
try {
|
|
272
|
-
return await publishLsRequestWithAck(mqttClient, content, requestId, timeout);
|
|
273
|
-
} catch (firstErr) {
|
|
274
|
-
var msgErr = firstErr && firstErr.message ? firstErr.message : String(firstErr);
|
|
275
|
-
if (!/timed out/i.test(msgErr)) throw firstErr;
|
|
276
|
-
logger.warn("sendMessage", "MQTT ack timeout - one soft retry");
|
|
277
|
-
await new Promise(function (r) { setTimeout(r, 800 + Math.floor(Math.random() * 700)); });
|
|
278
|
-
mqttClient = await waitForMqtt(ctx, 3000);
|
|
279
|
-
if (!mqttClient || !mqttClient.connected) throw firstErr;
|
|
280
|
-
// new request id for retry
|
|
281
|
-
requestId = Math.floor(100 + Math.random() * 900);
|
|
282
|
-
content.request_id = requestId;
|
|
283
|
-
return await publishLsRequestWithAck(mqttClient, content, requestId, Math.min(timeout + 5000, 25000));
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
async function sendViaOldMessage(msg, threadID, replyToMessage, isSingleUser) {
|
|
288
|
-
if (typeof api.OldMessage !== "function") {
|
|
289
|
-
throw new Error("OldMessage fallback is not available");
|
|
290
|
-
}
|
|
291
|
-
return new Promise(function (res2, rej2) {
|
|
292
|
-
api.OldMessage(msg, threadID, function (err2, data2) {
|
|
293
|
-
if (err2) rej2(err2);
|
|
294
|
-
else res2(data2);
|
|
295
|
-
}, replyToMessage, isSingleUser);
|
|
296
|
-
});
|
|
231
|
+
return publishLsRequestWithAck(mqttClient, content, requestId, 15000);
|
|
297
232
|
}
|
|
298
233
|
|
|
299
234
|
return async function sendMessage(msg, threadID, callback, replyToMessage, isSingleUser) {
|
|
300
235
|
if (typeof msg === "string") msg = { body: msg };
|
|
301
|
-
if (typeof callback !== "function") callback = null;
|
|
302
|
-
var drop = ["text_effect_ids", "textEffect", "text_effect", "text_effect_id", "textEffectId", "textEffectID", "effect", "effect_id", "effectID", "text_effect_name", "effectName", "effect_name"];
|
|
303
|
-
for (var d = 0; d < drop.length; d++) delete msg[drop[d]];
|
|
236
|
+
if (typeof callback !== "function") { callback = null; }
|
|
304
237
|
|
|
305
238
|
var resolve, reject;
|
|
306
|
-
var promise = new Promise(
|
|
307
|
-
resolve = res;
|
|
308
|
-
reject = rej;
|
|
309
|
-
});
|
|
239
|
+
var promise = new Promise((res, rej) => { resolve = res; reject = rej; });
|
|
310
240
|
|
|
311
241
|
for (var key in msg) {
|
|
312
242
|
if (!ALLOWED[key]) {
|
|
313
|
-
var err =
|
|
243
|
+
var err = { error: "sendMessage: Unknown property '" + key + "'" };
|
|
314
244
|
if (callback) callback(err);
|
|
315
245
|
else reject(err);
|
|
316
246
|
return promise;
|
|
317
247
|
}
|
|
318
248
|
}
|
|
319
249
|
|
|
320
|
-
if (!threadID && threadID !== 0) {
|
|
321
|
-
var tidErr = new Error("threadID is required");
|
|
322
|
-
if (callback) callback(tidErr);
|
|
323
|
-
else reject(tidErr);
|
|
324
|
-
return promise;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
250
|
// Auto-detect isSingleUser from ctx.threadTypes if not explicitly provided.
|
|
251
|
+
// parseDelta in listenMqtt.js populates ctx.threadTypes[senderID] = 'dm' | 'group'
|
|
328
252
|
if (isSingleUser === undefined && ctx.threadTypes) {
|
|
329
|
-
isSingleUser = ctx.threadTypes[String(threadID)] ===
|
|
253
|
+
isSingleUser = ctx.threadTypes[String(threadID)] === 'dm';
|
|
330
254
|
}
|
|
331
255
|
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// Pace all outgoing traffic (anti-burst)
|
|
345
|
-
await waitTurn();
|
|
346
|
-
|
|
347
|
-
// ---- DM attachment path (skip MQTT) ----
|
|
348
|
-
// E2EE DMs: bridge only (MQTT strips attachment_fbids).
|
|
349
|
-
// Plain DMs: OldMessage (/messaging/send/ other_user_fbid).
|
|
256
|
+
// DM attachment sends — skip MQTT entirely.
|
|
257
|
+
// For E2EE DMs: route through the E2EE bridge (Noise WebSocket, Signal Protocol).
|
|
258
|
+
// Facebook strips attachment_fbids from MQTT messages in E2EE threads
|
|
259
|
+
// (can't re-encrypt CDN attachments on the fly), so MQTT silently drops them.
|
|
260
|
+
// The vendor's client.sendImage/sendVideo/sendAudio encrypts the file data
|
|
261
|
+
// and sends via the Noise WebSocket — the only path that actually delivers
|
|
262
|
+
// attachments in E2EE threads.
|
|
263
|
+
// For non-E2EE DMs: use OldMessage.
|
|
264
|
+
// /messaging/send/ with other_user_fbid routing works for plain DMs.
|
|
265
|
+
// (For E2EE DMs it returns 404 because the endpoint is deprecated for those.)
|
|
350
266
|
if (isSingleUser && msg.attachment) {
|
|
351
267
|
var useE2EE = api.e2ee && typeof api.e2ee.isConnected === "function" && api.e2ee.isConnected();
|
|
352
268
|
if (useE2EE) {
|
|
353
269
|
try {
|
|
354
|
-
var e2eeResult = await api.e2ee.sendMessage(String(threadID), msg, replyToMessage
|
|
270
|
+
var e2eeResult = await api.e2ee.sendMessage(String(threadID), msg, replyToMessage);
|
|
355
271
|
var wrapped = e2eeResult && e2eeResult.messageId
|
|
356
272
|
? { threadID: String(threadID), messageID: String(e2eeResult.messageId) }
|
|
357
273
|
: e2eeResult;
|
|
@@ -364,11 +280,13 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
364
280
|
}
|
|
365
281
|
} else {
|
|
366
282
|
try {
|
|
367
|
-
var omResult = await
|
|
283
|
+
var omResult = await new Promise((res2, rej2) => {
|
|
284
|
+
api.OldMessage(msg, threadID, (err2, data2) => err2 ? rej2(err2) : res2(data2), replyToMessage, true);
|
|
285
|
+
});
|
|
368
286
|
if (callback) callback(null, omResult);
|
|
369
287
|
else resolve(omResult);
|
|
370
288
|
} catch (omErr) {
|
|
371
|
-
logger.error("sendMessage", "DM attachment OldMessage failed: " + (omErr.message || omErr));
|
|
289
|
+
logger.error("sendMessage", "DM attachment via OldMessage failed: " + (omErr.error || omErr.message || omErr));
|
|
372
290
|
if (callback) callback(omErr);
|
|
373
291
|
else reject(omErr);
|
|
374
292
|
}
|
|
@@ -376,43 +294,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
376
294
|
return promise;
|
|
377
295
|
}
|
|
378
296
|
|
|
379
|
-
// ---- E2EE text path with cascade fallback ----
|
|
380
|
-
// Text replies to E2EE DMs should use the bridge; if it fails, try MQTT then OldMessage
|
|
381
|
-
// instead of hard-failing (Hardened6).
|
|
382
|
-
if (isSingleUser && !msg.attachment && !msg.sticker && !msg.location && !msg.emoji &&
|
|
383
|
-
api.e2ee && typeof api.e2ee.isConnected === "function" && api.e2ee.isConnected()) {
|
|
384
|
-
try {
|
|
385
|
-
var e2eeText = await api.e2ee.sendMessage(
|
|
386
|
-
String(threadID),
|
|
387
|
-
{ body: msg.body != null ? String(msg.body) : "" },
|
|
388
|
-
replyToMessage || msg.replyToMessage
|
|
389
|
-
);
|
|
390
|
-
var e2eeWrapped = e2eeText && e2eeText.messageId
|
|
391
|
-
? { threadID: String(threadID), messageID: String(e2eeText.messageId) }
|
|
392
|
-
: e2eeText;
|
|
393
|
-
if (ctx.threadTypes) ctx.threadTypes[String(threadID)] = "dm";
|
|
394
|
-
if (callback) callback(null, e2eeWrapped);
|
|
395
|
-
else resolve(e2eeWrapped);
|
|
396
|
-
return promise;
|
|
397
|
-
} catch (e2eeTextErr) {
|
|
398
|
-
logger.warn(
|
|
399
|
-
"sendMessage",
|
|
400
|
-
"E2EE DM text failed, cascading to MQTT/HTTP: " + (e2eeTextErr.message || e2eeTextErr)
|
|
401
|
-
);
|
|
402
|
-
// fall through to MQTT / OldMessage
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// ---- MQTT primary + OldMessage fallback ----
|
|
407
297
|
try {
|
|
408
|
-
var result = await sendViaMqtt(msg, threadID, replyToMessage
|
|
409
|
-
if (result && !result.threadID) result.threadID = String(threadID);
|
|
298
|
+
var result = await sendViaMqtt(msg, threadID, replyToMessage);
|
|
410
299
|
if (callback) callback(null, result);
|
|
411
300
|
else resolve(result);
|
|
412
301
|
} catch (mqttErr) {
|
|
413
302
|
logger.warn("sendMessage", "MQTT failed, falling back to OldMessage: " + (mqttErr.message || mqttErr));
|
|
414
303
|
try {
|
|
415
|
-
var fbResult = await
|
|
304
|
+
var fbResult = await new Promise((res2, rej2) => {
|
|
305
|
+
api.OldMessage(msg, threadID, (err2, data2) => err2 ? rej2(err2) : res2(data2), replyToMessage, isSingleUser);
|
|
306
|
+
});
|
|
416
307
|
if (callback) callback(null, fbResult);
|
|
417
308
|
else resolve(fbResult);
|
|
418
309
|
} catch (fbErr) {
|
|
@@ -424,4 +315,4 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
424
315
|
|
|
425
316
|
return promise;
|
|
426
317
|
};
|
|
427
|
-
};
|
|
318
|
+
};
|
|
@@ -79,8 +79,6 @@ function extractPhotoUrl(photo, depth = 0) {
|
|
|
79
79
|
"uri",
|
|
80
80
|
"url",
|
|
81
81
|
"image",
|
|
82
|
-
"full_image",
|
|
83
|
-
"viewer_image",
|
|
84
82
|
"photo",
|
|
85
83
|
"media",
|
|
86
84
|
"cover_photo",
|
|
@@ -92,32 +90,6 @@ function extractPhotoUrl(photo, depth = 0) {
|
|
|
92
90
|
return null;
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
// [Hardened] Fallback: read the cover photo straight from the profile page HTML,
|
|
97
|
-
// used when none of the GraphQL doc_ids returned a cover (doc_ids rotate often).
|
|
98
|
-
function decodeJsonString(raw) {
|
|
99
|
-
try { return JSON.parse('"' + raw + '"'); } catch { return String(raw).replace(/\\\//g, "/"); }
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function extractCoverFromHTML(html) {
|
|
103
|
-
if (!html || typeof html !== "string") return null;
|
|
104
|
-
const patterns = [
|
|
105
|
-
/"cover_photo"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
|
|
106
|
-
/"profile_cover_photo"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
|
|
107
|
-
/"coverPhoto"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
|
|
108
|
-
/"cover_photo"\s*:\s*\{[\s\S]{0,800}?"url"\s*:\s*"([^"]+)"/,
|
|
109
|
-
/property="og:image"\s+content="(https:\/\/[^"]+fbcdn[^"]+)"/i,
|
|
110
|
-
/content="(https:\/\/[^"]+fbcdn[^"]+)"\s+property="og:image"/i
|
|
111
|
-
];
|
|
112
|
-
for (const re of patterns) {
|
|
113
|
-
const m = html.match(re);
|
|
114
|
-
if (!m) continue;
|
|
115
|
-
const url = decodeJsonString(m[1]).replace(/&/g, "&");
|
|
116
|
-
if (/^https?:\/\//i.test(url) && /(fbcdn|scontent)/i.test(url)) return url;
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
93
|
function pickMeta(user) {
|
|
122
94
|
let friendshipStatus = null;
|
|
123
95
|
let gender = null;
|
|
@@ -142,6 +114,38 @@ function pickMeta(user) {
|
|
|
142
114
|
return { friendshipStatus, gender, shortName };
|
|
143
115
|
}
|
|
144
116
|
|
|
117
|
+
|
|
118
|
+
function findCoverUri(node, depth = 0) {
|
|
119
|
+
if (!node || depth > 12) return null;
|
|
120
|
+
if (typeof node === "string" || typeof node !== "object") return null;
|
|
121
|
+
for (const key of ["cover_photo", "coverPhoto", "profile_cover_photo", "timeline_cover_photo", "cover"]) {
|
|
122
|
+
if (node[key] != null) {
|
|
123
|
+
const direct = extractPhotoUrl(node[key]);
|
|
124
|
+
if (direct) return direct;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const list = Array.isArray(node) ? node : Object.keys(node).filter(k => k !== "extensions" && k !== "errors").map(k => node[k]);
|
|
128
|
+
for (const child of list) {
|
|
129
|
+
const found = findCoverUri(child, depth + 1);
|
|
130
|
+
if (found) return found;
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function coverFromHtml(html) {
|
|
136
|
+
const text = String(html || "");
|
|
137
|
+
const patterns = [
|
|
138
|
+
/"cover_photo"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
|
|
139
|
+
/"profile_cover_photo"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
|
|
140
|
+
/"timeline_cover_photo"\s*:\s*\{[\s\S]{0,400}?"uri"\s*:\s*"([^"]+)"/
|
|
141
|
+
];
|
|
142
|
+
for (const re of patterns) {
|
|
143
|
+
const match = text.match(re);
|
|
144
|
+
if (match && match[1]) return match[1].replace(/\\\//g, "/").replace(/\\u0026/g, "&");
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
145
149
|
function extractCoverPhoto(user) {
|
|
146
150
|
const cover = user?.cover_photo;
|
|
147
151
|
if (!cover) return null;
|
|
@@ -166,13 +170,9 @@ function normalizeUser(user) {
|
|
|
166
170
|
firstName: meta.shortName || null,
|
|
167
171
|
vanity,
|
|
168
172
|
thumbSrc: extractProfilePicture(user),
|
|
169
|
-
coverPhoto:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
extractPhotoUrl(user.profile_cover_photo) ||
|
|
173
|
-
extractPhotoUrl(user.cover_photo_renderer) ||
|
|
174
|
-
extractCoverPhoto(user) ||
|
|
175
|
-
null,
|
|
173
|
+
coverPhoto: extractPhotoUrl(
|
|
174
|
+
user.cover_photo || user.coverPhoto || user.profile_cover_photo
|
|
175
|
+
),
|
|
176
176
|
profileUrl: user.profile_url || user.url || null,
|
|
177
177
|
gender: meta.gender || null,
|
|
178
178
|
type: user.__typename || "User",
|
|
@@ -266,6 +266,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
266
266
|
const parsed = toJSONMaybe(response) || response;
|
|
267
267
|
const root = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
268
268
|
const normalized = normalizeUser(findUser(root));
|
|
269
|
+
const cover = findCoverUri(parsed) || findCoverUri(root);
|
|
270
|
+
if (normalized && cover && !normalized.coverPhoto) normalized.coverPhoto = cover;
|
|
269
271
|
if (!normalized?.id) continue;
|
|
270
272
|
if (!bestUser) {
|
|
271
273
|
bestUser = normalized;
|
|
@@ -281,30 +283,25 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
281
283
|
logger(`getUserInfoV2 ${doc.id}: ${error.message || error}`, "warn");
|
|
282
284
|
}
|
|
283
285
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
logger(`getUserInfoV2 cover html ${id}: ${error.message || error}`, "warn");
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
if (!bestUser.coverPhoto && process.env.FCA_COVER_DEBUG === "1") {
|
|
304
|
-
logger(`getUserInfoV2 cover ${id}: no cover found in GraphQL or profile HTML`, "warn");
|
|
286
|
+
return bestUser;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function fetchCoverFromProfile(userID) {
|
|
290
|
+
const urls = [
|
|
291
|
+
`https://www.facebook.com/profile.php?id=${userID}`,
|
|
292
|
+
`https://mbasic.facebook.com/profile.php?id=${userID}`
|
|
293
|
+
];
|
|
294
|
+
for (const url of urls) {
|
|
295
|
+
try {
|
|
296
|
+
const response = await defaultFuncs.get(url, ctx.jar);
|
|
297
|
+
const html = typeof response === "string" ? response : (response && (response.body || response.data)) || "";
|
|
298
|
+
const cover = coverFromHtml(html);
|
|
299
|
+
if (cover) return cover;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
logger(`getUserInfoV2 cover page: ${error.message || error}`, "warn");
|
|
305
302
|
}
|
|
306
303
|
}
|
|
307
|
-
return
|
|
304
|
+
return null;
|
|
308
305
|
}
|
|
309
306
|
|
|
310
307
|
async function fetchLegacy(userIDs) {
|
|
@@ -329,7 +326,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
329
326
|
lastName: nameParts.length > 1? nameParts.slice(1).join(" ") : null,
|
|
330
327
|
vanity: profile.vanity || null,
|
|
331
328
|
thumbSrc: null,
|
|
332
|
-
coverPhoto: extractPhotoUrl(profile.cover_photo),
|
|
329
|
+
coverPhoto: extractPhotoUrl(profile.cover_photo || profile.coverPhoto || profile.cover || profile.profile_cover_photo),
|
|
333
330
|
profileUrl: profile.uri || `https://www.facebook.com/profile.php?id=${id}`,
|
|
334
331
|
gender: profile.gender === 1? "male" : profile.gender === 2? "female" : "no specific gender",
|
|
335
332
|
type: profile.type || "User",
|
|
@@ -376,7 +373,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
376
373
|
for (let i = 0; i < ids.length; i++) {
|
|
377
374
|
const id = ids[i];
|
|
378
375
|
if (results[i].status === "fulfilled" && results[i].value?.id) {
|
|
379
|
-
|
|
376
|
+
const user = results[i].value;
|
|
377
|
+
if (!user.coverPhoto) {
|
|
378
|
+
user.coverPhoto = await fetchCoverFromProfile(id);
|
|
379
|
+
}
|
|
380
|
+
retObj[id] = formatUser(user, id);
|
|
380
381
|
} else {
|
|
381
382
|
needFallback.push(id);
|
|
382
383
|
}
|
|
@@ -414,13 +415,12 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
414
415
|
return callback(null, retObj);
|
|
415
416
|
}
|
|
416
417
|
})();
|
|
417
|
-
|
|
418
|
+
return returnPromise;
|
|
418
419
|
};
|
|
419
420
|
};
|
|
420
421
|
|
|
421
422
|
module.exports._private = {
|
|
422
423
|
extractPhotoUrl,
|
|
423
|
-
extractCoverFromHTML,
|
|
424
424
|
normalizeUser
|
|
425
425
|
};
|
|
426
426
|
|
package/src/utils/textEffects.js
CHANGED
|
@@ -71,16 +71,9 @@ function getTextEffectIds(message) {
|
|
|
71
71
|
const rawIDs = Array.isArray(message.text_effect_ids)
|
|
72
72
|
? message.text_effect_ids
|
|
73
73
|
: [message.text_effect_ids];
|
|
74
|
-
|
|
74
|
+
return rawIDs
|
|
75
75
|
.map(toTextEffectId)
|
|
76
76
|
.filter(Boolean);
|
|
77
|
-
// [Hardened7] `effect: "fire"` / `textEffect` / `effectName` only produced the single id; the
|
|
78
|
-
// array form (text_effect_ids) stayed empty, and Messenger reads the array. Always send both.
|
|
79
|
-
if (!ids.length) {
|
|
80
|
-
const single = getTextEffectId(message);
|
|
81
|
-
if (single) ids.push(single);
|
|
82
|
-
}
|
|
83
|
-
return ids;
|
|
84
77
|
}
|
|
85
78
|
|
|
86
79
|
module.exports = {
|