alicezetion 1.9.4 → 1.9.6

Sign up to get free protection for your applications and to get access to all the features.
package/src/react.js CHANGED
@@ -1,25 +1,10 @@
1
- /**
2
- * @fix by NTKhang
3
- * update as Thursday, 10 February 2022
4
- * do not remove the author name to get more updates
5
- */
6
-
7
1
  "use strict";
8
2
 
9
3
  const utils = require("../utils");
10
4
  const log = require("npmlog");
11
5
 
12
- function formatData(resData) {
13
- return {
14
- viewer_feedback_reaction_info: resData.feedback_react.feedback.viewer_feedback_reaction_info,
15
- supported_reactions: resData.feedback_react.feedback.supported_reactions,
16
- top_reactions: resData.feedback_react.feedback.top_reactions.edges,
17
- reaction_count: resData.feedback_react.feedback.reaction_count
18
- };
19
- }
20
-
21
6
  module.exports = function (defaultFuncs, api, ctx) {
22
- return function setPostReaction(postID, type, callback) {
7
+ return function setMessageReaction(reaction, messageID, callback, forceCustomReaction) {
23
8
  let resolveFunc = function () { };
24
9
  let rejectFunc = function () { };
25
10
  const returnPromise = new Promise(function (resolve, reject) {
@@ -28,82 +13,109 @@ module.exports = function (defaultFuncs, api, ctx) {
28
13
  });
29
14
 
30
15
  if (!callback) {
31
- if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
32
- callback = type;
33
- type = 0;
34
- }
35
- else {
36
- callback = function (err, data) {
37
- if (err) {
38
- return rejectFunc(err);
39
- }
40
- resolveFunc(data);
41
- };
42
- }
16
+ callback = function (err, friendList) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(friendList);
21
+ };
43
22
  }
44
23
 
45
- const map = {
46
- unlike: 0,
47
- like: 1,
48
- heart: 2,
49
- love: 16,
50
- haha: 4,
51
- wow: 3,
52
- sad: 7,
53
- angry: 8
54
- };
55
-
56
- if (utils.getType(type) !== "Number" && utils.getType(type) === "String") {
57
- type = map[type.toLowerCase()];
24
+ if (ctx.i_userID) {
25
+ throw { error: "Cannot set reaction as another profile." };
58
26
  }
59
27
 
60
- if (utils.getType(type) !== "Number" && utils.getType(type) !== "String") {
61
- throw {
62
- error: "setPostReaction: Invalid reaction type"
63
- };
28
+ switch (reaction) {
29
+ case "\uD83D\uDE0D": //:heart_eyes:
30
+ case "\uD83D\uDE06": //:laughing:
31
+ case "\uD83D\uDE2E": //:open_mouth:
32
+ case "\uD83D\uDE22": //:cry:
33
+ case "\uD83D\uDE20": //:angry:
34
+ case "\uD83D\uDC4D": //:thumbsup:
35
+ case "\uD83D\uDC4E": //:thumbsdown:
36
+ case "\u2764": //:heart:
37
+ case "\uD83D\uDC97": //:glowingheart:
38
+ case "":
39
+ //valid
40
+ break;
41
+ case ":heart_eyes:":
42
+ case ":love:":
43
+ reaction = "\uD83D\uDE0D";
44
+ break;
45
+ case ":laughing:":
46
+ case ":haha:":
47
+ reaction = "\uD83D\uDE06";
48
+ break;
49
+ case ":open_mouth:":
50
+ case ":wow:":
51
+ reaction = "\uD83D\uDE2E";
52
+ break;
53
+ case ":cry:":
54
+ case ":sad:":
55
+ reaction = "\uD83D\uDE22";
56
+ break;
57
+ case ":angry:":
58
+ reaction = "\uD83D\uDE20";
59
+ break;
60
+ case ":thumbsup:":
61
+ case ":like:":
62
+ reaction = "\uD83D\uDC4D";
63
+ break;
64
+ case ":thumbsdown:":
65
+ case ":dislike:":
66
+ reaction = "\uD83D\uDC4E";
67
+ break;
68
+ case ":heart:":
69
+ reaction = "\u2764";
70
+ break;
71
+ case ":glowingheart:":
72
+ reaction = "\uD83D\uDC97";
73
+ break;
74
+ default:
75
+ if (forceCustomReaction) {
76
+ break;
77
+ }
78
+ return callback({ error: "Reaction is not a valid emoji." });
64
79
  }
65
80
 
66
- if (type != 0 && !type) {
67
- throw {
68
- error: "setPostReaction: Invalid reaction type"
69
- };
70
- }
81
+ const variables = {
82
+ data: {
83
+ client_mutation_id: ctx.clientMutationId++,
84
+ actor_id: ctx.i_userID || ctx.userID,
85
+ action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
86
+ message_id: messageID,
87
+ reaction: reaction
88
+ }
89
+ };
71
90
 
72
- const form = {
73
- av: ctx.i_userID || ctx.userID,
74
- fb_api_caller_class: "RelayModern",
75
- fb_api_req_friendly_name: "CometUFIFeedbackReactMutation",
76
- doc_id: "4769042373179384",
77
- variables: JSON.stringify({
78
- input: {
79
- actor_id: ctx.i_userID || ctx.userID,
80
- feedback_id: (new Buffer("feedback:" + postID)).toString("base64"),
81
- feedback_reaction: type,
82
- feedback_source: "OBJECT",
83
- is_tracking_encrypted: true,
84
- tracking: [],
85
- session_id: "f7dd50dd-db6e-4598-8cd9-561d5002b423",
86
- client_mutation_id: Math.round(Math.random() * 19).toString()
87
- },
88
- useDefaultActor: false,
89
- scale: 3
90
- })
91
+ const qs = {
92
+ doc_id: "1491398900900362",
93
+ variables: JSON.stringify(variables),
94
+ dpr: 1
91
95
  };
92
96
 
93
97
  defaultFuncs
94
- .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
95
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
98
+ .postFormData(
99
+ "https://www.facebook.com/webgraphql/mutation/",
100
+ ctx.jar,
101
+ {},
102
+ qs
103
+ )
104
+ .then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
96
105
  .then(function (resData) {
97
- if (resData.errors) {
106
+ if (!resData) {
107
+ throw { error: "setReaction returned empty object." };
108
+ }
109
+ if (resData.error || resData.errors) {
98
110
  throw resData;
99
111
  }
100
- return callback(null, formatData(resData.data));
112
+ callback(null);
101
113
  })
102
114
  .catch(function (err) {
103
- log.error("setPostReaction", err);
115
+ log.error("setReaction", err);
104
116
  return callback(err);
105
117
  });
106
118
 
107
119
  return returnPromise;
108
120
  };
109
- };
121
+ };