@dongdev/fca-unofficial 3.0.25 → 3.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/CHANGELOG.md +196 -190
- package/DOCS.md +3 -6
- package/Fca_Database/database.sqlite +0 -0
- package/LICENSE-MIT +1 -1
- package/README.md +1 -1
- package/index.d.ts +745 -746
- package/module/config.js +29 -33
- package/module/login.js +133 -136
- package/module/loginHelper.js +1240 -1048
- package/module/options.js +44 -45
- package/package.json +81 -82
- package/src/api/messaging/changeAdminStatus.js +56 -56
- package/src/api/messaging/changeGroupImage.js +2 -1
- package/src/api/messaging/changeThreadEmoji.js +47 -47
- package/src/api/messaging/createPoll.js +25 -25
- package/src/api/messaging/deleteMessage.js +110 -30
- package/src/api/messaging/forwardAttachment.js +28 -28
- package/src/api/messaging/removeUserFromGroup.js +28 -73
- package/src/api/messaging/sendMessage.js +15 -17
- package/src/api/messaging/sendTypingIndicator.js +23 -23
- package/src/api/messaging/setMessageReaction.js +57 -60
- package/src/api/messaging/setTitle.js +47 -47
- package/src/api/messaging/uploadAttachment.js +471 -73
- package/src/api/socket/core/connectMqtt.js +250 -250
- package/src/api/socket/core/emitAuth.js +1 -1
- package/src/api/socket/core/getSeqID.js +322 -40
- package/src/api/socket/core/parseDelta.js +368 -377
- package/src/api/socket/listenMqtt.js +371 -360
- package/src/utils/client.js +2 -312
- package/src/utils/cookies.js +68 -0
- package/src/utils/format.js +117 -90
- package/src/utils/loginParser.js +347 -0
- package/src/utils/messageFormat.js +1173 -0
- package/src/api/socket/core/markDelivery.js +0 -12
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const log = require("npmlog");
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
4
|
+
const { getType, generateOfflineThreadingID } = require("../../utils/format");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
7
|
return function deleteMessage(messageOrMessages, callback) {
|
|
8
|
-
let resolveFunc = function() {};
|
|
9
|
-
let rejectFunc = function() {};
|
|
10
|
-
const returnPromise = new Promise(function(resolve, reject) {
|
|
8
|
+
let resolveFunc = function () {};
|
|
9
|
+
let rejectFunc = function () {};
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
11
|
resolveFunc = resolve;
|
|
12
12
|
rejectFunc = reject;
|
|
13
13
|
});
|
|
14
14
|
if (!callback) {
|
|
15
|
-
callback = function(err) {
|
|
15
|
+
callback = function (err) {
|
|
16
16
|
if (err) {
|
|
17
17
|
return rejectFunc(err);
|
|
18
18
|
}
|
|
@@ -20,36 +20,116 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const form = {
|
|
24
|
-
client: "mercury"
|
|
25
|
-
};
|
|
26
|
-
|
|
27
23
|
if (getType(messageOrMessages) !== "Array") {
|
|
28
24
|
messageOrMessages = [messageOrMessages];
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if (!ctx || !ctx.mqttClient) {
|
|
28
|
+
const err = new Error("Not connected to MQTT");
|
|
29
|
+
callback(err);
|
|
30
|
+
return rejectFunc(err);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
const epochId = String(generateOfflineThreadingID());
|
|
34
|
+
if (typeof ctx.wsTaskNumber !== "number") ctx.wsTaskNumber = 0;
|
|
35
|
+
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
36
|
+
|
|
37
|
+
const tasks = messageOrMessages.map((threadID) => {
|
|
38
|
+
const threadKey = String(threadID);
|
|
39
|
+
const taskPayload = `{"thread_key":${threadKey},"remove_type":0,"sync_group":1}`;
|
|
40
|
+
return {
|
|
41
|
+
failure_count: null,
|
|
42
|
+
label: "146",
|
|
43
|
+
payload: taskPayload,
|
|
44
|
+
queue_name: threadKey,
|
|
45
|
+
task_id: ++ctx.wsTaskNumber,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const payload = `{"epoch_id":${epochId},"tasks":${JSON.stringify(
|
|
50
|
+
tasks,
|
|
51
|
+
)},"version_id":"25909428212080747"}`;
|
|
52
|
+
|
|
53
|
+
const reqID = ++ctx.wsReqNumber;
|
|
54
|
+
const form = JSON.stringify({
|
|
55
|
+
app_id: "2220391788200892",
|
|
56
|
+
payload,
|
|
57
|
+
request_id: reqID,
|
|
58
|
+
type: 3,
|
|
59
|
+
});
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
let timer = null;
|
|
62
|
+
|
|
63
|
+
const cleanup = () => {
|
|
64
|
+
if (timer) {
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
timer = null;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
ctx.mqttClient?.removeListener("message", handleRes);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
// ignore
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handleRes = (topic, message) => {
|
|
76
|
+
if (topic !== "/ls_resp") return;
|
|
77
|
+
let msg;
|
|
78
|
+
try {
|
|
79
|
+
msg = JSON.parse(message.toString());
|
|
80
|
+
} catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (msg.request_id !== reqID) return;
|
|
84
|
+
cleanup();
|
|
85
|
+
try {
|
|
86
|
+
msg.payload =
|
|
87
|
+
typeof msg.payload === "string"
|
|
88
|
+
? JSON.parse(msg.payload)
|
|
89
|
+
: msg.payload;
|
|
90
|
+
} catch {}
|
|
91
|
+
callback(null, { success: true, response: msg.payload });
|
|
92
|
+
resolveFunc({ success: true, response: msg.payload });
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
ctx.mqttClient.on("message", handleRes);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
cleanup();
|
|
99
|
+
log.error("deleteMessage", err);
|
|
100
|
+
callback(err);
|
|
101
|
+
rejectFunc(err);
|
|
102
|
+
return returnPromise;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
timer = setTimeout(() => {
|
|
106
|
+
const err = new Error("MQTT response timeout");
|
|
107
|
+
cleanup();
|
|
108
|
+
log.error("deleteMessage", err);
|
|
109
|
+
callback(err);
|
|
110
|
+
rejectFunc(err);
|
|
111
|
+
}, 20000);
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
ctx.mqttClient.publish(
|
|
115
|
+
"/ls_req",
|
|
116
|
+
form,
|
|
117
|
+
{ qos: 1, retain: false },
|
|
118
|
+
(err) => {
|
|
119
|
+
if (err) {
|
|
120
|
+
cleanup();
|
|
121
|
+
log.error("deleteMessage", err);
|
|
122
|
+
callback(err);
|
|
123
|
+
rejectFunc(err);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
cleanup();
|
|
129
|
+
log.error("deleteMessage", err);
|
|
130
|
+
callback(err);
|
|
131
|
+
rejectFunc(err);
|
|
132
|
+
}
|
|
53
133
|
|
|
54
134
|
return returnPromise;
|
|
55
135
|
};
|
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
const { generateOfflineThreadingID } = require("../../utils/format");
|
|
4
4
|
|
|
5
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
-
return async function forwardMessage(threadID, forwardedMsgID, callback) {
|
|
7
|
-
let resolveFunc, rejectFunc;
|
|
8
|
-
const returnPromise = new Promise((resolve, reject) => {
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
return async function forwardMessage(threadID, forwardedMsgID, callback) {
|
|
7
|
+
let resolveFunc, rejectFunc;
|
|
8
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
9
9
|
resolveFunc = resolve;
|
|
10
10
|
rejectFunc = reject;
|
|
11
11
|
});
|
|
12
|
-
if (!callback) {
|
|
13
|
-
callback = (err, data) => {
|
|
14
|
-
if (err) return rejectFunc(err);
|
|
15
|
-
resolveFunc(data);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
if (!ctx.mqttClient) {
|
|
19
|
-
const err = new Error("Not connected to MQTT");
|
|
20
|
-
callback?.(err);
|
|
21
|
-
rejectFunc(err);
|
|
22
|
-
return returnPromise;
|
|
23
|
-
}
|
|
24
|
-
let count_req = 0
|
|
25
|
-
const payload = {
|
|
26
|
-
epoch_id: generateOfflineThreadingID(),
|
|
27
|
-
tasks: [
|
|
12
|
+
if (!callback) {
|
|
13
|
+
callback = (err, data) => {
|
|
14
|
+
if (err) return rejectFunc(err);
|
|
15
|
+
resolveFunc(data);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (!ctx.mqttClient) {
|
|
19
|
+
const err = new Error("Not connected to MQTT");
|
|
20
|
+
callback?.(err);
|
|
21
|
+
rejectFunc(err);
|
|
22
|
+
return returnPromise;
|
|
23
|
+
}
|
|
24
|
+
let count_req = 0
|
|
25
|
+
const payload = {
|
|
26
|
+
epoch_id: generateOfflineThreadingID(),
|
|
27
|
+
tasks: [
|
|
28
28
|
{
|
|
29
29
|
failure_count: null,
|
|
30
30
|
label: "46",
|
|
@@ -47,11 +47,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
47
47
|
};
|
|
48
48
|
const form = JSON.stringify({
|
|
49
49
|
app_id: "772021112871879",
|
|
50
|
-
payload: JSON.stringify(payload),
|
|
51
|
-
"request_id": ++count_req,
|
|
52
|
-
"type": 3
|
|
53
|
-
});
|
|
54
|
-
ctx.mqttClient.publish("/ls_req", form);
|
|
55
|
-
return returnPromise;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
50
|
+
payload: JSON.stringify(payload),
|
|
51
|
+
"request_id": ++count_req,
|
|
52
|
+
"type": 3
|
|
53
|
+
});
|
|
54
|
+
ctx.mqttClient.publish("/ls_req", form);
|
|
55
|
+
return returnPromise;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const { getType, generateOfflineThreadingID } = require("../../utils/format");
|
|
4
|
-
const { parseAndCheckLogin } = require("../../utils/client");
|
|
5
|
-
const log = require("npmlog");
|
|
3
|
+
const { getType, generateOfflineThreadingID } = require("../../utils/format");
|
|
6
4
|
|
|
7
5
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
8
|
-
function
|
|
6
|
+
return function removeUserFromGroup(userID, threadID, callback) {
|
|
7
|
+
if (!ctx.mqttClient) {
|
|
8
|
+
const err = new Error("Not connected to MQTT");
|
|
9
|
+
if (callback) return callback(err);
|
|
10
|
+
return Promise.reject(err);
|
|
11
|
+
}
|
|
9
12
|
if (!callback && (getType(threadID) === "Function" || getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
|
|
10
13
|
if (getType(threadID) !== "Number" && getType(threadID) !== "String") throw { error: "threadID should be of type Number or String and not " + getType(threadID) + "." };
|
|
11
14
|
if (getType(userID) !== "Number" && getType(userID) !== "String") throw { error: "userID should be of type Number or String and not " + getType(userID) + "." };
|
|
@@ -21,49 +24,12 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
21
24
|
resolveFunc(data);
|
|
22
25
|
};
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
31
|
-
.then(function (resData) {
|
|
32
|
-
if (!resData) throw { error: "Remove from group failed." };
|
|
33
|
-
if (resData.error) throw resData;
|
|
34
|
-
return callback();
|
|
35
|
-
})
|
|
36
|
-
.catch(function (err) {
|
|
37
|
-
log.error("removeUserFromGroup", err);
|
|
38
|
-
return callback(err);
|
|
39
|
-
});
|
|
40
|
-
return returnPromise;
|
|
41
|
-
};
|
|
42
|
-
function removeUserFromGroupMqtt(userID, threadID, callback) {
|
|
43
|
-
if (!ctx.mqttClient) {
|
|
44
|
-
throw new Error("Not connected to MQTT");
|
|
45
|
-
}
|
|
46
|
-
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
47
|
-
const reqID = ++ctx.wsReqNumber;
|
|
48
|
-
if (!callback && (getType(threadID) === "Function" || getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
|
|
49
|
-
if (getType(threadID) !== "Number" && getType(threadID) !== "String") throw { error: "threadID should be of type Number or String and not " + getType(threadID) + "." };
|
|
50
|
-
if (getType(userID) !== "Number" && getType(userID) !== "String") throw { error: "userID should be of type Number or String and not " + getType(userID) + "." };
|
|
51
|
-
var resolveFunc = function () { };
|
|
52
|
-
var rejectFunc = function () { };
|
|
53
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
|
54
|
-
resolveFunc = resolve;
|
|
55
|
-
rejectFunc = reject;
|
|
56
|
-
});
|
|
57
|
-
if (!callback) {
|
|
58
|
-
callback = function (err, data) {
|
|
59
|
-
if (err) return rejectFunc(err);
|
|
60
|
-
resolveFunc(data);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
var form = JSON.stringify({
|
|
64
|
-
"app_id": "2220391788200892",
|
|
65
|
-
"payload": JSON.stringify({
|
|
66
|
-
epoch_id: generateOfflineThreadingID(),
|
|
27
|
+
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
28
|
+
const reqID = ++ctx.wsReqNumber;
|
|
29
|
+
var form = JSON.stringify({
|
|
30
|
+
"app_id": "2220391788200892",
|
|
31
|
+
"payload": JSON.stringify({
|
|
32
|
+
epoch_id: generateOfflineThreadingID(),
|
|
67
33
|
tasks: [
|
|
68
34
|
{
|
|
69
35
|
failure_count: null,
|
|
@@ -77,31 +43,20 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
77
43
|
task_id: Math.random() * 1001 << 0
|
|
78
44
|
}
|
|
79
45
|
],
|
|
80
|
-
version_id: '
|
|
81
|
-
}),
|
|
82
|
-
"request_id": reqID,
|
|
83
|
-
"type": 3
|
|
84
|
-
});
|
|
85
|
-
ctx.mqttClient.publish('/ls_req', form, (err, data) => {
|
|
86
|
-
if (err) {
|
|
87
|
-
callback(err, null);
|
|
88
|
-
rejectFunc(err);
|
|
89
|
-
} else {
|
|
90
|
-
callback(null, true);
|
|
91
|
-
resolveFunc(true);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
46
|
+
version_id: '25002366262773827'
|
|
47
|
+
}),
|
|
48
|
+
"request_id": reqID,
|
|
49
|
+
"type": 3
|
|
50
|
+
});
|
|
51
|
+
ctx.mqttClient.publish('/ls_req', form, (err, data) => {
|
|
52
|
+
if (err) {
|
|
53
|
+
callback(err, null);
|
|
54
|
+
rejectFunc(err);
|
|
55
|
+
} else {
|
|
56
|
+
callback(null, true);
|
|
57
|
+
resolveFunc(true);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
94
60
|
return returnPromise;
|
|
95
61
|
};
|
|
96
|
-
|
|
97
|
-
if (ctx.mqttClient) {
|
|
98
|
-
try {
|
|
99
|
-
return removeUserFromGroupMqtt(userID, threadID, callback);
|
|
100
|
-
} catch (e) {
|
|
101
|
-
return removeUserFromGroupNoMqtt(userID, threadID, callback);
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
return removeUserFromGroupNoMqtt(userID, threadID, callback);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
};
|
|
62
|
+
};
|
|
@@ -12,30 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
"use strict";
|
|
14
14
|
const log = require("npmlog");
|
|
15
|
-
const { parseAndCheckLogin } = require("../../utils/client");
|
|
16
15
|
const { getType } = require("../../utils/format");
|
|
17
16
|
const { isReadableStream } = require("../../utils/constants");
|
|
18
17
|
const { generateOfflineThreadingID } = require("../../utils/format");
|
|
19
18
|
|
|
20
19
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
20
|
+
const uploadAttachment = require("./uploadAttachment")(defaultFuncs, api, ctx);
|
|
21
21
|
const hasLinks = s => typeof s === "string" && /(https?:\/\/|www\.|t\.me\/|fb\.me\/|youtu\.be\/|facebook\.com\/|youtube\.com\/)/i.test(s);
|
|
22
22
|
const emojiSizes = { small: 1, medium: 2, large: 3 };
|
|
23
23
|
|
|
24
|
-
async function uploadAttachment(streams) {
|
|
25
|
-
const uploads = streams.map(stream => {
|
|
26
|
-
if (!isReadableStream(stream)) throw { error: "Attachment should be a readable stream and not " + getType(stream) + "." };
|
|
27
|
-
const form = { farr: stream };
|
|
28
|
-
return defaultFuncs
|
|
29
|
-
.postFormData("https://www.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
|
|
30
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
31
|
-
.then(resData => {
|
|
32
|
-
if (resData.error) throw resData;
|
|
33
|
-
return resData.payload.metadata[0];
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
return Promise.all(uploads);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
24
|
function extractIdsFromPayload(payload) {
|
|
40
25
|
let messageID = null;
|
|
41
26
|
let threadID = null;
|
|
@@ -57,6 +42,19 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
57
42
|
|
|
58
43
|
function publishWithAck(content, text, reqID, callback) {
|
|
59
44
|
return new Promise((resolve, reject) => {
|
|
45
|
+
// Ensure MQTT client is available before using it
|
|
46
|
+
if (!ctx.mqttClient || typeof ctx.mqttClient.on !== "function" || typeof ctx.mqttClient.publish !== "function") {
|
|
47
|
+
const err = new Error("MQTT client is not initialized");
|
|
48
|
+
log.error("sendMessageMqtt", err);
|
|
49
|
+
callback && callback(err);
|
|
50
|
+
return reject(err);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Remove default max listeners limit to avoid MaxListenersExceededWarning
|
|
54
|
+
if (typeof ctx.mqttClient.setMaxListeners === "function") {
|
|
55
|
+
ctx.mqttClient.setMaxListeners(0);
|
|
56
|
+
}
|
|
57
|
+
|
|
60
58
|
let done = false;
|
|
61
59
|
const cleanup = () => {
|
|
62
60
|
if (done) return;
|
|
@@ -269,4 +267,4 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
269
267
|
content.payload = JSON.stringify(content.payload);
|
|
270
268
|
return publishWithAck(content, baseBody, reqID, callback);
|
|
271
269
|
};
|
|
272
|
-
};
|
|
270
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { getType } = require("../../utils/format.js");
|
|
3
3
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
4
|
-
return function sendTyping(threadID, isTyping, options, callback) {
|
|
5
|
-
var resolveFunc = function () { };
|
|
6
|
-
var rejectFunc = function () { };
|
|
7
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
|
8
|
-
resolveFunc = resolve;
|
|
9
|
-
rejectFunc = reject;
|
|
10
|
-
});
|
|
4
|
+
return function sendTyping(threadID, isTyping, options, callback) {
|
|
5
|
+
var resolveFunc = function () { };
|
|
6
|
+
var rejectFunc = function () { };
|
|
7
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
8
|
+
resolveFunc = resolve;
|
|
9
|
+
rejectFunc = reject;
|
|
10
|
+
});
|
|
11
11
|
if (getType(options) == "Function" || getType(options) == "AsyncFunction") {
|
|
12
12
|
callback = options;
|
|
13
13
|
options = {};
|
|
@@ -19,18 +19,18 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
19
19
|
resolveFunc(data);
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
if (!threadID) {
|
|
23
|
-
return callback(new Error("threadID is required"));
|
|
24
|
-
}
|
|
25
|
-
if (!ctx.mqttClient) {
|
|
26
|
-
const err = new Error("Not connected to MQTT");
|
|
27
|
-
callback(err);
|
|
28
|
-
rejectFunc(err);
|
|
29
|
-
return returnPromise;
|
|
30
|
-
}
|
|
31
|
-
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
32
|
-
const threadIDs = Array.isArray(threadID) ? threadID : [threadID];
|
|
33
|
-
threadIDs.forEach(tid => {
|
|
22
|
+
if (!threadID) {
|
|
23
|
+
return callback(new Error("threadID is required"));
|
|
24
|
+
}
|
|
25
|
+
if (!ctx.mqttClient) {
|
|
26
|
+
const err = new Error("Not connected to MQTT");
|
|
27
|
+
callback(err);
|
|
28
|
+
rejectFunc(err);
|
|
29
|
+
return returnPromise;
|
|
30
|
+
}
|
|
31
|
+
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
32
|
+
const threadIDs = Array.isArray(threadID) ? threadID : [threadID];
|
|
33
|
+
threadIDs.forEach(tid => {
|
|
34
34
|
var isGroupThread = getType(tid) === "Array" ? 0 : 1;
|
|
35
35
|
var threadType = isGroupThread ? 2 : 1;
|
|
36
36
|
var duration = options.duration || 10000;
|
|
@@ -52,10 +52,10 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
52
52
|
}),
|
|
53
53
|
version: "8965252033599983"
|
|
54
54
|
}),
|
|
55
|
-
request_id: ++ctx.wsReqNumber,
|
|
56
|
-
type: 4
|
|
57
|
-
}),
|
|
58
|
-
{
|
|
55
|
+
request_id: ++ctx.wsReqNumber,
|
|
56
|
+
type: 4
|
|
57
|
+
}),
|
|
58
|
+
{
|
|
59
59
|
qos: 1,
|
|
60
60
|
retain: false,
|
|
61
61
|
}
|
|
@@ -3,51 +3,48 @@
|
|
|
3
3
|
const logger = require("../../../func/logger");
|
|
4
4
|
const { generateOfflineThreadingID, getCurrentTimestamp } = require("../../utils/format");
|
|
5
5
|
|
|
6
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
-
return function setMessageReaction(reaction, messageID, threadID, callback, forceCustomReaction) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
threadID = undefined;
|
|
15
|
-
} else if (typeof
|
|
16
|
-
forceCustomReaction =
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
dataclass_params: null,
|
|
49
|
-
attachment_fbid: null
|
|
50
|
-
};
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function setMessageReaction(reaction, messageID, threadID, callback, forceCustomReaction) {
|
|
8
|
+
if (typeof threadID === "function") {
|
|
9
|
+
forceCustomReaction = callback;
|
|
10
|
+
callback = threadID;
|
|
11
|
+
threadID = undefined;
|
|
12
|
+
} else if (typeof threadID === "boolean") {
|
|
13
|
+
forceCustomReaction = threadID;
|
|
14
|
+
threadID = undefined;
|
|
15
|
+
} else if (typeof callback === "boolean") {
|
|
16
|
+
forceCustomReaction = callback;
|
|
17
|
+
callback = undefined;
|
|
18
|
+
}
|
|
19
|
+
const cb = typeof callback === "function" ? callback : undefined;
|
|
20
|
+
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
if (!ctx.mqttClient) {
|
|
23
|
+
const err = new Error("MQTT client not connected");
|
|
24
|
+
if (cb) cb(err);
|
|
25
|
+
return reject(err);
|
|
26
|
+
}
|
|
27
|
+
if (reaction === undefined || reaction === null || !messageID || !threadID) {
|
|
28
|
+
const err = new Error("Missing required parameters (reaction, messageID, threadID)");
|
|
29
|
+
if (cb) cb(err);
|
|
30
|
+
return reject(err);
|
|
31
|
+
}
|
|
32
|
+
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
33
|
+
if (typeof ctx.wsTaskNumber !== "number") ctx.wsTaskNumber = 0;
|
|
34
|
+
const reqID = ++ctx.wsReqNumber;
|
|
35
|
+
const taskID = ++ctx.wsTaskNumber;
|
|
36
|
+
const taskPayload = {
|
|
37
|
+
thread_key: threadID,
|
|
38
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
39
|
+
message_id: messageID,
|
|
40
|
+
reaction: reaction,
|
|
41
|
+
actor_id: ctx.userID,
|
|
42
|
+
reaction_style: forceCustomReaction ? 1 : null,
|
|
43
|
+
sync_group: 1,
|
|
44
|
+
send_attribution: 65537,
|
|
45
|
+
dataclass_params: null,
|
|
46
|
+
attachment_fbid: null
|
|
47
|
+
};
|
|
51
48
|
const task = {
|
|
52
49
|
failure_count: null,
|
|
53
50
|
label: "29",
|
|
@@ -77,18 +74,18 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
77
74
|
}
|
|
78
75
|
if (json.request_id !== reqID) return;
|
|
79
76
|
ctx.mqttClient.removeListener("message", handleResponse);
|
|
80
|
-
if (cb) cb(null, { success: true });
|
|
81
|
-
return resolve({ success: true });
|
|
82
|
-
};
|
|
83
|
-
ctx.mqttClient.on("message", handleResponse);
|
|
84
|
-
ctx.mqttClient.publish("/ls_req", JSON.stringify(mqttForm), { qos: 1, retain: false }, (err) => {
|
|
85
|
-
if (err) {
|
|
86
|
-
ctx.mqttClient.removeListener("message", handleResponse);
|
|
87
|
-
logger("setMessageReaction" + err, "error");
|
|
88
|
-
if (cb) cb(err);
|
|
89
|
-
return reject(err);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
};
|
|
77
|
+
if (cb) cb(null, { success: true });
|
|
78
|
+
return resolve({ success: true });
|
|
79
|
+
};
|
|
80
|
+
ctx.mqttClient.on("message", handleResponse);
|
|
81
|
+
ctx.mqttClient.publish("/ls_req", JSON.stringify(mqttForm), { qos: 1, retain: false }, (err) => {
|
|
82
|
+
if (err) {
|
|
83
|
+
ctx.mqttClient.removeListener("message", handleResponse);
|
|
84
|
+
logger("setMessageReaction" + err, "error");
|
|
85
|
+
if (cb) cb(err);
|
|
86
|
+
return reject(err);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
};
|