fca-nx 6.8.6 → 6.8.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.
Files changed (74) hide show
  1. package/func/checkUpdate.js +1 -1
  2. package/func/logAdapter.js +0 -2
  3. package/index.js +0 -3
  4. package/module/config.js +2 -7
  5. package/module/login.js +10 -38
  6. package/module/loginHelper.js +94 -163
  7. package/module/options.js +1 -7
  8. package/package.json +2 -2
  9. package/src/api/action/addfriend.js +3 -9
  10. package/src/api/action/changeAvatar.js +0 -1
  11. package/src/api/action/changeCover.js +1 -3
  12. package/src/api/action/enableAutoSaveAppState.js +5 -18
  13. package/src/api/action/refreshFb_dtsg.js +2 -2
  14. package/src/api/http/httpGet.js +2 -6
  15. package/src/api/http/httpPost.js +2 -7
  16. package/src/api/messaging/createNewGroup.js +1 -1
  17. package/src/api/messaging/deleteMessage.js +1 -1
  18. package/src/api/messaging/forwardMessage.js +1 -9
  19. package/src/api/messaging/getEmojiUrl.js +1 -5
  20. package/src/api/messaging/getMessage.js +2 -4
  21. package/src/api/messaging/getThemePictures.js +0 -7
  22. package/src/api/messaging/markAsRead.js +0 -1
  23. package/src/api/messaging/muteThread.js +1 -1
  24. package/src/api/messaging/pinMessage.js +1 -10
  25. package/src/api/messaging/scheduler.js +4 -71
  26. package/src/api/messaging/sendBroadcast.js +0 -15
  27. package/src/api/messaging/sendMessage.js +1 -10
  28. package/src/api/messaging/sendTypingIndicator.js +2 -2
  29. package/src/api/messaging/sessionGuard.js +9 -45
  30. package/src/api/messaging/setMessageReaction.js +1 -2
  31. package/src/api/messaging/threadColors.js +12 -45
  32. package/src/api/messaging/uploadAttachment.js +3 -37
  33. package/src/api/socket/core/connectMqtt.js +17 -60
  34. package/src/api/socket/core/emitAuth.js +2 -14
  35. package/src/api/socket/core/getSeqID.js +23 -29
  36. package/src/api/socket/core/getTaskResponseData.js +1 -3
  37. package/src/api/socket/core/parseDelta.js +1 -1
  38. package/src/api/socket/detail/buildStream.js +1 -4
  39. package/src/api/socket/detail/constants.js +1 -4
  40. package/src/api/socket/e2ee/crypto.js +2 -40
  41. package/src/api/socket/e2ee/index.js +10 -123
  42. package/src/api/socket/e2ee/protocol.js +1 -32
  43. package/src/api/socket/e2ee/ratchet.js +10 -44
  44. package/src/api/socket/e2ee/store.js +1 -13
  45. package/src/api/socket/listenE2EE.js +1 -25
  46. package/src/api/socket/listenMqtt.js +13 -29
  47. package/src/api/socket/middleware/index.js +7 -61
  48. package/src/api/socket/sendMessage.js +2 -19
  49. package/src/api/threads/getThreadHistory.js +38 -68
  50. package/src/api/threads/getThreadInfo.js +3 -4
  51. package/src/api/threads/getThreadList.js +31 -34
  52. package/src/api/threads/getThreadPictures.js +1 -1
  53. package/src/api/users/getUserInfo.js +2 -5
  54. package/src/api/users/getUserInfoV2.js +3 -9
  55. package/src/core/sendReqMqtt.js +1 -2
  56. package/src/database/helpers.js +0 -12
  57. package/src/database/models/index.js +1 -3
  58. package/src/utils/broadcast.js +1 -1
  59. package/src/utils/clientIdentity.js +3 -50
  60. package/src/utils/cookies.js +2 -4
  61. package/src/utils/format/utils.js +0 -10
  62. package/src/utils/headers.js +12 -26
  63. package/src/utils/instanceLock.js +3 -9
  64. package/src/utils/ipGuard.js +1 -15
  65. package/src/utils/loginParser/autoLogin.js +0 -12
  66. package/src/utils/loginParser/parseAndCheckLogin.js +0 -7
  67. package/src/utils/loginParser/textUtils.js +0 -6
  68. package/src/utils/request/config.js +1 -4
  69. package/src/utils/request/methods.js +1 -4
  70. package/src/utils/request/proxy.js +0 -13
  71. package/src/utils/request/retry.js +0 -1
  72. package/src/utils/request/sanitize.js +1 -1
  73. package/src/utils/sendThrottle.js +1 -14
  74. package/src/utils/utils.js +3 -17
package/module/options.js CHANGED
@@ -22,13 +22,7 @@ function setOptions(globalOptions, options) {
22
22
  }
23
23
  switch (key) {
24
24
  case "userAgent": {
25
- // Resolve through the centralized identity module so a custom UA still
26
- // gets internally-consistent sec-ch-ua/platform/arch hints instead of
27
- // silently keeping mismatched defaults from elsewhere in the code.
28
- // Note: once a session is connected, its identity is cached on ctx
29
- // (see src/utils/clientIdentity.js#getSessionIdentity) and will not
30
- // change mid-session even if this is called again - this call only
31
- // affects future/new sessions started from this globalOptions object.
25
+
32
26
  globalOptions.userAgent = getIdentity(options.userAgent).userAgent;
33
27
  break;
34
28
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fca-nx",
3
- "version": "6.8.6",
4
- "description": "Facebook Messenger API",
3
+ "version": "6.8.8",
4
+ "description": "Facebook Messenger api",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "exports": {
@@ -1,6 +1,4 @@
1
- /**
2
- * Send a friend request to a Facebook user.
3
- */
1
+
4
2
 
5
3
  "use strict";
6
4
 
@@ -31,9 +29,6 @@ module.exports = function (defaultFuncs, api, ctx) {
31
29
  }
32
30
  };
33
31
 
34
- /*
35
- * Validate user ID
36
- */
37
32
  let targetID;
38
33
  try {
39
34
  targetID = formatID(userID);
@@ -53,13 +48,12 @@ module.exports = function (defaultFuncs, api, ctx) {
53
48
  }
54
49
 
55
50
  const sendRequest = async function () {
56
- // Facebook retired the old /ajax/friends/requests/send/ action. The
57
- // profile button now uses this Relay mutation instead.
51
+
58
52
  if (!ctx.fb_dtsg && typeof api?.refreshFb_dtsg === "function") {
59
53
  try {
60
54
  await api.refreshFb_dtsg();
61
55
  } catch (_) {
62
- // The request below will return the actionable Facebook error.
56
+
63
57
  }
64
58
  }
65
59
 
@@ -32,7 +32,6 @@ module.exports = function(defaultFuncs, api, ctx) {
32
32
  })
33
33
  );
34
34
 
35
- // resolve all promises
36
35
  Promise.all(uploads)
37
36
  .then(function(resData) {
38
37
  callback(null, resData);
@@ -1,6 +1,4 @@
1
- /**d
2
- * Change Facebook Profile Cover Photo via GraphQL Mutation.
3
- */
1
+
4
2
 
5
3
  "use strict";
6
4
 
@@ -3,21 +3,12 @@ const fs = require("fs");
3
3
  const path = require("path");
4
4
  const logger = require("../../../func/logger");
5
5
 
6
- /**
7
- * Enable automatic AppState saving
8
- * @param {Object} options - Options for auto-save
9
- * @param {string} [options.filePath] - Path to save AppState (default: "appstate.json")
10
- * @param {number} [options.interval] - Save interval in milliseconds (default: 10 minutes)
11
- * @param {boolean} [options.saveOnLogin] - Save immediately on login (default: true)
12
- * @returns {Function} Function to disable auto-save
13
- */
14
6
  module.exports = function (defaultFuncs, api, ctx) {
15
7
  return function enableAutoSaveAppState(options = {}) {
16
8
  const filePath = options.filePath || path.join(process.cwd(), "appstate.json");
17
- const interval = options.interval || 5 * 60 * 1000; // [Hardened] 5 minutes default - keep session cookies fresh on disk
18
- const saveOnLogin = options.saveOnLogin !== false; // default true
9
+ const interval = options.interval || 5 * 60 * 1000;
10
+ const saveOnLogin = options.saveOnLogin !== false;
19
11
 
20
- // Save function
21
12
  function saveAppState() {
22
13
  try {
23
14
  const appState = api.getAppState();
@@ -34,34 +25,30 @@ module.exports = function (defaultFuncs, api, ctx) {
34
25
  }
35
26
  }
36
27
 
37
- // Save immediately if requested
38
28
  let immediateSaveTimer = null;
39
29
  if (saveOnLogin) {
40
- // Delay a bit to ensure login is complete
30
+
41
31
  immediateSaveTimer = setTimeout(() => {
42
32
  saveAppState();
43
33
  immediateSaveTimer = null;
44
34
  }, 2000);
45
35
  }
46
36
 
47
- // Set up interval
48
37
  const intervalId = setInterval(saveAppState, interval);
49
38
  logger(`Auto-save AppState enabled: ${filePath} (every ${Math.round(interval / 1000 / 60)} minutes)`, "info");
50
39
 
51
- // Store interval ID for cleanup
52
40
  if (!ctx._autoSaveInterval) {
53
41
  ctx._autoSaveInterval = [];
54
42
  }
55
43
  ctx._autoSaveInterval.push(intervalId);
56
44
 
57
- // Return disable function
58
45
  return function disableAutoSaveAppState() {
59
- // Clear immediate save timer if still pending
46
+
60
47
  if (immediateSaveTimer) {
61
48
  clearTimeout(immediateSaveTimer);
62
49
  immediateSaveTimer = null;
63
50
  }
64
- // Clear interval
51
+
65
52
  clearInterval(intervalId);
66
53
  const index = ctx._autoSaveInterval ? ctx._autoSaveInterval.indexOf(intervalId) : -1;
67
54
  if (index !== -1) {
@@ -24,7 +24,7 @@ function extractTokens(html) {
24
24
  }
25
25
 
26
26
  function ctxJazoestFallback(token) {
27
- // Classic jazoest = 2 + sum of char codes of fb_dtsg
27
+
28
28
  let sum = 0;
29
29
  for (let i = 0; i < token.length; i++) sum += token.charCodeAt(i);
30
30
  return "2" + sum;
@@ -74,7 +74,7 @@ module.exports = function (defaultFuncs, api, ctx) {
74
74
  const tokens = extractTokens(html);
75
75
  if (tokens && tokens.fb_dtsg) {
76
76
  Object.assign(ctx, { fb_dtsg: tokens.fb_dtsg, jazoest: tokens.jazoest });
77
- // Persist cookies from the HTML response if available
77
+
78
78
  try {
79
79
  const { saveCookies } = require("../../utils/client");
80
80
  if (res && res.headers) saveCookies(ctx.jar)(res);
@@ -1,7 +1,4 @@
1
- /**
2
- * Modified by Xalman
3
- * HTTP Get Helper Function with Clean Promise & Callback Handling
4
- */
1
+
5
2
 
6
3
  "use strict";
7
4
 
@@ -18,7 +15,6 @@ const httpGetFactory = function (defaultFuncs, api, ctx) {
18
15
  rejectFunc = reject;
19
16
  });
20
17
 
21
- // Handle optional 'form' parameter when callback is passed as second argument
22
18
  if (
23
19
  !callback &&
24
20
  (getType(form) === "Function" || getType(form) === "AsyncFunction")
@@ -49,7 +45,7 @@ const httpGetFactory = function (defaultFuncs, api, ctx) {
49
45
  try {
50
46
  data = JSON.stringify(data, null, 2);
51
47
  } catch {
52
- // Retain object if stringify fails
48
+
53
49
  }
54
50
  }
55
51
  handleCallback(null, data);
@@ -1,7 +1,4 @@
1
- /**
2
- * Modified by Xalman
3
- * HTTP Post Helper Function with Clean Promise/Callback Handling
4
- */
1
+
5
2
 
6
3
  "use strict";
7
4
 
@@ -18,7 +15,6 @@ const httpPostFactory = function (defaultFuncs, api, ctx) {
18
15
  rejectFunc = reject;
19
16
  });
20
17
 
21
- // Callback parameter handling
22
18
  if (
23
19
  !callback &&
24
20
  (getType(form) === "Function" || getType(form) === "AsyncFunction")
@@ -44,7 +40,6 @@ const httpPostFactory = function (defaultFuncs, api, ctx) {
44
40
 
45
41
  const executor = notAPI ? post : (defaultFuncs?.post || post);
46
42
 
47
- // Dynamic execution
48
43
  executor(url, ctx.jar, form, ctx.globalOptions || {})
49
44
  .then((resData) => {
50
45
  let data = resData?.data ?? resData;
@@ -52,7 +47,7 @@ const httpPostFactory = function (defaultFuncs, api, ctx) {
52
47
  try {
53
48
  data = JSON.stringify(data, null, 2);
54
49
  } catch {
55
- // retain object if JSON stringify fails
50
+
56
51
  }
57
52
  }
58
53
  handleCallback(null, data);
@@ -48,7 +48,7 @@ module.exports = function(defaultFuncs, api, ctx) {
48
48
  fb_api_caller_class: "RelayModern",
49
49
  fb_api_req_friendly_name: "MessengerGroupCreateMutation",
50
50
  av: ctx.i_userID || ctx.userID,
51
- //This doc_id is valid as of January 11th, 2020
51
+
52
52
  doc_id: "577041672419534",
53
53
  variables: JSON.stringify({
54
54
  input: {
@@ -68,7 +68,7 @@ module.exports = function (defaultFuncs, api, ctx) {
68
68
  try {
69
69
  ctx.mqttClient?.removeListener("message", handleRes);
70
70
  } catch (e) {
71
- // ignore
71
+
72
72
  }
73
73
  };
74
74
 
@@ -2,13 +2,6 @@
2
2
 
3
3
  const { generateOfflineThreadingID } = require("../../utils/format");
4
4
 
5
- /**
6
- * Forward a message to one or multiple threads.
7
- * @param {string} messageID - The ID of the message to forward.
8
- * @param {string|string[]} threadID - Thread ID or array of thread IDs to forward to.
9
- * @param {function} [callback] - Optional callback(err, results).
10
- * @returns {Promise}
11
- */
12
5
  module.exports = function (defaultFuncs, api, ctx) {
13
6
  return async function forwardMessage(messageID, threadID, callback) {
14
7
  let resolveFunc, rejectFunc;
@@ -36,7 +29,6 @@ module.exports = function (defaultFuncs, api, ctx) {
36
29
  return returnPromise;
37
30
  }
38
31
 
39
- // Support forwarding to multiple threads
40
32
  const targets = Array.isArray(threadID) ? threadID : [threadID];
41
33
 
42
34
  const results = [];
@@ -84,7 +76,7 @@ module.exports = function (defaultFuncs, api, ctx) {
84
76
  ctx.mqttClient.publish("/ls_req", JSON.stringify(content), { qos: 1, retain: false });
85
77
  } catch (err) {
86
78
  errors.push({ threadID: tid, error: err.message || String(err) });
87
- return res(); // continue to next thread
79
+ return res();
88
80
  }
89
81
 
90
82
  const timeout = setTimeout(() => {
@@ -4,11 +4,7 @@ const util = require("util");
4
4
 
5
5
  module.exports = function() {
6
6
  return function getEmojiUrl(c, size, pixelRatio) {
7
- /*
8
- Resolves Facebook Messenger emoji image asset URL for an emoji character.
9
- Supported sizes are 32, 64, and 128.
10
- Supported pixel ratios are '1.0' and '1.5' (possibly more; haven't tested)
11
- */
7
+
12
8
  const baseUrl = "https://static.xx.fbcdn.net/images/emoji.php/v8/z%s/%s";
13
9
  pixelRatio = pixelRatio || "1.0";
14
10
 
@@ -207,9 +207,7 @@ function formatMessage(threadID, data) {
207
207
  throw new Error(
208
208
  `Unknown message type: "${data.__typename}", if this happens to you let me know when it happens. Please open an issue at https://github.com/ntkhang03/fb-chat-api/issues.`
209
209
  );
210
- // If this happens to you let me know when it happens
211
- // Please open an issue at https://github.com/ntkhang03/fb-chat-api/issues.
212
- // return Object.assign({ type: "unknown", data });
210
+
213
211
  }
214
212
  }
215
213
 
@@ -253,7 +251,7 @@ module.exports = function(defaultFuncs, api, ctx) {
253
251
  av: ctx.globalOptions.pageID,
254
252
  queries: JSON.stringify({
255
253
  o0: {
256
- //This doc_id is valid as of ? (prob January 18, 2020)
254
+
257
255
  doc_id: "1768656253222505",
258
256
  query_params: {
259
257
  thread_and_message_id: {
@@ -3,9 +3,6 @@
3
3
  const log = require("../../../func/logAdapter");
4
4
  const { parseAndCheckLogin } = require("../../utils/client");
5
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.
9
6
  module.exports = function (defaultFuncs, api, ctx) {
10
7
  return function getThemePictures(id, callback) {
11
8
  let resolveFunc = function () { };
@@ -22,8 +19,6 @@ module.exports = function (defaultFuncs, api, ctx) {
22
19
  };
23
20
  }
24
21
 
25
- // [Hardened] Accept numbers/bigint too. Previously any non-string id was silently
26
- // replaced with "" and Facebook answered messenger_thread_theme: null.
27
22
  if (typeof id === "number" || typeof id === "bigint") id = String(id);
28
23
  id = typeof id === "string" ? id.trim() : "";
29
24
 
@@ -52,8 +47,6 @@ module.exports = function (defaultFuncs, api, ctx) {
52
47
  throw resData;
53
48
  }
54
49
 
55
- // [Hardened] Request worked but Facebook has no theme with this ID for this account.
56
- // Report as failure instead of a false "success" with null theme.
57
50
  if (!resData || !resData.data || !resData.data.messenger_thread_theme) {
58
51
  const notFound = {
59
52
  error: "Theme not found: Facebook returned no theme for ID " + id + ". Check the ID (use the theme_fbid of a real theme).",
@@ -29,7 +29,6 @@ module.exports = function(defaultFuncs, api, ctx) {
29
29
  form["watermarkTimestamp"] = new Date().getTime();
30
30
  form["shouldSendReadReceipt"] = true;
31
31
  form["commerce_last_message_type"] = "";
32
- //form["titanOriginatedThreadId"] = utils.generateThreadingID(ctx.clientID);
33
32
 
34
33
  let resData;
35
34
  try {
@@ -2,7 +2,7 @@
2
2
  const log = require("../../../func/logAdapter");
3
3
  const { parseAndCheckLogin, saveCookies } = require("../../utils/client");
4
4
  module.exports = function(defaultFuncs, api, ctx) {
5
- // muteSecond: -1=permanent mute, 0=unmute, 60=one minute, 3600=one hour, etc.
5
+
6
6
  return function muteThread(threadID, muteSeconds, callback) {
7
7
  let resolveFunc = function() {};
8
8
  let rejectFunc = function() {};
@@ -1,16 +1,8 @@
1
1
  "use strict";
2
2
 
3
- /**
4
- * Pin or unpin a message in a thread.
5
- * @param {string} messageID - The ID of the message to pin/unpin.
6
- * @param {string} threadID - The thread ID where the message is.
7
- * @param {boolean} [pin=true] - true to pin, false to unpin.
8
- * @param {function} [callback] - Optional callback(err, result).
9
- * @returns {Promise}
10
- */
11
3
  module.exports = function (defaultFuncs, api, ctx) {
12
4
  return function pinMessage(messageID, threadID, pin, callback) {
13
- // Handle optional pin param
5
+
14
6
  if (typeof pin === "function") {
15
7
  callback = pin;
16
8
  pin = true;
@@ -45,7 +37,6 @@ module.exports = function (defaultFuncs, api, ctx) {
45
37
  const reqID = ++ctx.wsReqNumber;
46
38
  const taskID = ++ctx.wsTaskNumber;
47
39
 
48
- // label 682 = pin, label 683 = unpin
49
40
  const label = pin ? "682" : "683";
50
41
 
51
42
  const taskPayload = {
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
2
  const logger = require("../../../func/logger");
3
3
 
4
- /**
5
- * Message Scheduler System
6
- * Allows scheduling messages to be sent at a specific time in the future
7
- */
8
4
  module.exports = function (defaultFuncs, api, ctx) {
9
- // Initialize scheduler on first call
5
+
10
6
  if (!ctx._scheduler) {
11
7
  ctx._scheduler = createSchedulerInstance(api);
12
8
  }
@@ -15,38 +11,12 @@ module.exports = function (defaultFuncs, api, ctx) {
15
11
  };
16
12
 
17
13
  function createSchedulerInstance(api) {
18
- const scheduledMessages = new Map(); // Map<id, ScheduledMessage>
14
+ const scheduledMessages = new Map();
19
15
  let nextId = 1;
20
16
 
21
- /**
22
- * Scheduled Message Object
23
- * @typedef {Object} ScheduledMessage
24
- * @property {string} id - Unique identifier
25
- * @property {string|Object} message - Message content
26
- * @property {string|string[]} threadID - Target thread ID(s)
27
- * @property {number} timestamp - When to send (Unix timestamp in ms)
28
- * @property {number} createdAt - When scheduled (Unix timestamp in ms)
29
- * @property {Object} options - Additional options (replyMessageID, isGroup, etc.)
30
- * @property {Function} callback - Optional callback when sent
31
- * @property {NodeJS.Timeout} timeout - Timeout reference
32
- * @property {boolean} cancelled - Whether cancelled
33
- */
34
-
35
- /**
36
- * Schedule a message to be sent at a specific time
37
- * @param {string|Object} message - Message content
38
- * @param {string|string[]} threadID - Target thread ID(s)
39
- * @param {Date|number|string} when - When to send (Date, timestamp, or ISO string)
40
- * @param {Object} [options] - Additional options
41
- * @param {string} [options.replyMessageID] - Message ID to reply to
42
- * @param {boolean} [options.isGroup] - Whether it's a group chat
43
- * @param {Function} [options.callback] - Callback when sent
44
- * @returns {string} Scheduled message ID
45
- */
46
17
  function scheduleMessage(message, threadID, when, options = {}) {
47
18
  let timestamp;
48
19
 
49
- // Parse when parameter
50
20
  if (when instanceof Date) {
51
21
  timestamp = when.getTime();
52
22
  } else if (typeof when === "number") {
@@ -57,7 +27,6 @@ function createSchedulerInstance(api) {
57
27
  throw new Error("Invalid 'when' parameter. Must be Date, number (timestamp), or ISO string");
58
28
  }
59
29
 
60
- // Validate timestamp
61
30
  if (isNaN(timestamp)) {
62
31
  throw new Error("Invalid date/time");
63
32
  }
@@ -70,7 +39,6 @@ function createSchedulerInstance(api) {
70
39
  const id = `scheduled_${nextId++}_${Date.now()}`;
71
40
  const delay = timestamp - now;
72
41
 
73
- // Create scheduled message object
74
42
  const scheduled = {
75
43
  id,
76
44
  message,
@@ -85,14 +53,12 @@ function createSchedulerInstance(api) {
85
53
  cancelled: false
86
54
  };
87
55
 
88
- // Set timeout to send message
89
56
  scheduled.timeout = setTimeout(() => {
90
57
  if (scheduled.cancelled) return;
91
58
 
92
59
  try {
93
60
  logger(`Sending scheduled message ${id}`, "info");
94
61
 
95
- // Send message
96
62
  api.sendMessage(
97
63
  message,
98
64
  threadID,
@@ -121,11 +87,6 @@ function createSchedulerInstance(api) {
121
87
  return id;
122
88
  }
123
89
 
124
- /**
125
- * Cancel a scheduled message
126
- * @param {string} id - Scheduled message ID
127
- * @returns {boolean} True if cancelled, false if not found
128
- */
129
90
  function cancelScheduledMessage(id) {
130
91
  const scheduled = scheduledMessages.get(id);
131
92
  if (!scheduled) {
@@ -133,7 +94,7 @@ function createSchedulerInstance(api) {
133
94
  }
134
95
 
135
96
  if (scheduled.cancelled) {
136
- return false; // Already cancelled
97
+ return false;
137
98
  }
138
99
 
139
100
  clearTimeout(scheduled.timeout);
@@ -143,18 +104,12 @@ function createSchedulerInstance(api) {
143
104
  return true;
144
105
  }
145
106
 
146
- /**
147
- * Get scheduled message info
148
- * @param {string} id - Scheduled message ID
149
- * @returns {ScheduledMessage|null} Scheduled message or null if not found
150
- */
151
107
  function getScheduledMessage(id) {
152
108
  const scheduled = scheduledMessages.get(id);
153
109
  if (!scheduled || scheduled.cancelled) {
154
110
  return null;
155
111
  }
156
112
 
157
- // Return a copy without internal properties
158
113
  return {
159
114
  id: scheduled.id,
160
115
  message: scheduled.message,
@@ -166,10 +121,6 @@ function createSchedulerInstance(api) {
166
121
  };
167
122
  }
168
123
 
169
- /**
170
- * List all scheduled messages
171
- * @returns {ScheduledMessage[]} Array of scheduled messages
172
- */
173
124
  function listScheduledMessages() {
174
125
  const now = Date.now();
175
126
  const list = [];
@@ -188,14 +139,9 @@ function createSchedulerInstance(api) {
188
139
  });
189
140
  }
190
141
 
191
- // Sort by timestamp
192
142
  return list.sort((a, b) => a.timestamp - b.timestamp);
193
143
  }
194
144
 
195
- /**
196
- * Cancel all scheduled messages
197
- * @returns {number} Number of cancelled messages
198
- */
199
145
  function cancelAllScheduledMessages() {
200
146
  let count = 0;
201
147
  for (const id of scheduledMessages.keys()) {
@@ -207,17 +153,10 @@ function createSchedulerInstance(api) {
207
153
  return count;
208
154
  }
209
155
 
210
- /**
211
- * Get count of scheduled messages
212
- * @returns {number} Count
213
- */
214
156
  function getScheduledCount() {
215
157
  return scheduledMessages.size;
216
158
  }
217
159
 
218
- /**
219
- * Clear expired/cancelled messages from memory
220
- */
221
160
  function cleanup() {
222
161
  const now = Date.now();
223
162
  let cleaned = 0;
@@ -234,13 +173,8 @@ function createSchedulerInstance(api) {
234
173
  }
235
174
  }
236
175
 
237
- // Auto cleanup every 5 minutes
238
176
  const cleanupInterval = setInterval(cleanup, 5 * 60 * 1000);
239
177
 
240
- /**
241
- * Destroy scheduler and cleanup all resources
242
- * @returns {number} Number of cancelled messages
243
- */
244
178
  function destroy() {
245
179
  clearInterval(cleanupInterval);
246
180
  const count = cancelAllScheduledMessages();
@@ -248,7 +182,6 @@ function createSchedulerInstance(api) {
248
182
  return count;
249
183
  }
250
184
 
251
- // Return scheduler API
252
185
  return {
253
186
  scheduleMessage,
254
187
  cancelScheduledMessage,
@@ -258,7 +191,7 @@ function createSchedulerInstance(api) {
258
191
  getScheduledCount,
259
192
  cleanup,
260
193
  destroy,
261
- // Cleanup interval reference for manual cleanup if needed
194
+
262
195
  _cleanupInterval: cleanupInterval
263
196
  };
264
197
  }
@@ -2,21 +2,6 @@
2
2
 
3
3
  var logger = require("../../utils/logger");
4
4
 
5
- /**
6
- * sendBroadcast — Send a message to multiple threads in parallel
7
- * with rate limiting and per-thread delivery tracking.
8
- *
9
- * Usage:
10
- * api.sendBroadcast(msg, threadIDs, [options], [callback])
11
- *
12
- * Options:
13
- * delay {number} ms between each send (default: 1000)
14
- * parallel {number} max concurrent sends (default: 3)
15
- * onEach {function(err, result, threadID)} called after each individual send
16
- *
17
- * Returns:
18
- * Promise<{ sent: string[], failed: { id, error }[], total: number }>
19
- */
20
5
  module.exports = function (defaultFuncs, api, ctx) {
21
6
  return function sendBroadcast(msg, threadIDs, options, callback) {
22
7
  if (typeof options === "function") {
@@ -1,13 +1,4 @@
1
- /**
2
- * Created by Donix-VN (DongDev)
3
- * Modified by MueidMursalinRifat & Xalman
4
- * Send a message using MQTT.
5
- * @param {string|object} msg - The message object or text to send.
6
- * @param {string} threadID - The ID of the thread to send the message to.
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.
10
- */
1
+
11
2
 
12
3
  "use strict";
13
4
  const log = require("../../../func/logAdapter");
@@ -8,7 +8,7 @@ module.exports = function (defaultFuncs, api, ctx) {
8
8
  resolveFunc = resolve;
9
9
  rejectFunc = reject;
10
10
  });
11
- returnPromise.catch(function () { }); // [Fixed by xalman] unawaited callers caused unhandledRejection
11
+ returnPromise.catch(function () { });
12
12
  if (getType(options) == "Function" || getType(options) == "AsyncFunction") {
13
13
  callback = options;
14
14
  options = {};
@@ -23,7 +23,7 @@ module.exports = function (defaultFuncs, api, ctx) {
23
23
  if (!threadID) {
24
24
  return callback(new Error("threadID is required"));
25
25
  }
26
- // [Fixed by xalman] E2EE DM: show typing through the E2EE bridge instead of (useless) MQTT.
26
+
27
27
  if (typeof threadID === "string" || typeof threadID === "number") {
28
28
  var _tid = String(threadID);
29
29
  if (ctx.threadTypes && ctx.threadTypes[_tid] === "dm" && ctx.e2ee &&