alicezetion 1.5.7 → 1.5.9
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,47 +1,36 @@
|
|
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 changeBlockedStatus(userID, block, 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
|
-
return callback();
|
40
|
-
})
|
41
|
-
.catch(function (err) {
|
42
|
-
log.error("changeBlockedStatus", err);
|
43
|
-
return callback(err);
|
44
|
-
});
|
45
|
-
return returnPromise;
|
46
|
-
};
|
47
|
-
};
|
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 changeBlockedStatus(userID, block, 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) return rejectFunc(err);
|
18
|
+
resolveFunc();
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
defaultFuncs
|
23
|
+
.post(`https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`, ctx.jar, { fbid: userID })
|
24
|
+
.then(utils.saveCookies(ctx.jar))
|
25
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
26
|
+
.then(function (resData) {
|
27
|
+
if (resData.error) throw resData;
|
28
|
+
return callback();
|
29
|
+
})
|
30
|
+
.catch(function (err) {
|
31
|
+
log.error("changeBlockedStatus", err);
|
32
|
+
return callback(err);
|
33
|
+
});
|
34
|
+
return returnPromise;
|
35
|
+
};
|
36
|
+
};
|
@@ -1,129 +1,105 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
var bluebird = require("bluebird");
|
6
|
-
|
7
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
8
|
-
function handleUpload(image, callback) {
|
9
|
-
var uploads = [];
|
10
|
-
|
11
|
-
var form = {
|
12
|
-
images_only: "true",
|
13
|
-
"attachment[]": image
|
14
|
-
};
|
15
|
-
|
16
|
-
uploads.push(
|
17
|
-
defaultFuncs
|
18
|
-
.postFormData(
|
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
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
form["thread_image_id"] = payload[0]["image_id"];
|
107
|
-
form["thread_id"] = threadID;
|
108
|
-
|
109
|
-
defaultFuncs
|
110
|
-
.post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
|
111
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
112
|
-
.then(function(resData) {
|
113
|
-
// check for errors here
|
114
|
-
|
115
|
-
if (resData.error) {
|
116
|
-
throw resData;
|
117
|
-
}
|
118
|
-
|
119
|
-
return callback();
|
120
|
-
})
|
121
|
-
.catch(function(err) {
|
122
|
-
log.error("changeGroupImage", err);
|
123
|
-
return callback(err);
|
124
|
-
});
|
125
|
-
});
|
126
|
-
|
127
|
-
return returnPromise;
|
128
|
-
};
|
129
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
var bluebird = require("bluebird");
|
6
|
+
|
7
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
8
|
+
function handleUpload(image, callback) {
|
9
|
+
var uploads = [];
|
10
|
+
|
11
|
+
var form = {
|
12
|
+
images_only: "true",
|
13
|
+
"attachment[]": image
|
14
|
+
};
|
15
|
+
|
16
|
+
uploads.push(
|
17
|
+
defaultFuncs
|
18
|
+
.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
|
19
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
20
|
+
.then(function (resData) {
|
21
|
+
if (resData.error) throw resData;
|
22
|
+
return resData.payload.metadata[0];
|
23
|
+
})
|
24
|
+
);
|
25
|
+
|
26
|
+
// resolve all promises
|
27
|
+
bluebird
|
28
|
+
.all(uploads)
|
29
|
+
.then(resData => callback(null, resData))
|
30
|
+
.catch(function (err) {
|
31
|
+
log.error("handleUpload", err);
|
32
|
+
return callback(err);
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
return function changeGroupImage(image, threadID, callback) {
|
37
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
|
38
|
+
|
39
|
+
var resolveFunc = function () { };
|
40
|
+
var rejectFunc = function () { };
|
41
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
42
|
+
resolveFunc = resolve;
|
43
|
+
rejectFunc = reject;
|
44
|
+
});
|
45
|
+
|
46
|
+
if (!callback) {
|
47
|
+
callback = function (err) {
|
48
|
+
if (err) return rejectFunc(err);
|
49
|
+
resolveFunc();
|
50
|
+
};
|
51
|
+
}
|
52
|
+
|
53
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
54
|
+
var form = {
|
55
|
+
client: "mercury",
|
56
|
+
action_type: "ma-type:log-message",
|
57
|
+
author: "fbid:" + ctx.userID,
|
58
|
+
author_email: "",
|
59
|
+
ephemeral_ttl_mode: "0",
|
60
|
+
is_filtered_content: false,
|
61
|
+
is_filtered_content_account: false,
|
62
|
+
is_filtered_content_bh: false,
|
63
|
+
is_filtered_content_invalid_app: false,
|
64
|
+
is_filtered_content_quasar: false,
|
65
|
+
is_forward: false,
|
66
|
+
is_spoof_warning: false,
|
67
|
+
is_unread: false,
|
68
|
+
log_message_type: "log:thread-image",
|
69
|
+
manual_retry_cnt: "0",
|
70
|
+
message_id: messageAndOTID,
|
71
|
+
offline_threading_id: messageAndOTID,
|
72
|
+
source: "source:chat:web",
|
73
|
+
"source_tags[0]": "source:chat",
|
74
|
+
status: "0",
|
75
|
+
thread_fbid: threadID,
|
76
|
+
thread_id: "",
|
77
|
+
timestamp: Date.now(),
|
78
|
+
timestamp_absolute: "Today",
|
79
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
80
|
+
timestamp_time_passed: "0"
|
81
|
+
};
|
82
|
+
|
83
|
+
handleUpload(image, function (err, payload) {
|
84
|
+
if (err) return callback(err);
|
85
|
+
|
86
|
+
form["thread_image_id"] = payload[0]["image_id"];
|
87
|
+
form["thread_id"] = threadID;
|
88
|
+
|
89
|
+
defaultFuncs
|
90
|
+
.post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
|
91
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
92
|
+
.then(function (resData) {
|
93
|
+
// check for errors here
|
94
|
+
if (resData.error) throw resData;
|
95
|
+
return callback();
|
96
|
+
})
|
97
|
+
.catch(function (err) {
|
98
|
+
log.error("changeGroupImage", err);
|
99
|
+
return callback(err);
|
100
|
+
});
|
101
|
+
});
|
102
|
+
|
103
|
+
return returnPromise;
|
104
|
+
};
|
105
|
+
};
|
@@ -1,59 +1,43 @@
|
|
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
|
-
|
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
|
-
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
|
+
"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) return rejectFunc(err);
|
17
|
+
resolveFunc();
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
var form = {
|
22
|
+
nickname: nickname,
|
23
|
+
participant_id: participantID,
|
24
|
+
thread_or_other_fbid: threadID
|
25
|
+
};
|
26
|
+
|
27
|
+
defaultFuncs
|
28
|
+
.post("https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1", ctx.jar, form)
|
29
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
30
|
+
.then(function (resData) {
|
31
|
+
if (resData.error === 1545014) throw { error: "Trying to change nickname of user isn't in thread" };
|
32
|
+
if (resData.error === 1357031) throw { error: "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." };
|
33
|
+
if (resData.error) throw resData;
|
34
|
+
return callback();
|
35
|
+
})
|
36
|
+
.catch(function (err) {
|
37
|
+
log.error("changeNickname", "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.");
|
38
|
+
return callback(err);
|
39
|
+
});
|
40
|
+
|
41
|
+
return returnPromise;
|
42
|
+
};
|
43
|
+
};
|
@@ -1,71 +1,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 changeThreadColor(color, 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
|
-
|
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
|
-
|
61
|
-
|
62
|
-
return callback();
|
63
|
-
})
|
64
|
-
.catch(function(err) {
|
65
|
-
log.error("changeThreadColor", err);
|
66
|
-
return callback(err);
|
67
|
-
});
|
68
|
-
|
69
|
-
return returnPromise;
|
70
|
-
};
|
71
|
-
};
|
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 changeThreadColor(color, 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) return rejectFunc(err);
|
18
|
+
resolveFunc(err);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
var validatedColor = color !== null ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
|
23
|
+
var colorList = Object.keys(api.threadColors).map(function (name) {
|
24
|
+
return api.threadColors[name];
|
25
|
+
});
|
26
|
+
if (!colorList.includes(validatedColor)) throw { error: "The color you are trying to use is not a valid thread color. Use api.threadColors to find acceptable values." };
|
27
|
+
|
28
|
+
var form = {
|
29
|
+
dpr: 1,
|
30
|
+
queries: JSON.stringify({
|
31
|
+
o0: {
|
32
|
+
//This doc_id is valid as of January 31, 2020
|
33
|
+
doc_id: "1727493033983591",
|
34
|
+
query_params: {
|
35
|
+
data: {
|
36
|
+
actor_id: ctx.userID,
|
37
|
+
client_mutation_id: "0",
|
38
|
+
source: "SETTINGS",
|
39
|
+
theme_id: validatedColor,
|
40
|
+
thread_id: threadID
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
})
|
45
|
+
};
|
46
|
+
|
47
|
+
defaultFuncs
|
48
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
49
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
50
|
+
.then(function (resData) {
|
51
|
+
if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
52
|
+
return callback();
|
53
|
+
})
|
54
|
+
.catch(function (err) {
|
55
|
+
log.error("changeThreadColor", err);
|
56
|
+
return callback(err);
|
57
|
+
});
|
58
|
+
|
59
|
+
return returnPromise;
|
60
|
+
};
|
61
|
+
};
|
@@ -1,55 +1,41 @@
|
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
.
|
30
|
-
"
|
31
|
-
|
32
|
-
|
33
|
-
)
|
34
|
-
.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
};
|
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) return rejectFunc(err);
|
18
|
+
resolveFunc();
|
19
|
+
};
|
20
|
+
}
|
21
|
+
var form = {
|
22
|
+
emoji_choice: emoji,
|
23
|
+
thread_or_other_fbid: threadID
|
24
|
+
};
|
25
|
+
|
26
|
+
defaultFuncs
|
27
|
+
.post("https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg", ctx.jar, form)
|
28
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
29
|
+
.then(function (resData) {
|
30
|
+
if (resData.error === 1357031) throw { error: "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." };
|
31
|
+
if (resData.error) throw resData;
|
32
|
+
return callback();
|
33
|
+
})
|
34
|
+
.catch(function (err) {
|
35
|
+
log.error("changeThreadEmoji", err);
|
36
|
+
return callback(err);
|
37
|
+
});
|
38
|
+
|
39
|
+
return returnPromise;
|
40
|
+
};
|
41
|
+
};
|