alicezetion 1.0.2 → 1.0.4
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 +488 -560
- package/package.json +25 -25
- package/replit.nix +5 -0
- package/src/addExternalModule.js +15 -0
- package/{alice → src}/addUserToGroup.js +16 -52
- package/src/changeAdminStatus.js +47 -0
- package/src/changeArchivedStatus.js +41 -0
- package/{alice → src}/changeBio.js +6 -19
- package/{alice → src}/changeBlockedStatus.js +3 -14
- package/{alice → src}/changeGroupImage.js +16 -40
- package/src/changeNickname.js +43 -0
- package/{alice → src}/changeThreadColor.js +10 -20
- package/src/changeThreadEmoji.js +41 -0
- package/src/chat.js +315 -0
- package/{alice → src}/createNewGroup.js +12 -28
- package/{alice → src}/createPoll.js +13 -25
- package/src/deleteMessage.js +44 -0
- package/src/deleteThread.js +42 -0
- package/src/forwardAttachment.js +47 -0
- package/src/forwardMessage.js +0 -0
- package/{alice → src}/getCurrentUserID.js +1 -1
- package/{alice → src}/getEmojiUrl.js +2 -4
- package/{alice → src}/getFriendsList.js +10 -21
- package/{alice → src}/getThreadHistory.js +58 -166
- package/{alice → src}/getThreadHistoryDeprecated.js +20 -42
- package/{alice → src}/getThreadInfo.js +25 -60
- package/src/getThreadInfoDeprecated.js +56 -0
- package/{alice → src}/getThreadList.js +41 -66
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/{alice → src}/getUserID.js +9 -14
- package/{alice → src}/getUserInfo.js +13 -19
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/{alice → src}/httpGet.js +12 -17
- package/{alice → src}/httpPost.js +12 -17
- package/src/listen.js +553 -0
- package/src/listenMqtt-Test.js +687 -0
- package/src/listenMqtt.js +677 -0
- package/{alice → src}/logout.js +13 -20
- package/{alice → src}/markAsDelivered.js +11 -22
- package/{alice → src}/markAsRead.js +11 -21
- package/{alice → src}/markAsReadAll.js +10 -20
- package/{alice → src}/markAsSeen.js +7 -18
- package/{alice → src}/muteThread.js +11 -18
- package/src/removeUserFromGroup.js +45 -0
- package/{alice → src}/resolvePhotoUrl.js +8 -17
- package/{alice → src}/searchForThread.js +10 -21
- package/{alice → src}/sendTypingIndicator.js +14 -47
- package/{alice → src}/setMessageReaction.js +12 -26
- package/{alice → src}/setPostReaction.js +13 -26
- package/{alice → src}/setTitle.js +13 -29
- package/src/threadColors.js +41 -0
- package/{alice → src}/unfriend.js +9 -19
- package/{alice → src}/unsendMessage.js +9 -19
- package/utils.js +1021 -1190
- package/alice/addExternalModule.js +0 -19
- package/alice/changeAdminStatus.js +0 -79
- package/alice/changeArchivedStatus.js +0 -55
- package/alice/changeNickname.js +0 -59
- package/alice/changeThreadEmoji.js +0 -55
- package/alice/deleteMessage.js +0 -56
- package/alice/deleteThread.js +0 -56
- package/alice/forwardAttachment.js +0 -60
- package/alice/getThreadInfoDeprecated.js +0 -80
- package/alice/getThreadListDeprecated.js +0 -75
- package/alice/getThreadPictures.js +0 -79
- package/alice/handleFriendRequest.js +0 -61
- package/alice/handleMessageRequest.js +0 -65
- package/alice/listenMqtt.js +0 -789
- package/alice/removeUserFromGroup.js +0 -79
- package/alice/sendMessage.js +0 -459
- package/alice/threadColors.js +0 -57
@@ -1,19 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
const utils = require("../utils");
|
4
|
-
|
5
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
6
|
-
return function addExternalModule(moduleObj) {
|
7
|
-
if (utils.getType(moduleObj) == "Object") {
|
8
|
-
for (let apiName in moduleObj) {
|
9
|
-
if (utils.getType(moduleObj[apiName]) == "Function") {
|
10
|
-
api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
11
|
-
} else {
|
12
|
-
throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
|
13
|
-
}
|
14
|
-
}
|
15
|
-
} else {
|
16
|
-
throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
|
17
|
-
}
|
18
|
-
};
|
19
|
-
};
|
@@ -1,79 +0,0 @@
|
|
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 changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
|
8
|
-
if (utils.getType(threadID) !== "String") {
|
9
|
-
throw {error: "changeAdminStatus: threadID must be a string"};
|
10
|
-
}
|
11
|
-
|
12
|
-
if (utils.getType(adminIDs) === "String") {
|
13
|
-
adminIDs = [adminIDs];
|
14
|
-
}
|
15
|
-
|
16
|
-
if (utils.getType(adminIDs) !== "Array") {
|
17
|
-
throw {error: "changeAdminStatus: adminIDs must be an array or string"};
|
18
|
-
}
|
19
|
-
|
20
|
-
if (utils.getType(adminStatus) !== "Boolean") {
|
21
|
-
throw {error: "changeAdminStatus: adminStatus must be a string"};
|
22
|
-
}
|
23
|
-
|
24
|
-
var resolveFunc = function(){};
|
25
|
-
var rejectFunc = function(){};
|
26
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
27
|
-
resolveFunc = resolve;
|
28
|
-
rejectFunc = reject;
|
29
|
-
});
|
30
|
-
|
31
|
-
if (!callback) {
|
32
|
-
callback = function (err) {
|
33
|
-
if (err) {
|
34
|
-
return rejectFunc(err);
|
35
|
-
}
|
36
|
-
resolveFunc();
|
37
|
-
};
|
38
|
-
}
|
39
|
-
|
40
|
-
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
41
|
-
throw {error: "changeAdminStatus: callback is not a function"};
|
42
|
-
}
|
43
|
-
|
44
|
-
let form = {
|
45
|
-
"thread_fbid": threadID,
|
46
|
-
};
|
47
|
-
|
48
|
-
let i = 0;
|
49
|
-
for (let u of adminIDs) {
|
50
|
-
form[`admin_ids[${i++}]`] = u;
|
51
|
-
}
|
52
|
-
form["add"] = adminStatus;
|
53
|
-
|
54
|
-
defaultFuncs
|
55
|
-
.post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, form)
|
56
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
57
|
-
.then(function(resData) {
|
58
|
-
if (resData.error) {
|
59
|
-
switch (resData.error) {
|
60
|
-
case 1976004:
|
61
|
-
throw { error: "Cannot alter admin status: you are not an admin.", rawResponse: resData };
|
62
|
-
case 1357031:
|
63
|
-
throw { error: "Cannot alter admin status: this thread is not a group chat.", rawResponse: resData };
|
64
|
-
default:
|
65
|
-
throw { error: "Cannot alter admin status: unknown error.", rawResponse: resData };
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
callback();
|
70
|
-
})
|
71
|
-
.catch(function(err) {
|
72
|
-
log.error("changeAdminStatus", err);
|
73
|
-
return callback(err);
|
74
|
-
});
|
75
|
-
|
76
|
-
return returnPromise;
|
77
|
-
};
|
78
|
-
};
|
79
|
-
|
@@ -1,55 +0,0 @@
|
|
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 changeArchivedStatus(threadOrThreads, archive, 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
|
-
return rejectFunc(err);
|
19
|
-
}
|
20
|
-
resolveFunc();
|
21
|
-
};
|
22
|
-
}
|
23
|
-
|
24
|
-
var form = {};
|
25
|
-
|
26
|
-
if (utils.getType(threadOrThreads) === "Array") {
|
27
|
-
for (var i = 0; i < threadOrThreads.length; i++) {
|
28
|
-
form["ids[" + threadOrThreads[i] + "]"] = archive;
|
29
|
-
}
|
30
|
-
} else {
|
31
|
-
form["ids[" + threadOrThreads + "]"] = archive;
|
32
|
-
}
|
33
|
-
|
34
|
-
defaultFuncs
|
35
|
-
.post(
|
36
|
-
"https://www.facebook.com/ajax/mercury/change_archived_status.php",
|
37
|
-
ctx.jar,
|
38
|
-
form
|
39
|
-
)
|
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("changeArchivedStatus", err);
|
50
|
-
return callback(err);
|
51
|
-
});
|
52
|
-
|
53
|
-
return returnPromise;
|
54
|
-
};
|
55
|
-
};
|
package/alice/changeNickname.js
DELETED
@@ -1,59 +0,0 @@
|
|
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 changeNickname(nickname, threadID, participantID, 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
|
-
if (!callback) {
|
15
|
-
callback = function (err) {
|
16
|
-
if (err) {
|
17
|
-
return rejectFunc(err);
|
18
|
-
}
|
19
|
-
resolveFunc();
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
var form = {
|
24
|
-
nickname: nickname,
|
25
|
-
participant_id: participantID,
|
26
|
-
thread_or_other_fbid: threadID
|
27
|
-
};
|
28
|
-
|
29
|
-
defaultFuncs
|
30
|
-
.post(
|
31
|
-
"https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1",
|
32
|
-
ctx.jar,
|
33
|
-
form
|
34
|
-
)
|
35
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
-
.then(function(resData) {
|
37
|
-
if (resData.error === 1545014) {
|
38
|
-
throw { error: "Trying to change nickname of user isn't in thread" };
|
39
|
-
}
|
40
|
-
if (resData.error === 1357031) {
|
41
|
-
throw {
|
42
|
-
error:
|
43
|
-
"Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname."
|
44
|
-
};
|
45
|
-
}
|
46
|
-
if (resData.error) {
|
47
|
-
throw resData;
|
48
|
-
}
|
49
|
-
|
50
|
-
return callback();
|
51
|
-
})
|
52
|
-
.catch(function(err) {
|
53
|
-
log.error("changeNickname", err);
|
54
|
-
return callback(err);
|
55
|
-
});
|
56
|
-
|
57
|
-
return returnPromise;
|
58
|
-
};
|
59
|
-
};
|
@@ -1,55 +0,0 @@
|
|
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 changeThreadEmoji(emoji, threadID, 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
|
-
return rejectFunc(err);
|
19
|
-
}
|
20
|
-
resolveFunc();
|
21
|
-
};
|
22
|
-
}
|
23
|
-
var form = {
|
24
|
-
emoji_choice: emoji,
|
25
|
-
thread_or_other_fbid: threadID
|
26
|
-
};
|
27
|
-
|
28
|
-
defaultFuncs
|
29
|
-
.post(
|
30
|
-
"https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg",
|
31
|
-
ctx.jar,
|
32
|
-
form
|
33
|
-
)
|
34
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
35
|
-
.then(function(resData) {
|
36
|
-
if (resData.error === 1357031) {
|
37
|
-
throw {
|
38
|
-
error:
|
39
|
-
"Trying to change emoji of a chat that doesn't exist. Have at least one message in the thread before trying to change the emoji."
|
40
|
-
};
|
41
|
-
}
|
42
|
-
if (resData.error) {
|
43
|
-
throw resData;
|
44
|
-
}
|
45
|
-
|
46
|
-
return callback();
|
47
|
-
})
|
48
|
-
.catch(function(err) {
|
49
|
-
log.error("changeThreadEmoji", err);
|
50
|
-
return callback(err);
|
51
|
-
});
|
52
|
-
|
53
|
-
return returnPromise;
|
54
|
-
};
|
55
|
-
};
|
package/alice/deleteMessage.js
DELETED
@@ -1,56 +0,0 @@
|
|
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 deleteMessage(messageOrMessages, 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
|
-
if (!callback) {
|
15
|
-
callback = function(err) {
|
16
|
-
if (err) {
|
17
|
-
return rejectFunc(err);
|
18
|
-
}
|
19
|
-
resolveFunc();
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
var form = {
|
24
|
-
client: "mercury"
|
25
|
-
};
|
26
|
-
|
27
|
-
if (utils.getType(messageOrMessages) !== "Array") {
|
28
|
-
messageOrMessages = [messageOrMessages];
|
29
|
-
}
|
30
|
-
|
31
|
-
for (var i = 0; i < messageOrMessages.length; i++) {
|
32
|
-
form["message_ids[" + i + "]"] = messageOrMessages[i];
|
33
|
-
}
|
34
|
-
|
35
|
-
defaultFuncs
|
36
|
-
.post(
|
37
|
-
"https://www.facebook.com/ajax/mercury/delete_messages.php",
|
38
|
-
ctx.jar,
|
39
|
-
form
|
40
|
-
)
|
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("deleteMessage", err);
|
51
|
-
return callback(err);
|
52
|
-
});
|
53
|
-
|
54
|
-
return returnPromise;
|
55
|
-
};
|
56
|
-
};
|
package/alice/deleteThread.js
DELETED
@@ -1,56 +0,0 @@
|
|
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 deleteThread(threadOrThreads, 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
|
-
if (!callback) {
|
15
|
-
callback = function(err) {
|
16
|
-
if (err) {
|
17
|
-
return rejectFunc(err);
|
18
|
-
}
|
19
|
-
resolveFunc();
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
var form = {
|
24
|
-
client: "mercury"
|
25
|
-
};
|
26
|
-
|
27
|
-
if (utils.getType(threadOrThreads) !== "Array") {
|
28
|
-
threadOrThreads = [threadOrThreads];
|
29
|
-
}
|
30
|
-
|
31
|
-
for (var i = 0; i < threadOrThreads.length; i++) {
|
32
|
-
form["ids[" + i + "]"] = threadOrThreads[i];
|
33
|
-
}
|
34
|
-
|
35
|
-
defaultFuncs
|
36
|
-
.post(
|
37
|
-
"https://www.facebook.com/ajax/mercury/delete_thread.php",
|
38
|
-
ctx.jar,
|
39
|
-
form
|
40
|
-
)
|
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("deleteThread", err);
|
51
|
-
return callback(err);
|
52
|
-
});
|
53
|
-
|
54
|
-
return returnPromise;
|
55
|
-
};
|
56
|
-
};
|
@@ -1,60 +0,0 @@
|
|
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 forwardAttachment(attachmentID, userOrUsers, 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
|
-
if (!callback) {
|
15
|
-
callback = function(err) {
|
16
|
-
if (err) {
|
17
|
-
return rejectFunc(err);
|
18
|
-
}
|
19
|
-
resolveFunc();
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
var form = {
|
24
|
-
attachment_id: attachmentID
|
25
|
-
};
|
26
|
-
|
27
|
-
if (utils.getType(userOrUsers) !== "Array") {
|
28
|
-
userOrUsers = [userOrUsers];
|
29
|
-
}
|
30
|
-
|
31
|
-
var timestamp = Math.floor(Date.now() / 1000);
|
32
|
-
|
33
|
-
for (var i = 0; i < userOrUsers.length; i++) {
|
34
|
-
//That's good, the key of the array is really timestmap in seconds + index
|
35
|
-
//Probably time when the attachment will be sent?
|
36
|
-
form["recipient_map[" + (timestamp + i) + "]"] = userOrUsers[i];
|
37
|
-
}
|
38
|
-
|
39
|
-
defaultFuncs
|
40
|
-
.post(
|
41
|
-
"https://www.facebook.com/mercury/attachments/forward/",
|
42
|
-
ctx.jar,
|
43
|
-
form
|
44
|
-
)
|
45
|
-
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
46
|
-
.then(function(resData) {
|
47
|
-
if (resData.error) {
|
48
|
-
throw resData;
|
49
|
-
}
|
50
|
-
|
51
|
-
return callback();
|
52
|
-
})
|
53
|
-
.catch(function(err) {
|
54
|
-
log.error("forwardAttachment", err);
|
55
|
-
return callback(err);
|
56
|
-
});
|
57
|
-
|
58
|
-
return returnPromise;
|
59
|
-
};
|
60
|
-
};
|
@@ -1,80 +0,0 @@
|
|
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 getThreadInfo(threadID, 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
|
-
var form = {
|
25
|
-
client: "mercury"
|
26
|
-
};
|
27
|
-
|
28
|
-
api.getUserInfo(threadID, function(err, userRes) {
|
29
|
-
if (err) {
|
30
|
-
return callback(err);
|
31
|
-
}
|
32
|
-
var key = Object.keys(userRes).length > 0 ? "user_ids" : "thread_fbids";
|
33
|
-
form["threads[" + key + "][0]"] = threadID;
|
34
|
-
|
35
|
-
if (ctx.globalOptions.pageId)
|
36
|
-
form.request_user_id = ctx.globalOptions.pageId;
|
37
|
-
|
38
|
-
defaultFuncs
|
39
|
-
.post(
|
40
|
-
"https://www.facebook.com/ajax/mercury/thread_info.php",
|
41
|
-
ctx.jar,
|
42
|
-
form
|
43
|
-
)
|
44
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
45
|
-
.then(function(resData) {
|
46
|
-
if (resData.error) {
|
47
|
-
throw resData;
|
48
|
-
} else if (!resData.payload) {
|
49
|
-
throw {
|
50
|
-
error: "Could not retrieve thread Info."
|
51
|
-
};
|
52
|
-
}
|
53
|
-
var threadData = resData.payload.threads[0];
|
54
|
-
var userData = userRes[threadID];
|
55
|
-
|
56
|
-
if (threadData == null) {
|
57
|
-
throw {
|
58
|
-
error: "ThreadData is null"
|
59
|
-
};
|
60
|
-
}
|
61
|
-
|
62
|
-
threadData.name =
|
63
|
-
userData != null && userData.name != null
|
64
|
-
? userData.name
|
65
|
-
: threadData.name;
|
66
|
-
threadData.image_src =
|
67
|
-
userData != null && userData.thumbSrc != null
|
68
|
-
? userData.thumbSrc
|
69
|
-
: threadData.image_src;
|
70
|
-
|
71
|
-
callback(null, utils.formatThread(threadData));
|
72
|
-
})
|
73
|
-
.catch(function(err) {
|
74
|
-
log.error("getThreadInfo", err);
|
75
|
-
return callback(err);
|
76
|
-
});
|
77
|
-
});
|
78
|
-
return returnPromise;
|
79
|
-
};
|
80
|
-
};
|
@@ -1,75 +0,0 @@
|
|
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
|
-
throw {
|
11
|
-
error: "Please pass a number as a second argument."
|
12
|
-
};
|
13
|
-
} else if (
|
14
|
-
utils.getType(type) === "Function" ||
|
15
|
-
utils.getType(type) === "AsyncFunction"
|
16
|
-
) {
|
17
|
-
callback = type;
|
18
|
-
type = "inbox"; //default to inbox
|
19
|
-
} else if (utils.getType(type) !== "String") {
|
20
|
-
throw {
|
21
|
-
error:
|
22
|
-
"Please pass a String as a third argument. Your options are: inbox, pending, and archived"
|
23
|
-
};
|
24
|
-
} else {
|
25
|
-
throw {
|
26
|
-
error: "getThreadList: need callback"
|
27
|
-
};
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
if (type === "archived") {
|
32
|
-
type = "action:archived";
|
33
|
-
} else if (type !== "inbox" && type !== "pending" && type !== "other") {
|
34
|
-
throw {
|
35
|
-
error:
|
36
|
-
"type can only be one of the following: inbox, pending, archived, other"
|
37
|
-
};
|
38
|
-
}
|
39
|
-
|
40
|
-
if (end <= start) end = start + 20;
|
41
|
-
|
42
|
-
var form = {
|
43
|
-
client: "mercury"
|
44
|
-
};
|
45
|
-
|
46
|
-
form[type + "[offset]"] = start;
|
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,79 +0,0 @@
|
|
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, friendList) {
|
17
|
-
if (err) {
|
18
|
-
return rejectFunc(err);
|
19
|
-
}
|
20
|
-
resolveFunc(friendList);
|
21
|
-
};
|
22
|
-
}
|
23
|
-
|
24
|
-
var form = {
|
25
|
-
thread_id: threadID,
|
26
|
-
offset: offset,
|
27
|
-
limit: limit
|
28
|
-
};
|
29
|
-
|
30
|
-
defaultFuncs
|
31
|
-
.post(
|
32
|
-
"https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
|
33
|
-
ctx.jar,
|
34
|
-
form
|
35
|
-
)
|
36
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
37
|
-
.then(function(resData) {
|
38
|
-
if (resData.error) {
|
39
|
-
throw resData;
|
40
|
-
}
|
41
|
-
return Promise.all(
|
42
|
-
resData.payload.imagesData.map(function(image) {
|
43
|
-
form = {
|
44
|
-
thread_id: threadID,
|
45
|
-
image_id: image.fbid
|
46
|
-
};
|
47
|
-
return defaultFuncs
|
48
|
-
.post(
|
49
|
-
"https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
|
50
|
-
ctx.jar,
|
51
|
-
form
|
52
|
-
)
|
53
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
54
|
-
.then(function(resData) {
|
55
|
-
if (resData.error) {
|
56
|
-
throw resData;
|
57
|
-
}
|
58
|
-
// the response is pretty messy
|
59
|
-
var queryThreadID =
|
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
|
-
};
|