alicezetion 1.9.2 → 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. package/package.json +1 -1
  2. package/src/addExternalModule.js +19 -0
  3. package/src/addUserToGroup.js +113 -0
  4. package/src/changeAdminStatus.js +79 -0
  5. package/src/changeArchivedStatus.js +55 -0
  6. package/{leiamnash → src}/changeAvatar.js +2 -3
  7. package/src/changeBio.js +77 -0
  8. package/src/changeBlockedStatus.js +47 -0
  9. package/src/changeGroupImage.js +132 -0
  10. package/src/changeNickname.js +59 -0
  11. package/src/changeThreadColor.js +65 -0
  12. package/src/changeThreadEmoji.js +55 -0
  13. package/{leiamnash → src}/chat.js +29 -4
  14. package/src/createNewGroup.js +86 -0
  15. package/src/createPoll.js +71 -0
  16. package/src/deleteMessage.js +56 -0
  17. package/src/deleteThread.js +56 -0
  18. package/src/edit.js +66 -0
  19. package/src/forwardAttachment.js +60 -0
  20. package/src/getCurrentUserID.js +7 -0
  21. package/src/getEmojiUrl.js +29 -0
  22. package/src/getFriendsList.js +83 -0
  23. package/src/getThreadHistory.js +666 -0
  24. package/src/getThreadInfo.js +232 -0
  25. package/src/getThreadList.js +241 -0
  26. package/src/getThreadPictures.js +79 -0
  27. package/src/getUserID.js +66 -0
  28. package/src/getUserInfo.js +74 -0
  29. package/src/handleFriendRequest.js +61 -0
  30. package/src/handleMessageRequest.js +65 -0
  31. package/src/httpGet.js +57 -0
  32. package/src/httpPost.js +57 -0
  33. package/src/httpPostFormData.js +63 -0
  34. package/src/listenMqtt.js +853 -0
  35. package/src/logout.js +75 -0
  36. package/src/markAsDelivered.js +58 -0
  37. package/src/markAsRead.js +80 -0
  38. package/src/markAsReadAll.js +50 -0
  39. package/src/markAsSeen.js +59 -0
  40. package/src/muteThread.js +52 -0
  41. package/src/react.js +109 -0
  42. package/{leiamnash → src}/refreshFb_dtsg.js +1 -1
  43. package/src/removeUserFromGroup.js +79 -0
  44. package/src/resolvePhotoUrl.js +45 -0
  45. package/src/searchForThread.js +53 -0
  46. package/src/seen.js +50 -0
  47. package/src/sendMessage.js +477 -0
  48. package/src/sendTypingIndicator.js +103 -0
  49. package/src/setMessageReaction.js +121 -0
  50. package/src/setPostReaction.js +109 -0
  51. package/src/setTitle.js +86 -0
  52. package/src/threadColors.js +131 -0
  53. package/src/unfriend.js +52 -0
  54. package/src/unsendMessage.js +49 -0
  55. package/{leiamnash → src}/uploadAttachment.js +1 -2
  56. package/leiamnash/addExternalModule.js +0 -15
  57. package/leiamnash/addUserToGroup.js +0 -77
  58. package/leiamnash/changeAdminStatus.js +0 -47
  59. package/leiamnash/changeArchivedStatus.js +0 -41
  60. package/leiamnash/changeBio.js +0 -64
  61. package/leiamnash/changeBlockedStatus.js +0 -36
  62. package/leiamnash/changeGroupImage.js +0 -105
  63. package/leiamnash/changeNickname.js +0 -43
  64. package/leiamnash/changeThreadColor.js +0 -61
  65. package/leiamnash/changeThreadEmoji.js +0 -41
  66. package/leiamnash/createNewGroup.js +0 -70
  67. package/leiamnash/createPoll.js +0 -59
  68. package/leiamnash/deleteMessage.js +0 -44
  69. package/leiamnash/deleteThread.js +0 -42
  70. package/leiamnash/edit.js +0 -59
  71. package/leiamnash/forwardAttachment.js +0 -47
  72. package/leiamnash/forwardMessage.js +0 -0
  73. package/leiamnash/getCurrentUserID.js +0 -7
  74. package/leiamnash/getEmojiUrl.js +0 -27
  75. package/leiamnash/getFriendsList.js +0 -73
  76. package/leiamnash/getInfoVideo.js +0 -134
  77. package/leiamnash/getThreadHistory.js +0 -537
  78. package/leiamnash/getThreadHistoryDeprecated.js +0 -71
  79. package/leiamnash/getThreadInfo.js +0 -171
  80. package/leiamnash/getThreadInfoDeprecated.js +0 -56
  81. package/leiamnash/getThreadList.js +0 -213
  82. package/leiamnash/getThreadListDeprecated.js +0 -46
  83. package/leiamnash/getThreadPictures.js +0 -59
  84. package/leiamnash/getUserID.js +0 -61
  85. package/leiamnash/getUserInfo.js +0 -66
  86. package/leiamnash/handleFriendRequest.js +0 -46
  87. package/leiamnash/handleMessageRequest.js +0 -47
  88. package/leiamnash/httpGet.js +0 -47
  89. package/leiamnash/httpPost.js +0 -47
  90. package/leiamnash/httpPostFormData.js +0 -42
  91. package/leiamnash/listenMqtt.js +0 -853
  92. package/leiamnash/logout.js +0 -68
  93. package/leiamnash/markAsDelivered.js +0 -47
  94. package/leiamnash/markAsRead.js +0 -70
  95. package/leiamnash/markAsReadAll.js +0 -40
  96. package/leiamnash/markAsSeen.js +0 -48
  97. package/leiamnash/muteThread.js +0 -45
  98. package/leiamnash/react.js +0 -109
  99. package/leiamnash/removeUserFromGroup.js +0 -45
  100. package/leiamnash/resolvePhotoUrl.js +0 -36
  101. package/leiamnash/searchForThread.js +0 -42
  102. package/leiamnash/seen.js +0 -40
  103. package/leiamnash/sendMessage.js +0 -315
  104. package/leiamnash/sendTypingIndicator.js +0 -70
  105. package/leiamnash/setMessageReaction.js +0 -103
  106. package/leiamnash/setPostReaction.js +0 -63
  107. package/leiamnash/setTitle.js +0 -70
  108. package/leiamnash/threadColors.js +0 -41
  109. package/leiamnash/unfriend.js +0 -42
  110. package/leiamnash/unsendMessage.js +0 -39
  111. /package/{leiamnash → src}/getMessage.js +0 -0
package/src/logout.js ADDED
@@ -0,0 +1,75 @@
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 logout(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, friendList) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(friendList);
21
+ };
22
+ }
23
+
24
+ const form = {
25
+ pmid: "0"
26
+ };
27
+
28
+ defaultFuncs
29
+ .post(
30
+ "https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1",
31
+ ctx.jar,
32
+ form
33
+ )
34
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
+ .then(function (resData) {
36
+ const elem = resData.jsmods.instances[0][2][0].filter(function (v) {
37
+ return v.value === "logout";
38
+ })[0];
39
+
40
+ const html = resData.jsmods.markup.filter(function (v) {
41
+ return v[0] === elem.markup.__m;
42
+ })[0][1].__html;
43
+
44
+ const form = {
45
+ fb_dtsg: utils.getFrom(html, '"fb_dtsg" value="', '"'),
46
+ ref: utils.getFrom(html, '"ref" value="', '"'),
47
+ h: utils.getFrom(html, '"h" value="', '"')
48
+ };
49
+
50
+ return defaultFuncs
51
+ .post("https://www.facebook.com/logout.php", ctx.jar, form)
52
+ .then(utils.saveCookies(ctx.jar));
53
+ })
54
+ .then(function (res) {
55
+ if (!res.headers) {
56
+ throw { error: "An error occurred when logging out." };
57
+ }
58
+
59
+ return defaultFuncs
60
+ .get(res.headers.location, ctx.jar)
61
+ .then(utils.saveCookies(ctx.jar));
62
+ })
63
+ .then(function () {
64
+ ctx.loggedIn = false;
65
+ log.info("logout", "Logged out successfully.");
66
+ callback();
67
+ })
68
+ .catch(function (err) {
69
+ log.error("logout", err);
70
+ return callback(err);
71
+ });
72
+
73
+ return returnPromise;
74
+ };
75
+ };
@@ -0,0 +1,58 @@
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 markAsDelivered(threadID, messageID, 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, friendList) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(friendList);
21
+ };
22
+ }
23
+
24
+ if (!threadID || !messageID) {
25
+ return callback("Error: messageID or threadID is not defined");
26
+ }
27
+
28
+ const form = {};
29
+
30
+ form["message_ids[0]"] = messageID;
31
+ form["thread_ids[" + threadID + "][0]"] = messageID;
32
+
33
+ defaultFuncs
34
+ .post(
35
+ "https://www.facebook.com/ajax/mercury/delivery_receipts.php",
36
+ ctx.jar,
37
+ form
38
+ )
39
+ .then(utils.saveCookies(ctx.jar))
40
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
41
+ .then(function (resData) {
42
+ if (resData.error) {
43
+ throw resData;
44
+ }
45
+
46
+ return callback();
47
+ })
48
+ .catch(function (err) {
49
+ log.error("markAsDelivered", err);
50
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
51
+ ctx.loggedIn = false;
52
+ }
53
+ return callback(err);
54
+ });
55
+
56
+ return returnPromise;
57
+ };
58
+ };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return async function markAsRead(threadID, read, callback) {
8
+ if (utils.getType(read) === 'Function' || utils.getType(read) === 'AsyncFunction') {
9
+ callback = read;
10
+ read = true;
11
+ }
12
+ if (read == undefined) {
13
+ read = true;
14
+ }
15
+
16
+ if (!callback) {
17
+ callback = () => { };
18
+ }
19
+
20
+ const form = {};
21
+
22
+ if (typeof ctx.globalOptions.pageID !== 'undefined') {
23
+ form["source"] = "PagesManagerMessagesInterface";
24
+ form["request_user_id"] = ctx.globalOptions.pageID;
25
+ form["ids[" + threadID + "]"] = read;
26
+ form["watermarkTimestamp"] = new Date().getTime();
27
+ form["shouldSendReadReceipt"] = true;
28
+ form["commerce_last_message_type"] = "";
29
+ //form["titanOriginatedThreadId"] = utils.generateThreadingID(ctx.clientID);
30
+
31
+ let resData;
32
+ try {
33
+ resData = await (
34
+ defaultFuncs
35
+ .post(
36
+ "https://www.facebook.com/ajax/mercury/change_read_status.php",
37
+ ctx.jar,
38
+ form
39
+ )
40
+ .then(utils.saveCookies(ctx.jar))
41
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
42
+ );
43
+ } catch (e) {
44
+ callback(e);
45
+ return e;
46
+ }
47
+
48
+ if (resData.error) {
49
+ const err = resData.error;
50
+ log.error("markAsRead", err);
51
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
52
+ ctx.loggedIn = false;
53
+ }
54
+ callback(err);
55
+ return err;
56
+ }
57
+
58
+ callback();
59
+ return null;
60
+ } else {
61
+ try {
62
+ if (ctx.mqttClient) {
63
+ const err = await new Promise(r => ctx.mqttClient.publish("/mark_thread", JSON.stringify({
64
+ threadID,
65
+ mark: "read",
66
+ state: read
67
+ }), { qos: 1, retain: false }, r));
68
+ if (err) throw err;
69
+ } else {
70
+ throw {
71
+ error: "You can only use this function after you start listening."
72
+ };
73
+ }
74
+ } catch (e) {
75
+ callback(e);
76
+ return e;
77
+ }
78
+ }
79
+ };
80
+ };
@@ -0,0 +1,50 @@
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 markAsReadAll(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, friendList) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(friendList);
21
+ };
22
+ }
23
+
24
+ const form = {
25
+ folder: 'inbox'
26
+ };
27
+
28
+ defaultFuncs
29
+ .post(
30
+ "https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
31
+ ctx.jar,
32
+ form
33
+ )
34
+ .then(utils.saveCookies(ctx.jar))
35
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
+ .then(function (resData) {
37
+ if (resData.error) {
38
+ throw resData;
39
+ }
40
+
41
+ return callback();
42
+ })
43
+ .catch(function (err) {
44
+ log.error("markAsReadAll", err);
45
+ return callback(err);
46
+ });
47
+
48
+ return returnPromise;
49
+ };
50
+ };
@@ -0,0 +1,59 @@
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 markAsRead(seen_timestamp, callback) {
8
+ if (utils.getType(seen_timestamp) == "Function" ||
9
+ utils.getType(seen_timestamp) == "AsyncFunction") {
10
+ callback = seen_timestamp;
11
+ seen_timestamp = Date.now();
12
+ }
13
+
14
+ let resolveFunc = function () { };
15
+ let rejectFunc = function () { };
16
+ const returnPromise = new Promise(function (resolve, reject) {
17
+ resolveFunc = resolve;
18
+ rejectFunc = reject;
19
+ });
20
+
21
+ if (!callback) {
22
+ callback = function (err, friendList) {
23
+ if (err) {
24
+ return rejectFunc(err);
25
+ }
26
+ resolveFunc(friendList);
27
+ };
28
+ }
29
+
30
+ const form = {
31
+ seen_timestamp: seen_timestamp
32
+ };
33
+
34
+ defaultFuncs
35
+ .post(
36
+ "https://www.facebook.com/ajax/mercury/mark_seen.php",
37
+ ctx.jar,
38
+ form
39
+ )
40
+ .then(utils.saveCookies(ctx.jar))
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("markAsSeen", err);
51
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
52
+ ctx.loggedIn = false;
53
+ }
54
+ return callback(err);
55
+ });
56
+
57
+ return returnPromise;
58
+ };
59
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ // muteSecond: -1=permanent mute, 0=unmute, 60=one minute, 3600=one hour, etc.
8
+ return function muteThread(threadID, muteSeconds, callback) {
9
+ let resolveFunc = function () { };
10
+ let rejectFunc = function () { };
11
+ const returnPromise = new Promise(function (resolve, reject) {
12
+ resolveFunc = resolve;
13
+ rejectFunc = reject;
14
+ });
15
+
16
+ if (!callback) {
17
+ callback = function (err, friendList) {
18
+ if (err) {
19
+ return rejectFunc(err);
20
+ }
21
+ resolveFunc(friendList);
22
+ };
23
+ }
24
+
25
+ const form = {
26
+ thread_fbid: threadID,
27
+ mute_settings: muteSeconds
28
+ };
29
+
30
+ defaultFuncs
31
+ .post(
32
+ "https://www.facebook.com/ajax/mercury/change_mute_thread.php",
33
+ ctx.jar,
34
+ form
35
+ )
36
+ .then(utils.saveCookies(ctx.jar))
37
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
38
+ .then(function (resData) {
39
+ if (resData.error) {
40
+ throw resData;
41
+ }
42
+
43
+ return callback();
44
+ })
45
+ .catch(function (err) {
46
+ log.error("muteThread", err);
47
+ return callback(err);
48
+ });
49
+
50
+ return returnPromise;
51
+ };
52
+ };
package/src/react.js ADDED
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @fix by NTKhang
3
+ * update as Thursday, 10 February 2022
4
+ * do not remove the author name to get more updates
5
+ */
6
+
7
+ "use strict";
8
+
9
+ const utils = require("../utils");
10
+ const log = require("npmlog");
11
+
12
+ function formatData(resData) {
13
+ return {
14
+ viewer_feedback_reaction_info: resData.feedback_react.feedback.viewer_feedback_reaction_info,
15
+ supported_reactions: resData.feedback_react.feedback.supported_reactions,
16
+ top_reactions: resData.feedback_react.feedback.top_reactions.edges,
17
+ reaction_count: resData.feedback_react.feedback.reaction_count
18
+ };
19
+ }
20
+
21
+ module.exports = function (defaultFuncs, api, ctx) {
22
+ return function setPostReaction(postID, type, callback) {
23
+ let resolveFunc = function () { };
24
+ let rejectFunc = function () { };
25
+ const returnPromise = new Promise(function (resolve, reject) {
26
+ resolveFunc = resolve;
27
+ rejectFunc = reject;
28
+ });
29
+
30
+ if (!callback) {
31
+ if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
32
+ callback = type;
33
+ type = 0;
34
+ }
35
+ else {
36
+ callback = function (err, data) {
37
+ if (err) {
38
+ return rejectFunc(err);
39
+ }
40
+ resolveFunc(data);
41
+ };
42
+ }
43
+ }
44
+
45
+ const map = {
46
+ unlike: 0,
47
+ like: 1,
48
+ heart: 2,
49
+ love: 16,
50
+ haha: 4,
51
+ wow: 3,
52
+ sad: 7,
53
+ angry: 8
54
+ };
55
+
56
+ if (utils.getType(type) !== "Number" && utils.getType(type) === "String") {
57
+ type = map[type.toLowerCase()];
58
+ }
59
+
60
+ if (utils.getType(type) !== "Number" && utils.getType(type) !== "String") {
61
+ throw {
62
+ error: "setPostReaction: Invalid reaction type"
63
+ };
64
+ }
65
+
66
+ if (type != 0 && !type) {
67
+ throw {
68
+ error: "setPostReaction: Invalid reaction type"
69
+ };
70
+ }
71
+
72
+ const form = {
73
+ av: ctx.i_userID || ctx.userID,
74
+ fb_api_caller_class: "RelayModern",
75
+ fb_api_req_friendly_name: "CometUFIFeedbackReactMutation",
76
+ doc_id: "4769042373179384",
77
+ variables: JSON.stringify({
78
+ input: {
79
+ actor_id: ctx.i_userID || ctx.userID,
80
+ feedback_id: (new Buffer("feedback:" + postID)).toString("base64"),
81
+ feedback_reaction: type,
82
+ feedback_source: "OBJECT",
83
+ is_tracking_encrypted: true,
84
+ tracking: [],
85
+ session_id: "f7dd50dd-db6e-4598-8cd9-561d5002b423",
86
+ client_mutation_id: Math.round(Math.random() * 19).toString()
87
+ },
88
+ useDefaultActor: false,
89
+ scale: 3
90
+ })
91
+ };
92
+
93
+ defaultFuncs
94
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
95
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
96
+ .then(function (resData) {
97
+ if (resData.errors) {
98
+ throw resData;
99
+ }
100
+ return callback(null, formatData(resData.data));
101
+ })
102
+ .catch(function (err) {
103
+ log.error("setPostReaction", err);
104
+ return callback(err);
105
+ });
106
+
107
+ return returnPromise;
108
+ };
109
+ };
@@ -78,4 +78,4 @@ module.exports = function (defaultFuncs, api, ctx) {
78
78
 
79
79
  return returnPromise;
80
80
  };
81
- };
81
+ };
@@ -0,0 +1,79 @@
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 removeUserFromGroup(userID, threadID, callback) {
8
+ if (
9
+ !callback &&
10
+ (utils.getType(threadID) === "Function" ||
11
+ utils.getType(threadID) === "AsyncFunction")
12
+ ) {
13
+ throw { error: "please pass a threadID as a second argument." };
14
+ }
15
+ if (
16
+ utils.getType(threadID) !== "Number" &&
17
+ utils.getType(threadID) !== "String"
18
+ ) {
19
+ throw {
20
+ error:
21
+ "threadID should be of type Number or String and not " +
22
+ utils.getType(threadID) +
23
+ "."
24
+ };
25
+ }
26
+ if (
27
+ utils.getType(userID) !== "Number" &&
28
+ utils.getType(userID) !== "String"
29
+ ) {
30
+ throw {
31
+ error:
32
+ "userID should be of type Number or String and not " +
33
+ utils.getType(userID) +
34
+ "."
35
+ };
36
+ }
37
+
38
+ let resolveFunc = function () { };
39
+ let rejectFunc = function () { };
40
+ const returnPromise = new Promise(function (resolve, reject) {
41
+ resolveFunc = resolve;
42
+ rejectFunc = reject;
43
+ });
44
+
45
+ if (!callback) {
46
+ callback = function (err, friendList) {
47
+ if (err) {
48
+ return rejectFunc(err);
49
+ }
50
+ resolveFunc(friendList);
51
+ };
52
+ }
53
+
54
+ const form = {
55
+ uid: userID,
56
+ tid: threadID
57
+ };
58
+
59
+ defaultFuncs
60
+ .post("https://www.facebook.com/chat/remove_participants", ctx.jar, form)
61
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
62
+ .then(function (resData) {
63
+ if (!resData) {
64
+ throw { error: "Remove from group failed." };
65
+ }
66
+ if (resData.error) {
67
+ throw resData;
68
+ }
69
+
70
+ return callback();
71
+ })
72
+ .catch(function (err) {
73
+ log.error("removeUserFromGroup", err);
74
+ return callback(err);
75
+ });
76
+
77
+ return returnPromise;
78
+ };
79
+ };
@@ -0,0 +1,45 @@
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 resolvePhotoUrl(photoID, 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, friendList) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(friendList);
21
+ };
22
+ }
23
+
24
+ defaultFuncs
25
+ .get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, {
26
+ photo_id: photoID
27
+ })
28
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
29
+ .then(resData => {
30
+ if (resData.error) {
31
+ throw resData;
32
+ }
33
+
34
+ const photoUrl = resData.jsmods.require[0][3][0];
35
+
36
+ return callback(null, photoUrl);
37
+ })
38
+ .catch(err => {
39
+ log.error("resolvePhotoUrl", err);
40
+ return callback(err);
41
+ });
42
+
43
+ return returnPromise;
44
+ };
45
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return function searchForThread(name, callback) {
7
+ let resolveFunc = function () { };
8
+ let rejectFunc = function () { };
9
+ const returnPromise = new Promise(function (resolve, reject) {
10
+ resolveFunc = resolve;
11
+ rejectFunc = reject;
12
+ });
13
+
14
+ if (!callback) {
15
+ callback = function (err, friendList) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc(friendList);
20
+ };
21
+ }
22
+
23
+ const tmpForm = {
24
+ client: "web_messenger",
25
+ query: name,
26
+ offset: 0,
27
+ limit: 21,
28
+ index: "fbid"
29
+ };
30
+
31
+ defaultFuncs
32
+ .post(
33
+ "https://www.facebook.com/ajax/mercury/search_threads.php",
34
+ ctx.jar,
35
+ tmpForm
36
+ )
37
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
38
+ .then(function (resData) {
39
+ if (resData.error) {
40
+ throw resData;
41
+ }
42
+ if (!resData.payload.mercury_payload.threads) {
43
+ return callback({ error: "Could not find thread `" + name + "`." });
44
+ }
45
+ return callback(
46
+ null,
47
+ resData.payload.mercury_payload.threads.map(utils.formatThread)
48
+ );
49
+ });
50
+
51
+ return returnPromise;
52
+ };
53
+ };