@dongdev/fca-unofficial 2.0.7 → 2.0.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/CHANGELOG.md +3 -0
  2. package/func/checkUpdate.js +9 -9
  3. package/func/logger.js +40 -104
  4. package/module/login.js +4 -4
  5. package/module/loginHelper.js +3 -3
  6. package/module/options.js +5 -9
  7. package/package.json +5 -5
  8. package/src/api/action/addExternalModule.js +5 -5
  9. package/src/api/action/changeAvatar.js +11 -10
  10. package/src/api/action/changeBio.js +7 -8
  11. package/src/api/action/getCurrentUserID.js +1 -1
  12. package/src/api/action/handleFriendRequest.js +5 -5
  13. package/src/api/action/logout.js +9 -8
  14. package/src/api/action/refreshFb_dtsg.js +17 -12
  15. package/src/api/action/setPostReaction.js +10 -11
  16. package/src/api/action/unfriend.js +3 -4
  17. package/src/api/http/httpGet.js +7 -8
  18. package/src/api/http/httpPost.js +7 -8
  19. package/src/api/http/postFormData.js +6 -5
  20. package/src/api/messaging/addUserToGroup.js +0 -1
  21. package/src/api/messaging/changeAdminStatus.js +108 -89
  22. package/src/api/messaging/changeArchivedStatus.js +6 -6
  23. package/src/api/messaging/changeBlockedStatus.js +3 -4
  24. package/src/api/messaging/changeGroupImage.js +72 -117
  25. package/src/api/messaging/changeNickname.js +59 -48
  26. package/src/api/messaging/changeThreadColor.js +61 -47
  27. package/src/api/messaging/changeThreadEmoji.js +106 -0
  28. package/src/api/messaging/createNewGroup.js +5 -5
  29. package/src/api/messaging/createPoll.js +36 -63
  30. package/src/api/messaging/deleteMessage.js +4 -4
  31. package/src/api/messaging/deleteThread.js +4 -4
  32. package/src/api/messaging/forwardAttachment.js +38 -47
  33. package/src/api/messaging/getFriendsList.js +5 -6
  34. package/src/api/messaging/getMessage.js +4 -9
  35. package/src/api/messaging/handleMessageRequest.js +5 -5
  36. package/src/api/messaging/markAsDelivered.js +5 -5
  37. package/src/api/messaging/markAsRead.js +7 -7
  38. package/src/api/messaging/markAsReadAll.js +3 -4
  39. package/src/api/messaging/markAsSeen.js +7 -7
  40. package/src/api/messaging/muteThread.js +3 -4
  41. package/src/api/messaging/removeUserFromGroup.js +82 -56
  42. package/src/api/messaging/resolvePhotoUrl.js +2 -3
  43. package/src/api/messaging/searchForThread.js +2 -3
  44. package/src/api/messaging/sendMessage.js +171 -101
  45. package/src/api/messaging/sendMessageMqtt.js +14 -12
  46. package/src/api/messaging/sendTypingIndicator.js +11 -11
  47. package/src/api/messaging/setMessageReaction.js +68 -82
  48. package/src/api/messaging/setTitle.js +77 -48
  49. package/src/api/messaging/shareContact.js +2 -4
  50. package/src/api/messaging/threadColors.js +0 -3
  51. package/src/api/messaging/unsendMessage.js +74 -37
  52. package/src/api/messaging/uploadAttachment.js +11 -9
  53. package/src/api/socket/core/connectMqtt.js +180 -0
  54. package/src/api/socket/core/getSeqID.js +25 -0
  55. package/src/api/socket/core/getTaskResponseData.js +22 -0
  56. package/src/api/socket/core/markDelivery.js +12 -0
  57. package/src/api/socket/core/parseDelta.js +351 -0
  58. package/src/api/socket/detail/buildStream.js +176 -68
  59. package/src/api/socket/detail/constants.js +24 -0
  60. package/src/api/socket/listenMqtt.js +80 -1005
  61. package/src/api/{messaging → threads}/getThreadHistory.js +5 -22
  62. package/src/api/threads/getThreadInfo.js +35 -248
  63. package/src/api/threads/getThreadList.js +20 -20
  64. package/src/api/threads/getThreadPictures.js +3 -4
  65. package/src/api/users/getUserID.js +5 -6
  66. package/src/api/users/getUserInfo.js +305 -73
  67. package/src/api/users/getUserInfoV2.js +134 -0
  68. package/src/database/models/user.js +32 -0
  69. package/src/database/userData.js +89 -0
  70. package/src/utils/constants.js +12 -2
  71. package/src/utils/format.js +1051 -0
  72. package/src/utils/request.js +75 -7
  73. package/src/api/threads/changeThreadEmoji.js +0 -55
  74. package/src/utils/index.js +0 -1497
@@ -1,10 +1,9 @@
1
- "use strict";
2
-
3
1
  const axios = require("axios");
4
2
  const { CookieJar } = require("tough-cookie");
5
3
  const { wrapper } = require("axios-cookiejar-support");
6
4
  const FormData = require("form-data");
7
5
  const { HttpsProxyAgent } = require("https-proxy-agent");
6
+ const { Readable } = require("stream");
8
7
 
9
8
  const headersMod = require("./headers");
10
9
  const getHeaders = headersMod.getHeaders || headersMod;
@@ -50,6 +49,25 @@ function cfg(base = {}) {
50
49
  };
51
50
  }
52
51
 
52
+ function toStringVal(v) {
53
+ if (v === undefined || v === null) return "";
54
+ if (typeof v === "bigint") return v.toString();
55
+ if (typeof v === "boolean") return v ? "true" : "false";
56
+ return String(v);
57
+ }
58
+
59
+ function isStream(v) {
60
+ return v && typeof v === "object" && typeof v.pipe === "function" && typeof v.on === "function";
61
+ }
62
+
63
+ function isBlobLike(v) {
64
+ return v && typeof v.arrayBuffer === "function" && (typeof v.type === "string" || typeof v.name === "string");
65
+ }
66
+
67
+ function isPairArrayList(arr) {
68
+ return Array.isArray(arr) && arr.length > 0 && arr.every(x => Array.isArray(x) && x.length === 2 && typeof x[0] === "string");
69
+ }
70
+
53
71
  function cleanGet(url) {
54
72
  return requestWithRetry(() => client.get(url, cfg()));
55
73
  }
@@ -71,9 +89,19 @@ function post(url, reqJar, form, options, ctx, customHeader) {
71
89
  if (form && typeof form === "object") {
72
90
  for (const k of Object.keys(form)) {
73
91
  let v = form[k];
92
+ if (isPairArrayList(v)) {
93
+ for (const [kk, vv] of v) p.append(`${k}[${kk}]`, toStringVal(vv));
94
+ continue;
95
+ }
96
+ if (Array.isArray(v)) {
97
+ for (const x of v) {
98
+ if (Array.isArray(x) && x.length === 2 && typeof x[1] !== "object") p.append(k, toStringVal(x[1]));
99
+ else p.append(k, toStringVal(x));
100
+ }
101
+ continue;
102
+ }
74
103
  if (getType(v) === "Object") v = JSON.stringify(v);
75
- if (Array.isArray(v)) v.forEach(x => p.append(k, x));
76
- else p.append(k, v);
104
+ p.append(k, toStringVal(v));
77
105
  }
78
106
  }
79
107
  data = p.toString();
@@ -82,13 +110,53 @@ function post(url, reqJar, form, options, ctx, customHeader) {
82
110
  return requestWithRetry(() => client.post(url, data, cfg({ reqJar, headers })));
83
111
  }
84
112
 
85
- function postFormData(url, reqJar, form, qs, options, ctx) {
113
+ async function postFormData(url, reqJar, form, qs, options, ctx) {
86
114
  const fd = new FormData();
87
115
  if (form && typeof form === "object") {
88
116
  for (const k of Object.keys(form)) {
89
117
  const v = form[k];
90
- if (Array.isArray(v)) v.forEach(x => fd.append(k, x));
91
- else fd.append(k, v);
118
+ if (v === undefined || v === null) continue;
119
+ if (isPairArrayList(v)) {
120
+ for (const [kk, vv] of v) fd.append(`${k}[${kk}]`, typeof vv === "object" && !Buffer.isBuffer(vv) && !isStream(vv) ? JSON.stringify(vv) : vv);
121
+ continue;
122
+ }
123
+ if (Array.isArray(v)) {
124
+ for (const x of v) {
125
+ if (Array.isArray(x) && x.length === 2 && x[1] && typeof x[1] === "object" && !Buffer.isBuffer(x[1]) && !isStream(x[1])) {
126
+ fd.append(k, x[0], x[1]);
127
+ } else if (Array.isArray(x) && x.length === 2 && typeof x[1] !== "object") {
128
+ fd.append(k, toStringVal(x[1]));
129
+ } else if (x && typeof x === "object" && "value" in x && "options" in x) {
130
+ fd.append(k, x.value, x.options || {});
131
+ } else if (isStream(x) || Buffer.isBuffer(x) || typeof x === "string") {
132
+ fd.append(k, x);
133
+ } else if (isBlobLike(x)) {
134
+ const buf = Buffer.from(await x.arrayBuffer());
135
+ fd.append(k, buf, { filename: x.name || k, contentType: x.type || undefined });
136
+ } else {
137
+ fd.append(k, JSON.stringify(x));
138
+ }
139
+ }
140
+ continue;
141
+ }
142
+ if (v && typeof v === "object" && "value" in v && "options" in v) {
143
+ fd.append(k, v.value, v.options || {});
144
+ continue;
145
+ }
146
+ if (isStream(v) || Buffer.isBuffer(v) || typeof v === "string") {
147
+ fd.append(k, v);
148
+ continue;
149
+ }
150
+ if (isBlobLike(v)) {
151
+ const buf = Buffer.from(await v.arrayBuffer());
152
+ fd.append(k, buf, { filename: v.name || k, contentType: v.type || undefined });
153
+ continue;
154
+ }
155
+ if (typeof v === "number" || typeof v === "boolean") {
156
+ fd.append(k, toStringVal(v));
157
+ continue;
158
+ }
159
+ fd.append(k, JSON.stringify(v));
92
160
  }
93
161
  }
94
162
  const headers = { ...getHeaders(url, options, ctx), ...fd.getHeaders() };
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require("../../utils");
4
- const log = require("npmlog");
5
-
6
- module.exports = function(defaultFuncs, api, ctx) {
7
- return function changeThreadEmoji(emoji, threadID, callback) {
8
- let resolveFunc = function() {};
9
- let rejectFunc = function() {};
10
- const returnPromise = new Promise(function(resolve, reject) {
11
- resolveFunc = resolve;
12
- rejectFunc = reject;
13
- });
14
-
15
- if (!callback) {
16
- callback = function(err) {
17
- if (err) {
18
- return rejectFunc(err);
19
- }
20
- resolveFunc();
21
- };
22
- }
23
- const form = {
24
- emoji_choice: emoji,
25
- thread_or_other_fbid: threadID
26
- };
27
-
28
- defaultFuncs
29
- .post(
30
- "https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg",
31
- ctx.jar,
32
- form
33
- )
34
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
- .then(function(resData) {
36
- if (resData.error === 1357031) {
37
- throw {
38
- error:
39
- "Trying to change emoji of a chat that doesn't exist. Have at least one message in the thread before trying to change the emoji."
40
- };
41
- }
42
- if (resData.error) {
43
- throw resData;
44
- }
45
-
46
- return callback();
47
- })
48
- .catch(function(err) {
49
- log.error("changeThreadEmoji", err);
50
- return callback(err);
51
- });
52
-
53
- return returnPromise;
54
- };
55
- };