alicezetion 1.0.2 → 1.0.4

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