node-ainzfb-new 1.6.2823-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 +4 -4
- 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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-ainzfb-new",
|
3
|
-
"version": "1.6.
|
3
|
+
"version": "1.6.2909-test",
|
4
4
|
"description": "A Facebook chat API that doesn't rely on XMPP. Will NOT be deprecated after April 30th 2015.",
|
5
5
|
"scripts": {
|
6
6
|
"test": "mocha",
|
@@ -26,7 +26,7 @@
|
|
26
26
|
"aes-js": "latest",
|
27
27
|
"assert": "latest",
|
28
28
|
"better-sqlite3": "latest",
|
29
|
-
"bluebird": "
|
29
|
+
"bluebird": "latest",
|
30
30
|
"chalk": "^4.1.2",
|
31
31
|
"cheerio": "latest",
|
32
32
|
"crypto": "latest",
|
@@ -37,10 +37,10 @@
|
|
37
37
|
"lodash": "",
|
38
38
|
"mqtt": "^4.3.7",
|
39
39
|
"node-superfetch": "^0.2.3",
|
40
|
-
"npmlog": "
|
40
|
+
"npmlog": "latest",
|
41
41
|
"path": "latest",
|
42
42
|
"pretty-ms": "latest",
|
43
|
-
"request": "
|
43
|
+
"request": "latest",
|
44
44
|
"semver": "latest",
|
45
45
|
"sus-support": "git+https://github.com/amogusdevlol/sus-support.git",
|
46
46
|
"websocket-stream": "latest"
|
package/src/addExternalModule.js
CHANGED
@@ -2,15 +2,22 @@
|
|
2
2
|
|
3
3
|
const utils = require("../utils");
|
4
4
|
|
5
|
-
module.exports = function
|
5
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
6
6
|
return function addExternalModule(moduleObj) {
|
7
7
|
if (utils.getType(moduleObj) == "Object") {
|
8
8
|
for (let apiName in moduleObj) {
|
9
|
-
if (utils.getType(moduleObj[apiName]) == "Function")
|
10
|
-
|
11
|
-
|
9
|
+
if (utils.getType(moduleObj[apiName]) == "Function")
|
10
|
+
api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
11
|
+
else
|
12
|
+
throw new Error(
|
13
|
+
`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(
|
14
|
+
moduleObj[apiName]
|
15
|
+
)}!`
|
16
|
+
);
|
12
17
|
}
|
13
|
-
}
|
14
|
-
|
18
|
+
} else
|
19
|
+
throw new Error(
|
20
|
+
`moduleObj must be an object, not ${utils.getType(moduleObj)}!`
|
21
|
+
);
|
15
22
|
};
|
16
23
|
};
|
package/src/addUserToGroup.js
CHANGED
@@ -3,25 +3,39 @@
|
|
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 addUserToGroup(userID, threadID, 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
|
-
if (
|
15
|
+
if (
|
16
|
+
!callback &&
|
17
|
+
(utils.getType(threadID) === "Function" ||
|
18
|
+
utils.getType(threadID) === "AsyncFunction")
|
19
|
+
)
|
20
|
+
throw { error: "please pass a threadID as a second argument." };
|
16
21
|
|
17
22
|
if (!callback) {
|
18
|
-
callback = function
|
23
|
+
callback = function(err) {
|
19
24
|
if (err) return rejectFunc(err);
|
20
25
|
resolveFunc();
|
21
26
|
};
|
22
27
|
}
|
23
28
|
|
24
|
-
if (
|
29
|
+
if (
|
30
|
+
utils.getType(threadID) !== "Number" &&
|
31
|
+
utils.getType(threadID) !== "String"
|
32
|
+
)
|
33
|
+
throw {
|
34
|
+
error:
|
35
|
+
"ThreadID should be of type Number or String and not " +
|
36
|
+
utils.getType(threadID) +
|
37
|
+
"."
|
38
|
+
};
|
25
39
|
|
26
40
|
if (utils.getType(userID) !== "Array") userID = [userID];
|
27
41
|
|
@@ -54,21 +68,30 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
54
68
|
};
|
55
69
|
|
56
70
|
for (var i = 0; i < userID.length; i++) {
|
57
|
-
if (
|
58
|
-
|
71
|
+
if (
|
72
|
+
utils.getType(userID[i]) !== "Number" &&
|
73
|
+
utils.getType(userID[i]) !== "String"
|
74
|
+
)
|
75
|
+
throw {
|
76
|
+
error:
|
77
|
+
"Elements of userID should be of type Number or String and not " +
|
78
|
+
utils.getType(userID[i]) +
|
79
|
+
"."
|
80
|
+
};
|
81
|
+
form["log_message_data[added_participants][" + i + "]"] =
|
82
|
+
"fbid:" + userID[i];
|
59
83
|
}
|
60
84
|
|
61
85
|
defaultFuncs
|
62
86
|
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
63
87
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
64
|
-
.then(function
|
88
|
+
.then(function(resData) {
|
65
89
|
if (!resData) throw { error: "Add to group failed." };
|
66
90
|
if (resData.error) throw resData;
|
67
91
|
|
68
|
-
|
69
92
|
return callback();
|
70
93
|
})
|
71
|
-
.catch(function
|
94
|
+
.catch(function(err) {
|
72
95
|
log.error("addUserToGroup", err);
|
73
96
|
return callback(err);
|
74
97
|
});
|
package/src/changeAdminStatus.js
CHANGED
@@ -6,7 +6,7 @@ const log = require("npmlog");
|
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
|
8
8
|
if (utils.getType(threadID) !== "String") {
|
9
|
-
throw {error: "changeAdminStatus: threadID must be a string"};
|
9
|
+
throw { error: "changeAdminStatus: threadID must be a string" };
|
10
10
|
}
|
11
11
|
|
12
12
|
if (utils.getType(adminIDs) === "String") {
|
@@ -14,22 +14,22 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
if (utils.getType(adminIDs) !== "Array") {
|
17
|
-
throw {error: "changeAdminStatus: adminIDs must be an array or string"};
|
17
|
+
throw { error: "changeAdminStatus: adminIDs must be an array or string" };
|
18
18
|
}
|
19
19
|
|
20
20
|
if (utils.getType(adminStatus) !== "Boolean") {
|
21
|
-
throw {error: "changeAdminStatus: adminStatus must be a string"};
|
21
|
+
throw { error: "changeAdminStatus: adminStatus must be a string" };
|
22
22
|
}
|
23
23
|
|
24
|
-
var resolveFunc = function(){};
|
25
|
-
var rejectFunc = function(){};
|
26
|
-
var returnPromise = new Promise(function
|
24
|
+
var resolveFunc = function() {};
|
25
|
+
var rejectFunc = function() {};
|
26
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
27
27
|
resolveFunc = resolve;
|
28
28
|
rejectFunc = reject;
|
29
29
|
});
|
30
30
|
|
31
31
|
if (!callback) {
|
32
|
-
callback = function
|
32
|
+
callback = function(err) {
|
33
33
|
if (err) {
|
34
34
|
return rejectFunc(err);
|
35
35
|
}
|
@@ -37,12 +37,15 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
37
37
|
};
|
38
38
|
}
|
39
39
|
|
40
|
-
if (
|
41
|
-
|
40
|
+
if (
|
41
|
+
utils.getType(callback) !== "Function" &&
|
42
|
+
utils.getType(callback) !== "AsyncFunction"
|
43
|
+
) {
|
44
|
+
throw { error: "changeAdminStatus: callback is not a function" };
|
42
45
|
}
|
43
46
|
|
44
47
|
let form = {
|
45
|
-
|
48
|
+
thread_fbid: threadID
|
46
49
|
};
|
47
50
|
|
48
51
|
let i = 0;
|
@@ -52,17 +55,31 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
52
55
|
form["add"] = adminStatus;
|
53
56
|
|
54
57
|
defaultFuncs
|
55
|
-
.post(
|
58
|
+
.post(
|
59
|
+
"https://www.facebook.com/messaging/save_admins/?dpr=1",
|
60
|
+
ctx.jar,
|
61
|
+
form
|
62
|
+
)
|
56
63
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
57
64
|
.then(function(resData) {
|
58
65
|
if (resData.error) {
|
59
66
|
switch (resData.error) {
|
60
67
|
case 1976004:
|
61
|
-
throw {
|
68
|
+
throw {
|
69
|
+
error: "Cannot alter admin status: you are not an admin.",
|
70
|
+
rawResponse: resData
|
71
|
+
};
|
62
72
|
case 1357031:
|
63
|
-
throw {
|
73
|
+
throw {
|
74
|
+
error:
|
75
|
+
"Cannot alter admin status: this thread is not a group chat.",
|
76
|
+
rawResponse: resData
|
77
|
+
};
|
64
78
|
default:
|
65
|
-
throw {
|
79
|
+
throw {
|
80
|
+
error: "Cannot alter admin status: unknown error.",
|
81
|
+
rawResponse: resData
|
82
|
+
};
|
66
83
|
}
|
67
84
|
}
|
68
85
|
|
@@ -72,8 +89,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
72
89
|
log.error("changeAdminStatus", err);
|
73
90
|
return callback(err);
|
74
91
|
});
|
75
|
-
|
92
|
+
|
76
93
|
return returnPromise;
|
77
94
|
};
|
78
95
|
};
|
79
|
-
|
@@ -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 changeArchivedStatus(threadOrThreads, archive, 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) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
resolveFunc();
|
19
19
|
};
|
@@ -21,17 +21,23 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
21
21
|
|
22
22
|
var form = {};
|
23
23
|
|
24
|
-
if (utils.getType(threadOrThreads) === "Array")
|
24
|
+
if (utils.getType(threadOrThreads) === "Array")
|
25
|
+
for (var i = 0; i < threadOrThreads.length; i++)
|
26
|
+
form["ids[" + threadOrThreads[i] + "]"] = archive;
|
25
27
|
else form["ids[" + threadOrThreads + "]"] = archive;
|
26
28
|
|
27
29
|
defaultFuncs
|
28
|
-
.post(
|
30
|
+
.post(
|
31
|
+
"https://www.facebook.com/ajax/mercury/change_archived_status.php",
|
32
|
+
ctx.jar,
|
33
|
+
form
|
34
|
+
)
|
29
35
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
30
|
-
.then(function
|
36
|
+
.then(function(resData) {
|
31
37
|
if (resData.error) throw resData;
|
32
38
|
return callback();
|
33
39
|
})
|
34
|
-
.catch(function
|
40
|
+
.catch(function(err) {
|
35
41
|
log.error("changeArchivedStatus", err);
|
36
42
|
return callback(err);
|
37
43
|
});
|
package/src/changeAvt.js
CHANGED
@@ -10,76 +10,82 @@ var log = require("npmlog");
|
|
10
10
|
* @returns The JSON.parse(Data.split("for (;;);")[1]); is returning the following:
|
11
11
|
* {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
|
12
12
|
*/
|
13
|
-
async function postImage(Api,BotID,form) {
|
14
|
-
|
15
|
-
|
13
|
+
async function postImage(Api, BotID, form) {
|
14
|
+
var Data = await Api.httpPostFormData(
|
15
|
+
`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`,
|
16
|
+
form
|
17
|
+
);
|
18
|
+
return JSON.parse(Data.split("for (;;);")[1]);
|
16
19
|
}
|
17
20
|
|
18
21
|
module.exports = function(defaultFuncs, api, ctx) {
|
19
|
-
/* Changing the profile picture of the bot. */
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
/* Changing the profile picture of the bot. */
|
23
|
+
return function changeAvt(link, caption, callback) {
|
24
|
+
var resolveFunc = function() {};
|
25
|
+
var rejectFunc = function() {};
|
26
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
27
|
+
resolveFunc = resolve;
|
28
|
+
rejectFunc = reject;
|
29
|
+
});
|
27
30
|
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
}
|
31
|
+
if (!callback) {
|
32
|
+
callback = function(err, data) {
|
33
|
+
if (err) return rejectFunc(err);
|
34
|
+
resolveFunc(data);
|
35
|
+
};
|
36
|
+
}
|
37
|
+
try {
|
38
|
+
var Fetch = require("axios");
|
39
|
+
Fetch.get(link, { responseType: "stream" }).then(data => {
|
40
|
+
postImage(api, ctx.userID, { file: data.data }).then(data => {
|
41
|
+
if (data.error)
|
42
|
+
throw new Error({
|
43
|
+
error: data.error,
|
44
|
+
des: data.error.errorDescription
|
45
|
+
});
|
46
|
+
var form = {
|
47
|
+
av: ctx.userID,
|
48
|
+
fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
|
49
|
+
fb_api_caller_class: "RelayModern",
|
50
|
+
doc_id: "5066134240065849",
|
51
|
+
variables: JSON.stringify({
|
52
|
+
input: {
|
53
|
+
caption: caption || "",
|
54
|
+
existing_photo_id: data.payload.fbid,
|
55
|
+
expiration_time: null,
|
56
|
+
profile_id: ctx.userID,
|
57
|
+
profile_pic_method: "EXISTING",
|
58
|
+
profile_pic_source: "TIMELINE",
|
59
|
+
scaled_crop_rect: {
|
60
|
+
height: 1,
|
61
|
+
width: 1,
|
62
|
+
x: 0,
|
63
|
+
y: 0
|
64
|
+
},
|
65
|
+
skip_cropping: true,
|
66
|
+
actor_id: ctx.userID,
|
67
|
+
client_mutation_id: Math.round(Math.random() * 19).toString()
|
68
|
+
},
|
69
|
+
isPage: false,
|
70
|
+
isProfile: true,
|
71
|
+
scale: 3
|
72
|
+
})
|
73
|
+
};
|
74
|
+
defaultFuncs
|
75
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
76
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
77
|
+
.then(function(resData) {
|
78
|
+
if (resData.error) throw resData;
|
79
|
+
else return callback(null, true);
|
80
|
+
})
|
81
|
+
.catch(function(err) {
|
82
|
+
return callback(err);
|
83
|
+
});
|
84
|
+
});
|
85
|
+
});
|
86
|
+
} catch (e) {
|
87
|
+
throw e;
|
88
|
+
}
|
89
|
+
return returnPromise;
|
90
|
+
};
|
91
|
+
};
|
package/src/changeBio.js
CHANGED
@@ -3,19 +3,23 @@
|
|
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 changeBio(bio, publish, 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
|
-
if (
|
16
|
+
if (
|
17
|
+
utils.getType(publish) == "Function" ||
|
18
|
+
utils.getType(publish) == "AsyncFunction"
|
19
|
+
)
|
20
|
+
callback = publish;
|
17
21
|
else {
|
18
|
-
callback = function
|
22
|
+
callback = function(err) {
|
19
23
|
if (err) return rejectFunc(err);
|
20
24
|
resolveFunc();
|
21
25
|
};
|
@@ -50,12 +54,12 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
50
54
|
defaultFuncs
|
51
55
|
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
52
56
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
53
|
-
.then(function
|
57
|
+
.then(function(resData) {
|
54
58
|
if (resData.errors) throw resData;
|
55
59
|
|
56
60
|
return callback();
|
57
61
|
})
|
58
|
-
.catch(function
|
62
|
+
.catch(function(err) {
|
59
63
|
log.error("changeBio", err);
|
60
64
|
return callback(err);
|
61
65
|
});
|
@@ -3,31 +3,37 @@
|
|
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 changeBlockedStatus(userID, block, 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) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
resolveFunc();
|
19
19
|
};
|
20
20
|
}
|
21
21
|
|
22
22
|
defaultFuncs
|
23
|
-
.post(
|
23
|
+
.post(
|
24
|
+
`https://www.facebook.com/messaging/${
|
25
|
+
block ? "" : "un"
|
26
|
+
}block_messages/`,
|
27
|
+
ctx.jar,
|
28
|
+
{ fbid: userID }
|
29
|
+
)
|
24
30
|
.then(utils.saveCookies(ctx.jar))
|
25
31
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
26
|
-
.then(function
|
32
|
+
.then(function(resData) {
|
27
33
|
if (resData.error) throw resData;
|
28
34
|
return callback();
|
29
35
|
})
|
30
|
-
.catch(function
|
36
|
+
.catch(function(err) {
|
31
37
|
log.error("changeBlockedStatus", err);
|
32
38
|
return callback(err);
|
33
39
|
});
|
package/src/changeGroupImage.js
CHANGED
@@ -4,7 +4,7 @@ var utils = require("../utils");
|
|
4
4
|
var log = require("npmlog");
|
5
5
|
var bluebird = require("bluebird");
|
6
6
|
|
7
|
-
module.exports = function
|
7
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
8
8
|
function handleUpload(image, callback) {
|
9
9
|
var uploads = [];
|
10
10
|
|
@@ -15,9 +15,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
15
15
|
|
16
16
|
uploads.push(
|
17
17
|
defaultFuncs
|
18
|
-
.postFormData(
|
18
|
+
.postFormData(
|
19
|
+
"https://upload.facebook.com/ajax/mercury/upload.php",
|
20
|
+
ctx.jar,
|
21
|
+
form,
|
22
|
+
{}
|
23
|
+
)
|
19
24
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
20
|
-
.then(function
|
25
|
+
.then(function(resData) {
|
21
26
|
if (resData.error) throw resData;
|
22
27
|
|
23
28
|
return resData.payload.metadata[0];
|
@@ -28,24 +33,29 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
28
33
|
bluebird
|
29
34
|
.all(uploads)
|
30
35
|
.then(resData => callback(null, resData))
|
31
|
-
.catch(function
|
36
|
+
.catch(function(err) {
|
32
37
|
log.error("handleUpload", err);
|
33
38
|
return callback(err);
|
34
39
|
});
|
35
40
|
}
|
36
41
|
|
37
42
|
return function changeGroupImage(image, threadID, callback) {
|
38
|
-
if (
|
43
|
+
if (
|
44
|
+
!callback &&
|
45
|
+
(utils.getType(threadID) === "Function" ||
|
46
|
+
utils.getType(threadID) === "AsyncFunction")
|
47
|
+
)
|
48
|
+
throw { error: "please pass a threadID as a second argument." };
|
39
49
|
|
40
|
-
var resolveFunc = function
|
41
|
-
var rejectFunc = function
|
42
|
-
var returnPromise = new Promise(function
|
50
|
+
var resolveFunc = function() {};
|
51
|
+
var rejectFunc = function() {};
|
52
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
43
53
|
resolveFunc = resolve;
|
44
54
|
rejectFunc = reject;
|
45
55
|
});
|
46
56
|
|
47
57
|
if (!callback) {
|
48
|
-
callback = function
|
58
|
+
callback = function(err) {
|
49
59
|
if (err) return rejectFunc(err);
|
50
60
|
resolveFunc();
|
51
61
|
};
|
@@ -81,21 +91,25 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
81
91
|
timestamp_time_passed: "0"
|
82
92
|
};
|
83
93
|
|
84
|
-
handleUpload(image, function
|
94
|
+
handleUpload(image, function(err, payload) {
|
85
95
|
if (err) return callback(err);
|
86
96
|
|
87
97
|
form["thread_image_id"] = payload[0]["image_id"];
|
88
98
|
form["thread_id"] = threadID;
|
89
99
|
|
90
100
|
defaultFuncs
|
91
|
-
.post(
|
101
|
+
.post(
|
102
|
+
"https://www.facebook.com/messaging/set_thread_image/",
|
103
|
+
ctx.jar,
|
104
|
+
form
|
105
|
+
)
|
92
106
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
93
|
-
.then(function
|
107
|
+
.then(function(resData) {
|
94
108
|
// check for errors here
|
95
109
|
if (resData.error) throw resData;
|
96
110
|
return callback();
|
97
111
|
})
|
98
|
-
.catch(function
|
112
|
+
.catch(function(err) {
|
99
113
|
log.error("changeGroupImage", err);
|
100
114
|
return callback(err);
|
101
115
|
});
|