alicezetion 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/alice/addExternalModule.js +19 -19
- package/alice/addUserToGroup.js +113 -113
- package/alice/changeAdminStatus.js +79 -79
- package/alice/changeArchivedStatus.js +55 -55
- package/alice/changeBio.js +77 -77
- package/alice/changeBlockedStatus.js +47 -47
- package/alice/changeGroupImage.js +129 -129
- package/alice/changeNickname.js +59 -59
- package/alice/changeThreadColor.js +71 -71
- package/alice/changeThreadEmoji.js +55 -55
- package/alice/{sendMessage.js → chat.js} +459 -459
- package/alice/createNewGroup.js +86 -86
- package/alice/createPoll.js +71 -71
- package/alice/deleteMessage.js +56 -56
- package/alice/deleteThread.js +56 -56
- package/alice/forwardAttachment.js +60 -60
- package/alice/getCurrentUserID.js +7 -7
- package/alice/getEmojiUrl.js +29 -29
- package/alice/getFriendsList.js +84 -84
- package/alice/getThreadHistory.js +645 -645
- package/alice/getThreadHistoryDeprecated.js +93 -93
- package/alice/getThreadInfo.js +206 -206
- package/alice/getThreadInfoDeprecated.js +80 -80
- package/alice/getThreadList.js +238 -238
- package/alice/getThreadListDeprecated.js +75 -75
- package/alice/getThreadPictures.js +79 -79
- package/alice/getUserID.js +66 -66
- package/alice/getUserInfo.js +72 -72
- package/alice/handleFriendRequest.js +61 -61
- package/alice/handleMessageRequest.js +65 -65
- package/alice/httpGet.js +52 -52
- package/alice/httpPost.js +52 -52
- package/alice/listenMqtt.js +789 -789
- package/alice/logout.js +75 -75
- package/alice/markAsDelivered.js +58 -58
- package/alice/markAsRead.js +80 -80
- package/alice/markAsSeen.js +59 -59
- package/alice/muteThread.js +52 -52
- package/alice/{setMessageReaction.js → react.js} +117 -117
- package/alice/removeUserFromGroup.js +79 -79
- package/alice/resolvePhotoUrl.js +45 -45
- package/alice/searchForThread.js +53 -53
- package/alice/{markAsReadAll.js → seen.js} +49 -49
- package/alice/sendTypingIndicator.js +103 -103
- package/alice/setPostReaction.js +76 -76
- package/alice/setTitle.js +86 -86
- package/alice/threadColors.js +57 -57
- package/alice/unfriend.js +52 -52
- package/alice/unsendMessage.js +49 -49
- package/index.js +604 -604
- package/package.json +74 -77
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +7 -0
- package/test/example-config.json +18 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/utils.js +1357 -1359
- package/.travis.yml +0 -6
@@ -1,117 +1,117 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
-
return function setMessageReaction(reaction, messageID, callback, forceCustomReaction) {
|
8
|
-
var resolveFunc = function(){};
|
9
|
-
var rejectFunc = function(){};
|
10
|
-
var 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
|
-
switch (reaction) {
|
25
|
-
case "\uD83D\uDE0D": //:heart_eyes:
|
26
|
-
case "\uD83D\uDE06": //:laughing:
|
27
|
-
case "\uD83D\uDE2E": //:open_mouth:
|
28
|
-
case "\uD83D\uDE22": //:cry:
|
29
|
-
case "\uD83D\uDE20": //:angry:
|
30
|
-
case "\uD83D\uDC4D": //:thumbsup:
|
31
|
-
case "\uD83D\uDC4E": //:thumbsdown:
|
32
|
-
case "\u2764": //:heart:
|
33
|
-
case "\uD83D\uDC97": //:glowingheart:
|
34
|
-
case "":
|
35
|
-
//valid
|
36
|
-
break;
|
37
|
-
case ":heart_eyes:":
|
38
|
-
case ":love:":
|
39
|
-
reaction = "\uD83D\uDE0D";
|
40
|
-
break;
|
41
|
-
case ":laughing:":
|
42
|
-
case ":haha:":
|
43
|
-
reaction = "\uD83D\uDE06";
|
44
|
-
break;
|
45
|
-
case ":open_mouth:":
|
46
|
-
case ":wow:":
|
47
|
-
reaction = "\uD83D\uDE2E";
|
48
|
-
break;
|
49
|
-
case ":cry:":
|
50
|
-
case ":sad:":
|
51
|
-
reaction = "\uD83D\uDE22";
|
52
|
-
break;
|
53
|
-
case ":angry:":
|
54
|
-
reaction = "\uD83D\uDE20";
|
55
|
-
break;
|
56
|
-
case ":thumbsup:":
|
57
|
-
case ":like:":
|
58
|
-
reaction = "\uD83D\uDC4D";
|
59
|
-
break;
|
60
|
-
case ":thumbsdown:":
|
61
|
-
case ":dislike:":
|
62
|
-
reaction = "\uD83D\uDC4E";
|
63
|
-
break;
|
64
|
-
case ":heart:":
|
65
|
-
reaction = "\u2764";
|
66
|
-
break;
|
67
|
-
case ":glowingheart:":
|
68
|
-
reaction = "\uD83D\uDC97";
|
69
|
-
break;
|
70
|
-
default:
|
71
|
-
if (forceCustomReaction) {
|
72
|
-
break;
|
73
|
-
}
|
74
|
-
return callback({ error: "Reaction is not a valid emoji." });
|
75
|
-
}
|
76
|
-
|
77
|
-
var variables = {
|
78
|
-
data: {
|
79
|
-
client_mutation_id: ctx.clientMutationId++,
|
80
|
-
actor_id: ctx.userID,
|
81
|
-
action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
|
82
|
-
message_id: messageID,
|
83
|
-
reaction: reaction
|
84
|
-
}
|
85
|
-
};
|
86
|
-
|
87
|
-
var qs = {
|
88
|
-
doc_id: "1491398900900362",
|
89
|
-
variables: JSON.stringify(variables),
|
90
|
-
dpr: 1
|
91
|
-
};
|
92
|
-
|
93
|
-
defaultFuncs
|
94
|
-
.postFormData(
|
95
|
-
"https://www.facebook.com/webgraphql/mutation/",
|
96
|
-
ctx.jar,
|
97
|
-
{},
|
98
|
-
qs
|
99
|
-
)
|
100
|
-
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
101
|
-
.then(function(resData) {
|
102
|
-
if (!resData) {
|
103
|
-
throw { error: "setReaction returned empty object." };
|
104
|
-
}
|
105
|
-
if (resData.error) {
|
106
|
-
throw resData;
|
107
|
-
}
|
108
|
-
callback(null);
|
109
|
-
})
|
110
|
-
.catch(function(err) {
|
111
|
-
log.error("setReaction", err);
|
112
|
-
return callback(err);
|
113
|
-
});
|
114
|
-
|
115
|
-
return returnPromise;
|
116
|
-
};
|
117
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
+
return function setMessageReaction(reaction, messageID, callback, forceCustomReaction) {
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
|
+
var 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
|
+
switch (reaction) {
|
25
|
+
case "\uD83D\uDE0D": //:heart_eyes:
|
26
|
+
case "\uD83D\uDE06": //:laughing:
|
27
|
+
case "\uD83D\uDE2E": //:open_mouth:
|
28
|
+
case "\uD83D\uDE22": //:cry:
|
29
|
+
case "\uD83D\uDE20": //:angry:
|
30
|
+
case "\uD83D\uDC4D": //:thumbsup:
|
31
|
+
case "\uD83D\uDC4E": //:thumbsdown:
|
32
|
+
case "\u2764": //:heart:
|
33
|
+
case "\uD83D\uDC97": //:glowingheart:
|
34
|
+
case "":
|
35
|
+
//valid
|
36
|
+
break;
|
37
|
+
case ":heart_eyes:":
|
38
|
+
case ":love:":
|
39
|
+
reaction = "\uD83D\uDE0D";
|
40
|
+
break;
|
41
|
+
case ":laughing:":
|
42
|
+
case ":haha:":
|
43
|
+
reaction = "\uD83D\uDE06";
|
44
|
+
break;
|
45
|
+
case ":open_mouth:":
|
46
|
+
case ":wow:":
|
47
|
+
reaction = "\uD83D\uDE2E";
|
48
|
+
break;
|
49
|
+
case ":cry:":
|
50
|
+
case ":sad:":
|
51
|
+
reaction = "\uD83D\uDE22";
|
52
|
+
break;
|
53
|
+
case ":angry:":
|
54
|
+
reaction = "\uD83D\uDE20";
|
55
|
+
break;
|
56
|
+
case ":thumbsup:":
|
57
|
+
case ":like:":
|
58
|
+
reaction = "\uD83D\uDC4D";
|
59
|
+
break;
|
60
|
+
case ":thumbsdown:":
|
61
|
+
case ":dislike:":
|
62
|
+
reaction = "\uD83D\uDC4E";
|
63
|
+
break;
|
64
|
+
case ":heart:":
|
65
|
+
reaction = "\u2764";
|
66
|
+
break;
|
67
|
+
case ":glowingheart:":
|
68
|
+
reaction = "\uD83D\uDC97";
|
69
|
+
break;
|
70
|
+
default:
|
71
|
+
if (forceCustomReaction) {
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
return callback({ error: "Reaction is not a valid emoji." });
|
75
|
+
}
|
76
|
+
|
77
|
+
var variables = {
|
78
|
+
data: {
|
79
|
+
client_mutation_id: ctx.clientMutationId++,
|
80
|
+
actor_id: ctx.userID,
|
81
|
+
action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
|
82
|
+
message_id: messageID,
|
83
|
+
reaction: reaction
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
var qs = {
|
88
|
+
doc_id: "1491398900900362",
|
89
|
+
variables: JSON.stringify(variables),
|
90
|
+
dpr: 1
|
91
|
+
};
|
92
|
+
|
93
|
+
defaultFuncs
|
94
|
+
.postFormData(
|
95
|
+
"https://www.facebook.com/webgraphql/mutation/",
|
96
|
+
ctx.jar,
|
97
|
+
{},
|
98
|
+
qs
|
99
|
+
)
|
100
|
+
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
101
|
+
.then(function(resData) {
|
102
|
+
if (!resData) {
|
103
|
+
throw { error: "setReaction returned empty object." };
|
104
|
+
}
|
105
|
+
if (resData.error) {
|
106
|
+
throw resData;
|
107
|
+
}
|
108
|
+
callback(null);
|
109
|
+
})
|
110
|
+
.catch(function(err) {
|
111
|
+
log.error("setReaction", err);
|
112
|
+
return callback(err);
|
113
|
+
});
|
114
|
+
|
115
|
+
return returnPromise;
|
116
|
+
};
|
117
|
+
};
|
@@ -1,79 +1,79 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var 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
|
-
var resolveFunc = function(){};
|
39
|
-
var rejectFunc = function(){};
|
40
|
-
var 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
|
-
var 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
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var 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
|
+
var resolveFunc = function(){};
|
39
|
+
var rejectFunc = function(){};
|
40
|
+
var 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
|
+
var 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
|
+
};
|
package/alice/resolvePhotoUrl.js
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
-
return function resolvePhotoUrl(photoID, callback) {
|
8
|
-
var resolveFunc = function(){};
|
9
|
-
var rejectFunc = function(){};
|
10
|
-
var 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
|
-
var 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
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
+
return function resolvePhotoUrl(photoID, callback) {
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
|
+
var 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
|
+
var 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
|
+
};
|
package/alice/searchForThread.js
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
|
5
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
6
|
-
return function searchForThread(name, callback) {
|
7
|
-
var resolveFunc = function(){};
|
8
|
-
var rejectFunc = function(){};
|
9
|
-
var 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
|
-
var 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
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
|
5
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
6
|
+
return function searchForThread(name, callback) {
|
7
|
+
var resolveFunc = function(){};
|
8
|
+
var rejectFunc = function(){};
|
9
|
+
var 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
|
+
var 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
|
+
};
|