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,50 +1,50 @@
|
|
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 markAsReadAll(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
|
-
folder: 'inbox'
|
26
|
-
};
|
27
|
-
|
28
|
-
defaultFuncs
|
29
|
-
.post(
|
30
|
-
"https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
|
31
|
-
ctx.jar,
|
32
|
-
form
|
33
|
-
)
|
34
|
-
.then(utils.saveCookies(ctx.jar))
|
35
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
-
.then(function(resData) {
|
37
|
-
if (resData.error) {
|
38
|
-
throw resData;
|
39
|
-
}
|
40
|
-
|
41
|
-
return callback();
|
42
|
-
})
|
43
|
-
.catch(function(err) {
|
44
|
-
log.error("markAsReadAll", err);
|
45
|
-
return callback(err);
|
46
|
-
});
|
47
|
-
|
48
|
-
return returnPromise;
|
49
|
-
};
|
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 markAsReadAll(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
|
+
folder: 'inbox'
|
26
|
+
};
|
27
|
+
|
28
|
+
defaultFuncs
|
29
|
+
.post(
|
30
|
+
"https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
|
31
|
+
ctx.jar,
|
32
|
+
form
|
33
|
+
)
|
34
|
+
.then(utils.saveCookies(ctx.jar))
|
35
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
+
.then(function(resData) {
|
37
|
+
if (resData.error) {
|
38
|
+
throw resData;
|
39
|
+
}
|
40
|
+
|
41
|
+
return callback();
|
42
|
+
})
|
43
|
+
.catch(function(err) {
|
44
|
+
log.error("markAsReadAll", err);
|
45
|
+
return callback(err);
|
46
|
+
});
|
47
|
+
|
48
|
+
return returnPromise;
|
49
|
+
};
|
50
50
|
};
|
@@ -1,103 +1,103 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
-
function makeTypingIndicator(typ, threadID, callback, isGroup) {
|
8
|
-
var form = {
|
9
|
-
typ: +typ,
|
10
|
-
to: "",
|
11
|
-
source: "mercury-chat",
|
12
|
-
thread: threadID
|
13
|
-
};
|
14
|
-
|
15
|
-
// Check if thread is a single person chat or a group chat
|
16
|
-
// More info on this is in api.sendMessage
|
17
|
-
if (utils.getType(isGroup) == "Boolean") {
|
18
|
-
if (!isGroup) {
|
19
|
-
form.to = threadID;
|
20
|
-
}
|
21
|
-
defaultFuncs
|
22
|
-
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
23
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
24
|
-
.then(function (resData) {
|
25
|
-
if (resData.error) {
|
26
|
-
throw resData;
|
27
|
-
}
|
28
|
-
|
29
|
-
return callback();
|
30
|
-
})
|
31
|
-
.catch(function (err) {
|
32
|
-
log.error("sendTypingIndicator", err);
|
33
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in") {
|
34
|
-
ctx.loggedIn = false;
|
35
|
-
}
|
36
|
-
return callback(err);
|
37
|
-
});
|
38
|
-
} else {
|
39
|
-
api.getUserInfo(threadID, function (err, res) {
|
40
|
-
if (err) {
|
41
|
-
return callback(err);
|
42
|
-
}
|
43
|
-
|
44
|
-
// If id is single person chat
|
45
|
-
if (Object.keys(res).length > 0) {
|
46
|
-
form.to = threadID;
|
47
|
-
}
|
48
|
-
|
49
|
-
defaultFuncs
|
50
|
-
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
51
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
52
|
-
.then(function (resData) {
|
53
|
-
if (resData.error) {
|
54
|
-
throw resData;
|
55
|
-
}
|
56
|
-
|
57
|
-
return callback();
|
58
|
-
})
|
59
|
-
.catch(function (err) {
|
60
|
-
log.error("sendTypingIndicator", err);
|
61
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
62
|
-
ctx.loggedIn = false;
|
63
|
-
}
|
64
|
-
return callback(err);
|
65
|
-
});
|
66
|
-
});
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
|
-
return function sendTypingIndicator(threadID, callback, isGroup) {
|
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
|
-
}
|
81
|
-
callback = () => { };
|
82
|
-
}
|
83
|
-
|
84
|
-
makeTypingIndicator(true, threadID, callback, isGroup);
|
85
|
-
|
86
|
-
return function end(cb) {
|
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
|
-
}
|
97
|
-
cb = () => { };
|
98
|
-
}
|
99
|
-
|
100
|
-
makeTypingIndicator(false, threadID, cb, isGroup);
|
101
|
-
};
|
102
|
-
};
|
103
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
function makeTypingIndicator(typ, threadID, callback, isGroup) {
|
8
|
+
var form = {
|
9
|
+
typ: +typ,
|
10
|
+
to: "",
|
11
|
+
source: "mercury-chat",
|
12
|
+
thread: threadID
|
13
|
+
};
|
14
|
+
|
15
|
+
// Check if thread is a single person chat or a group chat
|
16
|
+
// More info on this is in api.sendMessage
|
17
|
+
if (utils.getType(isGroup) == "Boolean") {
|
18
|
+
if (!isGroup) {
|
19
|
+
form.to = threadID;
|
20
|
+
}
|
21
|
+
defaultFuncs
|
22
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
23
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
24
|
+
.then(function (resData) {
|
25
|
+
if (resData.error) {
|
26
|
+
throw resData;
|
27
|
+
}
|
28
|
+
|
29
|
+
return callback();
|
30
|
+
})
|
31
|
+
.catch(function (err) {
|
32
|
+
log.error("sendTypingIndicator", err);
|
33
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in") {
|
34
|
+
ctx.loggedIn = false;
|
35
|
+
}
|
36
|
+
return callback(err);
|
37
|
+
});
|
38
|
+
} else {
|
39
|
+
api.getUserInfo(threadID, function (err, res) {
|
40
|
+
if (err) {
|
41
|
+
return callback(err);
|
42
|
+
}
|
43
|
+
|
44
|
+
// If id is single person chat
|
45
|
+
if (Object.keys(res).length > 0) {
|
46
|
+
form.to = threadID;
|
47
|
+
}
|
48
|
+
|
49
|
+
defaultFuncs
|
50
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
51
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
52
|
+
.then(function (resData) {
|
53
|
+
if (resData.error) {
|
54
|
+
throw resData;
|
55
|
+
}
|
56
|
+
|
57
|
+
return callback();
|
58
|
+
})
|
59
|
+
.catch(function (err) {
|
60
|
+
log.error("sendTypingIndicator", err);
|
61
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
62
|
+
ctx.loggedIn = false;
|
63
|
+
}
|
64
|
+
return callback(err);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
return function sendTypingIndicator(threadID, callback, isGroup) {
|
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
|
+
}
|
81
|
+
callback = () => { };
|
82
|
+
}
|
83
|
+
|
84
|
+
makeTypingIndicator(true, threadID, callback, isGroup);
|
85
|
+
|
86
|
+
return function end(cb) {
|
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
|
+
}
|
97
|
+
cb = () => { };
|
98
|
+
}
|
99
|
+
|
100
|
+
makeTypingIndicator(false, threadID, cb, isGroup);
|
101
|
+
};
|
102
|
+
};
|
103
|
+
};
|
package/alice/setPostReaction.js
CHANGED
@@ -1,76 +1,76 @@
|
|
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 unsendMessage(postID, type, 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 map = {
|
25
|
-
like: 1,
|
26
|
-
heart: 2,
|
27
|
-
wow: 3,
|
28
|
-
haha: 4,
|
29
|
-
sad: 7,
|
30
|
-
angry: 8
|
31
|
-
};
|
32
|
-
if (typeof type != "number") {
|
33
|
-
type = map[type.toLocaleLowerCase()];
|
34
|
-
if (!type) {
|
35
|
-
type = 1;
|
36
|
-
}
|
37
|
-
}
|
38
|
-
var form = {
|
39
|
-
av: ctx.userID,
|
40
|
-
fb_api_caller_class: "RelayModern",
|
41
|
-
fb_api_req_friendly_name: "UFI2FeedbackReactMutation",
|
42
|
-
//This doc_id is valid as of January 17th, 2020
|
43
|
-
doc_id: "2580813318646067",
|
44
|
-
variables: JSON.stringify({
|
45
|
-
input: {
|
46
|
-
client_mutation_id: "7",
|
47
|
-
actor_id: ctx.userID,
|
48
|
-
feedback_reaction: type,
|
49
|
-
|
50
|
-
},
|
51
|
-
useDefaultActor: true
|
52
|
-
})
|
53
|
-
};
|
54
|
-
|
55
|
-
defaultFuncs
|
56
|
-
.post(
|
57
|
-
"https://www.facebook.com/api/graphql/",
|
58
|
-
ctx.jar,
|
59
|
-
form
|
60
|
-
)
|
61
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
62
|
-
.then(function(resData) {
|
63
|
-
if (resData.error) {
|
64
|
-
throw resData;
|
65
|
-
}
|
66
|
-
|
67
|
-
return callback();
|
68
|
-
})
|
69
|
-
.catch(function(err) {
|
70
|
-
log.error("setPostReaction", err);
|
71
|
-
return callback(err);
|
72
|
-
});
|
73
|
-
|
74
|
-
return returnPromise;
|
75
|
-
};
|
76
|
-
};
|
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 unsendMessage(postID, type, 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 map = {
|
25
|
+
like: 1,
|
26
|
+
heart: 2,
|
27
|
+
wow: 3,
|
28
|
+
haha: 4,
|
29
|
+
sad: 7,
|
30
|
+
angry: 8
|
31
|
+
};
|
32
|
+
if (typeof type != "number") {
|
33
|
+
type = map[type.toLocaleLowerCase()];
|
34
|
+
if (!type) {
|
35
|
+
type = 1;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
var form = {
|
39
|
+
av: ctx.userID,
|
40
|
+
fb_api_caller_class: "RelayModern",
|
41
|
+
fb_api_req_friendly_name: "UFI2FeedbackReactMutation",
|
42
|
+
//This doc_id is valid as of January 17th, 2020
|
43
|
+
doc_id: "2580813318646067",
|
44
|
+
variables: JSON.stringify({
|
45
|
+
input: {
|
46
|
+
client_mutation_id: "7",
|
47
|
+
actor_id: ctx.userID,
|
48
|
+
feedback_reaction: type,
|
49
|
+
|
50
|
+
},
|
51
|
+
useDefaultActor: true
|
52
|
+
})
|
53
|
+
};
|
54
|
+
|
55
|
+
defaultFuncs
|
56
|
+
.post(
|
57
|
+
"https://www.facebook.com/api/graphql/",
|
58
|
+
ctx.jar,
|
59
|
+
form
|
60
|
+
)
|
61
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
62
|
+
.then(function(resData) {
|
63
|
+
if (resData.error) {
|
64
|
+
throw resData;
|
65
|
+
}
|
66
|
+
|
67
|
+
return callback();
|
68
|
+
})
|
69
|
+
.catch(function(err) {
|
70
|
+
log.error("setPostReaction", err);
|
71
|
+
return callback(err);
|
72
|
+
});
|
73
|
+
|
74
|
+
return returnPromise;
|
75
|
+
};
|
76
|
+
};
|
package/alice/setTitle.js
CHANGED
@@ -1,86 +1,86 @@
|
|
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 setTitle(newTitle, 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
|
-
|
16
|
-
var resolveFunc = function(){};
|
17
|
-
var rejectFunc = function(){};
|
18
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
19
|
-
resolveFunc = resolve;
|
20
|
-
rejectFunc = reject;
|
21
|
-
});
|
22
|
-
|
23
|
-
if (!callback) {
|
24
|
-
callback = function (err, friendList) {
|
25
|
-
if (err) {
|
26
|
-
return rejectFunc(err);
|
27
|
-
}
|
28
|
-
resolveFunc(friendList);
|
29
|
-
};
|
30
|
-
}
|
31
|
-
|
32
|
-
var messageAndOTID = utils.generateOfflineThreadingID();
|
33
|
-
var form = {
|
34
|
-
client: "mercury",
|
35
|
-
action_type: "ma-type:log-message",
|
36
|
-
author: "fbid:" + ctx.userID,
|
37
|
-
author_email: "",
|
38
|
-
coordinates: "",
|
39
|
-
timestamp: Date.now(),
|
40
|
-
timestamp_absolute: "Today",
|
41
|
-
timestamp_relative: utils.generateTimestampRelative(),
|
42
|
-
timestamp_time_passed: "0",
|
43
|
-
is_unread: false,
|
44
|
-
is_cleared: false,
|
45
|
-
is_forward: false,
|
46
|
-
is_filtered_content: false,
|
47
|
-
is_spoof_warning: false,
|
48
|
-
source: "source:chat:web",
|
49
|
-
"source_tags[0]": "source:chat",
|
50
|
-
status: "0",
|
51
|
-
offline_threading_id: messageAndOTID,
|
52
|
-
message_id: messageAndOTID,
|
53
|
-
threading_id: utils.generateThreadingID(ctx.clientID),
|
54
|
-
manual_retry_cnt: "0",
|
55
|
-
thread_fbid: threadID,
|
56
|
-
thread_name: newTitle,
|
57
|
-
thread_id: threadID,
|
58
|
-
log_message_type: "log:thread-name"
|
59
|
-
};
|
60
|
-
|
61
|
-
defaultFuncs
|
62
|
-
.post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
|
63
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
64
|
-
.then(function(resData) {
|
65
|
-
if (resData.error && resData.error === 1545012) {
|
66
|
-
throw { error: "Cannot change chat title: Not member of chat." };
|
67
|
-
}
|
68
|
-
|
69
|
-
if (resData.error && resData.error === 1545003) {
|
70
|
-
throw { error: "Cannot set title of single-user chat." };
|
71
|
-
}
|
72
|
-
|
73
|
-
if (resData.error) {
|
74
|
-
throw resData;
|
75
|
-
}
|
76
|
-
|
77
|
-
return callback();
|
78
|
-
})
|
79
|
-
.catch(function(err) {
|
80
|
-
log.error("setTitle", err);
|
81
|
-
return callback(err);
|
82
|
-
});
|
83
|
-
|
84
|
-
return returnPromise;
|
85
|
-
};
|
86
|
-
};
|
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 setTitle(newTitle, 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
|
+
|
16
|
+
var resolveFunc = function(){};
|
17
|
+
var rejectFunc = function(){};
|
18
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
19
|
+
resolveFunc = resolve;
|
20
|
+
rejectFunc = reject;
|
21
|
+
});
|
22
|
+
|
23
|
+
if (!callback) {
|
24
|
+
callback = function (err, friendList) {
|
25
|
+
if (err) {
|
26
|
+
return rejectFunc(err);
|
27
|
+
}
|
28
|
+
resolveFunc(friendList);
|
29
|
+
};
|
30
|
+
}
|
31
|
+
|
32
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
33
|
+
var form = {
|
34
|
+
client: "mercury",
|
35
|
+
action_type: "ma-type:log-message",
|
36
|
+
author: "fbid:" + ctx.userID,
|
37
|
+
author_email: "",
|
38
|
+
coordinates: "",
|
39
|
+
timestamp: Date.now(),
|
40
|
+
timestamp_absolute: "Today",
|
41
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
42
|
+
timestamp_time_passed: "0",
|
43
|
+
is_unread: false,
|
44
|
+
is_cleared: false,
|
45
|
+
is_forward: false,
|
46
|
+
is_filtered_content: false,
|
47
|
+
is_spoof_warning: false,
|
48
|
+
source: "source:chat:web",
|
49
|
+
"source_tags[0]": "source:chat",
|
50
|
+
status: "0",
|
51
|
+
offline_threading_id: messageAndOTID,
|
52
|
+
message_id: messageAndOTID,
|
53
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
54
|
+
manual_retry_cnt: "0",
|
55
|
+
thread_fbid: threadID,
|
56
|
+
thread_name: newTitle,
|
57
|
+
thread_id: threadID,
|
58
|
+
log_message_type: "log:thread-name"
|
59
|
+
};
|
60
|
+
|
61
|
+
defaultFuncs
|
62
|
+
.post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
|
63
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
64
|
+
.then(function(resData) {
|
65
|
+
if (resData.error && resData.error === 1545012) {
|
66
|
+
throw { error: "Cannot change chat title: Not member of chat." };
|
67
|
+
}
|
68
|
+
|
69
|
+
if (resData.error && resData.error === 1545003) {
|
70
|
+
throw { error: "Cannot set title of single-user chat." };
|
71
|
+
}
|
72
|
+
|
73
|
+
if (resData.error) {
|
74
|
+
throw resData;
|
75
|
+
}
|
76
|
+
|
77
|
+
return callback();
|
78
|
+
})
|
79
|
+
.catch(function(err) {
|
80
|
+
log.error("setTitle", err);
|
81
|
+
return callback(err);
|
82
|
+
});
|
83
|
+
|
84
|
+
return returnPromise;
|
85
|
+
};
|
86
|
+
};
|