alicezetion 1.6.9 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/.travis.yml +6 -0
  4. package/index.js +182 -495
  5. package/package.json +10 -8
  6. package/replit.nix +4 -6
  7. package/src/addExternalModule.js +15 -0
  8. package/{leiamnash → src}/addUserToGroup.js +16 -52
  9. package/src/changeAdminStatus.js +47 -0
  10. package/src/changeArchivedStatus.js +41 -0
  11. package/{leiamnash → src}/changeBio.js +6 -19
  12. package/{leiamnash → src}/changeBlockedStatus.js +3 -14
  13. package/{leiamnash → src}/changeGroupImage.js +16 -40
  14. package/src/changeNickname.js +43 -0
  15. package/{leiamnash → src}/changeThreadColor.js +10 -20
  16. package/src/changeThreadEmoji.js +41 -0
  17. package/src/chat.js +315 -0
  18. package/{leiamnash → src}/createNewGroup.js +12 -28
  19. package/{leiamnash → src}/createPoll.js +13 -25
  20. package/src/deleteMessage.js +44 -0
  21. package/src/deleteThread.js +42 -0
  22. package/src/forwardAttachment.js +47 -0
  23. package/src/forwardMessage.js +0 -0
  24. package/{leiamnash → src}/getCurrentUserID.js +1 -1
  25. package/{leiamnash → src}/getEmojiUrl.js +2 -4
  26. package/{leiamnash → src}/getFriendsList.js +10 -21
  27. package/{leiamnash → src}/getThreadHistory.js +58 -166
  28. package/{leiamnash → src}/getThreadHistoryDeprecated.js +20 -42
  29. package/src/getThreadInfo.js +171 -0
  30. package/src/getThreadInfoDeprecated.js +56 -0
  31. package/{leiamnash → src}/getThreadList.js +41 -66
  32. package/src/getThreadListDeprecated.js +46 -0
  33. package/src/getThreadPictures.js +59 -0
  34. package/{leiamnash → src}/getUserID.js +9 -14
  35. package/{leiamnash → src}/getUserInfo.js +12 -18
  36. package/src/handleFriendRequest.js +46 -0
  37. package/src/handleMessageRequest.js +47 -0
  38. package/{leiamnash → src}/httpGet.js +12 -17
  39. package/{leiamnash → src}/httpPost.js +12 -17
  40. package/src/listen.js +553 -0
  41. package/src/listenMqtt-Test.js +687 -0
  42. package/src/listenMqtt.js +677 -0
  43. package/{leiamnash → src}/logout.js +13 -20
  44. package/{leiamnash → src}/markAsDelivered.js +11 -22
  45. package/{leiamnash → src}/markAsRead.js +11 -21
  46. package/{leiamnash → src}/markAsReadAll.js +10 -20
  47. package/{leiamnash → src}/markAsSeen.js +7 -18
  48. package/{leiamnash → src}/muteThread.js +11 -18
  49. package/src/removeUserFromGroup.js +45 -0
  50. package/{leiamnash → src}/resolvePhotoUrl.js +8 -17
  51. package/{leiamnash → src}/searchForThread.js +10 -21
  52. package/src/sendMessage.js +315 -0
  53. package/{leiamnash → src}/sendTypingIndicator.js +14 -47
  54. package/{leiamnash → src}/setMessageReaction.js +12 -26
  55. package/{leiamnash → src}/setPostReaction.js +13 -26
  56. package/{leiamnash → src}/setTitle.js +13 -29
  57. package/src/threadColors.js +41 -0
  58. package/{leiamnash → src}/unfriend.js +9 -19
  59. package/{leiamnash → src}/unsendMessage.js +9 -19
  60. package/test/data/shareAttach.js +146 -0
  61. package/test/data/something.mov +0 -0
  62. package/test/data/test.png +0 -0
  63. package/test/data/test.txt +7 -0
  64. package/test/example-config.json +18 -0
  65. package/test/test-page.js +140 -0
  66. package/test/test.js +385 -0
  67. package/utils.js +1021 -1238
  68. package/leiamnash/addExternalModule.js +0 -19
  69. package/leiamnash/changeAdminStatus.js +0 -79
  70. package/leiamnash/changeApprovalMode.js +0 -80
  71. package/leiamnash/changeArchivedStatus.js +0 -55
  72. package/leiamnash/changeNickname.js +0 -59
  73. package/leiamnash/changeThreadEmoji.js +0 -55
  74. package/leiamnash/chat.js +0 -447
  75. package/leiamnash/deleteMessage.js +0 -56
  76. package/leiamnash/deleteThread.js +0 -56
  77. package/leiamnash/forwardAttachment.js +0 -60
  78. package/leiamnash/getThreadInfo.js +0 -212
  79. package/leiamnash/getThreadInfoDeprecated.js +0 -80
  80. package/leiamnash/getThreadListDeprecated.js +0 -75
  81. package/leiamnash/getThreadPictures.js +0 -79
  82. package/leiamnash/handleFriendRequest.js +0 -61
  83. package/leiamnash/handleMessageRequest.js +0 -65
  84. package/leiamnash/listenMqtt.js +0 -1129
  85. package/leiamnash/removeUserFromGroup.js +0 -79
  86. package/leiamnash/threadColors.js +0 -57
package/package.json CHANGED
@@ -1,28 +1,30 @@
1
1
  {
2
2
  "name": "alicezetion",
3
- "version": "1.6.9",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "scripts": {
6
+ "test": "mocha",
6
7
  "lint": "./node_modules/.bin/eslint **.js",
7
8
  "prettier": "prettier utils.js src/* --write"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
11
- "url": ""
12
+ "url": "https://leiamnash.vercel.app"
12
13
  },
13
14
  "keywords": [
14
- "leiamnash"
15
+ "leiamnash",
16
+ "alice"
15
17
  ],
16
18
  "bugs": {
17
- "url": "https://leiamnash.vercel.app"
19
+ "url": ""
18
20
  },
19
21
  "author": "LeiamNash",
20
22
  "license": "MIT",
21
23
  "dependencies": {
22
24
  "bluebird": "^2.11.0",
23
- "cheerio": "^1.0.0-rc.12",
25
+ "cheerio": "^0.22.0",
24
26
  "https-proxy-agent": "^4.0.0",
25
- "mqtt": "^4.3.7",
27
+ "mqtt": "^3.0.0",
26
28
  "npmlog": "^1.2.0",
27
29
  "request": "^2.53.0",
28
30
  "websocket-stream": "^5.5.0"
@@ -32,7 +34,7 @@
32
34
  },
33
35
  "devDependencies": {
34
36
  "eslint": "^7.5.0",
35
- "mocha": "^10.2.0",
37
+ "mocha": "^7.0.1",
36
38
  "prettier": "^1.11.1"
37
39
  },
38
40
  "eslintConfig": {
@@ -69,4 +71,4 @@
69
71
  ]
70
72
  }
71
73
  }
72
- }
74
+ }
package/replit.nix CHANGED
@@ -1,8 +1,6 @@
1
1
  { pkgs }: {
2
- deps = [
3
- pkgs.nodejs-16_x
4
- pkgs.bashInteractive
5
- pkgs.nodePackages.bash-language-server
6
- pkgs.man
7
- ];
2
+ deps = [
3
+ pkgs.nodejs-16_x
4
+ pkgs.cowsay
5
+ ];
8
6
  }
@@ -0,0 +1,15 @@
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") api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
10
+ else throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
11
+ }
12
+ }
13
+ else throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
14
+ };
15
+ };
@@ -3,47 +3,27 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function addUserToGroup(userID, threadID, 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
- 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." };
21
- }
15
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
22
16
 
23
17
  if (!callback) {
24
- callback = function(err) {
25
- if (err) {
26
- return rejectFunc(err);
27
- }
18
+ callback = function (err) {
19
+ if (err) return rejectFunc(err);
28
20
  resolveFunc();
29
21
  };
30
22
  }
31
23
 
32
- if (
33
- utils.getType(threadID) !== "Number" &&
34
- utils.getType(threadID) !== "String"
35
- ) {
36
- throw {
37
- error:
38
- "ThreadID should be of type Number or String and not " +
39
- utils.getType(threadID) +
40
- "."
41
- };
42
- }
24
+ if (utils.getType(threadID) !== "Number" && utils.getType(threadID) !== "String") throw { error: "ThreadID should be of type Number or String and not " + utils.getType(threadID) + "." };
43
25
 
44
- if (utils.getType(userID) !== "Array") {
45
- userID = [userID];
46
- }
26
+ if (utils.getType(userID) !== "Array") userID = [userID];
47
27
 
48
28
  var messageAndOTID = utils.generateOfflineThreadingID();
49
29
  var form = {
@@ -74,40 +54,24 @@ module.exports = function(defaultFuncs, api, ctx) {
74
54
  };
75
55
 
76
56
  for (var i = 0; i < userID.length; i++) {
77
- if (
78
- utils.getType(userID[i]) !== "Number" &&
79
- utils.getType(userID[i]) !== "String"
80
- ) {
81
- throw {
82
- error:
83
- "Elements of userID should be of type Number or String and not " +
84
- utils.getType(userID[i]) +
85
- "."
86
- };
87
- }
88
-
89
- form["log_message_data[added_participants][" + i + "]"] =
90
- "fbid:" + userID[i];
57
+ if (utils.getType(userID[i]) !== "Number" && utils.getType(userID[i]) !== "String") throw { error: "Elements of userID should be of type Number or String and not " + utils.getType(userID[i]) + "." };
58
+ form["log_message_data[added_participants][" + i + "]"] = "fbid:" + userID[i];
91
59
  }
92
60
 
93
61
  defaultFuncs
94
62
  .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
95
63
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
96
- .then(function(resData) {
97
- if (!resData) {
98
- throw { error: "Add to group failed." };
99
- }
100
- if (resData.error) {
101
- throw resData;
102
- }
64
+ .then(function (resData) {
65
+ if (!resData) throw { error: "Add to group failed." };
66
+ if (resData.error) throw resData;
103
67
 
104
68
  return callback();
105
69
  })
106
- .catch(function(err) {
107
- log.error("addUserToGroup", err);
70
+ .catch(function (err) {
71
+ log.error("addUserToGroup", "» Cannot add user to the voice chat. Please try again after");
108
72
  return callback(err);
109
73
  });
110
-
74
+
111
75
  return returnPromise;
112
76
  };
113
77
  };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return function changeAdminStatus(threadID, adminID, adminStatus) {
7
+ if (utils.getType(threadID) !== "String") throw { error: "changeAdminStatus: threadID must be a string" };
8
+ if (utils.getType(adminID) !== "String" && utils.getType(adminID) !== "Array") throw { error: "changeAdminStatus: adminID must be a string or an array" };
9
+ if (utils.getType(adminStatus) !== "Boolean") throw { error: "changeAdminStatus: adminStatus must be true or false" };
10
+
11
+ let wsContent = {
12
+ request_id: 1,
13
+ type: 3,
14
+ payload: {
15
+ version_id: '3816854585040595',
16
+ tasks: [],
17
+ epoch_id: 6763184801413415579,
18
+ data_trace_id: null
19
+ },
20
+ app_id: '772021112871879'
21
+ }
22
+
23
+ if (utils.getType(adminID) === "Array") {
24
+ for (let i = 0; i < adminID.length; i++) {
25
+ wsContent.payload.tasks.push({
26
+ label: '25',
27
+ payload: JSON.stringify({ thread_key: threadID, contact_id: adminID[i], is_admin: adminStatus }),
28
+ queue_name: 'admin_status',
29
+ task_id: i + 1,
30
+ failure_count: null
31
+ });
32
+ }
33
+ }
34
+ else {
35
+ wsContent.payload.tasks.push({
36
+ label: '25',
37
+ payload: JSON.stringify({ thread_key: threadID, contact_id: adminID, is_admin: adminStatus }),
38
+ queue_name: 'admin_status',
39
+ task_id: 1,
40
+ failure_count: null
41
+ });
42
+ }
43
+
44
+ wsContent.payload = JSON.stringify(wsContent.payload);
45
+ return new Promise((resolve, reject) => ctx.mqttClient && ctx.mqttClient.publish('/ls_req', JSON.stringify(wsContent), {}, (err, _packet) => err ? reject(err) : resolve()));
46
+ };
47
+ };
@@ -0,0 +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 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) return rejectFunc(err);
18
+ resolveFunc();
19
+ };
20
+ }
21
+
22
+ var form = {};
23
+
24
+ if (utils.getType(threadOrThreads) === "Array") for (var i = 0; i < threadOrThreads.length; i++) form["ids[" + threadOrThreads[i] + "]"] = archive;
25
+ else form["ids[" + threadOrThreads + "]"] = archive;
26
+
27
+ defaultFuncs
28
+ .post("https://www.facebook.com/ajax/mercury/change_archived_status.php", ctx.jar, form)
29
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
30
+ .then(function (resData) {
31
+ if (resData.error) throw resData;
32
+ return callback();
33
+ })
34
+ .catch(function (err) {
35
+ log.error("changeArchivedStatus", err);
36
+ return callback(err);
37
+ });
38
+
39
+ return returnPromise;
40
+ };
41
+ };
@@ -13,22 +13,16 @@ module.exports = function (defaultFuncs, api, ctx) {
13
13
  });
14
14
 
15
15
  if (!callback) {
16
- if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") {
17
- callback = publish;
18
- } else {
16
+ if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") callback = publish;
17
+ else {
19
18
  callback = function (err) {
20
- if (err) {
21
- return rejectFunc(err);
22
- }
19
+ if (err) return rejectFunc(err);
23
20
  resolveFunc();
24
21
  };
25
22
  }
26
23
  }
27
24
 
28
- if (utils.getType(publish) != "Boolean") {
29
- publish = false;
30
- }
31
-
25
+ if (utils.getType(publish) != "Boolean") publish = false;
32
26
  if (utils.getType(bio) != "String") {
33
27
  bio = "";
34
28
  publish = false;
@@ -54,17 +48,10 @@ module.exports = function (defaultFuncs, api, ctx) {
54
48
  };
55
49
 
56
50
  defaultFuncs
57
- .post(
58
- "https://www.facebook.com/api/graphql/",
59
- ctx.jar,
60
- form
61
- )
51
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
62
52
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
63
53
  .then(function (resData) {
64
- if (resData.errors) {
65
- throw resData;
66
- }
67
-
54
+ if (resData.errors) throw resData;
68
55
  return callback();
69
56
  })
70
57
  .catch(function (err) {
@@ -14,28 +14,17 @@ module.exports = function (defaultFuncs, api, ctx) {
14
14
 
15
15
  if (!callback) {
16
16
  callback = function (err) {
17
- if (err) {
18
- return rejectFunc(err);
19
- }
17
+ if (err) return rejectFunc(err);
20
18
  resolveFunc();
21
19
  };
22
20
  }
23
21
 
24
22
  defaultFuncs
25
- .post(
26
- `https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`,
27
- ctx.jar,
28
- {
29
- fbid: userID
30
- }
31
- )
23
+ .post(`https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`, ctx.jar, { fbid: userID })
32
24
  .then(utils.saveCookies(ctx.jar))
33
25
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
34
26
  .then(function (resData) {
35
- if (resData.error) {
36
- throw resData;
37
- }
38
-
27
+ if (resData.error) throw resData;
39
28
  return callback();
40
29
  })
41
30
  .catch(function (err) {
@@ -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(defaultFuncs, api, ctx) {
7
+ module.exports = function (defaultFuncs, api, ctx) {
8
8
  function handleUpload(image, callback) {
9
9
  var uploads = [];
10
10
 
@@ -15,18 +15,10 @@ module.exports = function(defaultFuncs, api, ctx) {
15
15
 
16
16
  uploads.push(
17
17
  defaultFuncs
18
- .postFormData(
19
- "https://upload.facebook.com/ajax/mercury/upload.php",
20
- ctx.jar,
21
- form,
22
- {}
23
- )
18
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
24
19
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
25
- .then(function(resData) {
26
- if (resData.error) {
27
- throw resData;
28
- }
29
-
20
+ .then(function (resData) {
21
+ if (resData.error) throw resData;
30
22
  return resData.payload.metadata[0];
31
23
  })
32
24
  );
@@ -34,36 +26,26 @@ module.exports = function(defaultFuncs, api, ctx) {
34
26
  // resolve all promises
35
27
  bluebird
36
28
  .all(uploads)
37
- .then(function(resData) {
38
- callback(null, resData);
39
- })
40
- .catch(function(err) {
29
+ .then(resData => callback(null, resData))
30
+ .catch(function (err) {
41
31
  log.error("handleUpload", err);
42
32
  return callback(err);
43
33
  });
44
34
  }
45
35
 
46
36
  return function changeGroupImage(image, threadID, callback) {
47
- if (
48
- !callback &&
49
- (utils.getType(threadID) === "Function" ||
50
- utils.getType(threadID) === "AsyncFunction")
51
- ) {
52
- throw { error: "please pass a threadID as a second argument." };
53
- }
37
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
54
38
 
55
- var resolveFunc = function(){};
56
- var rejectFunc = function(){};
39
+ var resolveFunc = function () { };
40
+ var rejectFunc = function () { };
57
41
  var returnPromise = new Promise(function (resolve, reject) {
58
42
  resolveFunc = resolve;
59
43
  rejectFunc = reject;
60
44
  });
61
45
 
62
46
  if (!callback) {
63
- callback = function(err) {
64
- if (err) {
65
- return rejectFunc(err);
66
- }
47
+ callback = function (err) {
48
+ if (err) return rejectFunc(err);
67
49
  resolveFunc();
68
50
  };
69
51
  }
@@ -98,10 +80,8 @@ module.exports = function(defaultFuncs, api, ctx) {
98
80
  timestamp_time_passed: "0"
99
81
  };
100
82
 
101
- handleUpload(image, function(err, payload) {
102
- if (err) {
103
- return callback(err);
104
- }
83
+ handleUpload(image, function (err, payload) {
84
+ if (err) return callback(err);
105
85
 
106
86
  form["thread_image_id"] = payload[0]["image_id"];
107
87
  form["thread_id"] = threadID;
@@ -109,16 +89,12 @@ module.exports = function(defaultFuncs, api, ctx) {
109
89
  defaultFuncs
110
90
  .post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
111
91
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
112
- .then(function(resData) {
92
+ .then(function (resData) {
113
93
  // check for errors here
114
-
115
- if (resData.error) {
116
- throw resData;
117
- }
118
-
94
+ if (resData.error) throw resData;
119
95
  return callback();
120
96
  })
121
- .catch(function(err) {
97
+ .catch(function (err) {
122
98
  log.error("changeGroupImage", err);
123
99
  return callback(err);
124
100
  });
@@ -0,0 +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) 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
+ };
@@ -3,34 +3,27 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function changeThreadColor(color, threadID, 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
- return rejectFunc(err);
19
- }
16
+ callback = function (err) {
17
+ if (err) return rejectFunc(err);
20
18
  resolveFunc(err);
21
19
  };
22
20
  }
23
21
 
24
22
  var validatedColor = color !== null ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
25
- var colorList = Object.keys(api.threadColors).map(function(name) {
23
+ var colorList = Object.keys(api.threadColors).map(function (name) {
26
24
  return api.threadColors[name];
27
25
  });
28
- if (!colorList.includes(validatedColor)) {
29
- throw {
30
- error:
31
- "The color you are trying to use is not a valid thread color. Use api.threadColors to find acceptable values."
32
- };
33
- }
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." };
34
27
 
35
28
  var form = {
36
29
  dpr: 1,
@@ -54,14 +47,11 @@ module.exports = function(defaultFuncs, api, ctx) {
54
47
  defaultFuncs
55
48
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
56
49
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
57
- .then(function(resData) {
58
- if (resData[resData.length - 1].error_results > 0) {
59
- throw resData[0].o0.errors;
60
- }
61
-
50
+ .then(function (resData) {
51
+ if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
62
52
  return callback();
63
53
  })
64
- .catch(function(err) {
54
+ .catch(function (err) {
65
55
  log.error("changeThreadColor", err);
66
56
  return callback(err);
67
57
  });
@@ -0,0 +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) 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
+ };