alicezetion 1.5.6 → 1.5.8
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/index.js +489 -526
- package/leiamnash/addExternalModule.js +15 -19
- package/leiamnash/addUserToGroup.js +77 -113
- package/leiamnash/changeAdminStatus.js +47 -79
- package/leiamnash/changeArchivedStatus.js +41 -55
- package/leiamnash/changeBio.js +64 -77
- package/leiamnash/changeBlockedStatus.js +36 -47
- package/leiamnash/changeGroupImage.js +105 -129
- package/leiamnash/changeNickname.js +43 -59
- package/leiamnash/changeThreadColor.js +61 -71
- package/leiamnash/changeThreadEmoji.js +41 -55
- package/leiamnash/chat.js +324 -459
- package/leiamnash/createNewGroup.js +70 -86
- package/leiamnash/createPoll.js +59 -71
- package/leiamnash/deleteMessage.js +44 -56
- package/leiamnash/deleteThread.js +42 -56
- package/leiamnash/forwardAttachment.js +47 -60
- package/leiamnash/forwardMessage.js +0 -0
- package/leiamnash/getCurrentUserID.js +7 -7
- package/leiamnash/getEmojiUrl.js +27 -29
- package/leiamnash/getFriendsList.js +73 -84
- package/leiamnash/getThreadHistory.js +537 -645
- package/leiamnash/getThreadHistoryDeprecated.js +71 -93
- package/leiamnash/getThreadInfo.js +171 -206
- package/leiamnash/getThreadInfoDeprecated.js +56 -80
- package/leiamnash/getThreadList.js +213 -238
- package/leiamnash/getThreadListDeprecated.js +46 -75
- package/leiamnash/getThreadPictures.js +59 -79
- package/leiamnash/getUserID.js +61 -66
- package/leiamnash/getUserInfo.js +66 -72
- package/leiamnash/handleFriendRequest.js +46 -61
- package/leiamnash/handleMessageRequest.js +47 -65
- package/leiamnash/httpGet.js +47 -52
- package/leiamnash/httpPost.js +47 -52
- package/leiamnash/listen.js +553 -0
- package/leiamnash/listenMqtt-Test.js +687 -0
- package/leiamnash/listenMqtt.js +685 -789
- package/leiamnash/logout.js +68 -75
- package/leiamnash/markAsDelivered.js +47 -58
- package/leiamnash/markAsRead.js +70 -80
- package/leiamnash/markAsReadAll.js +39 -49
- package/leiamnash/markAsSeen.js +48 -59
- package/leiamnash/muteThread.js +45 -52
- package/leiamnash/removeUserFromGroup.js +45 -79
- package/leiamnash/resolvePhotoUrl.js +36 -45
- package/leiamnash/searchForThread.js +42 -53
- package/leiamnash/sendTypingIndicator.js +70 -103
- package/leiamnash/setMessageReaction.js +103 -117
- package/leiamnash/setPostReaction.js +63 -76
- package/leiamnash/setTitle.js +70 -86
- package/leiamnash/threadColors.js +41 -57
- package/leiamnash/unfriend.js +42 -52
- package/leiamnash/unsendMessage.js +39 -49
- package/package.json +73 -71
- package/utils.js +1198 -1356
@@ -1,75 +1,46 @@
|
|
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 getThreadList(start, end, type, callback) {
|
8
|
-
if (utils.getType(callback) === "Undefined") {
|
9
|
-
if (utils.getType(end) !== "Number") {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
if (
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
form[type + "[limit]"] = end - start;
|
48
|
-
|
49
|
-
if (ctx.globalOptions.pageID) {
|
50
|
-
form.request_user_id = ctx.globalOptions.pageID;
|
51
|
-
}
|
52
|
-
|
53
|
-
defaultFuncs
|
54
|
-
.post(
|
55
|
-
"https://www.facebook.com/ajax/mercury/threadlist_info.php",
|
56
|
-
ctx.jar,
|
57
|
-
form
|
58
|
-
)
|
59
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
60
|
-
.then(function(resData) {
|
61
|
-
if (resData.error) {
|
62
|
-
throw resData;
|
63
|
-
}
|
64
|
-
log.verbose("getThreadList", JSON.stringify(resData.payload.threads));
|
65
|
-
return callback(
|
66
|
-
null,
|
67
|
-
(resData.payload.threads || []).map(utils.formatThread)
|
68
|
-
);
|
69
|
-
})
|
70
|
-
.catch(function(err) {
|
71
|
-
log.error("getThreadList", err);
|
72
|
-
return callback(err);
|
73
|
-
});
|
74
|
-
};
|
75
|
-
};
|
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 getThreadList(start, end, type, callback) {
|
8
|
+
if (utils.getType(callback) === "Undefined") {
|
9
|
+
if (utils.getType(end) !== "Number") throw { error: "Please pass a number as a second argument." };
|
10
|
+
else if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
|
11
|
+
callback = type;
|
12
|
+
type = "inbox"; //default to inbox
|
13
|
+
}
|
14
|
+
else if (utils.getType(type) !== "String") throw { error: "Please pass a String as a third argument. Your options are: inbox, pending, and archived" };
|
15
|
+
else throw { error: "getThreadList: need callback" };
|
16
|
+
}
|
17
|
+
|
18
|
+
if (type === "archived") type = "action:archived";
|
19
|
+
else if (type !== "inbox" && type !== "pending" && type !== "other") throw { error: "type can only be one of the following: inbox, pending, archived, other" };
|
20
|
+
|
21
|
+
|
22
|
+
if (end <= start) end = start + 20;
|
23
|
+
|
24
|
+
var form = {
|
25
|
+
client: "mercury"
|
26
|
+
};
|
27
|
+
|
28
|
+
form[type + "[offset]"] = start;
|
29
|
+
form[type + "[limit]"] = end - start;
|
30
|
+
|
31
|
+
if (ctx.globalOptions.pageID) form.request_user_id = ctx.globalOptions.pageID;
|
32
|
+
|
33
|
+
defaultFuncs
|
34
|
+
.post("https://www.facebook.com/ajax/mercury/threadlist_info.php", ctx.jar, form)
|
35
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
+
.then(function (resData) {
|
37
|
+
if (resData.error) throw resData;
|
38
|
+
log.verbose("getThreadList", JSON.stringify(resData.payload.threads));
|
39
|
+
return callback(null, (resData.payload.threads || []).map(utils.formatThread));
|
40
|
+
})
|
41
|
+
.catch(function (err) {
|
42
|
+
log.error("getThreadList", err);
|
43
|
+
return callback(err);
|
44
|
+
});
|
45
|
+
};
|
46
|
+
};
|
@@ -1,79 +1,59 @@
|
|
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 getThreadPictures(threadID, offset, limit, 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,
|
17
|
-
if (err)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
resData.jsmods.require[0][3][1].query_metadata.query_path[0]
|
61
|
-
.message_thread;
|
62
|
-
var imageData =
|
63
|
-
resData.jsmods.require[0][3][1].query_results[queryThreadID]
|
64
|
-
.message_images.edges[0].node.image2;
|
65
|
-
return imageData;
|
66
|
-
});
|
67
|
-
})
|
68
|
-
);
|
69
|
-
})
|
70
|
-
.then(function(resData) {
|
71
|
-
callback(null, resData);
|
72
|
-
})
|
73
|
-
.catch(function(err) {
|
74
|
-
log.error("Error in getThreadPictures", err);
|
75
|
-
callback(err);
|
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 getThreadPictures(threadID, offset, limit, 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, data) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc(data);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
var form = {
|
23
|
+
thread_id: threadID,
|
24
|
+
offset: offset,
|
25
|
+
limit: limit
|
26
|
+
};
|
27
|
+
|
28
|
+
defaultFuncs
|
29
|
+
.post("https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php", ctx.jar, form)
|
30
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
31
|
+
.then(function (resData) {
|
32
|
+
if (resData.error) throw resData;
|
33
|
+
return Promise.all(
|
34
|
+
resData.payload.imagesData.map(function (image) {
|
35
|
+
form = {
|
36
|
+
thread_id: threadID,
|
37
|
+
image_id: image.fbid
|
38
|
+
};
|
39
|
+
return defaultFuncs
|
40
|
+
.post("https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php", ctx.jar, form)
|
41
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
42
|
+
.then(function (resData) {
|
43
|
+
if (resData.error) throw resData;
|
44
|
+
// the response is pretty messy
|
45
|
+
var queryThreadID = resData.jsmods.require[0][3][1].query_metadata.query_path[0].message_thread;
|
46
|
+
var imageData = resData.jsmods.require[0][3][1].query_results[queryThreadID].message_images.edges[0].node.image2;
|
47
|
+
return imageData;
|
48
|
+
});
|
49
|
+
})
|
50
|
+
);
|
51
|
+
})
|
52
|
+
.then(resData => callback(null, resData))
|
53
|
+
.catch(function (err) {
|
54
|
+
log.error("Error in getThreadPictures", err);
|
55
|
+
callback(err);
|
56
|
+
});
|
57
|
+
return returnPromise;
|
58
|
+
};
|
59
|
+
};
|
package/leiamnash/getUserID.js
CHANGED
@@ -1,66 +1,61 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
function formatData(data) {
|
7
|
-
return {
|
8
|
-
userID: utils.formatID(data.uid.toString()),
|
9
|
-
photoUrl: data.photo,
|
10
|
-
indexRank: data.index_rank,
|
11
|
-
name: data.text,
|
12
|
-
isVerified: data.is_verified,
|
13
|
-
profileUrl: data.path,
|
14
|
-
category: data.category,
|
15
|
-
score: data.score,
|
16
|
-
type: data.type
|
17
|
-
};
|
18
|
-
}
|
19
|
-
|
20
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
21
|
-
return function getUserID(name, callback) {
|
22
|
-
var resolveFunc = function(){};
|
23
|
-
var rejectFunc = function(){};
|
24
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
25
|
-
resolveFunc = resolve;
|
26
|
-
rejectFunc = reject;
|
27
|
-
});
|
28
|
-
|
29
|
-
if (!callback) {
|
30
|
-
callback = function (err,
|
31
|
-
if (err)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
});
|
63
|
-
|
64
|
-
return returnPromise;
|
65
|
-
};
|
66
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
function formatData(data) {
|
7
|
+
return {
|
8
|
+
userID: utils.formatID(data.uid.toString()),
|
9
|
+
photoUrl: data.photo,
|
10
|
+
indexRank: data.index_rank,
|
11
|
+
name: data.text,
|
12
|
+
isVerified: data.is_verified,
|
13
|
+
profileUrl: data.path,
|
14
|
+
category: data.category,
|
15
|
+
score: data.score,
|
16
|
+
type: data.type
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
21
|
+
return function getUserID(name, callback) {
|
22
|
+
var resolveFunc = function () { };
|
23
|
+
var rejectFunc = function () { };
|
24
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
25
|
+
resolveFunc = resolve;
|
26
|
+
rejectFunc = reject;
|
27
|
+
});
|
28
|
+
|
29
|
+
if (!callback) {
|
30
|
+
callback = function (err, data) {
|
31
|
+
if (err) return rejectFunc(err);
|
32
|
+
resolveFunc(data);
|
33
|
+
};
|
34
|
+
}
|
35
|
+
|
36
|
+
var form = {
|
37
|
+
value: name.toLowerCase(),
|
38
|
+
viewer: ctx.userID,
|
39
|
+
rsp: "search",
|
40
|
+
context: "search",
|
41
|
+
path: "/home.php",
|
42
|
+
request_id: utils.getGUID()
|
43
|
+
};
|
44
|
+
|
45
|
+
defaultFuncs
|
46
|
+
.get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
|
47
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
48
|
+
.then(function (resData) {
|
49
|
+
if (resData.error) throw resData;
|
50
|
+
|
51
|
+
var data = resData.payload.entries;
|
52
|
+
callback(null, data.map(formatData));
|
53
|
+
})
|
54
|
+
.catch(function (err) {
|
55
|
+
log.error("getUserID", err);
|
56
|
+
return callback(err);
|
57
|
+
});
|
58
|
+
|
59
|
+
return returnPromise;
|
60
|
+
};
|
61
|
+
};
|
package/leiamnash/getUserInfo.js
CHANGED
@@ -1,72 +1,66 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
function formatData(data) {
|
7
|
-
var retObj = {};
|
8
|
-
|
9
|
-
for (var prop in data) {
|
10
|
-
// eslint-disable-next-line no-prototype-builtins
|
11
|
-
if (data.hasOwnProperty(prop)) {
|
12
|
-
var innerObj = data[prop];
|
13
|
-
retObj[prop] = {
|
14
|
-
name: innerObj.name,
|
15
|
-
firstName: innerObj.firstName,
|
16
|
-
vanity: innerObj.vanity,
|
17
|
-
thumbSrc: innerObj.thumbSrc,
|
18
|
-
profileUrl: innerObj.uri,
|
19
|
-
gender: innerObj.gender,
|
20
|
-
type: innerObj.type,
|
21
|
-
isFriend: innerObj.is_friend,
|
22
|
-
isBirthday: !!innerObj.is_birthday
|
23
|
-
};
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
return retObj;
|
28
|
-
}
|
29
|
-
|
30
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
31
|
-
return function getUserInfo(id, callback) {
|
32
|
-
var resolveFunc = function(){};
|
33
|
-
var rejectFunc = function(){};
|
34
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
35
|
-
resolveFunc = resolve;
|
36
|
-
rejectFunc = reject;
|
37
|
-
});
|
38
|
-
|
39
|
-
if (!callback) {
|
40
|
-
callback = function (err,
|
41
|
-
if (err)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
return callback(err);
|
68
|
-
});
|
69
|
-
|
70
|
-
return returnPromise;
|
71
|
-
};
|
72
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
function formatData(data) {
|
7
|
+
var retObj = {};
|
8
|
+
|
9
|
+
for (var prop in data) {
|
10
|
+
// eslint-disable-next-line no-prototype-builtins
|
11
|
+
if (data.hasOwnProperty(prop)) {
|
12
|
+
var innerObj = data[prop];
|
13
|
+
retObj[prop] = {
|
14
|
+
name: innerObj.name,
|
15
|
+
firstName: innerObj.firstName,
|
16
|
+
vanity: innerObj.vanity,
|
17
|
+
thumbSrc: innerObj.thumbSrc,
|
18
|
+
profileUrl: innerObj.uri,
|
19
|
+
gender: innerObj.gender,
|
20
|
+
type: innerObj.type,
|
21
|
+
isFriend: innerObj.is_friend,
|
22
|
+
isBirthday: !!innerObj.is_birthday
|
23
|
+
};
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
return retObj;
|
28
|
+
}
|
29
|
+
|
30
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
31
|
+
return function getUserInfo(id, callback) {
|
32
|
+
var resolveFunc = function () { };
|
33
|
+
var rejectFunc = function () { };
|
34
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
35
|
+
resolveFunc = resolve;
|
36
|
+
rejectFunc = reject;
|
37
|
+
});
|
38
|
+
|
39
|
+
if (!callback) {
|
40
|
+
callback = function (err, userInfo) {
|
41
|
+
if (err) return rejectFunc(err);
|
42
|
+
resolveFunc(userInfo);
|
43
|
+
};
|
44
|
+
}
|
45
|
+
|
46
|
+
if (utils.getType(id) !== "Array") id = [id];
|
47
|
+
|
48
|
+
var form = {};
|
49
|
+
id.map(function (v, i) {
|
50
|
+
form["ids[" + i + "]"] = v;
|
51
|
+
});
|
52
|
+
defaultFuncs
|
53
|
+
.post("https://www.facebook.com/chat/user_info/", ctx.jar, form)
|
54
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
55
|
+
.then(function (resData) {
|
56
|
+
if (resData.error) throw resData;
|
57
|
+
return callback(null, formatData(resData.payload.profiles));
|
58
|
+
})
|
59
|
+
.catch(function (err) {
|
60
|
+
log.error("getUserInfo", "Can't get user info");
|
61
|
+
return callback(err);
|
62
|
+
});
|
63
|
+
|
64
|
+
return returnPromise;
|
65
|
+
};
|
66
|
+
};
|
@@ -1,61 +1,46 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
throw {
|
48
|
-
err: resData.payload.err
|
49
|
-
};
|
50
|
-
}
|
51
|
-
|
52
|
-
return callback();
|
53
|
-
})
|
54
|
-
.catch(function(err) {
|
55
|
-
log.error("handleFriendRequest", err);
|
56
|
-
return callback(err);
|
57
|
-
});
|
58
|
-
|
59
|
-
return returnPromise;
|
60
|
-
};
|
61
|
-
};
|
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 handleFriendRequest(userID, accept, callback) {
|
8
|
+
if (utils.getType(accept) !== "Boolean") throw { error: "Please pass a boolean as a second argument." };
|
9
|
+
|
10
|
+
var resolveFunc = function() {};
|
11
|
+
var rejectFunc = function() {};
|
12
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
13
|
+
resolveFunc = resolve;
|
14
|
+
rejectFunc = reject;
|
15
|
+
});
|
16
|
+
|
17
|
+
if (!callback) {
|
18
|
+
callback = function(err, data) {
|
19
|
+
if (err) return rejectFunc(err);
|
20
|
+
resolveFunc(data);
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
var form = {
|
25
|
+
viewer_id: userID,
|
26
|
+
"frefs[0]": "jwl",
|
27
|
+
floc: "friend_center_requests",
|
28
|
+
ref: "/reqs.php",
|
29
|
+
action: (accept ? "confirm" : "reject")
|
30
|
+
};
|
31
|
+
|
32
|
+
defaultFuncs
|
33
|
+
.post("https://www.facebook.com/requests/friends/ajax/", ctx.jar, form)
|
34
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
35
|
+
.then(function(resData) {
|
36
|
+
if (resData.payload.err) throw { err: resData.payload.err };
|
37
|
+
return callback();
|
38
|
+
})
|
39
|
+
.catch(function(err) {
|
40
|
+
log.error("handleFriendRequest", err);
|
41
|
+
return callback(err);
|
42
|
+
});
|
43
|
+
|
44
|
+
return returnPromise;
|
45
|
+
};
|
46
|
+
};
|