node-ainzfb-new 1.6.2902-test → 1.6.2909-test
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +7 -7
- package/src/addExternalModule.js +13 -6
- package/src/addUserToGroup.js +35 -12
- package/src/changeAdminStatus.js +32 -16
- package/src/changeArchivedStatus.js +15 -9
- package/src/changeAvt.js +75 -69
- package/src/changeBio.js +12 -8
- package/src/changeBlockedStatus.js +14 -8
- package/src/changeGroupImage.js +27 -13
- package/src/changeNickname.js +19 -10
- package/src/changeThreadColor.js +15 -10
- package/src/changeThreadEmoji.js +17 -9
- package/src/createNewGroup.js +18 -10
- package/src/createPoll.js +16 -11
- package/src/deleteMessage.js +16 -10
- package/src/deleteThread.js +16 -10
- package/src/forwardAttachment.js +14 -9
- package/src/getAccessToken.js +21 -21
- package/src/getCurrentUserID.js +1 -1
- package/src/getEmojiUrl.js +3 -2
- package/src/getFriendsList.js +18 -10
- package/src/getMessage.js +52 -48
- package/src/getThreadHistory.js +156 -59
- package/src/getThreadHistoryDeprecated.js +26 -15
- package/src/getThreadInfo.js +3423 -18
- package/src/getThreadInfoDeprecated.js +25 -13
- package/src/getThreadList.js +112 -53
- package/src/getThreadListDeprecated.js +30 -12
- package/src/getThreadPictures.js +25 -13
- package/src/getUserID.js +7 -7
- package/src/getUserInfo.js +12 -9
- package/src/getUserInfoV2.js +19 -22
- package/src/handleFriendRequest.js +10 -9
- package/src/handleMessageRequest.js +16 -10
- package/src/httpGet.js +18 -13
- package/src/httpPost.js +18 -13
- package/src/httpPostFormData.js +14 -9
- package/src/listenMqtt.js +1218 -571
- package/src/logout.js +18 -13
- package/src/markAsDelivered.js +16 -10
- package/src/markAsRead.js +36 -24
- package/src/markAsReadAll.js +14 -10
- package/src/markAsSeen.js +18 -11
- package/src/muteThread.js +12 -8
- package/src/removeUserFromGroup.js +33 -10
- package/src/resolvePhotoUrl.js +8 -6
- package/src/searchForThread.js +13 -8
- package/src/sendMessage.js +172 -78
- package/src/sendTypingIndicator.js +29 -14
- package/src/setMessageReaction.js +13 -8
- package/src/setPostReaction.js +97 -95
- package/src/setTitle.js +18 -12
- package/src/threadColors.js +17 -17
- package/src/unfriend.js +14 -9
- package/src/unsendMessage.js +7 -7
- package/utils.js +2273 -1066
package/src/logout.js
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function logout(callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
|
-
callback = function
|
16
|
+
callback = function(err, friendList) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
|
19
19
|
resolveFunc(friendList);
|
@@ -25,14 +25,18 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
25
25
|
};
|
26
26
|
|
27
27
|
defaultFuncs
|
28
|
-
.post(
|
28
|
+
.post(
|
29
|
+
"https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1",
|
30
|
+
ctx.jar,
|
31
|
+
form
|
32
|
+
)
|
29
33
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
30
|
-
.then(function
|
31
|
-
var elem = resData.jsmods.instances[0][2][0].filter(function
|
34
|
+
.then(function(resData) {
|
35
|
+
var elem = resData.jsmods.instances[0][2][0].filter(function(v) {
|
32
36
|
return v.value === "logout";
|
33
37
|
})[0];
|
34
38
|
|
35
|
-
var html = resData.jsmods.markup.filter(function
|
39
|
+
var html = resData.jsmods.markup.filter(function(v) {
|
36
40
|
return v[0] === elem.markup.__m;
|
37
41
|
})[0][1].__html;
|
38
42
|
|
@@ -46,19 +50,20 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
46
50
|
.post("https://www.facebook.com/logout.php", ctx.jar, form)
|
47
51
|
.then(utils.saveCookies(ctx.jar));
|
48
52
|
})
|
49
|
-
.then(function
|
50
|
-
if (!res.headers)
|
53
|
+
.then(function(res) {
|
54
|
+
if (!res.headers)
|
55
|
+
throw { error: "An error occurred when logging out." };
|
51
56
|
|
52
57
|
return defaultFuncs
|
53
58
|
.get(res.headers.location, ctx.jar)
|
54
59
|
.then(utils.saveCookies(ctx.jar));
|
55
60
|
})
|
56
|
-
.then(function
|
61
|
+
.then(function() {
|
57
62
|
ctx.loggedIn = false;
|
58
63
|
log.info("logout", "Logged out successfully.");
|
59
64
|
callback();
|
60
65
|
})
|
61
|
-
.catch(function
|
66
|
+
.catch(function(err) {
|
62
67
|
log.error("logout", err);
|
63
68
|
return callback(err);
|
64
69
|
});
|
package/src/markAsDelivered.js
CHANGED
@@ -3,24 +3,25 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function markAsDelivered(threadID, messageID, callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
|
-
callback = function
|
16
|
+
callback = function(err, data) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
|
19
19
|
resolveFunc(data);
|
20
20
|
};
|
21
21
|
}
|
22
22
|
|
23
|
-
if (!threadID || !messageID)
|
23
|
+
if (!threadID || !messageID)
|
24
|
+
return callback("Error: messageID or threadID is not defined");
|
24
25
|
|
25
26
|
var form = {};
|
26
27
|
|
@@ -28,17 +29,22 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
28
29
|
form["thread_ids[" + threadID + "][0]"] = messageID;
|
29
30
|
|
30
31
|
defaultFuncs
|
31
|
-
.post(
|
32
|
+
.post(
|
33
|
+
"https://www.facebook.com/ajax/mercury/delivery_receipts.php",
|
34
|
+
ctx.jar,
|
35
|
+
form
|
36
|
+
)
|
32
37
|
.then(utils.saveCookies(ctx.jar))
|
33
38
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
34
|
-
.then(function
|
39
|
+
.then(function(resData) {
|
35
40
|
if (resData.error) throw resData;
|
36
41
|
|
37
42
|
return callback();
|
38
43
|
})
|
39
|
-
.catch(function
|
44
|
+
.catch(function(err) {
|
40
45
|
log.error("markAsDelivered", err);
|
41
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
46
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
47
|
+
ctx.loggedIn = false;
|
42
48
|
|
43
49
|
return callback(err);
|
44
50
|
});
|
package/src/markAsRead.js
CHANGED
@@ -3,19 +3,22 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return async function markAsRead(threadID, read, callback) {
|
8
|
-
if (
|
8
|
+
if (
|
9
|
+
utils.getType(read) === "Function" ||
|
10
|
+
utils.getType(read) === "AsyncFunction"
|
11
|
+
) {
|
9
12
|
callback = read;
|
10
13
|
read = true;
|
11
14
|
}
|
12
15
|
if (read == undefined) read = true;
|
13
16
|
|
14
|
-
if (!callback) callback = () => {
|
17
|
+
if (!callback) callback = () => {};
|
15
18
|
|
16
19
|
var form = {};
|
17
20
|
|
18
|
-
if (typeof ctx.globalOptions.pageID !==
|
21
|
+
if (typeof ctx.globalOptions.pageID !== "undefined") {
|
19
22
|
form["source"] = "PagesManagerMessagesInterface";
|
20
23
|
form["request_user_id"] = ctx.globalOptions.pageID;
|
21
24
|
form["ids[" + threadID + "]"] = read;
|
@@ -26,14 +29,15 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
26
29
|
|
27
30
|
let resData;
|
28
31
|
try {
|
29
|
-
resData = await
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
resData = await defaultFuncs
|
33
|
+
.post(
|
34
|
+
"https://www.facebook.com/ajax/mercury/change_read_status.php",
|
35
|
+
ctx.jar,
|
36
|
+
form
|
37
|
+
)
|
38
|
+
.then(utils.saveCookies(ctx.jar))
|
39
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
40
|
+
} catch (e) {
|
37
41
|
callback(e);
|
38
42
|
return e;
|
39
43
|
}
|
@@ -41,27 +45,35 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
41
45
|
if (resData.error) {
|
42
46
|
let err = resData.error;
|
43
47
|
log.error("markAsRead", err);
|
44
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
48
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
49
|
+
ctx.loggedIn = false;
|
45
50
|
callback(err);
|
46
51
|
return err;
|
47
52
|
}
|
48
53
|
|
49
54
|
callback();
|
50
55
|
return null;
|
51
|
-
}
|
52
|
-
else {
|
56
|
+
} else {
|
53
57
|
try {
|
54
58
|
if (ctx.mqttClient) {
|
55
|
-
let err = await new Promise(r =>
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
let err = await new Promise(r =>
|
60
|
+
ctx.mqttClient.publish(
|
61
|
+
"/mark_thread",
|
62
|
+
JSON.stringify({
|
63
|
+
threadID,
|
64
|
+
mark: "read",
|
65
|
+
state: read
|
66
|
+
}),
|
67
|
+
{ qos: 1, retain: false },
|
68
|
+
r
|
69
|
+
)
|
70
|
+
);
|
60
71
|
if (err) throw err;
|
61
|
-
}
|
62
|
-
|
63
|
-
|
64
|
-
|
72
|
+
} else
|
73
|
+
throw {
|
74
|
+
error: "You can only use this function after you start listening."
|
75
|
+
};
|
76
|
+
} catch (e) {
|
65
77
|
callback(e);
|
66
78
|
return e;
|
67
79
|
}
|
package/src/markAsReadAll.js
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function markAsReadAll(callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
|
-
callback = function
|
16
|
+
callback = function(err, data) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
|
19
19
|
resolveFunc(data);
|
@@ -21,23 +21,27 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
var form = {
|
24
|
-
folder:
|
24
|
+
folder: "inbox"
|
25
25
|
};
|
26
26
|
|
27
27
|
defaultFuncs
|
28
|
-
.post(
|
28
|
+
.post(
|
29
|
+
"https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
|
30
|
+
ctx.jar,
|
31
|
+
form
|
32
|
+
)
|
29
33
|
.then(utils.saveCookies(ctx.jar))
|
30
34
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
31
|
-
.then(function
|
35
|
+
.then(function(resData) {
|
32
36
|
if (resData.error) throw resData;
|
33
37
|
|
34
38
|
return callback();
|
35
39
|
})
|
36
|
-
.catch(function
|
40
|
+
.catch(function(err) {
|
37
41
|
log.error("markAsReadAll", err);
|
38
42
|
return callback(err);
|
39
43
|
});
|
40
44
|
|
41
45
|
return returnPromise;
|
42
46
|
};
|
43
|
-
};
|
47
|
+
};
|
package/src/markAsSeen.js
CHANGED
@@ -3,23 +3,25 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function markAsSeen(seen_timestamp, callback) {
|
8
|
-
if (
|
9
|
-
utils.getType(seen_timestamp) == "
|
8
|
+
if (
|
9
|
+
utils.getType(seen_timestamp) == "Function" ||
|
10
|
+
utils.getType(seen_timestamp) == "AsyncFunction"
|
11
|
+
) {
|
10
12
|
callback = seen_timestamp;
|
11
13
|
seen_timestamp = Date.now();
|
12
14
|
}
|
13
15
|
|
14
|
-
var resolveFunc = function
|
15
|
-
var rejectFunc = function
|
16
|
-
var returnPromise = new Promise(function
|
16
|
+
var resolveFunc = function() {};
|
17
|
+
var rejectFunc = function() {};
|
18
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
17
19
|
resolveFunc = resolve;
|
18
20
|
rejectFunc = reject;
|
19
21
|
});
|
20
22
|
|
21
23
|
if (!callback) {
|
22
|
-
callback = function
|
24
|
+
callback = function(err, data) {
|
23
25
|
if (err) return rejectFunc(err);
|
24
26
|
|
25
27
|
resolveFunc(data);
|
@@ -31,17 +33,22 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
31
33
|
};
|
32
34
|
|
33
35
|
defaultFuncs
|
34
|
-
.post(
|
36
|
+
.post(
|
37
|
+
"https://www.facebook.com/ajax/mercury/mark_seen.php",
|
38
|
+
ctx.jar,
|
39
|
+
form
|
40
|
+
)
|
35
41
|
.then(utils.saveCookies(ctx.jar))
|
36
42
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
37
|
-
.then(function
|
43
|
+
.then(function(resData) {
|
38
44
|
if (resData.error) throw resData;
|
39
45
|
|
40
46
|
return callback();
|
41
47
|
})
|
42
|
-
.catch(function
|
48
|
+
.catch(function(err) {
|
43
49
|
log.error("markAsSeen", err);
|
44
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
50
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
51
|
+
ctx.loggedIn = false;
|
45
52
|
|
46
53
|
return callback(err);
|
47
54
|
});
|
package/src/muteThread.js
CHANGED
@@ -3,18 +3,18 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
// muteSecond: -1=permanent mute, 0=unmute, 60=one minute, 3600=one hour, etc.
|
8
8
|
return function muteThread(threadID, muteSeconds, callback) {
|
9
|
-
var resolveFunc = function
|
10
|
-
var rejectFunc = function
|
11
|
-
var returnPromise = new Promise(function
|
9
|
+
var resolveFunc = function() {};
|
10
|
+
var rejectFunc = function() {};
|
11
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
12
12
|
resolveFunc = resolve;
|
13
13
|
rejectFunc = reject;
|
14
14
|
});
|
15
15
|
|
16
16
|
if (!callback) {
|
17
|
-
callback = function
|
17
|
+
callback = function(err, data) {
|
18
18
|
if (err) return rejectFunc(err);
|
19
19
|
|
20
20
|
resolveFunc(data);
|
@@ -27,17 +27,21 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
27
27
|
};
|
28
28
|
|
29
29
|
defaultFuncs
|
30
|
-
.post(
|
30
|
+
.post(
|
31
|
+
"https://www.facebook.com/ajax/mercury/change_mute_thread.php",
|
32
|
+
ctx.jar,
|
33
|
+
form
|
34
|
+
)
|
31
35
|
.then(utils.saveCookies(ctx.jar))
|
32
36
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
33
|
-
.then(function
|
37
|
+
.then(function(resData) {
|
34
38
|
if (resData.error) {
|
35
39
|
throw resData;
|
36
40
|
}
|
37
41
|
|
38
42
|
return callback();
|
39
43
|
})
|
40
|
-
.catch(function
|
44
|
+
.catch(function(err) {
|
41
45
|
log.error("muteThread", err);
|
42
46
|
return callback(err);
|
43
47
|
});
|
@@ -3,21 +3,44 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function removeUserFromGroup(userID, threadID, callback) {
|
8
|
-
if (
|
9
|
-
|
10
|
-
|
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
|
+
if (
|
15
|
+
utils.getType(threadID) !== "Number" &&
|
16
|
+
utils.getType(threadID) !== "String"
|
17
|
+
)
|
18
|
+
throw {
|
19
|
+
error:
|
20
|
+
"threadID should be of type Number or String and not " +
|
21
|
+
utils.getType(threadID) +
|
22
|
+
"."
|
23
|
+
};
|
24
|
+
if (
|
25
|
+
utils.getType(userID) !== "Number" &&
|
26
|
+
utils.getType(userID) !== "String"
|
27
|
+
)
|
28
|
+
throw {
|
29
|
+
error:
|
30
|
+
"userID should be of type Number or String and not " +
|
31
|
+
utils.getType(userID) +
|
32
|
+
"."
|
33
|
+
};
|
11
34
|
|
12
|
-
var resolveFunc = function
|
13
|
-
var rejectFunc = function
|
14
|
-
var returnPromise = new Promise(function
|
35
|
+
var resolveFunc = function() {};
|
36
|
+
var rejectFunc = function() {};
|
37
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
15
38
|
resolveFunc = resolve;
|
16
39
|
rejectFunc = reject;
|
17
40
|
});
|
18
41
|
|
19
42
|
if (!callback) {
|
20
|
-
callback = function
|
43
|
+
callback = function(err, data) {
|
21
44
|
if (err) return rejectFunc(err);
|
22
45
|
|
23
46
|
resolveFunc(data);
|
@@ -32,14 +55,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
32
55
|
defaultFuncs
|
33
56
|
.post("https://www.facebook.com/chat/remove_participants", ctx.jar, form)
|
34
57
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
35
|
-
.then(function
|
58
|
+
.then(function(resData) {
|
36
59
|
if (!resData) throw { error: "Remove from group failed." };
|
37
60
|
|
38
61
|
if (resData.error) throw resData;
|
39
62
|
|
40
63
|
return callback();
|
41
64
|
})
|
42
|
-
.catch(function
|
65
|
+
.catch(function(err) {
|
43
66
|
log.error("removeUserFromGroup", err);
|
44
67
|
return callback(err);
|
45
68
|
});
|
package/src/resolvePhotoUrl.js
CHANGED
@@ -3,24 +3,26 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function resolvePhotoUrl(photoID, callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
|
-
callback = function
|
16
|
+
callback = function(err, data) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
resolveFunc(data);
|
19
19
|
};
|
20
20
|
}
|
21
21
|
|
22
22
|
defaultFuncs
|
23
|
-
.get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, {
|
23
|
+
.get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, {
|
24
|
+
photo_id: photoID
|
25
|
+
})
|
24
26
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
25
27
|
.then(resData => {
|
26
28
|
if (resData.error) throw resData;
|
package/src/searchForThread.js
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
|
5
|
-
module.exports = function
|
5
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
6
6
|
return function searchForThread(name, callback) {
|
7
|
-
var resolveFunc = function
|
8
|
-
var rejectFunc = function
|
9
|
-
var returnPromise = new Promise(function
|
7
|
+
var resolveFunc = function() {};
|
8
|
+
var rejectFunc = function() {};
|
9
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
10
10
|
resolveFunc = resolve;
|
11
11
|
rejectFunc = reject;
|
12
12
|
});
|
13
13
|
|
14
14
|
if (!callback) {
|
15
|
-
callback = function
|
15
|
+
callback = function(err, data) {
|
16
16
|
if (err) return rejectFunc(err);
|
17
17
|
resolveFunc(data);
|
18
18
|
};
|
@@ -27,11 +27,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
27
27
|
};
|
28
28
|
|
29
29
|
defaultFuncs
|
30
|
-
.post(
|
30
|
+
.post(
|
31
|
+
"https://www.facebook.com/ajax/mercury/search_threads.php",
|
32
|
+
ctx.jar,
|
33
|
+
tmpForm
|
34
|
+
)
|
31
35
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
32
|
-
.then(function
|
36
|
+
.then(function(resData) {
|
33
37
|
if (resData.error) throw resData;
|
34
|
-
if (!resData.payload.mercury_payload.threads)
|
38
|
+
if (!resData.payload.mercury_payload.threads)
|
39
|
+
return callback({ error: "Could not find thread `" + name + "`." });
|
35
40
|
return callback(
|
36
41
|
null,
|
37
42
|
resData.payload.mercury_payload.threads.map(utils.formatThread)
|