fca-nx 6.7.4 → 6.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fca-nx",
3
- "version": "6.7.4",
3
+ "version": "6.7.5",
4
4
  "description": "Facebook Messenger API for Node.js — Fast, Secure, and Feature-Rich",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -2,7 +2,10 @@
2
2
 
3
3
  const log = require("../../../func/logAdapter");
4
4
  const { parseAndCheckLogin } = require("../../utils/client");
5
- const { getType } = require("../../utils/format");
5
+
6
+ // api.getThemePictures(themeID, callback?)
7
+ // themeID = the theme_fbid (digits), e.g. from api.getThreadInfo(tid).threadTheme.id
8
+ // or from an api.createThemeAI() result.
6
9
  module.exports = function (defaultFuncs, api, ctx) {
7
10
  return function getThemePictures(id, callback) {
8
11
  let resolveFunc = function () { };
@@ -12,24 +15,21 @@ module.exports = function (defaultFuncs, api, ctx) {
12
15
  rejectFunc = reject;
13
16
  });
14
17
 
15
- if (!callback) {
16
- if (
17
- getType(callback) == "Function" ||
18
- getType(callback) == "AsyncFunction"
19
- ) {
20
- callback = callback;
21
- } else {
22
- callback = function (err, data) {
23
- if (err) {
24
- return rejectFunc(err);
25
- }
26
- resolveFunc(data);
27
- };
28
- }
18
+ if (typeof callback !== "function") {
19
+ callback = function (err, data) {
20
+ if (err) return rejectFunc(err);
21
+ resolveFunc(data);
22
+ };
29
23
  }
30
24
 
31
- if (getType(id) != "String") {
32
- id = "";
25
+ // [Fixed by xalman] Accept numbers too. Before, any non-string id was silently
26
+ // replaced with "" and Facebook answered messenger_thread_theme: null.
27
+ if (typeof id === "number" || typeof id === "bigint") id = String(id);
28
+ id = typeof id === "string" ? id.trim() : "";
29
+
30
+ if (!/^\d+$/.test(id)) {
31
+ callback({ error: "getThemePictures: a numeric theme ID is required (theme_fbid), got: " + JSON.stringify(id) });
32
+ return returnPromise;
33
33
  }
34
34
 
35
35
  const form = {
@@ -37,19 +37,30 @@ module.exports = function (defaultFuncs, api, ctx) {
37
37
  fb_api_req_friendly_name: "MWPThreadThemeProviderQuery",
38
38
  doc_id: "9734829906576883",
39
39
  server_timestamps: true,
40
- variables: JSON.stringify({
41
- id
42
- }),
40
+ variables: JSON.stringify({ id }),
43
41
  av: ctx.userID
44
42
  };
43
+
45
44
  defaultFuncs
46
45
  .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
47
46
  .then(parseAndCheckLogin(ctx, defaultFuncs))
48
47
  .then(function (resData) {
49
- if (resData.errors) {
48
+ if (resData && resData.errors) {
50
49
  throw resData;
51
50
  }
52
51
 
52
+ // [Fixed by xalman] The request itself worked (doc_id is valid) but Facebook has
53
+ // no theme with this ID for this account. Report it as a failure instead of "success".
54
+ if (!resData || !resData.data || !resData.data.messenger_thread_theme) {
55
+ const notFound = {
56
+ error: "Theme not found: Facebook returned no theme for ID " + id + ". Check the ID (use the theme_fbid of a real theme).",
57
+ themeID: id,
58
+ raw: resData
59
+ };
60
+ log.error("getThemePictures", notFound.error);
61
+ return callback(notFound);
62
+ }
63
+
53
64
  return callback(null, resData);
54
65
  })
55
66
  .catch(function (err) {
@@ -23,9 +23,8 @@ const T_MS_WAIT_TIMEOUT_MS = 5000;
23
23
  // Set env FCA_NX_MQTT_IMMEDIATE_RECONNECT=0 (or mqtt option immediateReconnect:false) to get the
24
24
  // old scheduled behaviour back.
25
25
  function isImmediateReconnect(ctx) {
26
- if (process.env.FCA_NX_MQTT_IMMEDIATE_RECONNECT === "0") return false;
27
- if (ctx && ctx._mqttOpt && ctx._mqttOpt.immediateReconnect === false) return false;
28
- return true;
26
+ // [Fixed by xalman] opt-in only: instant reconnects can create overlapping sessions
27
+ return process.env.FCA_NX_MQTT_IMMEDIATE_RECONNECT === "1";
29
28
  }
30
29
 
31
30
  function computeBackoff(ctx, baseMs) {
@@ -21,7 +21,7 @@ const createEmitAuth = require("./core/emitAuth");
21
21
  const createMiddlewareSystem = require("./middleware");
22
22
 
23
23
  const CYCLE_MS_DEFAULT = 60 * 60 * 1000;
24
- const RECONNECT_DELAY_MS_DEFAULT = 3000;
24
+ const RECONNECT_DELAY_MS_DEFAULT = 5000;
25
25
  const UNSUB_ALL_TIMEOUT_MS = 5000;
26
26
  const MAX_MQTT_RECONNECT_DELAY_MS = 60000;
27
27
  const MAX_MQTT_RECONNECT_COOLDOWN_MS = 10 * 60 * 1000; // long cooldown after exhausting fast retries - never give up permanently
@@ -112,7 +112,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
112
112
  // [Fixed by xalman] immediate first reconnect (see connectMqtt.js computeBackoff). Called with
113
113
  // reconnectAttempts === 0 for a fresh cycle/disconnect and === 1 for the first retry after a
114
114
  // failed getSeqID; both go out at once, later ones back off 1s, 2s, 4s ... up to 60s.
115
- const immediate = process.env.FCA_NX_MQTT_IMMEDIATE_RECONNECT !== "0" && conf.immediateReconnect !== false;
115
+ const immediate = process.env.FCA_NX_MQTT_IMMEDIATE_RECONNECT === "1"; // [Fixed by xalman] off by default: instant reconnect loops look like multiple sessions
116
116
  if (immediate) {
117
117
  if (reconnectAttempts <= 1) return 0;
118
118
  const fast = Math.min(1000 * Math.pow(2, reconnectAttempts - 2), MAX_MQTT_RECONNECT_DELAY_MS);
@@ -300,6 +300,7 @@ module.exports = function (defaultFuncs, api, ctx) {
300
300
  // in inbox. (Group chats and normal MQTT DMs are unchanged.)
301
301
  if (isSingleUser && !msg.attachment && !msg.sticker && !msg.location && !msg.emoji &&
302
302
  api.e2ee && typeof api.e2ee.isConnected === "function" && api.e2ee.isConnected()) {
303
+ if (getTextEffectId(msg)) logger.warn("sendMessage", "Text effects are not supported in E2EE DMs - sending plain text. Use a group chat for effects.");
303
304
  try {
304
305
  var e2eeText = await api.e2ee.sendMessage(String(threadID), { body: msg.body != null ? String(msg.body) : "" }, replyToMessage || msg.replyToMessage);
305
306
  var e2eeWrapped = e2eeText && e2eeText.messageId
@@ -336,4 +337,4 @@ module.exports = function (defaultFuncs, api, ctx) {
336
337
 
337
338
  return promise;
338
339
  };
339
- };
340
+ };
@@ -90,6 +90,30 @@ function extractPhotoUrl(photo, depth = 0) {
90
90
  return null;
91
91
  }
92
92
 
93
+
94
+ // [Fixed by xalman] Fallback: read the cover photo straight from the profile page HTML,
95
+ // used when none of the GraphQL doc_ids returned a cover (doc_ids rotate often).
96
+ function decodeJsonString(raw) {
97
+ try { return JSON.parse('"' + raw + '"'); } catch { return raw.replace(/\\\//g, "/"); }
98
+ }
99
+
100
+ function extractCoverFromHTML(html) {
101
+ if (!html || typeof html !== "string") return null;
102
+ const patterns = [
103
+ /"cover_photo"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
104
+ /"profile_cover_photo"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
105
+ /"coverPhoto"\s*:\s*\{[\s\S]{0,800}?"uri"\s*:\s*"([^"]+)"/,
106
+ /"cover_photo"\s*:\s*\{[\s\S]{0,800}?"url"\s*:\s*"([^"]+)"/
107
+ ];
108
+ for (const re of patterns) {
109
+ const m = html.match(re);
110
+ if (!m) continue;
111
+ const url = decodeJsonString(m[1]).replace(/&amp;/g, "&");
112
+ if (/^https?:\/\//i.test(url) && /(fbcdn|scontent)/i.test(url)) return url;
113
+ }
114
+ return null;
115
+ }
116
+
93
117
  function pickMeta(user) {
94
118
  let friendshipStatus = null;
95
119
  let gender = null;
@@ -249,6 +273,23 @@ module.exports = function (defaultFuncs, api, ctx) {
249
273
  logger(`getUserInfoV2 ${doc.id}: ${error.message || error}`, "warn");
250
274
  }
251
275
  }
276
+ if (bestUser && !bestUser.coverPhoto) {
277
+ const pages = [`https://www.facebook.com/profile.php?id=${id}`];
278
+ if (bestUser.vanity && bestUser.vanity !== id) pages.push(`https://www.facebook.com/${bestUser.vanity}`);
279
+ for (const url of pages) {
280
+ try {
281
+ const res = await defaultFuncs.get(url, ctx.jar, null, ctx);
282
+ const html = typeof res === "string" ? res : res?.data;
283
+ const cover = extractCoverFromHTML(html);
284
+ if (cover) { bestUser.coverPhoto = cover; break; }
285
+ } catch (error) {
286
+ logger(`getUserInfoV2 cover html ${id}: ${error.message || error}`, "warn");
287
+ }
288
+ }
289
+ if (!bestUser.coverPhoto && process.env.FCA_COVER_DEBUG === "1") {
290
+ logger(`getUserInfoV2 cover ${id}: no cover found in GraphQL or profile HTML (account may have no cover photo)`, "warn");
291
+ }
292
+ }
252
293
  return bestUser;
253
294
  }
254
295
 
@@ -311,7 +352,7 @@ module.exports = function (defaultFuncs, api, ctx) {
311
352
  if (!ids.length) {
312
353
  const error = new Error("Invalid user ID(s)");
313
354
  callback(error);
314
- returnPromise;
355
+ return returnPromise;
315
356
  }
316
357
  (async () => {
317
358
  try {
@@ -365,6 +406,7 @@ module.exports = function (defaultFuncs, api, ctx) {
365
406
 
366
407
  module.exports._private = {
367
408
  extractPhotoUrl,
409
+ extractCoverFromHTML,
368
410
  normalizeUser
369
411
  };
370
412
 
@@ -65,8 +65,8 @@ function createFallbackNamespaces(api) {
65
65
  setEmoji: bindOptionalMethod(api, "changeThreadEmoji"),
66
66
  setNickname: bindOptionalMethod(api, "changeNickname"),
67
67
  createPoll: bindOptionalMethod(api, "createPoll"),
68
- createThemeAI: bindOptionalMethod(api, "createThemeAI"),
69
- getThemePictures: bindOptionalMethod(api, "getThemePictures"),
68
+ createThemeAI: bindLiveMethod(api, "createThemeAI"),
69
+ getThemePictures: bindLiveMethod(api, "getThemePictures"),
70
70
  delete: bindOptionalMethod(api, "deleteThread"),
71
71
  colors: readOptionalMember(api, "threadColors"),
72
72
  handleMessageRequest: bindOptionalMethod(api, "handleMessageRequest"),