alicezetion 1.1.0 → 1.1.2
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 +556 -490
- package/leiamnash/addExternalModule.js +19 -0
- package/{src → leiamnash}/addUserToGroup.js +52 -16
- package/leiamnash/changeAdminStatus.js +79 -0
- package/leiamnash/changeArchivedStatus.js +55 -0
- package/{src → leiamnash}/changeBio.js +19 -6
- package/{src → leiamnash}/changeBlockedStatus.js +14 -3
- package/{src → leiamnash}/changeGroupImage.js +40 -16
- package/leiamnash/changeNickname.js +59 -0
- package/{src → leiamnash}/changeThreadColor.js +20 -10
- package/leiamnash/changeThreadEmoji.js +55 -0
- package/leiamnash/chat.js +459 -0
- package/{src → leiamnash}/createNewGroup.js +28 -12
- package/{src → leiamnash}/createPoll.js +25 -13
- package/leiamnash/deleteMessage.js +56 -0
- package/leiamnash/deleteThread.js +56 -0
- package/leiamnash/forwardAttachment.js +60 -0
- package/{src → leiamnash}/getCurrentUserID.js +1 -1
- package/{src → leiamnash}/getEmojiUrl.js +4 -2
- package/{src → leiamnash}/getFriendsList.js +21 -10
- package/{src → leiamnash}/getThreadHistory.js +166 -58
- package/{src → leiamnash}/getThreadHistoryDeprecated.js +42 -20
- package/{src → leiamnash}/getThreadInfo.js +60 -25
- package/leiamnash/getThreadInfoDeprecated.js +80 -0
- package/{src → leiamnash}/getThreadList.js +66 -41
- package/leiamnash/getThreadListDeprecated.js +75 -0
- package/leiamnash/getThreadPictures.js +79 -0
- package/{src → leiamnash}/getUserID.js +14 -9
- package/{src → leiamnash}/getUserInfo.js +1 -1
- package/leiamnash/handleFriendRequest.js +61 -0
- package/leiamnash/handleMessageRequest.js +65 -0
- package/{src → leiamnash}/httpGet.js +17 -12
- package/{src → leiamnash}/httpPost.js +17 -12
- package/leiamnash/listenMqtt.js +687 -0
- package/{src → leiamnash}/logout.js +20 -13
- package/{src → leiamnash}/markAsDelivered.js +22 -11
- package/{src → leiamnash}/markAsRead.js +21 -11
- package/{src → leiamnash}/markAsReadAll.js +20 -10
- package/{src → leiamnash}/markAsSeen.js +18 -7
- package/{src → leiamnash}/muteThread.js +18 -11
- package/leiamnash/removeUserFromGroup.js +79 -0
- package/{src → leiamnash}/resolvePhotoUrl.js +17 -8
- package/{src → leiamnash}/searchForThread.js +21 -10
- package/{src → leiamnash}/sendTypingIndicator.js +47 -14
- package/{src → leiamnash}/setMessageReaction.js +26 -12
- package/{src → leiamnash}/setPostReaction.js +26 -13
- package/{src → leiamnash}/setTitle.js +29 -13
- package/leiamnash/threadColors.js +57 -0
- package/{src → leiamnash}/unfriend.js +19 -9
- package/{src → leiamnash}/unsendMessage.js +19 -9
- package/package.json +9 -14
- package/replit.nix +0 -1
- package/utils.js +1193 -1023
- package/src/addExternalModule.js +0 -15
- package/src/changeAdminStatus.js +0 -47
- package/src/changeArchivedStatus.js +0 -41
- package/src/changeNickname.js +0 -43
- package/src/changeThreadEmoji.js +0 -41
- package/src/chat.js +0 -315
- package/src/deleteMessage.js +0 -44
- package/src/deleteThread.js +0 -42
- package/src/forwardAttachment.js +0 -47
- package/src/forwardMessage.js +0 -0
- package/src/getThreadInfoDeprecated.js +0 -56
- package/src/getThreadListDeprecated.js +0 -46
- package/src/getThreadPictures.js +0 -59
- package/src/handleFriendRequest.js +0 -46
- package/src/handleMessageRequest.js +0 -47
- package/src/listen.js +0 -553
- package/src/listenMqtt-Test.js +0 -687
- package/src/listenMqtt.js +0 -677
- package/src/removeUserFromGroup.js +0 -45
- package/src/threadColors.js +0 -41
@@ -3,10 +3,10 @@
|
|
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
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
10
|
var returnPromise = new Promise(function (resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
@@ -14,8 +14,9 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
14
14
|
|
15
15
|
if (!callback) {
|
16
16
|
callback = function (err, friendList) {
|
17
|
-
if (err)
|
18
|
-
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
19
20
|
resolveFunc(friendList);
|
20
21
|
};
|
21
22
|
}
|
@@ -25,14 +26,18 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
25
26
|
};
|
26
27
|
|
27
28
|
defaultFuncs
|
28
|
-
.post(
|
29
|
+
.post(
|
30
|
+
"https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1",
|
31
|
+
ctx.jar,
|
32
|
+
form
|
33
|
+
)
|
29
34
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
30
|
-
.then(function
|
31
|
-
var elem = resData.jsmods.instances[0][2][0].filter(function
|
35
|
+
.then(function(resData) {
|
36
|
+
var elem = resData.jsmods.instances[0][2][0].filter(function(v) {
|
32
37
|
return v.value === "logout";
|
33
38
|
})[0];
|
34
39
|
|
35
|
-
var html = resData.jsmods.markup.filter(function
|
40
|
+
var html = resData.jsmods.markup.filter(function(v) {
|
36
41
|
return v[0] === elem.markup.__m;
|
37
42
|
})[0][1].__html;
|
38
43
|
|
@@ -46,19 +51,21 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
46
51
|
.post("https://www.facebook.com/logout.php", ctx.jar, form)
|
47
52
|
.then(utils.saveCookies(ctx.jar));
|
48
53
|
})
|
49
|
-
.then(function
|
50
|
-
if (!res.headers)
|
54
|
+
.then(function(res) {
|
55
|
+
if (!res.headers) {
|
56
|
+
throw { error: "An error occurred when logging out." };
|
57
|
+
}
|
51
58
|
|
52
59
|
return defaultFuncs
|
53
60
|
.get(res.headers.location, ctx.jar)
|
54
61
|
.then(utils.saveCookies(ctx.jar));
|
55
62
|
})
|
56
|
-
.then(function
|
63
|
+
.then(function() {
|
57
64
|
ctx.loggedIn = false;
|
58
65
|
log.info("logout", "Logged out successfully.");
|
59
66
|
callback();
|
60
67
|
})
|
61
|
-
.catch(function
|
68
|
+
.catch(function(err) {
|
62
69
|
log.error("logout", err);
|
63
70
|
return callback(err);
|
64
71
|
});
|
@@ -5,40 +5,51 @@ var log = require("npmlog");
|
|
5
5
|
|
6
6
|
module.exports = function (defaultFuncs, api, ctx) {
|
7
7
|
return function markAsDelivered(threadID, messageID, callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
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 (err,
|
17
|
-
if (err)
|
18
|
-
|
19
|
-
|
16
|
+
callback = function (err, friendList) {
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
20
|
+
resolveFunc(friendList);
|
20
21
|
};
|
21
22
|
}
|
22
23
|
|
23
|
-
if (!threadID || !messageID)
|
24
|
+
if (!threadID || !messageID) {
|
25
|
+
return callback("Error: messageID or threadID is not defined");
|
26
|
+
}
|
24
27
|
|
25
28
|
var form = {};
|
29
|
+
|
26
30
|
form["message_ids[0]"] = messageID;
|
27
31
|
form["thread_ids[" + threadID + "][0]"] = messageID;
|
28
32
|
|
29
33
|
defaultFuncs
|
30
|
-
.post(
|
34
|
+
.post(
|
35
|
+
"https://www.facebook.com/ajax/mercury/delivery_receipts.php",
|
36
|
+
ctx.jar,
|
37
|
+
form
|
38
|
+
)
|
31
39
|
.then(utils.saveCookies(ctx.jar))
|
32
40
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
33
41
|
.then(function (resData) {
|
34
|
-
if (resData.error)
|
42
|
+
if (resData.error) {
|
43
|
+
throw resData;
|
44
|
+
}
|
35
45
|
|
36
46
|
return callback();
|
37
47
|
})
|
38
48
|
.catch(function (err) {
|
39
49
|
log.error("markAsDelivered", err);
|
40
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
41
|
-
|
50
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
51
|
+
ctx.loggedIn = false;
|
52
|
+
}
|
42
53
|
return callback(err);
|
43
54
|
});
|
44
55
|
|
@@ -9,9 +9,13 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
9
9
|
callback = read;
|
10
10
|
read = true;
|
11
11
|
}
|
12
|
-
if (read == undefined)
|
12
|
+
if (read == undefined) {
|
13
|
+
read = true;
|
14
|
+
}
|
13
15
|
|
14
|
-
if (!callback)
|
16
|
+
if (!callback) {
|
17
|
+
callback = () => { };
|
18
|
+
}
|
15
19
|
|
16
20
|
var form = {};
|
17
21
|
|
@@ -28,12 +32,15 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
28
32
|
try {
|
29
33
|
resData = await (
|
30
34
|
defaultFuncs
|
31
|
-
.post(
|
35
|
+
.post(
|
36
|
+
"https://www.facebook.com/ajax/mercury/change_read_status.php",
|
37
|
+
ctx.jar,
|
38
|
+
form
|
39
|
+
)
|
32
40
|
.then(utils.saveCookies(ctx.jar))
|
33
41
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
34
42
|
);
|
35
|
-
}
|
36
|
-
catch (e) {
|
43
|
+
} catch (e) {
|
37
44
|
callback(e);
|
38
45
|
return e;
|
39
46
|
}
|
@@ -41,15 +48,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
41
48
|
if (resData.error) {
|
42
49
|
let err = resData.error;
|
43
50
|
log.error("markAsRead", err);
|
44
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
51
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
52
|
+
ctx.loggedIn = false;
|
53
|
+
}
|
45
54
|
callback(err);
|
46
55
|
return err;
|
47
56
|
}
|
48
57
|
|
49
58
|
callback();
|
50
59
|
return null;
|
51
|
-
}
|
52
|
-
else {
|
60
|
+
} else {
|
53
61
|
try {
|
54
62
|
if (ctx.mqttClient) {
|
55
63
|
let err = await new Promise(r => ctx.mqttClient.publish("/mark_thread", JSON.stringify({
|
@@ -58,10 +66,12 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
58
66
|
state: read
|
59
67
|
}), { qos: 1, retain: false }, r));
|
60
68
|
if (err) throw err;
|
69
|
+
} else {
|
70
|
+
throw {
|
71
|
+
error: "You can only use this function after you start listening."
|
72
|
+
};
|
61
73
|
}
|
62
|
-
|
63
|
-
}
|
64
|
-
catch (e) {
|
74
|
+
} catch (e) {
|
65
75
|
callback(e);
|
66
76
|
return e;
|
67
77
|
}
|
@@ -3,19 +3,21 @@
|
|
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
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
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 (err,
|
17
|
-
if (err)
|
18
|
-
|
16
|
+
callback = function (err, friendList) {
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
20
|
+
resolveFunc(friendList);
|
19
21
|
};
|
20
22
|
}
|
21
23
|
|
@@ -24,17 +26,25 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
24
26
|
};
|
25
27
|
|
26
28
|
defaultFuncs
|
27
|
-
.post(
|
29
|
+
.post(
|
30
|
+
"https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
|
31
|
+
ctx.jar,
|
32
|
+
form
|
33
|
+
)
|
28
34
|
.then(utils.saveCookies(ctx.jar))
|
29
35
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
30
|
-
.then(function
|
31
|
-
if (resData.error)
|
36
|
+
.then(function(resData) {
|
37
|
+
if (resData.error) {
|
38
|
+
throw resData;
|
39
|
+
}
|
40
|
+
|
32
41
|
return callback();
|
33
42
|
})
|
34
|
-
.catch(function
|
43
|
+
.catch(function(err) {
|
35
44
|
log.error("markAsReadAll", err);
|
36
45
|
return callback(err);
|
37
46
|
});
|
47
|
+
|
38
48
|
return returnPromise;
|
39
49
|
};
|
40
50
|
};
|
@@ -19,10 +19,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
19
19
|
});
|
20
20
|
|
21
21
|
if (!callback) {
|
22
|
-
callback = function (err,
|
23
|
-
if (err)
|
24
|
-
|
25
|
-
|
22
|
+
callback = function (err, friendList) {
|
23
|
+
if (err) {
|
24
|
+
return rejectFunc(err);
|
25
|
+
}
|
26
|
+
resolveFunc(friendList);
|
26
27
|
};
|
27
28
|
}
|
28
29
|
|
@@ -31,18 +32,28 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
31
32
|
};
|
32
33
|
|
33
34
|
defaultFuncs
|
34
|
-
.post(
|
35
|
+
.post(
|
36
|
+
"https://www.facebook.com/ajax/mercury/mark_seen.php",
|
37
|
+
ctx.jar,
|
38
|
+
form
|
39
|
+
)
|
35
40
|
.then(utils.saveCookies(ctx.jar))
|
36
41
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
37
42
|
.then(function (resData) {
|
38
|
-
if (resData.error)
|
43
|
+
if (resData.error) {
|
44
|
+
throw resData;
|
45
|
+
}
|
46
|
+
|
39
47
|
return callback();
|
40
48
|
})
|
41
49
|
.catch(function (err) {
|
42
50
|
log.error("markAsSeen", err);
|
43
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
51
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
52
|
+
ctx.loggedIn = false;
|
53
|
+
}
|
44
54
|
return callback(err);
|
45
55
|
});
|
56
|
+
|
46
57
|
return returnPromise;
|
47
58
|
};
|
48
59
|
};
|
@@ -3,21 +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
|
// 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
|
9
|
+
var resolveFunc = function(){};
|
10
|
+
var rejectFunc = function(){};
|
11
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 (err,
|
18
|
-
if (err)
|
19
|
-
|
20
|
-
|
17
|
+
callback = function (err, friendList) {
|
18
|
+
if (err) {
|
19
|
+
return rejectFunc(err);
|
20
|
+
}
|
21
|
+
resolveFunc(friendList);
|
21
22
|
};
|
22
23
|
}
|
23
24
|
|
@@ -27,15 +28,21 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
27
28
|
};
|
28
29
|
|
29
30
|
defaultFuncs
|
30
|
-
.post(
|
31
|
+
.post(
|
32
|
+
"https://www.facebook.com/ajax/mercury/change_mute_thread.php",
|
33
|
+
ctx.jar,
|
34
|
+
form
|
35
|
+
)
|
31
36
|
.then(utils.saveCookies(ctx.jar))
|
32
37
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
33
|
-
.then(function
|
34
|
-
if (resData.error)
|
38
|
+
.then(function(resData) {
|
39
|
+
if (resData.error) {
|
40
|
+
throw resData;
|
41
|
+
}
|
35
42
|
|
36
43
|
return callback();
|
37
44
|
})
|
38
|
-
.catch(function
|
45
|
+
.catch(function(err) {
|
39
46
|
log.error("muteThread", err);
|
40
47
|
return callback(err);
|
41
48
|
});
|
@@ -0,0 +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
|
+
};
|
@@ -3,34 +3,43 @@
|
|
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
|
8
|
+
var resolveFunc = function(){};
|
9
|
+
var rejectFunc = function(){};
|
10
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 (err,
|
17
|
-
if (err)
|
18
|
-
|
16
|
+
callback = function (err, friendList) {
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
20
|
+
resolveFunc(friendList);
|
19
21
|
};
|
20
22
|
}
|
21
23
|
|
22
24
|
defaultFuncs
|
23
|
-
.get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, {
|
25
|
+
.get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, {
|
26
|
+
photo_id: photoID
|
27
|
+
})
|
24
28
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
25
29
|
.then(resData => {
|
26
|
-
if (resData.error)
|
30
|
+
if (resData.error) {
|
31
|
+
throw resData;
|
32
|
+
}
|
33
|
+
|
27
34
|
var photoUrl = resData.jsmods.require[0][3][0];
|
35
|
+
|
28
36
|
return callback(null, photoUrl);
|
29
37
|
})
|
30
38
|
.catch(err => {
|
31
39
|
log.error("resolvePhotoUrl", err);
|
32
40
|
return callback(err);
|
33
41
|
});
|
42
|
+
|
34
43
|
return returnPromise;
|
35
44
|
};
|
36
45
|
};
|
@@ -2,19 +2,21 @@
|
|
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
|
7
|
+
var resolveFunc = function(){};
|
8
|
+
var rejectFunc = function(){};
|
9
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 (err,
|
16
|
-
if (err)
|
17
|
-
|
15
|
+
callback = function (err, friendList) {
|
16
|
+
if (err) {
|
17
|
+
return rejectFunc(err);
|
18
|
+
}
|
19
|
+
resolveFunc(friendList);
|
18
20
|
};
|
19
21
|
}
|
20
22
|
|
@@ -27,16 +29,25 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
27
29
|
};
|
28
30
|
|
29
31
|
defaultFuncs
|
30
|
-
.post(
|
32
|
+
.post(
|
33
|
+
"https://www.facebook.com/ajax/mercury/search_threads.php",
|
34
|
+
ctx.jar,
|
35
|
+
tmpForm
|
36
|
+
)
|
31
37
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
32
|
-
.then(function
|
33
|
-
if (resData.error)
|
34
|
-
|
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
|
+
}
|
35
45
|
return callback(
|
36
46
|
null,
|
37
47
|
resData.payload.mercury_payload.threads.map(utils.formatThread)
|
38
48
|
);
|
39
49
|
});
|
50
|
+
|
40
51
|
return returnPromise;
|
41
52
|
};
|
42
53
|
};
|
@@ -15,36 +15,52 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
15
15
|
// Check if thread is a single person chat or a group chat
|
16
16
|
// More info on this is in api.sendMessage
|
17
17
|
if (utils.getType(isGroup) == "Boolean") {
|
18
|
-
if (!isGroup)
|
19
|
-
|
18
|
+
if (!isGroup) {
|
19
|
+
form.to = threadID;
|
20
|
+
}
|
20
21
|
defaultFuncs
|
21
22
|
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
22
23
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
23
24
|
.then(function (resData) {
|
24
|
-
if (resData.error)
|
25
|
+
if (resData.error) {
|
26
|
+
throw resData;
|
27
|
+
}
|
28
|
+
|
25
29
|
return callback();
|
26
30
|
})
|
27
31
|
.catch(function (err) {
|
28
32
|
log.error("sendTypingIndicator", err);
|
29
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in")
|
33
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in") {
|
34
|
+
ctx.loggedIn = false;
|
35
|
+
}
|
30
36
|
return callback(err);
|
31
37
|
});
|
32
|
-
}
|
33
|
-
else {
|
38
|
+
} else {
|
34
39
|
api.getUserInfo(threadID, function (err, res) {
|
35
|
-
if (err)
|
40
|
+
if (err) {
|
41
|
+
return callback(err);
|
42
|
+
}
|
43
|
+
|
36
44
|
// If id is single person chat
|
37
|
-
if (Object.keys(res).length > 0)
|
45
|
+
if (Object.keys(res).length > 0) {
|
46
|
+
form.to = threadID;
|
47
|
+
}
|
48
|
+
|
38
49
|
defaultFuncs
|
39
50
|
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
40
51
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
41
52
|
.then(function (resData) {
|
42
|
-
if (resData.error)
|
53
|
+
if (resData.error) {
|
54
|
+
throw resData;
|
55
|
+
}
|
56
|
+
|
43
57
|
return callback();
|
44
58
|
})
|
45
59
|
.catch(function (err) {
|
46
60
|
log.error("sendTypingIndicator", err);
|
47
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.")
|
61
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
62
|
+
ctx.loggedIn = false;
|
63
|
+
}
|
48
64
|
return callback(err);
|
49
65
|
});
|
50
66
|
});
|
@@ -52,18 +68,35 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
52
68
|
}
|
53
69
|
|
54
70
|
return function sendTypingIndicator(threadID, callback, isGroup) {
|
55
|
-
if (
|
56
|
-
|
71
|
+
if (
|
72
|
+
utils.getType(callback) !== "Function" &&
|
73
|
+
utils.getType(callback) !== "AsyncFunction"
|
74
|
+
) {
|
75
|
+
if (callback) {
|
76
|
+
log.warn(
|
77
|
+
"sendTypingIndicator",
|
78
|
+
"callback is not a function - ignoring."
|
79
|
+
);
|
80
|
+
}
|
57
81
|
callback = () => { };
|
58
82
|
}
|
59
83
|
|
60
84
|
makeTypingIndicator(true, threadID, callback, isGroup);
|
61
85
|
|
62
86
|
return function end(cb) {
|
63
|
-
if (
|
64
|
-
|
87
|
+
if (
|
88
|
+
utils.getType(cb) !== "Function" &&
|
89
|
+
utils.getType(cb) !== "AsyncFunction"
|
90
|
+
) {
|
91
|
+
if (cb) {
|
92
|
+
log.warn(
|
93
|
+
"sendTypingIndicator",
|
94
|
+
"callback is not a function - ignoring."
|
95
|
+
);
|
96
|
+
}
|
65
97
|
cb = () => { };
|
66
98
|
}
|
99
|
+
|
67
100
|
makeTypingIndicator(false, threadID, cb, isGroup);
|
68
101
|
};
|
69
102
|
};
|