@dongdev/fca-unofficial 2.0.7 → 2.0.10
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/DOCS.md +1699 -1434
- package/README.md +250 -168
- package/package.json +54 -28
- package/src/api/action/addExternalModule.js +5 -5
- package/src/api/action/changeAvatar.js +11 -10
- package/src/api/action/changeBio.js +7 -8
- package/src/api/action/getCurrentUserID.js +1 -1
- package/src/api/action/handleFriendRequest.js +5 -5
- package/src/api/action/logout.js +9 -8
- package/src/api/action/refreshFb_dtsg.js +17 -12
- package/src/api/action/setPostReaction.js +10 -11
- package/src/api/action/unfriend.js +3 -4
- package/src/api/http/httpGet.js +7 -8
- package/src/api/http/httpPost.js +7 -8
- package/src/api/http/postFormData.js +6 -5
- package/src/api/messaging/addUserToGroup.js +0 -1
- package/src/api/messaging/changeAdminStatus.js +108 -89
- package/src/api/messaging/changeArchivedStatus.js +6 -6
- package/src/api/messaging/changeBlockedStatus.js +3 -4
- package/src/api/messaging/changeGroupImage.js +72 -117
- package/src/api/messaging/changeNickname.js +59 -48
- package/src/api/messaging/changeThreadColor.js +61 -47
- package/src/api/messaging/changeThreadEmoji.js +106 -0
- package/src/api/messaging/createNewGroup.js +5 -5
- package/src/api/messaging/createPoll.js +36 -63
- package/src/api/messaging/deleteMessage.js +4 -4
- package/src/api/messaging/deleteThread.js +4 -4
- package/src/api/messaging/forwardAttachment.js +38 -47
- package/src/api/messaging/getFriendsList.js +5 -6
- package/src/api/messaging/getMessage.js +4 -9
- package/src/api/messaging/handleMessageRequest.js +5 -5
- package/src/api/messaging/markAsDelivered.js +5 -5
- package/src/api/messaging/markAsRead.js +7 -7
- package/src/api/messaging/markAsReadAll.js +3 -4
- package/src/api/messaging/markAsSeen.js +7 -7
- package/src/api/messaging/muteThread.js +3 -4
- package/src/api/messaging/removeUserFromGroup.js +82 -56
- package/src/api/messaging/resolvePhotoUrl.js +2 -3
- package/src/api/messaging/searchForThread.js +2 -3
- package/src/api/messaging/sendMessage.js +171 -101
- package/src/api/messaging/sendMessageMqtt.js +14 -12
- package/src/api/messaging/sendTypingIndicator.js +11 -11
- package/src/api/messaging/setMessageReaction.js +68 -82
- package/src/api/messaging/setTitle.js +77 -48
- package/src/api/messaging/shareContact.js +2 -4
- package/src/api/messaging/threadColors.js +0 -3
- package/src/api/messaging/unsendMessage.js +74 -37
- package/src/api/messaging/uploadAttachment.js +11 -9
- package/src/api/socket/core/connectMqtt.js +180 -0
- package/src/api/socket/core/getSeqID.js +25 -0
- package/src/api/socket/core/getTaskResponseData.js +22 -0
- package/src/api/socket/core/markDelivery.js +12 -0
- package/src/api/socket/core/parseDelta.js +351 -0
- package/src/api/socket/detail/buildStream.js +176 -68
- package/src/api/socket/detail/constants.js +24 -0
- package/src/api/socket/listenMqtt.js +80 -1005
- package/src/api/{messaging → threads}/getThreadHistory.js +5 -22
- package/src/api/threads/getThreadInfo.js +35 -248
- package/src/api/threads/getThreadList.js +20 -20
- package/src/api/threads/getThreadPictures.js +3 -4
- package/src/api/users/getUserID.js +5 -6
- package/src/api/users/getUserInfo.js +305 -73
- package/src/api/users/getUserInfoV2.js +134 -0
- package/src/database/models/user.js +32 -0
- package/src/database/userData.js +89 -0
- package/src/utils/constants.js +12 -2
- package/src/utils/format.js +1051 -0
- package/src/utils/request.js +75 -7
- package/CHANGELOG.md +0 -52
- package/LICENSE-MIT +0 -21
- package/func/checkUpdate.js +0 -58
- package/func/logger.js +0 -112
- package/func/login.js +0 -0
- package/index.d.ts +0 -618
- package/module/config.js +0 -34
- package/module/login.js +0 -47
- package/module/loginHelper.js +0 -635
- package/module/options.js +0 -49
- package/src/api/threads/changeThreadEmoji.js +0 -55
- package/src/utils/index.js +0 -1497
@@ -1,103 +1,122 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const
|
4
|
-
const log = require("npmlog");
|
3
|
+
const { generateOfflineThreadingID, getType } = require("../../utils/format");
|
5
4
|
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
-
|
8
|
-
if (
|
9
|
-
|
10
|
-
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
6
|
+
function changeAdminStatusNoMqtt(threadID, adminID, adminStatus) {
|
7
|
+
if (getType(threadID) !== "String") throw { error: "changeAdminStatus: threadID must be a string" };
|
8
|
+
if (getType(adminID) !== "String" && getType(adminID) !== "Array") throw { error: "changeAdminStatus: adminID must be a string or an array" };
|
9
|
+
if (getType(adminStatus) !== "Boolean") throw { error: "changeAdminStatus: adminStatus must be true or false" };
|
10
|
+
let wsContent = {
|
11
|
+
request_id: 1,
|
12
|
+
type: 3,
|
13
|
+
payload: {
|
14
|
+
version_id: '3816854585040595',
|
15
|
+
tasks: [],
|
16
|
+
epoch_id: generateOfflineThreadingID(),
|
17
|
+
data_trace_id: null
|
18
|
+
},
|
19
|
+
app_id: '772021112871879'
|
20
|
+
}
|
21
|
+
if (getType(adminID) === "Array") {
|
22
|
+
for (let i = 0; i < adminID.length; i++) {
|
23
|
+
wsContent.payload.tasks.push({
|
24
|
+
label: '25',
|
25
|
+
payload: JSON.stringify({ thread_key: threadID, contact_id: adminID[i], is_admin: adminStatus }),
|
26
|
+
queue_name: 'admin_status',
|
27
|
+
task_id: i + 1,
|
28
|
+
failure_count: null
|
29
|
+
});
|
30
|
+
}
|
31
|
+
} else {
|
32
|
+
wsContent.payload.tasks.push({
|
33
|
+
label: '25',
|
34
|
+
payload: JSON.stringify({ thread_key: threadID, contact_id: adminID, is_admin: adminStatus }),
|
35
|
+
queue_name: 'admin_status',
|
36
|
+
task_id: 1,
|
37
|
+
failure_count: null
|
11
38
|
});
|
12
39
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
40
|
+
wsContent.payload = JSON.stringify(wsContent.payload);
|
41
|
+
return new Promise((resolve, reject) => ctx.mqttClient && ctx.mqttClient.publish('/ls_req', JSON.stringify(wsContent), {}, (err, _packet) => err ? reject(err) : resolve()));
|
42
|
+
};
|
43
|
+
function changeAdminStatusMqtt(threadID, adminID, adminStatus) {
|
44
|
+
if (!ctx.mqttClient) {
|
45
|
+
throw new Error("Not connected to MQTT");
|
16
46
|
}
|
17
|
-
|
18
|
-
|
19
|
-
throw new utils.CustomError({
|
20
|
-
error: "changeAdminStatus: adminIDs must be an array or string"
|
21
|
-
});
|
47
|
+
if (getType(threadID) !== "String") {
|
48
|
+
throw { error: "changeAdminStatus: threadID must be a string" };
|
22
49
|
}
|
23
|
-
|
24
|
-
|
25
|
-
throw new utils.CustomError({
|
26
|
-
error: "changeAdminStatus: adminStatus must be a string"
|
27
|
-
});
|
50
|
+
if (getType(adminID) !== "String" && getType(adminID) !== "Array") {
|
51
|
+
throw { error: "changeAdminStatus: adminID must be a string or an array" };
|
28
52
|
}
|
29
|
-
|
30
|
-
|
31
|
-
let rejectFunc = function() {};
|
32
|
-
const returnPromise = new Promise(function(resolve, reject) {
|
33
|
-
resolveFunc = resolve;
|
34
|
-
rejectFunc = reject;
|
35
|
-
});
|
36
|
-
|
37
|
-
if (!callback) {
|
38
|
-
callback = function(err) {
|
39
|
-
if (err) {
|
40
|
-
return rejectFunc(err);
|
41
|
-
}
|
42
|
-
resolveFunc();
|
43
|
-
};
|
53
|
+
if (getType(adminStatus) !== "Boolean") {
|
54
|
+
throw { error: "changeAdminStatus: adminStatus must be true or false" };
|
44
55
|
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
const tasks = [];
|
57
|
+
const isAdmin = adminStatus ? 1 : 0;
|
58
|
+
const epochID = generateOfflineThreadingID();
|
59
|
+
if (getType(adminID) === "Array") {
|
60
|
+
adminID.forEach((id, index) => {
|
61
|
+
tasks.push({
|
62
|
+
failure_count: null,
|
63
|
+
label: "25",
|
64
|
+
payload: JSON.stringify({
|
65
|
+
thread_key: threadID,
|
66
|
+
contact_id: id,
|
67
|
+
is_admin: isAdmin
|
68
|
+
}),
|
69
|
+
queue_name: "admin_status",
|
70
|
+
task_id: index + 1
|
71
|
+
});
|
72
|
+
});
|
73
|
+
} else {
|
74
|
+
tasks.push({
|
75
|
+
failure_count: null,
|
76
|
+
label: "25",
|
77
|
+
payload: JSON.stringify({
|
78
|
+
thread_key: threadID,
|
79
|
+
contact_id: adminID,
|
80
|
+
is_admin: isAdmin
|
81
|
+
}),
|
82
|
+
queue_name: "admin_status",
|
83
|
+
task_id: 1
|
52
84
|
});
|
53
85
|
}
|
54
|
-
|
55
|
-
const form = {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
.then(function(resData) {
|
73
|
-
if (resData.error) {
|
74
|
-
switch (resData.error) {
|
75
|
-
case 1976004:
|
76
|
-
throw new utils.CustomError({
|
77
|
-
error: "Cannot alter admin status: you are not an admin.",
|
78
|
-
rawResponse: resData
|
79
|
-
});
|
80
|
-
case 1357031:
|
81
|
-
throw new utils.CustomError({
|
82
|
-
error:
|
83
|
-
"Cannot alter admin status: this thread is not a group chat.",
|
84
|
-
rawResponse: resData
|
85
|
-
});
|
86
|
-
default:
|
87
|
-
throw new utils.CustomError({
|
88
|
-
error: "Cannot alter admin status: unknown error.",
|
89
|
-
rawResponse: resData
|
90
|
-
});
|
86
|
+
let count_req = 0
|
87
|
+
const form = JSON.stringify({
|
88
|
+
app_id: "2220391788200892",
|
89
|
+
payload: JSON.stringify({
|
90
|
+
epoch_id: epochID,
|
91
|
+
tasks: tasks,
|
92
|
+
version_id: "8798795233522156"
|
93
|
+
}),
|
94
|
+
request_id: ++count_req,
|
95
|
+
type: 3
|
96
|
+
});
|
97
|
+
return new Promise((resolve, reject) => {
|
98
|
+
if (ctx.mqttClient) {
|
99
|
+
ctx.mqttClient.publish("/ls_req", form, {}, (err, _packet) => {
|
100
|
+
if (err) {
|
101
|
+
reject(err);
|
102
|
+
} else {
|
103
|
+
resolve();
|
91
104
|
}
|
92
|
-
}
|
93
|
-
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
105
|
+
});
|
106
|
+
} else {
|
107
|
+
reject(new Error("MQTT client is not available"));
|
108
|
+
}
|
109
|
+
});
|
110
|
+
};
|
111
|
+
return function changeAdminStatus(threadID, adminID, adminStatus) {
|
112
|
+
if (ctx.mqttClient) {
|
113
|
+
try {
|
114
|
+
changeAdminStatusMqtt(threadID, adminID, adminStatus);
|
115
|
+
} catch (e) {
|
116
|
+
changeAdminStatusNoMqtt(threadID, adminID, adminStatus);
|
117
|
+
}
|
118
|
+
} else {
|
119
|
+
changeAdminStatusNoMqtt(threadID, adminID, adminStatus);
|
120
|
+
}
|
102
121
|
};
|
103
122
|
};
|
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const utils = require("../../utils");
|
4
3
|
const log = require("npmlog");
|
5
|
-
|
4
|
+
const { formatID } = require("../../utils/format");
|
5
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
6
6
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function changeArchivedStatus(threadOrThreads, archive, callback) {
|
8
8
|
let resolveFunc = function() {};
|
@@ -23,12 +23,12 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
23
23
|
|
24
24
|
const form = {};
|
25
25
|
|
26
|
-
if (
|
26
|
+
if (Array.isArray(threadOrThreads)) {
|
27
27
|
for (let i = 0; i < threadOrThreads.length; i++) {
|
28
|
-
form["ids[" + threadOrThreads[i] + "]"] = archive;
|
28
|
+
form["ids[" + formatID(threadOrThreads[i]) + "]"] = archive;
|
29
29
|
}
|
30
30
|
} else {
|
31
|
-
form["ids[" + threadOrThreads + "]"] = archive;
|
31
|
+
form["ids[" + formatID(threadOrThreads) + "]"] = archive;
|
32
32
|
}
|
33
33
|
|
34
34
|
defaultFuncs
|
@@ -37,7 +37,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
37
37
|
ctx.jar,
|
38
38
|
form
|
39
39
|
)
|
40
|
-
.then(
|
40
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
41
41
|
.then(function(resData) {
|
42
42
|
if (resData.error) {
|
43
43
|
throw resData;
|
@@ -1,8 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const utils = require("../../utils");
|
4
3
|
const log = require("npmlog");
|
5
|
-
|
4
|
+
const { parseAndCheckLogin, saveCookies } = require("../../utils/client");
|
6
5
|
module.exports = function(defaultFuncs, api, ctx) {
|
7
6
|
return function changeBlockedStatus(userID, block, callback) {
|
8
7
|
let resolveFunc = function() {};
|
@@ -31,8 +30,8 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
31
30
|
fbid: userID
|
32
31
|
}
|
33
32
|
)
|
34
|
-
.then(
|
35
|
-
.then(
|
33
|
+
.then(saveCookies(ctx.jar))
|
34
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
36
35
|
.then(function(resData) {
|
37
36
|
if (resData.error) {
|
38
37
|
throw resData;
|
@@ -1,135 +1,90 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const
|
3
|
+
const { generateOfflineThreadingID } = require("../../utils/format.js");
|
4
4
|
const log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
7
|
-
function handleUpload(image
|
8
|
-
const uploads = [];
|
9
|
-
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
function handleUpload(image) {
|
10
8
|
const form = {
|
11
9
|
images_only: "true",
|
12
10
|
"attachment[]": image
|
13
11
|
};
|
14
|
-
|
15
|
-
|
16
|
-
defaultFuncs
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
form,
|
21
|
-
{}
|
22
|
-
)
|
23
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
24
|
-
.then(function(resData) {
|
25
|
-
if (resData.error) {
|
26
|
-
throw resData;
|
27
|
-
}
|
28
|
-
|
29
|
-
return resData.payload.metadata[0];
|
30
|
-
})
|
31
|
-
);
|
32
|
-
|
33
|
-
// resolve all promises
|
34
|
-
Promise.all(uploads)
|
35
|
-
.then(function(resData) {
|
36
|
-
callback(null, resData);
|
37
|
-
})
|
38
|
-
.catch(function(err) {
|
39
|
-
log.error("handleUpload", err);
|
40
|
-
return callback(err);
|
12
|
+
return defaultFuncs
|
13
|
+
.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
|
14
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
15
|
+
.then(resData => {
|
16
|
+
if (resData.error) throw resData;
|
17
|
+
return resData.payload.metadata[0];
|
41
18
|
});
|
42
19
|
}
|
43
|
-
|
44
20
|
return function changeGroupImage(image, threadID, callback) {
|
45
|
-
|
46
|
-
!
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if (err) {
|
67
|
-
return rejectFunc(err);
|
21
|
+
return new Promise((resolve, reject) => {
|
22
|
+
if (!ctx.mqttClient) {
|
23
|
+
const err = new Error("Not connected to MQTT");
|
24
|
+
callback?.(err);
|
25
|
+
return reject(err);
|
26
|
+
}
|
27
|
+
if (!threadID || typeof threadID !== "string") {
|
28
|
+
const err = new Error("Invalid threadID");
|
29
|
+
callback?.(err);
|
30
|
+
return reject(err);
|
31
|
+
}
|
32
|
+
const reqID = ++ctx.wsReqNumber;
|
33
|
+
const taskID = ++ctx.wsTaskNumber;
|
34
|
+
const onResponse = (topic, message) => {
|
35
|
+
if (topic !== "/ls_resp") return;
|
36
|
+
let jsonMsg;
|
37
|
+
try {
|
38
|
+
jsonMsg = JSON.parse(message.toString());
|
39
|
+
jsonMsg.payload = JSON.parse(jsonMsg.payload);
|
40
|
+
} catch (err) {
|
41
|
+
return;
|
68
42
|
}
|
69
|
-
|
43
|
+
if (jsonMsg.request_id !== reqID) return;
|
44
|
+
ctx.mqttClient.removeListener("message", onResponse);
|
45
|
+
callback?.(null, { success: true, response: jsonMsg.payload });
|
46
|
+
return resolve({ success: true, response: jsonMsg.payload });
|
70
47
|
};
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
if (err) {
|
105
|
-
return callback(err);
|
106
|
-
}
|
107
|
-
|
108
|
-
form["thread_image_id"] = payload[0]["image_id"];
|
109
|
-
form["thread_id"] = threadID;
|
110
|
-
|
111
|
-
defaultFuncs
|
112
|
-
.post(
|
113
|
-
"https://www.facebook.com/messaging/set_thread_image/",
|
114
|
-
ctx.jar,
|
115
|
-
form
|
116
|
-
)
|
117
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
118
|
-
.then(function(resData) {
|
119
|
-
// check for errors here
|
120
|
-
|
121
|
-
if (resData.error) {
|
122
|
-
throw resData;
|
123
|
-
}
|
124
|
-
|
125
|
-
return callback();
|
48
|
+
ctx.mqttClient.on("message", onResponse);
|
49
|
+
handleUpload(image)
|
50
|
+
.then(payload => {
|
51
|
+
const imageID = payload.image_id;
|
52
|
+
const taskPayload = {
|
53
|
+
thread_key: threadID,
|
54
|
+
image_id: imageID,
|
55
|
+
sync_group: 1
|
56
|
+
};
|
57
|
+
|
58
|
+
const mqttPayload = {
|
59
|
+
epoch_id: generateOfflineThreadingID(),
|
60
|
+
tasks: [
|
61
|
+
{
|
62
|
+
failure_count: null,
|
63
|
+
label: "37",
|
64
|
+
payload: JSON.stringify(taskPayload),
|
65
|
+
queue_name: "thread_image",
|
66
|
+
task_id: taskID
|
67
|
+
}
|
68
|
+
],
|
69
|
+
version_id: "8798795233522156"
|
70
|
+
};
|
71
|
+
const request = {
|
72
|
+
app_id: "2220391788200892",
|
73
|
+
payload: JSON.stringify(mqttPayload),
|
74
|
+
request_id: reqID,
|
75
|
+
type: 3
|
76
|
+
};
|
77
|
+
ctx.mqttClient.publish("/ls_req", JSON.stringify(request), {
|
78
|
+
qos: 1,
|
79
|
+
retain: false
|
80
|
+
});
|
126
81
|
})
|
127
|
-
.catch(
|
128
|
-
|
129
|
-
|
82
|
+
.catch(err => {
|
83
|
+
ctx.mqttClient.removeListener("message", onResponse);
|
84
|
+
log.error("changeGroupImageMqtt", err);
|
85
|
+
callback?.(err);
|
86
|
+
reject(err);
|
130
87
|
});
|
131
88
|
});
|
132
|
-
|
133
|
-
return returnPromise;
|
134
89
|
};
|
135
90
|
};
|
@@ -1,59 +1,70 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const
|
3
|
+
const { generateOfflineThreadingID } = require("../../utils/format.js");
|
4
4
|
const log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
7
|
return function changeNickname(nickname, threadID, participantID, callback) {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
return new Promise((resolve, reject) => {
|
9
|
+
if (!ctx.mqttClient) {
|
10
|
+
const err = new Error("Not connected to MQTT");
|
11
|
+
callback?.(err);
|
12
|
+
return reject(err);
|
13
|
+
}
|
14
|
+
if (!threadID || !participantID) {
|
15
|
+
const err = new Error("Missing required parameters");
|
16
|
+
callback?.(err);
|
17
|
+
return reject(err);
|
18
|
+
}
|
19
|
+
const reqID = ++ctx.wsReqNumber;
|
20
|
+
const taskID = ++ctx.wsTaskNumber;
|
21
|
+
const payload = {
|
22
|
+
epoch_id: generateOfflineThreadingID(),
|
23
|
+
tasks: [
|
24
|
+
{
|
25
|
+
failure_count: null,
|
26
|
+
label: "44",
|
27
|
+
payload: JSON.stringify({
|
28
|
+
thread_key: threadID,
|
29
|
+
contact_id: participantID,
|
30
|
+
nickname: nickname || "",
|
31
|
+
sync_group: 1
|
32
|
+
}),
|
33
|
+
queue_name: "thread_participant_nickname",
|
34
|
+
task_id: taskID
|
35
|
+
}
|
36
|
+
],
|
37
|
+
version_id: "8798795233522156"
|
20
38
|
};
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
-
.then(function(resData) {
|
37
|
-
if (resData.error === 1545014) {
|
38
|
-
throw { error: "Trying to change nickname of user isn't in thread" };
|
39
|
-
}
|
40
|
-
if (resData.error === 1357031) {
|
41
|
-
throw {
|
42
|
-
error:
|
43
|
-
"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."
|
44
|
-
};
|
39
|
+
const request = {
|
40
|
+
app_id: "2220391788200892",
|
41
|
+
payload: JSON.stringify(payload),
|
42
|
+
request_id: reqID,
|
43
|
+
type: 3
|
44
|
+
};
|
45
|
+
const onResponse = (topic, message) => {
|
46
|
+
if (topic !== "/ls_resp") return;
|
47
|
+
let jsonMsg;
|
48
|
+
try {
|
49
|
+
jsonMsg = JSON.parse(message.toString());
|
50
|
+
jsonMsg.payload = JSON.parse(jsonMsg.payload);
|
51
|
+
} catch (err) {
|
52
|
+
return;
|
45
53
|
}
|
46
|
-
if (
|
47
|
-
|
54
|
+
if (jsonMsg.request_id !== reqID) return;
|
55
|
+
ctx.mqttClient.removeListener("message", onResponse);
|
56
|
+
callback?.(null, { success: true, response: jsonMsg.payload });
|
57
|
+
return resolve({ success: true, response: jsonMsg.payload });
|
58
|
+
};
|
59
|
+
ctx.mqttClient.on("message", onResponse);
|
60
|
+
ctx.mqttClient.publish("/ls_req", JSON.stringify(request), { qos: 1, retain: false }, (err) => {
|
61
|
+
if (err) {
|
62
|
+
ctx.mqttClient.removeListener("message", onResponse);
|
63
|
+
log.error("changeNicknameMqtt", err);
|
64
|
+
callback?.(err);
|
65
|
+
return reject(err);
|
48
66
|
}
|
49
|
-
|
50
|
-
return callback();
|
51
|
-
})
|
52
|
-
.catch(function(err) {
|
53
|
-
log.error("changeNickname", err);
|
54
|
-
return callback(err);
|
55
67
|
});
|
56
|
-
|
57
|
-
return returnPromise;
|
68
|
+
});
|
58
69
|
};
|
59
70
|
};
|