node-ainzfb-new 1.6.32-stable → 1.6.2210-test

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. package/index.js +1 -1
  2. package/package.json +3 -3
  3. package/src/addExternalModule.js +6 -13
  4. package/src/addUserToGroup.js +12 -35
  5. package/src/changeAdminStatus.js +16 -32
  6. package/src/changeArchivedStatus.js +9 -15
  7. package/src/changeBio.js +8 -12
  8. package/src/changeBlockedStatus.js +8 -14
  9. package/src/changeGroupImage.js +13 -27
  10. package/src/changeNickname.js +10 -19
  11. package/src/changeThreadColor.js +10 -15
  12. package/src/changeThreadEmoji.js +9 -17
  13. package/src/createNewGroup.js +10 -18
  14. package/src/createPoll.js +11 -16
  15. package/src/deleteMessage.js +10 -16
  16. package/src/deleteThread.js +10 -16
  17. package/src/forwardAttachment.js +9 -14
  18. package/src/getCurrentUserID.js +1 -1
  19. package/src/getEmojiUrl.js +2 -3
  20. package/src/getFriendsList.js +10 -18
  21. package/src/getMessage.js +48 -52
  22. package/src/getThreadHistory.js +59 -156
  23. package/src/getThreadHistoryDeprecated.js +15 -26
  24. package/src/getThreadInfoDeprecated.js +13 -25
  25. package/src/getThreadList.js +53 -112
  26. package/src/getThreadListDeprecated.js +12 -30
  27. package/src/getThreadPictures.js +13 -25
  28. package/src/getUserID.js +7 -8
  29. package/src/getUserInfo.js +9 -12
  30. package/src/handleFriendRequest.js +9 -10
  31. package/src/handleMessageRequest.js +10 -16
  32. package/src/httpGet.js +13 -18
  33. package/src/httpPost.js +13 -18
  34. package/src/httpPostFormData.js +9 -14
  35. package/src/listenMqtt.js +571 -1218
  36. package/src/logout.js +13 -18
  37. package/src/markAsDelivered.js +10 -16
  38. package/src/markAsRead.js +24 -36
  39. package/src/markAsReadAll.js +10 -14
  40. package/src/markAsSeen.js +11 -18
  41. package/src/muteThread.js +8 -12
  42. package/src/removeUserFromGroup.js +10 -33
  43. package/src/resolvePhotoUrl.js +6 -8
  44. package/src/searchForThread.js +8 -13
  45. package/src/sendMessage.js +78 -172
  46. package/src/sendTypingIndicator.js +14 -29
  47. package/src/setMessageReaction.js +8 -13
  48. package/src/setPostReaction.js +95 -97
  49. package/src/setTitle.js +12 -18
  50. package/src/threadColors.js +17 -17
  51. package/src/unfriend.js +9 -14
  52. package/src/unsendMessage.js +7 -7
  53. package/utils.js +19 -18
  54. package/src/changeAvt.js +0 -91
package/src/logout.js CHANGED
@@ -3,17 +3,17 @@
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() {};
10
- var returnPromise = new Promise(function(resolve, reject) {
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
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) {
16
+ callback = function (err, friendList) {
17
17
  if (err) return rejectFunc(err);
18
18
 
19
19
  resolveFunc(friendList);
@@ -25,18 +25,14 @@ module.exports = function(defaultFuncs, api, ctx) {
25
25
  };
26
26
 
27
27
  defaultFuncs
28
- .post(
29
- "https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1",
30
- ctx.jar,
31
- form
32
- )
28
+ .post("https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1", ctx.jar, form)
33
29
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
34
- .then(function(resData) {
35
- 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) {
36
32
  return v.value === "logout";
37
33
  })[0];
38
34
 
39
- var html = resData.jsmods.markup.filter(function(v) {
35
+ var html = resData.jsmods.markup.filter(function (v) {
40
36
  return v[0] === elem.markup.__m;
41
37
  })[0][1].__html;
42
38
 
@@ -50,20 +46,19 @@ module.exports = function(defaultFuncs, api, ctx) {
50
46
  .post("https://www.facebook.com/logout.php", ctx.jar, form)
51
47
  .then(utils.saveCookies(ctx.jar));
52
48
  })
53
- .then(function(res) {
54
- if (!res.headers)
55
- throw { error: "An error occurred when logging out." };
49
+ .then(function (res) {
50
+ if (!res.headers) throw { error: "An error occurred when logging out." };
56
51
 
57
52
  return defaultFuncs
58
53
  .get(res.headers.location, ctx.jar)
59
54
  .then(utils.saveCookies(ctx.jar));
60
55
  })
61
- .then(function() {
56
+ .then(function () {
62
57
  ctx.loggedIn = false;
63
58
  log.info("logout", "Logged out successfully.");
64
59
  callback();
65
60
  })
66
- .catch(function(err) {
61
+ .catch(function (err) {
67
62
  log.error("logout", err);
68
63
  return callback(err);
69
64
  });
@@ -3,25 +3,24 @@
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 markAsDelivered(threadID, messageID, callback) {
8
- var resolveFunc = function() {};
9
- var rejectFunc = function() {};
10
- var returnPromise = new Promise(function(resolve, reject) {
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
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, data) {
16
+ callback = function (err, data) {
17
17
  if (err) return rejectFunc(err);
18
18
 
19
19
  resolveFunc(data);
20
20
  };
21
21
  }
22
22
 
23
- if (!threadID || !messageID)
24
- return callback("Error: messageID or threadID is not defined");
23
+ if (!threadID || !messageID) return callback("Error: messageID or threadID is not defined");
25
24
 
26
25
  var form = {};
27
26
 
@@ -29,22 +28,17 @@ module.exports = function(defaultFuncs, api, ctx) {
29
28
  form["thread_ids[" + threadID + "][0]"] = messageID;
30
29
 
31
30
  defaultFuncs
32
- .post(
33
- "https://www.facebook.com/ajax/mercury/delivery_receipts.php",
34
- ctx.jar,
35
- form
36
- )
31
+ .post("https://www.facebook.com/ajax/mercury/delivery_receipts.php", ctx.jar, form)
37
32
  .then(utils.saveCookies(ctx.jar))
38
33
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
39
- .then(function(resData) {
34
+ .then(function (resData) {
40
35
  if (resData.error) throw resData;
41
36
 
42
37
  return callback();
43
38
  })
44
- .catch(function(err) {
39
+ .catch(function (err) {
45
40
  log.error("markAsDelivered", err);
46
- if (utils.getType(err) == "Object" && err.error === "Not logged in.")
47
- ctx.loggedIn = false;
41
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
48
42
 
49
43
  return callback(err);
50
44
  });
package/src/markAsRead.js CHANGED
@@ -3,22 +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 async function markAsRead(threadID, read, callback) {
8
- if (
9
- utils.getType(read) === "Function" ||
10
- utils.getType(read) === "AsyncFunction"
11
- ) {
8
+ if (utils.getType(read) === 'Function' || utils.getType(read) === 'AsyncFunction') {
12
9
  callback = read;
13
10
  read = true;
14
11
  }
15
12
  if (read == undefined) read = true;
16
13
 
17
- if (!callback) callback = () => {};
14
+ if (!callback) callback = () => { };
18
15
 
19
16
  var form = {};
20
17
 
21
- if (typeof ctx.globalOptions.pageID !== "undefined") {
18
+ if (typeof ctx.globalOptions.pageID !== 'undefined') {
22
19
  form["source"] = "PagesManagerMessagesInterface";
23
20
  form["request_user_id"] = ctx.globalOptions.pageID;
24
21
  form["ids[" + threadID + "]"] = read;
@@ -29,15 +26,14 @@ module.exports = function(defaultFuncs, api, ctx) {
29
26
 
30
27
  let resData;
31
28
  try {
32
- resData = await defaultFuncs
33
- .post(
34
- "https://www.facebook.com/ajax/mercury/change_read_status.php",
35
- ctx.jar,
36
- form
37
- )
38
- .then(utils.saveCookies(ctx.jar))
39
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
40
- } catch (e) {
29
+ resData = await (
30
+ defaultFuncs
31
+ .post("https://www.facebook.com/ajax/mercury/change_read_status.php", ctx.jar, form)
32
+ .then(utils.saveCookies(ctx.jar))
33
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
34
+ );
35
+ }
36
+ catch (e) {
41
37
  callback(e);
42
38
  return e;
43
39
  }
@@ -45,35 +41,27 @@ module.exports = function(defaultFuncs, api, ctx) {
45
41
  if (resData.error) {
46
42
  let err = resData.error;
47
43
  log.error("markAsRead", err);
48
- if (utils.getType(err) == "Object" && err.error === "Not logged in.")
49
- ctx.loggedIn = false;
44
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
50
45
  callback(err);
51
46
  return err;
52
47
  }
53
48
 
54
49
  callback();
55
50
  return null;
56
- } else {
51
+ }
52
+ else {
57
53
  try {
58
54
  if (ctx.mqttClient) {
59
- let err = await new Promise(r =>
60
- ctx.mqttClient.publish(
61
- "/mark_thread",
62
- JSON.stringify({
63
- threadID,
64
- mark: "read",
65
- state: read
66
- }),
67
- { qos: 1, retain: false },
68
- r
69
- )
70
- );
55
+ let err = await new Promise(r => ctx.mqttClient.publish("/mark_thread", JSON.stringify({
56
+ threadID,
57
+ mark: "read",
58
+ state: read
59
+ }), { qos: 1, retain: false }, r));
71
60
  if (err) throw err;
72
- } else
73
- throw {
74
- error: "You can only use this function after you start listening."
75
- };
76
- } catch (e) {
61
+ }
62
+ else throw { error: "You can only use this function after you start listening." };
63
+ }
64
+ catch (e) {
77
65
  callback(e);
78
66
  return e;
79
67
  }
@@ -3,17 +3,17 @@
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() {};
10
- var returnPromise = new Promise(function(resolve, reject) {
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
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, data) {
16
+ callback = function (err, data) {
17
17
  if (err) return rejectFunc(err);
18
18
 
19
19
  resolveFunc(data);
@@ -21,27 +21,23 @@ module.exports = function(defaultFuncs, api, ctx) {
21
21
  }
22
22
 
23
23
  var form = {
24
- folder: "inbox"
24
+ folder: 'inbox'
25
25
  };
26
26
 
27
27
  defaultFuncs
28
- .post(
29
- "https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",
30
- ctx.jar,
31
- form
32
- )
28
+ .post("https://www.facebook.com/ajax/mercury/mark_folder_as_read.php", ctx.jar, form)
33
29
  .then(utils.saveCookies(ctx.jar))
34
30
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
- .then(function(resData) {
31
+ .then(function (resData) {
36
32
  if (resData.error) throw resData;
37
33
 
38
34
  return callback();
39
35
  })
40
- .catch(function(err) {
36
+ .catch(function (err) {
41
37
  log.error("markAsReadAll", err);
42
38
  return callback(err);
43
39
  });
44
40
 
45
41
  return returnPromise;
46
42
  };
47
- };
43
+ };
package/src/markAsSeen.js CHANGED
@@ -3,25 +3,23 @@
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 markAsSeen(seen_timestamp, callback) {
8
- if (
9
- utils.getType(seen_timestamp) == "Function" ||
10
- utils.getType(seen_timestamp) == "AsyncFunction"
11
- ) {
8
+ if (utils.getType(seen_timestamp) == "Function" ||
9
+ utils.getType(seen_timestamp) == "AsyncFunction") {
12
10
  callback = seen_timestamp;
13
11
  seen_timestamp = Date.now();
14
12
  }
15
13
 
16
- var resolveFunc = function() {};
17
- var rejectFunc = function() {};
18
- var returnPromise = new Promise(function(resolve, reject) {
14
+ var resolveFunc = function () { };
15
+ var rejectFunc = function () { };
16
+ var returnPromise = new Promise(function (resolve, reject) {
19
17
  resolveFunc = resolve;
20
18
  rejectFunc = reject;
21
19
  });
22
20
 
23
21
  if (!callback) {
24
- callback = function(err, data) {
22
+ callback = function (err, data) {
25
23
  if (err) return rejectFunc(err);
26
24
 
27
25
  resolveFunc(data);
@@ -33,22 +31,17 @@ module.exports = function(defaultFuncs, api, ctx) {
33
31
  };
34
32
 
35
33
  defaultFuncs
36
- .post(
37
- "https://www.facebook.com/ajax/mercury/mark_seen.php",
38
- ctx.jar,
39
- form
40
- )
34
+ .post("https://www.facebook.com/ajax/mercury/mark_seen.php", ctx.jar, form)
41
35
  .then(utils.saveCookies(ctx.jar))
42
36
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
43
- .then(function(resData) {
37
+ .then(function (resData) {
44
38
  if (resData.error) throw resData;
45
39
 
46
40
  return callback();
47
41
  })
48
- .catch(function(err) {
42
+ .catch(function (err) {
49
43
  log.error("markAsSeen", err);
50
- if (utils.getType(err) == "Object" && err.error === "Not logged in.")
51
- ctx.loggedIn = false;
44
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
52
45
 
53
46
  return callback(err);
54
47
  });
package/src/muteThread.js CHANGED
@@ -3,18 +3,18 @@
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() {};
11
- var returnPromise = new Promise(function(resolve, reject) {
9
+ var resolveFunc = function () { };
10
+ var rejectFunc = function () { };
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, data) {
17
+ callback = function (err, data) {
18
18
  if (err) return rejectFunc(err);
19
19
 
20
20
  resolveFunc(data);
@@ -27,21 +27,17 @@ module.exports = function(defaultFuncs, api, ctx) {
27
27
  };
28
28
 
29
29
  defaultFuncs
30
- .post(
31
- "https://www.facebook.com/ajax/mercury/change_mute_thread.php",
32
- ctx.jar,
33
- form
34
- )
30
+ .post("https://www.facebook.com/ajax/mercury/change_mute_thread.php", ctx.jar, form)
35
31
  .then(utils.saveCookies(ctx.jar))
36
32
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
37
- .then(function(resData) {
33
+ .then(function (resData) {
38
34
  if (resData.error) {
39
35
  throw resData;
40
36
  }
41
37
 
42
38
  return callback();
43
39
  })
44
- .catch(function(err) {
40
+ .catch(function (err) {
45
41
  log.error("muteThread", err);
46
42
  return callback(err);
47
43
  });
@@ -3,44 +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
  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
- if (
15
- utils.getType(threadID) !== "Number" &&
16
- utils.getType(threadID) !== "String"
17
- )
18
- throw {
19
- error:
20
- "threadID should be of type Number or String and not " +
21
- utils.getType(threadID) +
22
- "."
23
- };
24
- if (
25
- utils.getType(userID) !== "Number" &&
26
- utils.getType(userID) !== "String"
27
- )
28
- throw {
29
- error:
30
- "userID should be of type Number or String and not " +
31
- utils.getType(userID) +
32
- "."
33
- };
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) + "." };
34
11
 
35
- var resolveFunc = function() {};
36
- var rejectFunc = function() {};
37
- var returnPromise = new Promise(function(resolve, reject) {
12
+ var resolveFunc = function () { };
13
+ var rejectFunc = function () { };
14
+ var returnPromise = new Promise(function (resolve, reject) {
38
15
  resolveFunc = resolve;
39
16
  rejectFunc = reject;
40
17
  });
41
18
 
42
19
  if (!callback) {
43
- callback = function(err, data) {
20
+ callback = function (err, data) {
44
21
  if (err) return rejectFunc(err);
45
22
 
46
23
  resolveFunc(data);
@@ -55,14 +32,14 @@ module.exports = function(defaultFuncs, api, ctx) {
55
32
  defaultFuncs
56
33
  .post("https://www.facebook.com/chat/remove_participants", ctx.jar, form)
57
34
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
58
- .then(function(resData) {
35
+ .then(function (resData) {
59
36
  if (!resData) throw { error: "Remove from group failed." };
60
37
 
61
38
  if (resData.error) throw resData;
62
39
 
63
40
  return callback();
64
41
  })
65
- .catch(function(err) {
42
+ .catch(function (err) {
66
43
  log.error("removeUserFromGroup", err);
67
44
  return callback(err);
68
45
  });
@@ -3,26 +3,24 @@
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() {};
10
- var returnPromise = new Promise(function(resolve, reject) {
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
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, data) {
16
+ callback = function (err, data) {
17
17
  if (err) return rejectFunc(err);
18
18
  resolveFunc(data);
19
19
  };
20
20
  }
21
21
 
22
22
  defaultFuncs
23
- .get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, {
24
- photo_id: photoID
25
- })
23
+ .get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, { photo_id: photoID })
26
24
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
27
25
  .then(resData => {
28
26
  if (resData.error) throw resData;
@@ -2,17 +2,17 @@
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() {};
9
- var returnPromise = new Promise(function(resolve, reject) {
7
+ var resolveFunc = function () { };
8
+ var rejectFunc = function () { };
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, data) {
15
+ callback = function (err, data) {
16
16
  if (err) return rejectFunc(err);
17
17
  resolveFunc(data);
18
18
  };
@@ -27,16 +27,11 @@ module.exports = function(defaultFuncs, api, ctx) {
27
27
  };
28
28
 
29
29
  defaultFuncs
30
- .post(
31
- "https://www.facebook.com/ajax/mercury/search_threads.php",
32
- ctx.jar,
33
- tmpForm
34
- )
30
+ .post("https://www.facebook.com/ajax/mercury/search_threads.php", ctx.jar, tmpForm)
35
31
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
- .then(function(resData) {
32
+ .then(function (resData) {
37
33
  if (resData.error) throw resData;
38
- if (!resData.payload.mercury_payload.threads)
39
- return callback({ error: "Could not find thread `" + name + "`." });
34
+ if (!resData.payload.mercury_payload.threads) return callback({ error: "Could not find thread `" + name + "`." });
40
35
  return callback(
41
36
  null,
42
37
  resData.payload.mercury_payload.threads.map(utils.formatThread)