nexus-fca 1.0.0

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 (180) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/DOCS.md +2047 -0
  3. package/Fca_Database/database.sqlite +0 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +240 -0
  6. package/docs/README.md +9 -0
  7. package/docs/addExternalModule.md +15 -0
  8. package/docs/addUserToGroup.md +20 -0
  9. package/docs/changeAdminStatus.md +21 -0
  10. package/docs/changeArchivedStatus.md +19 -0
  11. package/docs/changeAvatar.md +21 -0
  12. package/docs/changeAvatarV2.md +18 -0
  13. package/docs/changeBio.md +15 -0
  14. package/docs/changeBlockedStatus.md +16 -0
  15. package/docs/changeBlockedStatusMqtt.md +16 -0
  16. package/docs/changeCover.md +15 -0
  17. package/docs/changeGroupImage.md +16 -0
  18. package/docs/changeName.md +18 -0
  19. package/docs/changeNickname.md +17 -0
  20. package/docs/changeThreadColor.md +16 -0
  21. package/docs/changeThreadEmoji.md +16 -0
  22. package/docs/changeUsername.md +15 -0
  23. package/docs/createCommentPost.md +16 -0
  24. package/docs/createNewGroup.md +16 -0
  25. package/docs/createPoll.md +17 -0
  26. package/docs/createPost.md +15 -0
  27. package/docs/deleteMessage.md +15 -0
  28. package/docs/deleteThread.md +15 -0
  29. package/docs/editMessage.md +16 -0
  30. package/docs/follow.md +15 -0
  31. package/docs/forwardAttachment.md +16 -0
  32. package/docs/getAccess.md +17 -0
  33. package/docs/getAvatarUser.md +15 -0
  34. package/docs/getBotInitialData.md +14 -0
  35. package/docs/getCtx.md +14 -0
  36. package/docs/getCurrentUserID.md +12 -0
  37. package/docs/getEmojiUrl.md +17 -0
  38. package/docs/getFriendsList.md +14 -0
  39. package/docs/getMessage.md +15 -0
  40. package/docs/getOptions.md +14 -0
  41. package/docs/getRegion.md +14 -0
  42. package/docs/getThreadHistory.md +17 -0
  43. package/docs/getThreadHistoryDeprecated.md +17 -0
  44. package/docs/getThreadInfo.md +15 -0
  45. package/docs/getThreadInfoDeprecated.md +17 -0
  46. package/docs/getThreadList.md +17 -0
  47. package/docs/getThreadListDeprecated.md +17 -0
  48. package/docs/getThreadPictures.md +17 -0
  49. package/docs/getUID.md +15 -0
  50. package/docs/getUserID.md +15 -0
  51. package/docs/getUserInfo.md +15 -0
  52. package/docs/handleFriendRequest.md +16 -0
  53. package/docs/handleMessageRequest.md +16 -0
  54. package/docs/httpGet.md +15 -0
  55. package/docs/httpPost.md +16 -0
  56. package/docs/httpPostFormData.md +16 -0
  57. package/docs/listenMqtt.md +17 -0
  58. package/docs/listenNotification.md +14 -0
  59. package/docs/logout.md +14 -0
  60. package/docs/markAsDelivered.md +16 -0
  61. package/docs/markAsRead.md +16 -0
  62. package/docs/markAsReadAll.md +14 -0
  63. package/docs/markAsSeen.md +15 -0
  64. package/docs/muteThread.md +16 -0
  65. package/docs/pinMessage.md +17 -0
  66. package/docs/postFormData.md +16 -0
  67. package/docs/refreshFb_dtsg.md +14 -0
  68. package/docs/removeUserFromGroup.md +16 -0
  69. package/docs/resolvePhotoUrl.md +15 -0
  70. package/docs/searchForThread.md +15 -0
  71. package/docs/searchStickers.md +15 -0
  72. package/docs/sendComment.md +16 -0
  73. package/docs/sendMessage.md +16 -0
  74. package/docs/sendMessageMqtt.md +16 -0
  75. package/docs/sendTypingIndicator.md +15 -0
  76. package/docs/setMessageReaction.md +17 -0
  77. package/docs/setMessageReactionMqtt.md +16 -0
  78. package/docs/setPostReaction.md +16 -0
  79. package/docs/setProfileGuard.md +15 -0
  80. package/docs/setStoryReaction.md +16 -0
  81. package/docs/setTitle.md +16 -0
  82. package/docs/shareContact.md +16 -0
  83. package/docs/shareLink.md +16 -0
  84. package/docs/stopListenMqtt.md +8 -0
  85. package/docs/threadColors.md +11 -0
  86. package/docs/unfriend.md +15 -0
  87. package/docs/unsendMessage.md +15 -0
  88. package/docs/uploadAttachment.md +15 -0
  89. package/fca-config.json +7 -0
  90. package/index.d.ts +618 -0
  91. package/index.js +361 -0
  92. package/lib/database/models/index.js +47 -0
  93. package/lib/database/models/thread.js +31 -0
  94. package/lib/database/threadData.js +93 -0
  95. package/lib/logger.js +24 -0
  96. package/lib/login.js +0 -0
  97. package/package.json +90 -0
  98. package/src/addExternalModule.js +19 -0
  99. package/src/addUserToGroup.js +113 -0
  100. package/src/changeAdminStatus.js +79 -0
  101. package/src/changeArchivedStatus.js +55 -0
  102. package/src/changeAvatar.js +126 -0
  103. package/src/changeAvatarV2.js +77 -0
  104. package/src/changeBio.js +77 -0
  105. package/src/changeBlockedStatus.js +47 -0
  106. package/src/changeBlockedStatusMqtt.js +71 -0
  107. package/src/changeCover.js +72 -0
  108. package/src/changeGroupImage.js +132 -0
  109. package/src/changeName.js +79 -0
  110. package/src/changeNickname.js +59 -0
  111. package/src/changeThreadColor.js +65 -0
  112. package/src/changeThreadEmoji.js +55 -0
  113. package/src/changeUsername.js +58 -0
  114. package/src/createCommentPost.js +225 -0
  115. package/src/createNewGroup.js +86 -0
  116. package/src/createPoll.js +71 -0
  117. package/src/createPost.js +276 -0
  118. package/src/deleteMessage.js +56 -0
  119. package/src/deleteThread.js +56 -0
  120. package/src/editMessage.js +57 -0
  121. package/src/follow.js +54 -0
  122. package/src/forwardAttachment.js +60 -0
  123. package/src/getAccess.js +67 -0
  124. package/src/getAvatarUser.js +56 -0
  125. package/src/getBotInitialData.js +37 -0
  126. package/src/getCtx.js +6 -0
  127. package/src/getCurrentUserID.js +7 -0
  128. package/src/getEmojiUrl.js +29 -0
  129. package/src/getFriendsList.js +83 -0
  130. package/src/getMessage.js +796 -0
  131. package/src/getOptions.js +6 -0
  132. package/src/getRegion.js +8 -0
  133. package/src/getThreadHistory.js +666 -0
  134. package/src/getThreadHistoryDeprecated.js +55 -0
  135. package/src/getThreadInfo.js +535 -0
  136. package/src/getThreadInfoDeprecated.js +49 -0
  137. package/src/getThreadList.js +192 -0
  138. package/src/getThreadListDeprecated.js +54 -0
  139. package/src/getThreadPictures.js +79 -0
  140. package/src/getUID.js +67 -0
  141. package/src/getUserID.js +66 -0
  142. package/src/getUserInfo.js +80 -0
  143. package/src/handleFriendRequest.js +61 -0
  144. package/src/handleMessageRequest.js +65 -0
  145. package/src/httpGet.js +57 -0
  146. package/src/httpPost.js +57 -0
  147. package/src/httpPostFormData.js +63 -0
  148. package/src/listenMqtt.js +1039 -0
  149. package/src/listenNotification.js +65 -0
  150. package/src/logout.js +75 -0
  151. package/src/markAsDelivered.js +58 -0
  152. package/src/markAsRead.js +80 -0
  153. package/src/markAsReadAll.js +50 -0
  154. package/src/markAsSeen.js +59 -0
  155. package/src/muteThread.js +52 -0
  156. package/src/pinMessage.js +59 -0
  157. package/src/postFormData.js +46 -0
  158. package/src/refreshFb_dtsg.js +66 -0
  159. package/src/removeUserFromGroup.js +79 -0
  160. package/src/resolvePhotoUrl.js +45 -0
  161. package/src/searchForThread.js +53 -0
  162. package/src/searchStickers.js +51 -0
  163. package/src/sendComment.js +63 -0
  164. package/src/sendMessage.js +328 -0
  165. package/src/sendMessageMqtt.js +316 -0
  166. package/src/sendTypingIndicator.js +103 -0
  167. package/src/setMessageReaction.js +119 -0
  168. package/src/setMessageReactionMqtt.js +61 -0
  169. package/src/setPostReaction.js +109 -0
  170. package/src/setProfileGuard.js +45 -0
  171. package/src/setStoryReaction.js +62 -0
  172. package/src/setTitle.js +86 -0
  173. package/src/shareContact.js +49 -0
  174. package/src/shareLink.js +59 -0
  175. package/src/stopListenMqtt.js +21 -0
  176. package/src/threadColors.js +131 -0
  177. package/src/unfriend.js +52 -0
  178. package/src/unsendMessage.js +49 -0
  179. package/src/uploadAttachment.js +95 -0
  180. package/utils.js +1432 -0
@@ -0,0 +1,56 @@
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 deleteThread(threadOrThreads, 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
+ if (!callback) {
15
+ callback = function (err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+
23
+ const form = {
24
+ client: "mercury"
25
+ };
26
+
27
+ if (utils.getType(threadOrThreads) !== "Array") {
28
+ threadOrThreads = [threadOrThreads];
29
+ }
30
+
31
+ for (let i = 0; i < threadOrThreads.length; i++) {
32
+ form["ids[" + i + "]"] = threadOrThreads[i];
33
+ }
34
+
35
+ defaultFuncs
36
+ .post(
37
+ "https://www.facebook.com/ajax/mercury/delete_thread.php",
38
+ ctx.jar,
39
+ form
40
+ )
41
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
42
+ .then(function (resData) {
43
+ if (resData.error) {
44
+ throw resData;
45
+ }
46
+
47
+ return callback();
48
+ })
49
+ .catch(function (err) {
50
+ log.error("deleteThread", err);
51
+ return callback(err);
52
+ });
53
+
54
+ return returnPromise;
55
+ };
56
+ };
@@ -0,0 +1,57 @@
1
+ // Nexus-FCA: Advanced and Safe Facebook Chat API
2
+ // editMessage.js - Edit a sent message via MQTT
3
+
4
+ const { generateOfflineThreadingID } = require('../utils');
5
+
6
+ function canBeCalled(func) {
7
+ try {
8
+ Reflect.apply(func, null, []);
9
+ return true;
10
+ } catch (error) {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ module.exports = function (defaultFuncs, api, ctx) {
16
+ return function editMessage(text, messageID, callback) {
17
+ if (!ctx.mqttClient) {
18
+ throw new Error('Not connected to MQTT');
19
+ }
20
+
21
+ ctx.wsReqNumber += 1;
22
+ ctx.wsTaskNumber += 1;
23
+
24
+ const queryPayload = {
25
+ message_id: messageID,
26
+ text: text
27
+ };
28
+
29
+ const query = {
30
+ failure_count: null,
31
+ label: '742',
32
+ payload: JSON.stringify(queryPayload),
33
+ queue_name: 'edit_message',
34
+ task_id: ctx.wsTaskNumber
35
+ };
36
+
37
+ const context = {
38
+ app_id: '2220391788200892',
39
+ payload: JSON.stringify({
40
+ data_trace_id: null,
41
+ epoch_id: parseInt(generateOfflineThreadingID()),
42
+ tasks: [query],
43
+ version_id: '6903494529735864'
44
+ }),
45
+ request_id: ctx.wsReqNumber,
46
+ type: 3
47
+ };
48
+
49
+ // if (canBeCalled(callback)) {
50
+ // ctx.reqCallbacks[ctx.wsReqNumber] = callback;
51
+ // }
52
+
53
+ ctx.mqttClient.publish('/ls_req', JSON.stringify(context), {
54
+ qos: 1, retain: false
55
+ });
56
+ };
57
+ };
package/src/follow.js ADDED
@@ -0,0 +1,54 @@
1
+ // Nexus-FCA: Advanced and Safe Facebook Chat API
2
+ // follow.js - Follow or unfollow a user
3
+
4
+ module.exports = function (defaultFuncs, api, ctx) {
5
+ return function follow(senderID, boolean, callback) {
6
+ let form;
7
+ if (boolean) {
8
+ form = {
9
+ av: ctx.userID,
10
+ fb_api_req_friendly_name: "CometUserFollowMutation",
11
+ fb_api_caller_class: "RelayModern",
12
+ doc_id: "25472099855769847",
13
+ variables: JSON.stringify({
14
+ input: {
15
+ attribution_id_v2:
16
+ "ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,via_cold_start,1717249218695,723451,250100865708545,,",
17
+ is_tracking_encrypted: true,
18
+ subscribe_location: "PROFILE",
19
+ subscribee_id: senderID,
20
+ tracking: null,
21
+ actor_id: ctx.userID,
22
+ client_mutation_id: "1",
23
+ },
24
+ scale: 1,
25
+ }),
26
+ };
27
+ } else {
28
+ form = {
29
+ av: ctx.userID,
30
+ fb_api_req_friendly_name: "CometUserUnfollowMutation",
31
+ fb_api_caller_class: "RelayModern",
32
+ doc_id: "25472099855769847",
33
+ variables: JSON.stringify({
34
+ action_render_location: "WWW_COMET_FRIEND_MENU",
35
+ input: {
36
+ attribution_id_v2:
37
+ "ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,tap_search_bar,1717294006136,602597,250100865708545,,",
38
+ is_tracking_encrypted: true,
39
+ subscribe_location: "PROFILE",
40
+ subscribee_id: senderID,
41
+ tracking: null,
42
+ actor_id: ctx.userID,
43
+ client_mutation_id: "1",
44
+ },
45
+ scale: 1,
46
+ }),
47
+ };
48
+ }
49
+ defaultFuncs
50
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
51
+ .then(() => callback && callback(null, true))
52
+ .catch(err => callback && callback(err, false));
53
+ };
54
+ };
@@ -0,0 +1,60 @@
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 forwardAttachment(attachmentID, userOrUsers, 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
+ if (!callback) {
15
+ callback = function (err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+
23
+ const form = {
24
+ attachment_id: attachmentID
25
+ };
26
+
27
+ if (utils.getType(userOrUsers) !== "Array") {
28
+ userOrUsers = [userOrUsers];
29
+ }
30
+
31
+ const timestamp = Math.floor(Date.now() / 1000);
32
+
33
+ for (let i = 0; i < userOrUsers.length; i++) {
34
+ //That's good, the key of the array is really timestmap in seconds + index
35
+ //Probably time when the attachment will be sent?
36
+ form["recipient_map[" + (timestamp + i) + "]"] = userOrUsers[i];
37
+ }
38
+
39
+ defaultFuncs
40
+ .post(
41
+ "https://www.facebook.com/mercury/attachments/forward/",
42
+ ctx.jar,
43
+ form
44
+ )
45
+ .then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
46
+ .then(function (resData) {
47
+ if (resData.error) {
48
+ throw resData;
49
+ }
50
+
51
+ return callback();
52
+ })
53
+ .catch(function (err) {
54
+ log.error("forwardAttachment", err);
55
+ return callback(err);
56
+ });
57
+
58
+ return returnPromise;
59
+ };
60
+ };
@@ -0,0 +1,67 @@
1
+ // Nexus-FCA: Advanced and Safe Facebook Chat API
2
+ // getAccess.js - Get Facebook access token (with 2FA support)
3
+
4
+ const utils = require('../utils');
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function getAccess(authCode = '', callback) {
8
+ let cb;
9
+ const url = 'https://business.facebook.com/';
10
+ const Referer = url + 'security/twofactor/reauth/?twofac_next=' + encodeURIComponent(url + 'content_management') + '&type=avoid_bypass&app_id=0&save_device=0';
11
+ const rt = new Promise(function (resolve, reject) {
12
+ cb = (error, token) => token ? resolve(token) : reject(error);
13
+ });
14
+
15
+ if (typeof authCode == 'function') {
16
+ callback = authCode;
17
+ authCode = '';
18
+ }
19
+ if (typeof callback == 'function') cb = callback;
20
+ if (!!ctx.access_token)
21
+ cb(null, ctx.access_token);
22
+ else
23
+ utils
24
+ .get(url + 'content_management', ctx.jar, null, ctx.globalOptions, null, {
25
+ noRef: true,
26
+ Origin: url
27
+ })
28
+ .then(function (res) {
29
+ const html = res.body;
30
+ const lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
31
+ return lsd;
32
+ })
33
+ .then(function (lsd) {
34
+ function submitCode(code) {
35
+ let pCb;
36
+ const rtPromise = new Promise(function (resolve) {
37
+ pCb = (error, token) => resolve(cb(error, token));
38
+ });
39
+ if (typeof code != 'string')
40
+ pCb({
41
+ error: 'submitCode',
42
+ lerror: 'code must be string',
43
+ continue: submitCode
44
+ });
45
+ else
46
+ defaultFuncs
47
+ .post(url + 'security/twofactor/reauth/enter/', ctx.jar, {
48
+ approvals_code: code,
49
+ save_device: true,
50
+ lsd
51
+ }, ctx.globalOptions, null, {
52
+ Referer,
53
+ Origin: url
54
+ })
55
+ .then(function (res) {
56
+ // ...handle response...
57
+ });
58
+ return rtPromise;
59
+ }
60
+ cb({
61
+ error: '2FA required',
62
+ continue: submitCode
63
+ });
64
+ });
65
+ return rt;
66
+ };
67
+ };
@@ -0,0 +1,56 @@
1
+ // Nexus-FCA: Advanced and Safe Facebook Chat API
2
+ // getAvatarUser.js - Get user avatar URLs
3
+
4
+ const utils = require('../utils');
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ function handleAvatar(userIDs, height, width) {
8
+ let cb;
9
+ const uploads = [];
10
+ const rtPromise = new Promise(function (resolve, reject) {
11
+ cb = (error, data) => data ? resolve(data) : reject(error);
12
+ });
13
+
14
+ userIDs.map(function (v) {
15
+ const mainPromise = defaultFuncs
16
+ .get(`https://graph.facebook.com/${v}/picture?height=${height}&width=${width}&redirect=false&access_token=` + ctx.access_token, ctx.jar)
17
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
18
+ .then(function (res) {
19
+ return {
20
+ userID: v,
21
+ url: res.data.url
22
+ };
23
+ })
24
+ .catch(function (err) {
25
+ return cb(err);
26
+ });
27
+ uploads.push(mainPromise);
28
+ });
29
+
30
+ Promise
31
+ .all(uploads)
32
+ .then(function (res) {
33
+ return cb(null, res.reduce(function (Obj, { userID, url }) {
34
+ Obj[userID] = url;
35
+ return Obj;
36
+ }, {}));
37
+ })
38
+ .catch(function (err) {
39
+ return cb(err);
40
+ });
41
+
42
+ return rtPromise;
43
+ }
44
+
45
+ return function getAvatarUser(userIDs, size = [1500, 1500], callback) {
46
+ let cb;
47
+ const rtPromise = new Promise(function (resolve, reject) {
48
+ cb = (err, res) => res ? resolve(res) : reject(err);
49
+ });
50
+ if (!Array.isArray(userIDs)) userIDs = [userIDs];
51
+ handleAvatar(userIDs, size[0], size[1])
52
+ .then(res => cb(null, res))
53
+ .catch(cb);
54
+ return rtPromise;
55
+ };
56
+ };
@@ -0,0 +1,37 @@
1
+ // Nexus-FCA: Advanced and Safe Facebook Chat API
2
+ // getBotInitialData.js - Fetch bot account info for admin/monitoring
3
+
4
+ const utils = require("../utils");
5
+
6
+ module.exports = (defaultFuncs, api, ctx) => {
7
+ return async (callback) => {
8
+ let resolveFunc = () => {};
9
+ let rejectFunc = () => {};
10
+ const returnPromise = new Promise((resolve, reject) => {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+ if (!callback) {
15
+ callback = (err, data) => {
16
+ if (err) return rejectFunc(err);
17
+ resolveFunc(data);
18
+ };
19
+ }
20
+ utils.log("Fetching account info...");
21
+ api.httpGet(`https://www.facebook.com/profile.php?id=${ctx.userID}`, null, {
22
+ customUserAgent: utils.windowsUserAgent
23
+ }, (err, data) => {
24
+ if (err) return callback(err);
25
+ const profileMatch = data.match(/"CurrentUserInitialData",\[\],\{(.*?)\},(.*?)\]/);
26
+ if (profileMatch && profileMatch[1]){
27
+ const accountJson = JSON.parse(`{${profileMatch[1]}}`);
28
+ accountJson.name = accountJson.NAME;
29
+ accountJson.uid = accountJson.USER_ID;
30
+ delete accountJson.NAME;
31
+ delete accountJson.USER_ID;
32
+ return callback(null, { ...accountJson });
33
+ } else return callback(null, { error: "Something went wrong. Maybe its possible that it has a limitation due to spam requests. You can try again later." });
34
+ }, true);
35
+ return returnPromise;
36
+ };
37
+ };
package/src/getCtx.js ADDED
@@ -0,0 +1,6 @@
1
+ // Nexus-FCA: Advanced and Safe Facebook Chat API
2
+ // getCtx.js - Get context property
3
+
4
+ module.exports = function (defaultFuncs, api, ctx) {
5
+ return (str) => ctx[str];
6
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ module.exports = function (defaultFuncs, api, ctx) {
4
+ return function getCurrentUserID() {
5
+ return ctx.i_userID || ctx.userID;
6
+ };
7
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ const util = require("util");
4
+
5
+ module.exports = function () {
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
+ */
12
+ const baseUrl = "https://static.xx.fbcdn.net/images/emoji.php/v8/z%s/%s";
13
+ pixelRatio = pixelRatio || "1.0";
14
+
15
+ const ending = util.format(
16
+ "%s/%s/%s.png",
17
+ pixelRatio,
18
+ size,
19
+ c.codePointAt(0).toString(16)
20
+ );
21
+ let base = 317426846;
22
+ for (let i = 0; i < ending.length; i++) {
23
+ base = (base << 5) - base + ending.charCodeAt(i);
24
+ }
25
+
26
+ const hashed = (base & 255).toString(16);
27
+ return util.format(baseUrl, hashed, ending);
28
+ };
29
+ };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ // [almost] copy pasted from one of FB's minified file (GenderConst)
7
+ const GENDERS = {
8
+ 0: "unknown",
9
+ 1: "female_singular",
10
+ 2: "male_singular",
11
+ 3: "female_singular_guess",
12
+ 4: "male_singular_guess",
13
+ 5: "mixed",
14
+ 6: "neuter_singular",
15
+ 7: "unknown_singular",
16
+ 8: "female_plural",
17
+ 9: "male_plural",
18
+ 10: "neuter_plural",
19
+ 11: "unknown_plural"
20
+ };
21
+
22
+ function formatData(obj) {
23
+ return Object.keys(obj).map(function (key) {
24
+ const user = obj[key];
25
+ return {
26
+ alternateName: user.alternateName,
27
+ firstName: user.firstName,
28
+ gender: GENDERS[user.gender],
29
+ userID: utils.formatID(user.id.toString()),
30
+ isFriend: user.is_friend != null && user.is_friend ? true : false,
31
+ fullName: user.name,
32
+ profilePicture: user.thumbSrc,
33
+ type: user.type,
34
+ profileUrl: user.uri,
35
+ vanity: user.vanity,
36
+ isBirthday: !!user.is_birthday
37
+ };
38
+ });
39
+ }
40
+
41
+ module.exports = function (defaultFuncs, api, ctx) {
42
+ return function getFriendsList(callback) {
43
+ let resolveFunc = function () { };
44
+ let rejectFunc = function () { };
45
+ const returnPromise = new Promise(function (resolve, reject) {
46
+ resolveFunc = resolve;
47
+ rejectFunc = reject;
48
+ });
49
+
50
+ if (!callback) {
51
+ callback = function (err, friendList) {
52
+ if (err) {
53
+ return rejectFunc(err);
54
+ }
55
+ resolveFunc(friendList);
56
+ };
57
+ }
58
+
59
+ defaultFuncs
60
+ .postFormData(
61
+ "https://www.facebook.com/chat/user_info_all",
62
+ ctx.jar,
63
+ {},
64
+ { viewer: ctx.i_userID || ctx.userID }
65
+ )
66
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
67
+ .then(function (resData) {
68
+ if (!resData) {
69
+ throw { error: "getFriendsList returned empty object." };
70
+ }
71
+ if (resData.error) {
72
+ throw resData;
73
+ }
74
+ callback(null, formatData(resData.payload));
75
+ })
76
+ .catch(function (err) {
77
+ log.error("getFriendsList", err);
78
+ return callback(err);
79
+ });
80
+
81
+ return returnPromise;
82
+ };
83
+ };