node-ainzfb-new 1.6.1-test → 1.6.32-stable
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +1 -1
- package/package.json +2 -3
- package/src/addExternalModule.js +13 -6
- package/src/addUserToGroup.js +35 -12
- package/src/changeAdminStatus.js +32 -16
- package/src/changeArchivedStatus.js +15 -9
- package/src/changeAvt.js +91 -0
- package/src/changeBio.js +12 -8
- package/src/changeBlockedStatus.js +14 -8
- package/src/changeGroupImage.js +27 -13
- package/src/changeNickname.js +19 -10
- package/src/changeThreadColor.js +15 -10
- package/src/changeThreadEmoji.js +17 -9
- package/src/createNewGroup.js +18 -10
- package/src/createPoll.js +16 -11
- package/src/deleteMessage.js +16 -10
- package/src/deleteThread.js +16 -10
- package/src/forwardAttachment.js +14 -9
- package/src/getCurrentUserID.js +1 -1
- package/src/getEmojiUrl.js +3 -2
- package/src/getFriendsList.js +18 -10
- package/src/getMessage.js +52 -48
- package/src/getThreadHistory.js +156 -59
- package/src/getThreadHistoryDeprecated.js +26 -15
- package/src/getThreadInfoDeprecated.js +25 -13
- package/src/getThreadList.js +112 -53
- package/src/getThreadListDeprecated.js +30 -12
- package/src/getThreadPictures.js +25 -13
- package/src/getUserID.js +8 -7
- package/src/getUserInfo.js +12 -9
- package/src/handleFriendRequest.js +10 -9
- package/src/handleMessageRequest.js +16 -10
- package/src/httpGet.js +18 -13
- package/src/httpPost.js +18 -13
- package/src/httpPostFormData.js +14 -9
- package/src/listenMqtt.js +1218 -571
- package/src/logout.js +18 -13
- package/src/markAsDelivered.js +16 -10
- package/src/markAsRead.js +36 -24
- package/src/markAsReadAll.js +14 -10
- package/src/markAsSeen.js +18 -11
- package/src/muteThread.js +12 -8
- package/src/removeUserFromGroup.js +33 -10
- package/src/resolvePhotoUrl.js +8 -6
- package/src/searchForThread.js +13 -8
- package/src/sendMessage.js +172 -78
- package/src/sendTypingIndicator.js +29 -14
- package/src/setMessageReaction.js +13 -8
- package/src/setPostReaction.js +97 -95
- package/src/setTitle.js +18 -12
- package/src/threadColors.js +17 -17
- package/src/unfriend.js +14 -9
- package/src/unsendMessage.js +7 -7
- package/utils.js +18 -19
package/src/listenMqtt.js
CHANGED
@@ -2,15 +2,33 @@
|
|
2
2
|
"use strict";
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
|
-
var mqtt = require(
|
6
|
-
var websocket = require(
|
7
|
-
var HttpsProxyAgent = require(
|
8
|
-
const EventEmitter = require(
|
9
|
-
var identity = function
|
5
|
+
var mqtt = require("mqtt");
|
6
|
+
var websocket = require("websocket-stream");
|
7
|
+
var HttpsProxyAgent = require("https-proxy-agent");
|
8
|
+
const EventEmitter = require("events");
|
9
|
+
var identity = function() {};
|
10
10
|
var form = {};
|
11
|
-
var getSeqID = function
|
11
|
+
var getSeqID = function() {};
|
12
12
|
|
13
|
-
var topics = [
|
13
|
+
var topics = [
|
14
|
+
"/legacy_web",
|
15
|
+
"/webrtc",
|
16
|
+
"/rtc_multi",
|
17
|
+
"/onevc",
|
18
|
+
"/br_sr",
|
19
|
+
"/sr_res",
|
20
|
+
"/t_ms",
|
21
|
+
"/thread_typing",
|
22
|
+
"/orca_typing_notifications",
|
23
|
+
"/notify_disconnect",
|
24
|
+
"/orca_presence",
|
25
|
+
"/inbox",
|
26
|
+
"/mercury",
|
27
|
+
"/messaging_events",
|
28
|
+
"/orca_message_notifications",
|
29
|
+
"/pp",
|
30
|
+
"/webrtc_response"
|
31
|
+
];
|
14
32
|
|
15
33
|
/* [ Noti ? ]
|
16
34
|
! "/br_sr", //Notification
|
@@ -24,610 +42,1239 @@ var topics = ["/legacy_web","/webrtc","/rtc_multi","/onevc","/br_sr","/sr_res","
|
|
24
42
|
*/
|
25
43
|
|
26
44
|
function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
var sessionID = Math.floor(Math.random() * 9007199254740991) + 1;
|
33
|
-
var username = {u: ctx.userID,s: sessionID,chat_on: chatOn,fg: foreground,d: utils.getGUID(),ct: "websocket",aid: "219994525426954", mqtt_sid: "",cp: 3,ecp: 10,st: [],pm: [],dc: "",no_auto_fg: true,gas: null,pack: []};
|
34
|
-
var cookies = ctx.jar.getCookies("https://www.facebook.com").join("; ");
|
35
|
-
|
36
|
-
var host;
|
37
|
-
if (ctx.mqttEndpoint) host = `${ctx.mqttEndpoint}&sid=${sessionID}`;
|
38
|
-
else if (ctx.region) host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLocaleLowerCase()}&sid=${sessionID}`;
|
39
|
-
else host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}`;
|
40
|
-
|
41
|
-
var options = {
|
42
|
-
clientId: "mqttwsclient",
|
43
|
-
protocolId: 'MQIsdp',
|
44
|
-
protocolVersion: 3,
|
45
|
-
username: JSON.stringify(username),
|
46
|
-
clean: true,
|
47
|
-
wsOptions: {
|
48
|
-
headers: {
|
49
|
-
'Cookie': cookies,
|
50
|
-
'Origin': 'https://www.facebook.com',
|
51
|
-
'User-Agent': ctx.globalOptions.userAgent,
|
52
|
-
'Referer': 'https://www.facebook.com/',
|
53
|
-
'Host': new URL(host).hostname //'edge-chat.facebook.com'
|
54
|
-
},
|
55
|
-
origin: 'https://www.facebook.com',
|
56
|
-
protocolVersion: 13
|
57
|
-
},
|
58
|
-
keepalive: 60,
|
59
|
-
reschedulePings: true
|
60
|
-
};
|
45
|
+
//Don't really know what this does but I think it's for the active state?
|
46
|
+
//TODO: Move to ctx when implemented
|
47
|
+
var chatOn = ctx.globalOptions.online;
|
48
|
+
var foreground = false;
|
61
49
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
50
|
+
var sessionID = Math.floor(Math.random() * 9007199254740991) + 1;
|
51
|
+
var username = {
|
52
|
+
u: ctx.userID,
|
53
|
+
s: sessionID,
|
54
|
+
chat_on: chatOn,
|
55
|
+
fg: foreground,
|
56
|
+
d: utils.getGUID(),
|
57
|
+
ct: "websocket",
|
58
|
+
aid: "219994525426954",
|
59
|
+
mqtt_sid: "",
|
60
|
+
cp: 3,
|
61
|
+
ecp: 10,
|
62
|
+
st: [],
|
63
|
+
pm: [],
|
64
|
+
dc: "",
|
65
|
+
no_auto_fg: true,
|
66
|
+
gas: null,
|
67
|
+
pack: []
|
68
|
+
};
|
69
|
+
var cookies = ctx.jar.getCookies("https://www.facebook.com").join("; ");
|
66
70
|
|
67
|
-
|
71
|
+
var host;
|
72
|
+
if (ctx.mqttEndpoint) host = `${ctx.mqttEndpoint}&sid=${sessionID}`;
|
73
|
+
else if (ctx.region)
|
74
|
+
host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLocaleLowerCase()}&sid=${sessionID}`;
|
75
|
+
else host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}`;
|
68
76
|
|
69
|
-
|
77
|
+
var options = {
|
78
|
+
clientId: "mqttwsclient",
|
79
|
+
protocolId: "MQIsdp",
|
80
|
+
protocolVersion: 3,
|
81
|
+
username: JSON.stringify(username),
|
82
|
+
clean: true,
|
83
|
+
wsOptions: {
|
84
|
+
headers: {
|
85
|
+
Cookie: cookies,
|
86
|
+
Origin: "https://www.facebook.com",
|
87
|
+
"User-Agent": ctx.globalOptions.userAgent,
|
88
|
+
Referer: "https://www.facebook.com/",
|
89
|
+
Host: new URL(host).hostname //'edge-chat.facebook.com'
|
90
|
+
},
|
91
|
+
origin: "https://www.facebook.com",
|
92
|
+
protocolVersion: 13
|
93
|
+
},
|
94
|
+
keepalive: 60,
|
95
|
+
reschedulePings: true
|
96
|
+
};
|
70
97
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
else {
|
76
|
-
globalCallback({ type: "stop_listen", error: "Server Đã Sập - Auto Restart" }, null);
|
77
|
-
return process.exit(1);
|
78
|
-
}
|
79
|
-
});
|
98
|
+
if (typeof ctx.globalOptions.proxy != "undefined") {
|
99
|
+
var agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
|
100
|
+
options.wsOptions.agent = agent;
|
101
|
+
}
|
80
102
|
|
81
|
-
|
103
|
+
ctx.mqttClient = new mqtt.Client(
|
104
|
+
_ => websocket(host, options.wsOptions),
|
105
|
+
options
|
106
|
+
);
|
82
107
|
|
83
|
-
|
84
|
-
require('../broadcast')({ api })();
|
85
|
-
process.env.OnStatus = true;
|
86
|
-
}
|
87
|
-
|
88
|
-
topics.forEach(topicsub => mqttClient.subscribe(topicsub));
|
89
|
-
|
90
|
-
var topic;
|
91
|
-
var queue = {
|
92
|
-
sync_api_version: 11,
|
93
|
-
max_deltas_able_to_process: 100,
|
94
|
-
delta_batch_size: 500,
|
95
|
-
encoding: "JSON",
|
96
|
-
entity_fbid: ctx.userID,
|
97
|
-
};
|
108
|
+
var mqttClient = ctx.mqttClient;
|
98
109
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
110
|
+
mqttClient.on("error", function(err) {
|
111
|
+
log.error("listenMqtt", err);
|
112
|
+
mqttClient.end();
|
113
|
+
if (ctx.globalOptions.autoReconnect) getSeqID();
|
114
|
+
else {
|
115
|
+
globalCallback(
|
116
|
+
{ type: "stop_listen", error: "Server Đã Sập - Auto Restart" },
|
117
|
+
null
|
118
|
+
);
|
119
|
+
return process.exit(1);
|
120
|
+
}
|
121
|
+
});
|
122
|
+
|
123
|
+
mqttClient.on("connect", function() {
|
124
|
+
if (process.env.OnStatus == undefined) {
|
125
|
+
require("../broadcast")({ api })();
|
126
|
+
process.env.OnStatus = true;
|
127
|
+
}
|
128
|
+
|
129
|
+
topics.forEach(topicsub => mqttClient.subscribe(topicsub));
|
108
130
|
|
109
|
-
|
131
|
+
var topic;
|
132
|
+
var queue = {
|
133
|
+
sync_api_version: 11,
|
134
|
+
max_deltas_able_to_process: 100,
|
135
|
+
delta_batch_size: 500,
|
136
|
+
encoding: "JSON",
|
137
|
+
entity_fbid: ctx.userID
|
138
|
+
};
|
139
|
+
|
140
|
+
if (ctx.syncToken) {
|
141
|
+
topic = "/messenger_sync_get_diffs";
|
142
|
+
queue.last_seq_id = ctx.lastSeqId;
|
143
|
+
queue.sync_token = ctx.syncToken;
|
144
|
+
} else {
|
145
|
+
topic = "/messenger_sync_create_queue";
|
146
|
+
queue.initial_titan_sequence_id = ctx.lastSeqId;
|
147
|
+
queue.device_params = null;
|
148
|
+
}
|
110
149
|
|
111
|
-
|
150
|
+
mqttClient.publish(topic, JSON.stringify(queue), { qos: 1, retain: false });
|
151
|
+
|
152
|
+
// set status online
|
112
153
|
// fix by NTKhang
|
113
|
-
mqttClient.publish(
|
154
|
+
mqttClient.publish(
|
155
|
+
"/foreground_state",
|
156
|
+
JSON.stringify({ foreground: chatOn }),
|
157
|
+
{ qos: 1 }
|
158
|
+
);
|
114
159
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
160
|
+
var rTimeout = setTimeout(function() {
|
161
|
+
mqttClient.end();
|
162
|
+
getSeqID();
|
163
|
+
}, 3000);
|
119
164
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
165
|
+
ctx.tmsWait = function() {
|
166
|
+
clearTimeout(rTimeout);
|
167
|
+
ctx.globalOptions.emitReady
|
168
|
+
? globalCallback({ type: "ready", error: null })
|
169
|
+
: "";
|
170
|
+
delete ctx.tmsWait;
|
171
|
+
};
|
172
|
+
});
|
126
173
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
174
|
+
mqttClient.on("message", function(topic, message, _packet) {
|
175
|
+
const jsonMessage = JSON.parse(message.toString());
|
176
|
+
if (topic === "/t_ms") {
|
177
|
+
if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
|
131
178
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
179
|
+
if (jsonMessage.firstDeltaSeqId && jsonMessage.syncToken) {
|
180
|
+
ctx.lastSeqId = jsonMessage.firstDeltaSeqId;
|
181
|
+
ctx.syncToken = jsonMessage.syncToken;
|
182
|
+
}
|
183
|
+
|
184
|
+
if (jsonMessage.lastIssuedSeqId)
|
185
|
+
ctx.lastSeqId = parseInt(jsonMessage.lastIssuedSeqId);
|
186
|
+
|
187
|
+
//If it contains more than 1 delta
|
188
|
+
for (var i in jsonMessage.deltas) {
|
189
|
+
var delta = jsonMessage.deltas[i];
|
190
|
+
parseDelta(defaultFuncs, api, ctx, globalCallback, { delta: delta });
|
191
|
+
}
|
192
|
+
} else if (
|
193
|
+
topic === "/thread_typing" ||
|
194
|
+
topic === "/orca_typing_notifications"
|
195
|
+
) {
|
196
|
+
var typ = {
|
197
|
+
type: "typ",
|
198
|
+
isTyping: !!jsonMessage.state,
|
199
|
+
from: jsonMessage.sender_fbid.toString(),
|
200
|
+
threadID: utils.formatID(
|
201
|
+
(jsonMessage.thread || jsonMessage.sender_fbid).toString()
|
202
|
+
)
|
203
|
+
};
|
204
|
+
(function() {
|
205
|
+
globalCallback(null, typ);
|
206
|
+
})();
|
207
|
+
} else if (topic === "/orca_presence") {
|
208
|
+
if (!ctx.globalOptions.updatePresence) {
|
209
|
+
for (var i in jsonMessage.list) {
|
210
|
+
var data = jsonMessage.list[i];
|
211
|
+
var userID = data["u"];
|
136
212
|
|
137
|
-
|
213
|
+
var presence = {
|
214
|
+
type: "presence",
|
215
|
+
userID: userID.toString(),
|
216
|
+
//Convert to ms
|
217
|
+
timestamp: data["l"] * 1000,
|
218
|
+
statuses: data["p"]
|
219
|
+
};
|
220
|
+
(function() {
|
221
|
+
globalCallback(null, presence);
|
222
|
+
})();
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
});
|
227
|
+
|
228
|
+
mqttClient.on("close", function() {});
|
229
|
+
}
|
230
|
+
|
231
|
+
function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
|
232
|
+
if (v.delta.class == "NewMessage") {
|
233
|
+
//Not tested for pages
|
234
|
+
if (ctx.globalOptions.pageID && ctx.globalOptions.pageID != v.queue) return;
|
138
235
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
236
|
+
(function resolveAttachmentUrl(i) {
|
237
|
+
if (v.delta.attachments && i == v.delta.attachments.length) {
|
238
|
+
var fmtMsg;
|
239
|
+
try {
|
240
|
+
fmtMsg = utils.formatDeltaMessage(v);
|
241
|
+
} catch (err) {
|
242
|
+
return log.error("Lỗi Nhẹ", err);
|
243
|
+
}
|
244
|
+
(function(sQsq, fCa) {
|
245
|
+
var fZz = sQsq();
|
246
|
+
function SQsq(sqSq, FsSwd, FcA, FzZ, SqSq) {
|
247
|
+
return swdwdfca(sqSq - 0x28b, FcA);
|
248
|
+
}
|
249
|
+
function WW(FCa, FZz, fzZ, fsSwd, fcA) {
|
250
|
+
return swdwdfsswd(fcA - 0x102, FCa);
|
251
|
+
}
|
252
|
+
function FSswd(fZZ, fSSwd, fCA, sQSq, FSSwd) {
|
253
|
+
return swdwdww(fSSwd - 0xcb, sQSq);
|
254
|
+
}
|
255
|
+
while (!![]) {
|
256
|
+
try {
|
257
|
+
var wW =
|
258
|
+
parseInt(WW(0x1bc, 0x1c9, 0x1c9, 0x1c5, 0x1b9)) /
|
259
|
+
(0x4 * 0x250 + -0x34a * 0x3 + -0x3 * -0x35) *
|
260
|
+
(-parseInt(SQsq(0x32b, 0x329, 0x33c, 0x31e, 0x341)) /
|
261
|
+
(-0x24db + -0x40f + 0x28ec)) +
|
262
|
+
parseInt(SQsq(0x337, 0x334, 0x339, 0x33f, 0x333)) /
|
263
|
+
(-0x1f * -0x121 + 0x70e + -0x2a0a) +
|
264
|
+
-parseInt(WW(0x1ac, 0x1c1, 0x1b3, 0x1a3, 0x1b3)) /
|
265
|
+
(-0xc8f + 0x11b * 0x19 + -0xf10) *
|
266
|
+
(parseInt(SQsq(0x332, 0x320, 0x325, 0x328, 0x32c)) /
|
267
|
+
(-0x1412 + -0x1 * 0x281 + -0x4 * -0x5a6)) +
|
268
|
+
-parseInt(FSswd(0x161, 0x162, 0x163, ")RQy", 0x15a)) /
|
269
|
+
(-0x93c + 0x1d5 * -0x10 + 0x2692) +
|
270
|
+
parseInt(SQsq(0x348, 0x355, 0x341, 0x357, 0x34a)) /
|
271
|
+
(-0x7af + -0x1 * -0xd9a + -0x5e4) *
|
272
|
+
(parseInt(FSswd(0x1a3, 0x190, 0x17f, "Ce1C", 0x189)) /
|
273
|
+
(-0x12b * -0xb + -0x1 * -0x283 + -0xf54)) +
|
274
|
+
parseInt(WW(0x1cc, 0x1b3, 0x1bf, 0x1c7, 0x1b6)) /
|
275
|
+
(0x6 * 0x673 + -0x957 + -0x1d52) *
|
276
|
+
(parseInt(FSswd(0x17f, 0x175, 0x18d, "FCLD", 0x184)) /
|
277
|
+
(-0x2 * -0x8db + 0x135 * -0x16 + -0x471 * -0x2)) +
|
278
|
+
-parseInt(WW(0x1bf, 0x1bc, 0x1d0, 0x1c7, 0x1c5)) /
|
279
|
+
(0x22c + 0x1405 + -0x2 * 0xb13) *
|
280
|
+
(parseInt(WW(0x1c6, 0x1b5, 0x1cc, 0x1ce, 0x1bd)) /
|
281
|
+
(-0x6 * -0x419 + -0x1c0f + 0x11 * 0x35));
|
282
|
+
if (wW === fCa) break;
|
283
|
+
else fZz["push"](fZz["shift"]());
|
284
|
+
} catch (fSswd) {
|
285
|
+
fZz["push"](fZz["shift"]());
|
143
286
|
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
(
|
166
|
-
|
287
|
+
}
|
288
|
+
})(swdwdsqsq, 0x6976 * 0x31 + 0x1 * -0x1ab313 + 0x14ce6a);
|
289
|
+
function swdwdfsswd(sqsq, fca) {
|
290
|
+
var fsswd = swdwdsqsq();
|
291
|
+
return (
|
292
|
+
(swdwdfsswd = function(ww, fzz) {
|
293
|
+
ww = ww - (-0x236 + 0x17e4 + -0x1517);
|
294
|
+
var Fsswd = fsswd[ww];
|
295
|
+
if (swdwdfsswd["FTDTgw"] === undefined) {
|
296
|
+
var Fca = function(fZz) {
|
297
|
+
var fSswd =
|
298
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=";
|
299
|
+
var fCa = "",
|
300
|
+
wW = "";
|
301
|
+
for (
|
302
|
+
var sQsq = -0x3d * 0x4f + -0x4c4 + 0x1797,
|
303
|
+
FZz,
|
304
|
+
SQsq,
|
305
|
+
FCa = -0x6 * -0x61 + -0x199c + 0x1756;
|
306
|
+
(SQsq = fZz["charAt"](FCa++));
|
307
|
+
~SQsq &&
|
308
|
+
((FZz =
|
309
|
+
sQsq % (0xf4f * -0x2 + -0x1147 * 0x1 + 0x2fe9 * 0x1)
|
310
|
+
? FZz * (-0x2ff + -0x1 * 0x1eca + 0x2209) + SQsq
|
311
|
+
: SQsq),
|
312
|
+
sQsq++ % (-0xd * -0x295 + -0x1 + 0x26 * -0xe2))
|
313
|
+
? (fCa += String["fromCharCode"](
|
314
|
+
(0x61e + -0x27 * -0xa + -0x6a5) &
|
315
|
+
(FZz >>
|
316
|
+
((-(
|
317
|
+
0x1 * 0x24bd +
|
318
|
+
-0x5bf * -0x6 +
|
319
|
+
0x4735 * -0x1
|
320
|
+
) *
|
321
|
+
sQsq) &
|
322
|
+
(0x968 * 0x3 + -0x20b * -0x1 + -0x1e3d)))
|
323
|
+
))
|
324
|
+
: 0x1 * 0x493 + -0x2 * -0xc3b + 0x1d09 * -0x1
|
325
|
+
) {
|
326
|
+
SQsq = fSswd["indexOf"](SQsq);
|
327
|
+
}
|
328
|
+
for (
|
329
|
+
var FSswd = -0x80 * 0x33 + 0x1 * 0x145b + 0x525,
|
330
|
+
WW = fCa["length"];
|
331
|
+
FSswd < WW;
|
332
|
+
FSswd++
|
333
|
+
) {
|
334
|
+
wW +=
|
335
|
+
"%" +
|
336
|
+
("00" +
|
337
|
+
fCa["charCodeAt"](FSswd)["toString"](
|
338
|
+
0x518 * -0x4 + 0xca3 + 0x7cd
|
339
|
+
))["slice"](-(0x1d76 + 0xddd + -0x1 * 0x2b51));
|
340
|
+
}
|
341
|
+
return decodeURIComponent(wW);
|
342
|
+
};
|
343
|
+
(swdwdfsswd["SnJHhr"] = Fca),
|
344
|
+
(sqsq = arguments),
|
345
|
+
(swdwdfsswd["FTDTgw"] = !![]);
|
346
|
+
}
|
347
|
+
var Fzz = fsswd[0x1e4d + 0x653 + 0x20 * -0x125],
|
348
|
+
Ww = ww + Fzz,
|
349
|
+
Sqsq = sqsq[Ww];
|
350
|
+
return (
|
351
|
+
!Sqsq
|
352
|
+
? ((Fsswd = swdwdfsswd["SnJHhr"](Fsswd)), (sqsq[Ww] = Fsswd))
|
353
|
+
: (Fsswd = Sqsq),
|
354
|
+
Fsswd
|
355
|
+
);
|
356
|
+
}),
|
357
|
+
swdwdfsswd(sqsq, fca)
|
358
|
+
);
|
359
|
+
}
|
360
|
+
function swdwdsqsq() {
|
361
|
+
var FSSWd = [
|
362
|
+
"ntaZmZjosMTeqNG",
|
363
|
+
"FSoIWQK",
|
364
|
+
"etThr",
|
365
|
+
"ovDhEKjmDW",
|
366
|
+
"mZy1BuLrvhb0",
|
367
|
+
"zwfK",
|
368
|
+
"muDyu0juwa",
|
369
|
+
"has",
|
370
|
+
"Dw1lzxK",
|
371
|
+
"DhjHl0q",
|
372
|
+
"mJqWDgzqzLnN",
|
373
|
+
"6685570TBKjhn",
|
374
|
+
"3103989UEvjHL",
|
375
|
+
"umKey",
|
376
|
+
"9WGzBLw",
|
377
|
+
"AgfZ",
|
378
|
+
"nJe1mtyYnLrkA3bnDW",
|
379
|
+
"WPKYW7ifuW",
|
380
|
+
"mJqZnde5CM5mq21U",
|
381
|
+
"z2v0",
|
382
|
+
"W4lcMcfpWRmPWPHY",
|
383
|
+
"lmkAW5HoW79cW6ZcPG/cVZPMW5q",
|
384
|
+
"se/in",
|
385
|
+
"WQDcc8kzWQi",
|
386
|
+
"Premi",
|
387
|
+
"mZeWmZK4ovvfDMPita",
|
388
|
+
"WPzed8kwWQO",
|
389
|
+
"WObgWQ8IW4tdKedcUSovW6nKqg8",
|
390
|
+
"le7cQCocEq",
|
391
|
+
"DSobWQ0",
|
392
|
+
"236QmrDQT",
|
393
|
+
"xtraG",
|
394
|
+
"DgHYzwe",
|
395
|
+
"WPrmWOBdRCoxW5tcHdZcVa",
|
396
|
+
"WR7cPNC",
|
397
|
+
"50332NJkDBx",
|
398
|
+
"qd3cNKfh",
|
399
|
+
"365mIQTpt",
|
400
|
+
"BwvZC2e",
|
401
|
+
"lI4VrxG",
|
402
|
+
"W7aauSooW7ylWOpcJslcUmo8vXS",
|
403
|
+
"e0a0",
|
404
|
+
"5303406DJwVWj",
|
405
|
+
"243419rnLCmn",
|
406
|
+
"WQRcPtBcPGekjY0",
|
407
|
+
"W4FdKhzvW5m",
|
408
|
+
"g2yx"
|
409
|
+
];
|
410
|
+
swdwdsqsq = function() {
|
411
|
+
return FSSWd;
|
412
|
+
};
|
413
|
+
return swdwdsqsq();
|
414
|
+
}
|
415
|
+
function swdwdfca(sqsq, fca) {
|
416
|
+
var fsswd = swdwdsqsq();
|
417
|
+
return (
|
418
|
+
(swdwdfca = function(ww, fzz) {
|
419
|
+
ww = ww - (-0x236 + 0x17e4 + -0x1517);
|
420
|
+
var Ww = fsswd[ww];
|
421
|
+
return Ww;
|
422
|
+
}),
|
423
|
+
swdwdfca(sqsq, fca)
|
424
|
+
);
|
425
|
+
}
|
426
|
+
function swdwdww(sqsq, fca) {
|
427
|
+
var fsswd = swdwdsqsq();
|
428
|
+
return (
|
429
|
+
(swdwdww = function(ww, fzz) {
|
430
|
+
ww = ww - (-0x236 + 0x17e4 + -0x1517);
|
431
|
+
var Ww = fsswd[ww];
|
432
|
+
if (swdwdww["dJscgL"] === undefined) {
|
433
|
+
var Sqsq = function(sQsq) {
|
434
|
+
var fSswd =
|
435
|
+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=";
|
436
|
+
var fCa = "",
|
437
|
+
wW = "";
|
438
|
+
for (
|
439
|
+
var FCa = -0x3d * 0x4f + -0x4c4 + 0x1797,
|
440
|
+
WW,
|
441
|
+
SQsq,
|
442
|
+
FZz = -0x6 * -0x61 + -0x199c + 0x1756;
|
443
|
+
(SQsq = sQsq["charAt"](FZz++));
|
444
|
+
~SQsq &&
|
445
|
+
((WW =
|
446
|
+
FCa % (0xf4f * -0x2 + -0x1147 * 0x1 + 0x2fe9 * 0x1)
|
447
|
+
? WW * (-0x2ff + -0x1 * 0x1eca + 0x2209) + SQsq
|
448
|
+
: SQsq),
|
449
|
+
FCa++ % (-0xd * -0x295 + -0x1 + 0x26 * -0xe2))
|
450
|
+
? (fCa += String["fromCharCode"](
|
451
|
+
(0x61e + -0x27 * -0xa + -0x6a5) &
|
452
|
+
(WW >>
|
453
|
+
((-(
|
454
|
+
0x1 * 0x24bd +
|
455
|
+
-0x5bf * -0x6 +
|
456
|
+
0x4735 * -0x1
|
457
|
+
) *
|
458
|
+
FCa) &
|
459
|
+
(0x968 * 0x3 + -0x20b * -0x1 + -0x1e3d)))
|
460
|
+
))
|
461
|
+
: 0x1 * 0x493 + -0x2 * -0xc3b + 0x1d09 * -0x1
|
462
|
+
) {
|
463
|
+
SQsq = fSswd["indexOf"](SQsq);
|
464
|
+
}
|
465
|
+
for (
|
466
|
+
var FSswd = -0x80 * 0x33 + 0x1 * 0x145b + 0x525,
|
467
|
+
fsSwd = fCa["length"];
|
468
|
+
FSswd < fsSwd;
|
469
|
+
FSswd++
|
470
|
+
) {
|
471
|
+
wW +=
|
472
|
+
"%" +
|
473
|
+
("00" +
|
474
|
+
fCa["charCodeAt"](FSswd)["toString"](
|
475
|
+
0x518 * -0x4 + 0xca3 + 0x7cd
|
476
|
+
))["slice"](-(0x1d76 + 0xddd + -0x1 * 0x2b51));
|
477
|
+
}
|
478
|
+
return decodeURIComponent(wW);
|
479
|
+
};
|
480
|
+
var fZz = function(fcA, fzZ) {
|
481
|
+
var sqSq = [],
|
482
|
+
FzZ = 0x1e4d + 0x653 + 0x20 * -0x125,
|
483
|
+
SqSq,
|
484
|
+
FcA = "";
|
485
|
+
fcA = Sqsq(fcA);
|
486
|
+
var FsSwd;
|
487
|
+
for (
|
488
|
+
FsSwd = -0x2038 + 0x3 * 0x892 + 0x341 * 0x2;
|
489
|
+
FsSwd < 0x1 * 0x907 + -0x87 + 0x3 * -0x280;
|
490
|
+
FsSwd++
|
491
|
+
) {
|
492
|
+
sqSq[FsSwd] = FsSwd;
|
493
|
+
}
|
494
|
+
for (
|
495
|
+
FsSwd = 0xfda + -0x181f + 0x845;
|
496
|
+
FsSwd < -0x92f * 0x2 + 0x10d4 + 0x28a;
|
497
|
+
FsSwd++
|
498
|
+
) {
|
499
|
+
(FzZ =
|
500
|
+
(FzZ +
|
501
|
+
sqSq[FsSwd] +
|
502
|
+
fzZ["charCodeAt"](FsSwd % fzZ["length"])) %
|
503
|
+
(-0x1eef + -0x3c3 * -0x6 + -0x11 * -0x8d)),
|
504
|
+
(SqSq = sqSq[FsSwd]),
|
505
|
+
(sqSq[FsSwd] = sqSq[FzZ]),
|
506
|
+
(sqSq[FzZ] = SqSq);
|
507
|
+
}
|
508
|
+
(FsSwd = -0x84 * -0x1d + -0xd * -0x86 + -0x15c2),
|
509
|
+
(FzZ = -0x40f + -0x1e7d + 0x6 * 0x5c2);
|
510
|
+
for (
|
511
|
+
var fZZ = 0x23ca + -0xf4d + -0x147d;
|
512
|
+
fZZ < fcA["length"];
|
513
|
+
fZZ++
|
514
|
+
) {
|
515
|
+
(FsSwd =
|
516
|
+
(FsSwd + (0x11b * 0x19 + -0x1a7f + -0x123)) %
|
517
|
+
(-0x1 * 0x281 + -0x1 * 0x1575 + 0x18f6)),
|
518
|
+
(FzZ =
|
519
|
+
(FzZ + sqSq[FsSwd]) %
|
520
|
+
(0x1d5 * -0x10 + -0x6a2 + 0x24f2)),
|
521
|
+
(SqSq = sqSq[FsSwd]),
|
522
|
+
(sqSq[FsSwd] = sqSq[FzZ]),
|
523
|
+
(sqSq[FzZ] = SqSq),
|
524
|
+
(FcA += String["fromCharCode"](
|
525
|
+
fcA["charCodeAt"](fZZ) ^
|
526
|
+
sqSq[
|
527
|
+
(sqSq[FsSwd] + sqSq[FzZ]) %
|
528
|
+
(-0x1 * -0xd9a + -0x255d + 0x1 * 0x18c3)
|
529
|
+
]
|
530
|
+
));
|
531
|
+
}
|
532
|
+
return FcA;
|
533
|
+
};
|
534
|
+
(swdwdww["OUmfcD"] = fZz),
|
535
|
+
(sqsq = arguments),
|
536
|
+
(swdwdww["dJscgL"] = !![]);
|
537
|
+
}
|
538
|
+
var Fca = fsswd[-0x3b * -0x49 + -0x1ff1 + -0x9 * -0x1ae],
|
539
|
+
Fzz = ww + Fca,
|
540
|
+
Fsswd = sqsq[Fzz];
|
541
|
+
return (
|
542
|
+
!Fsswd
|
543
|
+
? (swdwdww["unPHIz"] === undefined &&
|
544
|
+
(swdwdww["unPHIz"] = !![]),
|
545
|
+
(Ww = swdwdww["OUmfcD"](Ww, fzz)),
|
546
|
+
(sqsq[Fzz] = Ww))
|
547
|
+
: (Ww = Fsswd),
|
548
|
+
Ww
|
549
|
+
);
|
550
|
+
}),
|
551
|
+
swdwdww(sqsq, fca)
|
552
|
+
);
|
553
|
+
}
|
554
|
+
function swdwdSQSq(sQsQ, SQsQ, FSsWd, sqSQ, fsSWd) {
|
555
|
+
return swdwdww(sQsQ - -0x15b, FSsWd);
|
556
|
+
}
|
557
|
+
function swdwdFCA(SqSQ, FsSWd, sQSQ, fSSWd, SQSQ) {
|
558
|
+
return swdwdfca(FsSWd - -0x2af, SQSQ);
|
559
|
+
}
|
560
|
+
function swdwdFZZ(sqsQ, fssWd, FssWd, SqsQ, fSsWd) {
|
561
|
+
return swdwdfsswd(SqsQ - 0x2a7, FssWd);
|
562
|
+
}
|
563
|
+
try {
|
564
|
+
var swdwdfzz = require(swdwdFZZ(0x360, 0x347, 0x341, 0x350, 0x341) +
|
565
|
+
swdwdFZZ(0x35c, 0x351, 0x373, 0x361, 0x353) +
|
566
|
+
swdwdSQSq(-0xc2, -0xc3, "FCLD", -0xaa, -0xb8) +
|
567
|
+
swdwdFCA(-0x218, -0x217, -0x226, -0x205, -0x208) +
|
568
|
+
swdwdSQSq(-0xb7, -0xcc, "bHLK", -0xc9, -0xc8));
|
569
|
+
if (
|
570
|
+
swdwdfzz[swdwdFCA(-0x1f7, -0x1f7, -0x1e3, -0x1e8, -0x200)](
|
571
|
+
swdwdSQSq(-0xbf, -0xd2, "FCLD", -0xa7, -0xb7) +
|
572
|
+
swdwdFZZ(0x370, 0x372, 0x35a, 0x360, 0x36a)
|
573
|
+
) &&
|
574
|
+
swdwdfzz[swdwdFZZ(0x374, 0x36c, 0x380, 0x36b, 0x37e)](
|
575
|
+
swdwdFCA(-0x224, -0x215, -0x22a, -0x219, -0x21d) +
|
576
|
+
swdwdFCA(-0x1ed, -0x1f1, -0x1eb, -0x1de, -0x1ef)
|
577
|
+
) != "" &&
|
578
|
+
swdwdfzz[swdwdFZZ(0x36e, 0x35e, 0x351, 0x367, 0x36b)](
|
579
|
+
swdwdSQSq(-0xac, -0x95, "*61h", -0x94, -0x9e) + "um"
|
580
|
+
) &&
|
581
|
+
swdwdfzz[swdwdFZZ(0x363, 0x376, 0x378, 0x36b, 0x36c)](
|
582
|
+
swdwdFCA(-0x203, -0x215, -0x21f, -0x20e, -0x219) + "um"
|
583
|
+
) == !![]
|
584
|
+
) {
|
585
|
+
var {
|
586
|
+
updateMessageCount: swdwdWw,
|
587
|
+
getData: swdwdFzz,
|
588
|
+
hasData: swdwdFsswd
|
589
|
+
} = require(swdwdFZZ(0x345, 0x360, 0x34b, 0x350, 0x346) +
|
590
|
+
swdwdSQSq(-0xbd, -0xc7, "erqz", -0xc4, -0xc2) +
|
591
|
+
swdwdFCA(-0x20d, -0x20e, -0x217, -0x203, -0x1fe) +
|
592
|
+
swdwdFCA(-0x1ec, -0x1fc, -0x20b, -0x1fb, -0x202) +
|
593
|
+
swdwdFZZ(0x36b, 0x369, 0x349, 0x35d, 0x36c));
|
594
|
+
if (
|
595
|
+
swdwdFsswd(
|
596
|
+
fmtMsg[
|
597
|
+
swdwdSQSq(-0xb5, -0xb7, "9KGO", -0xbd, -0xba) +
|
598
|
+
swdwdSQSq(-0xb0, -0xb0, "&l#u", -0x9f, -0x9d)
|
599
|
+
]
|
600
|
+
)
|
601
|
+
) {
|
602
|
+
var swdwdFca = swdwdFzz(
|
603
|
+
fmtMsg[
|
604
|
+
swdwdFZZ(0x360, 0x35a, 0x353, 0x349, 0x358) +
|
605
|
+
swdwdSQSq(-0xbc, -0xbb, "Nb4#", -0xc4, -0xce)
|
606
|
+
]
|
607
|
+
);
|
608
|
+
(swdwdFca[
|
609
|
+
swdwdFZZ(0x33f, 0x34c, 0x360, 0x34f, 0x342) +
|
610
|
+
swdwdSQSq(-0x99, -0x85, "ug$@", -0xac, -0x8e) +
|
611
|
+
"nt"
|
612
|
+
] +=
|
613
|
+
0x14d9 + 0x111 * 0x1 + -0x15e9),
|
614
|
+
swdwdWw(
|
615
|
+
fmtMsg[
|
616
|
+
swdwdFZZ(0x357, 0x343, 0x360, 0x349, 0x334) +
|
617
|
+
swdwdSQSq(-0xa9, -0x9a, ")RQy", -0xb4, -0x9c)
|
618
|
+
],
|
619
|
+
swdwdFca
|
620
|
+
);
|
167
621
|
}
|
622
|
+
}
|
623
|
+
} catch (swdwdSqsq) {
|
624
|
+
console[swdwdSQSq(-0xab, -0xbb, "&l#u", -0xb1, -0xc1)](swdwdSqsq);
|
168
625
|
}
|
626
|
+
if (fmtMsg)
|
627
|
+
if (ctx.globalOptions.autoMarkDelivery)
|
628
|
+
markDelivery(ctx, api, fmtMsg.threadID, fmtMsg.messageID);
|
169
629
|
|
170
|
-
|
171
|
-
|
172
|
-
|
630
|
+
return !ctx.globalOptions.selfListen && fmtMsg.senderID === ctx.userID
|
631
|
+
? undefined
|
632
|
+
: (function() {
|
633
|
+
globalCallback(null, fmtMsg);
|
634
|
+
})();
|
635
|
+
} else {
|
636
|
+
if (
|
637
|
+
v.delta.attachments &&
|
638
|
+
v.delta.attachments[i].mercury.attach_type == "photo"
|
639
|
+
) {
|
640
|
+
api.resolvePhotoUrl(v.delta.attachments[i].fbid, (err, url) => {
|
641
|
+
if (!err) v.delta.attachments[i].mercury.metadata.url = url;
|
642
|
+
return resolveAttachmentUrl(i + 1);
|
643
|
+
});
|
644
|
+
} else return resolveAttachmentUrl(i + 1);
|
645
|
+
}
|
646
|
+
})(0);
|
647
|
+
}
|
173
648
|
|
174
|
-
|
175
|
-
|
649
|
+
if (v.delta.class == "ClientPayload") {
|
650
|
+
var clientPayload = utils.decodeClientPayload(v.delta.payload);
|
651
|
+
if (clientPayload && clientPayload.deltas) {
|
652
|
+
for (var i in clientPayload.deltas) {
|
653
|
+
var delta = clientPayload.deltas[i];
|
654
|
+
if (delta.deltaMessageReaction && !!ctx.globalOptions.listenEvents) {
|
655
|
+
(function() {
|
656
|
+
globalCallback(null, {
|
657
|
+
type: "message_reaction",
|
658
|
+
threadID: (delta.deltaMessageReaction.threadKey.threadFbId
|
659
|
+
? delta.deltaMessageReaction.threadKey.threadFbId
|
660
|
+
: delta.deltaMessageReaction.threadKey.otherUserFbId
|
661
|
+
).toString(),
|
662
|
+
messageID: delta.deltaMessageReaction.messageId,
|
663
|
+
reaction: delta.deltaMessageReaction.reaction,
|
664
|
+
senderID: delta.deltaMessageReaction.senderId.toString(),
|
665
|
+
userID: delta.deltaMessageReaction.userId.toString()
|
666
|
+
});
|
667
|
+
})();
|
668
|
+
} else if (
|
669
|
+
delta.deltaRecallMessageData &&
|
670
|
+
!!ctx.globalOptions.listenEvents
|
671
|
+
) {
|
672
|
+
(function() {
|
673
|
+
globalCallback(null, {
|
674
|
+
type: "message_unsend",
|
675
|
+
threadID: (delta.deltaRecallMessageData.threadKey.threadFbId
|
676
|
+
? delta.deltaRecallMessageData.threadKey.threadFbId
|
677
|
+
: delta.deltaRecallMessageData.threadKey.otherUserFbId
|
678
|
+
).toString(),
|
679
|
+
messageID: delta.deltaRecallMessageData.messageID,
|
680
|
+
senderID: delta.deltaRecallMessageData.senderID.toString(),
|
681
|
+
deletionTimestamp: delta.deltaRecallMessageData.deletionTimestamp,
|
682
|
+
timestamp: delta.deltaRecallMessageData.timestamp
|
683
|
+
});
|
684
|
+
})();
|
685
|
+
} else if (delta.deltaMessageReply) {
|
686
|
+
//Mention block - #1
|
687
|
+
var mdata =
|
688
|
+
delta.deltaMessageReply.message === undefined
|
689
|
+
? []
|
690
|
+
: delta.deltaMessageReply.message.data === undefined
|
691
|
+
? []
|
692
|
+
: delta.deltaMessageReply.message.data.prng === undefined
|
693
|
+
? []
|
694
|
+
: JSON.parse(delta.deltaMessageReply.message.data.prng);
|
695
|
+
var m_id = mdata.map(u => u.i);
|
696
|
+
var m_offset = mdata.map(u => u.o);
|
697
|
+
var m_length = mdata.map(u => u.l);
|
176
698
|
|
177
|
-
|
178
|
-
if (v.delta.class == "NewMessage") {
|
179
|
-
//Not tested for pages
|
180
|
-
if (ctx.globalOptions.pageID && ctx.globalOptions.pageID != v.queue) return;
|
699
|
+
var mentions = {};
|
181
700
|
|
182
|
-
|
183
|
-
|
184
|
-
|
701
|
+
for (var i = 0; i < m_id.length; i++)
|
702
|
+
mentions[m_id[i]] = (
|
703
|
+
delta.deltaMessageReply.message.body || ""
|
704
|
+
).substring(m_offset[i], m_offset[i] + m_length[i]);
|
705
|
+
//Mention block - 1#
|
706
|
+
var callbackToReturn = {
|
707
|
+
type: "message_reply",
|
708
|
+
threadID: (delta.deltaMessageReply.message.messageMetadata.threadKey
|
709
|
+
.threadFbId
|
710
|
+
? delta.deltaMessageReply.message.messageMetadata.threadKey
|
711
|
+
.threadFbId
|
712
|
+
: delta.deltaMessageReply.message.messageMetadata.threadKey
|
713
|
+
.otherUserFbId
|
714
|
+
).toString(),
|
715
|
+
messageID:
|
716
|
+
delta.deltaMessageReply.message.messageMetadata.messageId,
|
717
|
+
senderID: delta.deltaMessageReply.message.messageMetadata.actorFbId.toString(),
|
718
|
+
attachments: delta.deltaMessageReply.message.attachments
|
719
|
+
.map(function(att) {
|
720
|
+
var mercury = JSON.parse(att.mercuryJSON);
|
721
|
+
Object.assign(att, mercury);
|
722
|
+
return att;
|
723
|
+
})
|
724
|
+
.map(att => {
|
725
|
+
var x;
|
185
726
|
try {
|
186
|
-
|
187
|
-
} catch (
|
188
|
-
|
727
|
+
x = utils._formatAttachment(att);
|
728
|
+
} catch (ex) {
|
729
|
+
x = att;
|
730
|
+
x.error = ex;
|
731
|
+
x.type = "unknown";
|
189
732
|
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
733
|
+
return x;
|
734
|
+
}),
|
735
|
+
args: (delta.deltaMessageReply.message.body || "")
|
736
|
+
.trim()
|
737
|
+
.split(/\s+/),
|
738
|
+
body: delta.deltaMessageReply.message.body || "",
|
739
|
+
isGroup: !!delta.deltaMessageReply.message.messageMetadata.threadKey
|
740
|
+
.threadFbId,
|
741
|
+
mentions: mentions,
|
742
|
+
timestamp:
|
743
|
+
delta.deltaMessageReply.message.messageMetadata.timestamp,
|
744
|
+
participantIDs: (
|
745
|
+
delta.deltaMessageReply.message.participants || []
|
746
|
+
).map(e => e.toString())
|
747
|
+
};
|
205
748
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
} else if (delta.deltaRecallMessageData && !!ctx.globalOptions.listenEvents) {
|
223
|
-
(function () {
|
224
|
-
globalCallback(null, {
|
225
|
-
type: "message_unsend",
|
226
|
-
threadID: (delta.deltaRecallMessageData.threadKey.threadFbId ? delta.deltaRecallMessageData.threadKey.threadFbId : delta.deltaRecallMessageData.threadKey.otherUserFbId).toString(),
|
227
|
-
messageID: delta.deltaRecallMessageData.messageID,
|
228
|
-
senderID: delta.deltaRecallMessageData.senderID.toString(),
|
229
|
-
deletionTimestamp: delta.deltaRecallMessageData.deletionTimestamp,
|
230
|
-
timestamp: delta.deltaRecallMessageData.timestamp
|
231
|
-
});
|
232
|
-
})();
|
233
|
-
} else if (delta.deltaMessageReply) {
|
234
|
-
//Mention block - #1
|
235
|
-
var mdata =
|
236
|
-
delta.deltaMessageReply.message === undefined ? [] :
|
237
|
-
delta.deltaMessageReply.message.data === undefined ? [] :
|
238
|
-
delta.deltaMessageReply.message.data.prng === undefined ? [] :
|
239
|
-
JSON.parse(delta.deltaMessageReply.message.data.prng);
|
240
|
-
var m_id = mdata.map(u => u.i);
|
241
|
-
var m_offset = mdata.map(u => u.o);
|
242
|
-
var m_length = mdata.map(u => u.l);
|
243
|
-
|
244
|
-
var mentions = {};
|
245
|
-
|
246
|
-
for (var i = 0; i < m_id.length; i++) mentions[m_id[i]] = (delta.deltaMessageReply.message.body || "").substring(m_offset[i], m_offset[i] + m_length[i]);
|
247
|
-
//Mention block - 1#
|
248
|
-
var callbackToReturn = {
|
249
|
-
type: "message_reply",
|
250
|
-
threadID: (delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.message.messageMetadata.threadKey.otherUserFbId).toString(),
|
251
|
-
messageID: delta.deltaMessageReply.message.messageMetadata.messageId,
|
252
|
-
senderID: delta.deltaMessageReply.message.messageMetadata.actorFbId.toString(),
|
253
|
-
attachments: delta.deltaMessageReply.message.attachments.map(function (att) {
|
254
|
-
var mercury = JSON.parse(att.mercuryJSON);
|
255
|
-
Object.assign(att, mercury);
|
256
|
-
return att;
|
257
|
-
}).map(att => {
|
258
|
-
var x;
|
259
|
-
try {
|
260
|
-
x = utils._formatAttachment(att);
|
261
|
-
} catch (ex) {
|
262
|
-
x = att;
|
263
|
-
x.error = ex;
|
264
|
-
x.type = "unknown";
|
265
|
-
}
|
266
|
-
return x;
|
267
|
-
}),
|
268
|
-
args: (delta.deltaMessageReply.message.body || "").trim().split(/\s+/),
|
269
|
-
body: (delta.deltaMessageReply.message.body || ""),
|
270
|
-
isGroup: !!delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId,
|
271
|
-
mentions: mentions,
|
272
|
-
timestamp: delta.deltaMessageReply.message.messageMetadata.timestamp,
|
273
|
-
participantIDs: (delta.deltaMessageReply.message.participants || []).map(e => e.toString())
|
274
|
-
};
|
275
|
-
|
276
|
-
if (delta.deltaMessageReply.repliedToMessage) {
|
277
|
-
//Mention block - #2
|
278
|
-
mdata =
|
279
|
-
delta.deltaMessageReply.repliedToMessage === undefined ? [] :
|
280
|
-
delta.deltaMessageReply.repliedToMessage.data === undefined ? [] :
|
281
|
-
delta.deltaMessageReply.repliedToMessage.data.prng === undefined ? [] :
|
282
|
-
JSON.parse(delta.deltaMessageReply.repliedToMessage.data.prng);
|
283
|
-
m_id = mdata.map(u => u.i);
|
284
|
-
m_offset = mdata.map(u => u.o);
|
285
|
-
m_length = mdata.map(u => u.l);
|
286
|
-
|
287
|
-
var rmentions = {};
|
288
|
-
|
289
|
-
for (var i = 0; i < m_id.length; i++) rmentions[m_id[i]] = (delta.deltaMessageReply.repliedToMessage.body || "").substring(m_offset[i], m_offset[i] + m_length[i]);
|
290
|
-
//Mention block - 2#
|
291
|
-
callbackToReturn.messageReply = {
|
292
|
-
threadID: (delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.otherUserFbId).toString(),
|
293
|
-
messageID: delta.deltaMessageReply.repliedToMessage.messageMetadata.messageId,
|
294
|
-
senderID: delta.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),
|
295
|
-
attachments: delta.deltaMessageReply.repliedToMessage.attachments.map(function (att) {
|
296
|
-
var mercury = JSON.parse(att.mercuryJSON);
|
297
|
-
Object.assign(att, mercury);
|
298
|
-
return att;
|
299
|
-
}).map(att => {
|
300
|
-
var x;
|
301
|
-
try {
|
302
|
-
x = utils._formatAttachment(att);
|
303
|
-
} catch (ex) {
|
304
|
-
x = att;
|
305
|
-
x.error = ex;
|
306
|
-
x.type = "unknown";
|
307
|
-
}
|
308
|
-
return x;
|
309
|
-
}),
|
310
|
-
args: (delta.deltaMessageReply.repliedToMessage.body || "").trim().split(/\s+/),
|
311
|
-
body: delta.deltaMessageReply.repliedToMessage.body || "",
|
312
|
-
isGroup: !!delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId,
|
313
|
-
mentions: rmentions,
|
314
|
-
timestamp: delta.deltaMessageReply.repliedToMessage.messageMetadata.timestamp,
|
315
|
-
participantIDs: (delta.deltaMessageReply.repliedToMessage.participants || []).map(e => e.toString())
|
316
|
-
};
|
317
|
-
} else if (delta.deltaMessageReply.replyToMessageId) {
|
318
|
-
return defaultFuncs
|
319
|
-
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, {
|
320
|
-
"av": ctx.globalOptions.pageID,
|
321
|
-
"queries": JSON.stringify({
|
322
|
-
"o0": {
|
323
|
-
//Using the same doc_id as forcedFetch
|
324
|
-
"doc_id": "2848441488556444",
|
325
|
-
"query_params": {
|
326
|
-
"thread_and_message_id": {
|
327
|
-
"thread_id": callbackToReturn.threadID,
|
328
|
-
"message_id": delta.deltaMessageReply.replyToMessageId.id,
|
329
|
-
}
|
330
|
-
}
|
331
|
-
}
|
332
|
-
})
|
333
|
-
})
|
334
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
335
|
-
.then((resData) => {
|
336
|
-
if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
337
|
-
if (resData[resData.length - 1].successful_results === 0) throw { error: "forcedFetch: there was no successful_results", res: resData };
|
338
|
-
var fetchData = resData[0].o0.data.message;
|
339
|
-
var mobj = {};
|
340
|
-
for (var n in fetchData.message.ranges) mobj[fetchData.message.ranges[n].entity.id] = (fetchData.message.text || "").substr(fetchData.message.ranges[n].offset, fetchData.message.ranges[n].length);
|
341
|
-
|
342
|
-
callbackToReturn.messageReply = {
|
343
|
-
type: "Message",
|
344
|
-
threadID: callbackToReturn.threadID,
|
345
|
-
messageID: fetchData.message_id,
|
346
|
-
senderID: fetchData.message_sender.id.toString(),
|
347
|
-
attachments: fetchData.message.blob_attachment.map(att => {
|
348
|
-
var x;
|
349
|
-
try {
|
350
|
-
x = utils._formatAttachment({ blob_attachment: att });
|
351
|
-
} catch (ex) {
|
352
|
-
x = att;
|
353
|
-
x.error = ex;
|
354
|
-
x.type = "unknown";
|
355
|
-
}
|
356
|
-
return x;
|
357
|
-
}),
|
358
|
-
args: (fetchData.message.text || "").trim().split(/\s+/) || [],
|
359
|
-
body: fetchData.message.text || "",
|
360
|
-
isGroup: callbackToReturn.isGroup,
|
361
|
-
mentions: mobj,
|
362
|
-
timestamp: parseInt(fetchData.timestamp_precise)
|
363
|
-
};
|
364
|
-
})
|
365
|
-
.catch(err => log.error("forcedFetch", err))
|
366
|
-
.finally(function () {
|
367
|
-
if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
|
368
|
-
!ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function () { globalCallback(null, callbackToReturn); })();
|
369
|
-
});
|
370
|
-
} else callbackToReturn.delta = delta;
|
371
|
-
|
372
|
-
if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
|
373
|
-
|
374
|
-
return !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function () { globalCallback(null, callbackToReturn); })();
|
375
|
-
}
|
376
|
-
}
|
377
|
-
return;
|
378
|
-
}
|
379
|
-
}
|
749
|
+
if (delta.deltaMessageReply.repliedToMessage) {
|
750
|
+
//Mention block - #2
|
751
|
+
mdata =
|
752
|
+
delta.deltaMessageReply.repliedToMessage === undefined
|
753
|
+
? []
|
754
|
+
: delta.deltaMessageReply.repliedToMessage.data === undefined
|
755
|
+
? []
|
756
|
+
: delta.deltaMessageReply.repliedToMessage.data.prng ===
|
757
|
+
undefined
|
758
|
+
? []
|
759
|
+
: JSON.parse(
|
760
|
+
delta.deltaMessageReply.repliedToMessage.data.prng
|
761
|
+
);
|
762
|
+
m_id = mdata.map(u => u.i);
|
763
|
+
m_offset = mdata.map(u => u.o);
|
764
|
+
m_length = mdata.map(u => u.l);
|
380
765
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
766
|
+
var rmentions = {};
|
767
|
+
|
768
|
+
for (var i = 0; i < m_id.length; i++)
|
769
|
+
rmentions[m_id[i]] = (
|
770
|
+
delta.deltaMessageReply.repliedToMessage.body || ""
|
771
|
+
).substring(m_offset[i], m_offset[i] + m_length[i]);
|
772
|
+
//Mention block - 2#
|
773
|
+
callbackToReturn.messageReply = {
|
774
|
+
threadID: (delta.deltaMessageReply.repliedToMessage
|
775
|
+
.messageMetadata.threadKey.threadFbId
|
776
|
+
? delta.deltaMessageReply.repliedToMessage.messageMetadata
|
777
|
+
.threadKey.threadFbId
|
778
|
+
: delta.deltaMessageReply.repliedToMessage.messageMetadata
|
779
|
+
.threadKey.otherUserFbId
|
780
|
+
).toString(),
|
781
|
+
messageID:
|
782
|
+
delta.deltaMessageReply.repliedToMessage.messageMetadata
|
783
|
+
.messageId,
|
784
|
+
senderID: delta.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),
|
785
|
+
attachments: delta.deltaMessageReply.repliedToMessage.attachments
|
786
|
+
.map(function(att) {
|
787
|
+
var mercury = JSON.parse(att.mercuryJSON);
|
788
|
+
Object.assign(att, mercury);
|
789
|
+
return att;
|
790
|
+
})
|
791
|
+
.map(att => {
|
792
|
+
var x;
|
793
|
+
try {
|
794
|
+
x = utils._formatAttachment(att);
|
795
|
+
} catch (ex) {
|
796
|
+
x = att;
|
797
|
+
x.error = ex;
|
798
|
+
x.type = "unknown";
|
799
|
+
}
|
800
|
+
return x;
|
801
|
+
}),
|
802
|
+
args: (delta.deltaMessageReply.repliedToMessage.body || "")
|
803
|
+
.trim()
|
804
|
+
.split(/\s+/),
|
805
|
+
body: delta.deltaMessageReply.repliedToMessage.body || "",
|
806
|
+
isGroup: !!delta.deltaMessageReply.repliedToMessage
|
807
|
+
.messageMetadata.threadKey.threadFbId,
|
808
|
+
mentions: rmentions,
|
809
|
+
timestamp:
|
810
|
+
delta.deltaMessageReply.repliedToMessage.messageMetadata
|
811
|
+
.timestamp,
|
812
|
+
participantIDs: (
|
813
|
+
delta.deltaMessageReply.repliedToMessage.participants || []
|
814
|
+
).map(e => e.toString())
|
815
|
+
};
|
816
|
+
} else if (delta.deltaMessageReply.replyToMessageId) {
|
817
|
+
return defaultFuncs
|
818
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, {
|
819
|
+
av: ctx.globalOptions.pageID,
|
820
|
+
queries: JSON.stringify({
|
821
|
+
o0: {
|
822
|
+
//Using the same doc_id as forcedFetch
|
823
|
+
doc_id: "2848441488556444",
|
824
|
+
query_params: {
|
825
|
+
thread_and_message_id: {
|
826
|
+
thread_id: callbackToReturn.threadID,
|
827
|
+
message_id: delta.deltaMessageReply.replyToMessageId.id
|
828
|
+
}
|
829
|
+
}
|
830
|
+
}
|
831
|
+
})
|
832
|
+
})
|
833
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
834
|
+
.then(resData => {
|
835
|
+
if (resData[resData.length - 1].error_results > 0)
|
836
|
+
throw resData[0].o0.errors;
|
837
|
+
if (resData[resData.length - 1].successful_results === 0)
|
838
|
+
throw {
|
839
|
+
error: "forcedFetch: there was no successful_results",
|
840
|
+
res: resData
|
841
|
+
};
|
842
|
+
var fetchData = resData[0].o0.data.message;
|
843
|
+
var mobj = {};
|
844
|
+
for (var n in fetchData.message.ranges)
|
845
|
+
mobj[fetchData.message.ranges[n].entity.id] = (
|
846
|
+
fetchData.message.text || ""
|
847
|
+
).substr(
|
848
|
+
fetchData.message.ranges[n].offset,
|
849
|
+
fetchData.message.ranges[n].length
|
850
|
+
);
|
851
|
+
|
852
|
+
callbackToReturn.messageReply = {
|
853
|
+
type: "Message",
|
854
|
+
threadID: callbackToReturn.threadID,
|
855
|
+
messageID: fetchData.message_id,
|
856
|
+
senderID: fetchData.message_sender.id.toString(),
|
857
|
+
attachments: fetchData.message.blob_attachment.map(att => {
|
858
|
+
var x;
|
402
859
|
try {
|
403
|
-
|
404
|
-
} catch (
|
405
|
-
|
860
|
+
x = utils._formatAttachment({ blob_attachment: att });
|
861
|
+
} catch (ex) {
|
862
|
+
x = att;
|
863
|
+
x.error = ex;
|
864
|
+
x.type = "unknown";
|
406
865
|
}
|
407
|
-
return
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
var tid = v.delta.threadKey.threadFbId;
|
416
|
-
if (mid && tid) {
|
417
|
-
const form = {
|
418
|
-
"av": ctx.globalOptions.pageID,
|
419
|
-
"queries": JSON.stringify({
|
420
|
-
"o0": {
|
421
|
-
//This doc_id is valid as of March 25, 2020
|
422
|
-
"doc_id": "2848441488556444",
|
423
|
-
"query_params": {
|
424
|
-
"thread_and_message_id": {
|
425
|
-
"thread_id": tid.toString(),
|
426
|
-
"message_id": mid,
|
427
|
-
}
|
428
|
-
}
|
429
|
-
}
|
430
|
-
})
|
866
|
+
return x;
|
867
|
+
}),
|
868
|
+
args:
|
869
|
+
(fetchData.message.text || "").trim().split(/\s+/) || [],
|
870
|
+
body: fetchData.message.text || "",
|
871
|
+
isGroup: callbackToReturn.isGroup,
|
872
|
+
mentions: mobj,
|
873
|
+
timestamp: parseInt(fetchData.timestamp_precise)
|
431
874
|
};
|
875
|
+
})
|
876
|
+
.catch(err => log.error("forcedFetch", err))
|
877
|
+
.finally(function() {
|
878
|
+
if (ctx.globalOptions.autoMarkDelivery)
|
879
|
+
markDelivery(
|
880
|
+
ctx,
|
881
|
+
api,
|
882
|
+
callbackToReturn.threadID,
|
883
|
+
callbackToReturn.messageID
|
884
|
+
);
|
885
|
+
!ctx.globalOptions.selfListen &&
|
886
|
+
callbackToReturn.senderID === ctx.userID
|
887
|
+
? undefined
|
888
|
+
: (function() {
|
889
|
+
globalCallback(null, callbackToReturn);
|
890
|
+
})();
|
891
|
+
});
|
892
|
+
} else callbackToReturn.delta = delta;
|
432
893
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
undefined :
|
451
|
-
(function () {
|
452
|
-
globalCallback(null, {
|
453
|
-
type: "change_thread_image",
|
454
|
-
threadID: utils.formatID(tid.toString()),
|
455
|
-
snippet: fetchData.snippet,
|
456
|
-
timestamp: fetchData.timestamp_precise,
|
457
|
-
author: fetchData.message_sender.id,
|
458
|
-
image: {
|
459
|
-
attachmentID: fetchData.image_with_metadata && fetchData.image_with_metadata.legacy_attachment_id,
|
460
|
-
width: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.x,
|
461
|
-
height: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.y,
|
462
|
-
url: fetchData.image_with_metadata && fetchData.image_with_metadata.preview.uri
|
463
|
-
}
|
464
|
-
});
|
465
|
-
})();
|
466
|
-
break;
|
467
|
-
case "UserMessage":
|
468
|
-
log.info("ff-Return", {
|
469
|
-
type: "message",
|
470
|
-
senderID: utils.formatID(fetchData.message_sender.id),
|
471
|
-
body: fetchData.message.text || "",
|
472
|
-
threadID: utils.formatID(tid.toString()),
|
473
|
-
messageID: fetchData.message_id,
|
474
|
-
attachments: [{
|
475
|
-
type: "share",
|
476
|
-
ID: fetchData.extensible_attachment.legacy_attachment_id,
|
477
|
-
url: fetchData.extensible_attachment.story_attachment.url,
|
478
|
-
|
479
|
-
title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
|
480
|
-
description: fetchData.extensible_attachment.story_attachment.description.text,
|
481
|
-
source: fetchData.extensible_attachment.story_attachment.source,
|
482
|
-
|
483
|
-
image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
|
484
|
-
width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
|
485
|
-
height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
|
486
|
-
playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
|
487
|
-
duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
|
488
|
-
|
489
|
-
subattachments: fetchData.extensible_attachment.subattachments,
|
490
|
-
properties: fetchData.extensible_attachment.story_attachment.properties,
|
491
|
-
}],
|
492
|
-
mentions: {},
|
493
|
-
timestamp: parseInt(fetchData.timestamp_precise),
|
494
|
-
isGroup: (fetchData.message_sender.id != tid.toString())
|
495
|
-
});
|
496
|
-
globalCallback(null, {
|
497
|
-
type: "message",
|
498
|
-
senderID: utils.formatID(fetchData.message_sender.id),
|
499
|
-
body: fetchData.message.text || "",
|
500
|
-
threadID: utils.formatID(tid.toString()),
|
501
|
-
messageID: fetchData.message_id,
|
502
|
-
attachments: [{
|
503
|
-
type: "share",
|
504
|
-
ID: fetchData.extensible_attachment.legacy_attachment_id,
|
505
|
-
url: fetchData.extensible_attachment.story_attachment.url,
|
506
|
-
|
507
|
-
title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
|
508
|
-
description: fetchData.extensible_attachment.story_attachment.description.text,
|
509
|
-
source: fetchData.extensible_attachment.story_attachment.source,
|
510
|
-
|
511
|
-
image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
|
512
|
-
width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
|
513
|
-
height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
|
514
|
-
playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
|
515
|
-
duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
|
516
|
-
|
517
|
-
subattachments: fetchData.extensible_attachment.subattachments,
|
518
|
-
properties: fetchData.extensible_attachment.story_attachment.properties,
|
519
|
-
}],
|
520
|
-
mentions: {},
|
521
|
-
timestamp: parseInt(fetchData.timestamp_precise),
|
522
|
-
isGroup: (fetchData.message_sender.id != tid.toString())
|
523
|
-
});
|
524
|
-
}
|
525
|
-
} else log.error("forcedFetch", fetchData);
|
526
|
-
})
|
527
|
-
.catch((err) => log.error("forcedFetch", err));
|
528
|
-
}
|
529
|
-
break;
|
530
|
-
case "ThreadName":
|
531
|
-
case "ParticipantsAddedToGroupThread":
|
532
|
-
case "ParticipantLeftGroupThread":
|
533
|
-
var formattedEvent;
|
534
|
-
try {
|
535
|
-
formattedEvent = utils.formatDeltaEvent(v.delta);
|
536
|
-
} catch (err) {
|
537
|
-
return log.error("Lỗi Nhẹ", err);
|
538
|
-
}
|
539
|
-
return (!ctx.globalOptions.selfListen && formattedEvent.author.toString() === ctx.userID) || !ctx.loggedIn ? undefined : (function () { globalCallback(null, formattedEvent); })();
|
894
|
+
if (ctx.globalOptions.autoMarkDelivery)
|
895
|
+
markDelivery(
|
896
|
+
ctx,
|
897
|
+
api,
|
898
|
+
callbackToReturn.threadID,
|
899
|
+
callbackToReturn.messageID
|
900
|
+
);
|
901
|
+
|
902
|
+
return !ctx.globalOptions.selfListen &&
|
903
|
+
callbackToReturn.senderID === ctx.userID
|
904
|
+
? undefined
|
905
|
+
: (function() {
|
906
|
+
globalCallback(null, callbackToReturn);
|
907
|
+
})();
|
908
|
+
}
|
909
|
+
}
|
910
|
+
return;
|
540
911
|
}
|
541
|
-
}
|
912
|
+
}
|
913
|
+
|
914
|
+
if (v.delta.class !== "NewMessage" && !ctx.globalOptions.listenEvents) return;
|
915
|
+
switch (v.delta.class) {
|
916
|
+
case "ReadReceipt":
|
917
|
+
var fmtMsg;
|
918
|
+
try {
|
919
|
+
fmtMsg = utils.formatDeltaReadReceipt(v.delta);
|
920
|
+
} catch (err) {
|
921
|
+
return log.error("Lỗi Nhẹ", err);
|
922
|
+
}
|
923
|
+
return (function() {
|
924
|
+
globalCallback(null, fmtMsg);
|
925
|
+
})();
|
926
|
+
case "AdminTextMessage":
|
927
|
+
switch (v.delta.type) {
|
928
|
+
case "change_thread_theme":
|
929
|
+
case "change_thread_icon":
|
930
|
+
case "change_thread_nickname":
|
931
|
+
case "change_thread_admins":
|
932
|
+
case "change_thread_approval_mode":
|
933
|
+
case "group_poll":
|
934
|
+
case "messenger_call_log":
|
935
|
+
case "participant_joined_group_call":
|
936
|
+
var fmtMsg;
|
937
|
+
try {
|
938
|
+
fmtMsg = utils.formatDeltaEvent(v.delta);
|
939
|
+
} catch (err) {
|
940
|
+
return log.error("Lỗi Nhẹ", err);
|
941
|
+
}
|
942
|
+
return (function() {
|
943
|
+
globalCallback(null, fmtMsg);
|
944
|
+
})();
|
945
|
+
default:
|
946
|
+
return;
|
947
|
+
}
|
948
|
+
//For group images
|
949
|
+
case "ForcedFetch":
|
950
|
+
if (!v.delta.threadKey) return;
|
951
|
+
var mid = v.delta.messageId;
|
952
|
+
var tid = v.delta.threadKey.threadFbId;
|
953
|
+
if (mid && tid) {
|
954
|
+
const form = {
|
955
|
+
av: ctx.globalOptions.pageID,
|
956
|
+
queries: JSON.stringify({
|
957
|
+
o0: {
|
958
|
+
//This doc_id is valid as of March 25, 2020
|
959
|
+
doc_id: "2848441488556444",
|
960
|
+
query_params: {
|
961
|
+
thread_and_message_id: {
|
962
|
+
thread_id: tid.toString(),
|
963
|
+
message_id: mid
|
964
|
+
}
|
965
|
+
}
|
966
|
+
}
|
967
|
+
})
|
968
|
+
};
|
969
|
+
|
970
|
+
defaultFuncs
|
971
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
972
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
973
|
+
.then(resData => {
|
974
|
+
if (resData[resData.length - 1].error_results > 0)
|
975
|
+
throw resData[0].o0.errors;
|
976
|
+
|
977
|
+
if (resData[resData.length - 1].successful_results === 0)
|
978
|
+
throw {
|
979
|
+
error: "forcedFetch: there was no successful_results",
|
980
|
+
res: resData
|
981
|
+
};
|
542
982
|
|
983
|
+
var fetchData = resData[0].o0.data.message;
|
984
|
+
|
985
|
+
if (utils.getType(fetchData) == "Object") {
|
986
|
+
log.info("forcedFetch", fetchData);
|
987
|
+
switch (fetchData.__typename) {
|
988
|
+
case "ThreadImageMessage":
|
989
|
+
(!ctx.globalOptions.selfListen &&
|
990
|
+
fetchData.message_sender.id.toString() === ctx.userID) ||
|
991
|
+
!ctx.loggedIn
|
992
|
+
? undefined
|
993
|
+
: (function() {
|
994
|
+
globalCallback(null, {
|
995
|
+
type: "change_thread_image",
|
996
|
+
threadID: utils.formatID(tid.toString()),
|
997
|
+
snippet: fetchData.snippet,
|
998
|
+
timestamp: fetchData.timestamp_precise,
|
999
|
+
author: fetchData.message_sender.id,
|
1000
|
+
image: {
|
1001
|
+
attachmentID:
|
1002
|
+
fetchData.image_with_metadata &&
|
1003
|
+
fetchData.image_with_metadata
|
1004
|
+
.legacy_attachment_id,
|
1005
|
+
width:
|
1006
|
+
fetchData.image_with_metadata &&
|
1007
|
+
fetchData.image_with_metadata.original_dimensions
|
1008
|
+
.x,
|
1009
|
+
height:
|
1010
|
+
fetchData.image_with_metadata &&
|
1011
|
+
fetchData.image_with_metadata.original_dimensions
|
1012
|
+
.y,
|
1013
|
+
url:
|
1014
|
+
fetchData.image_with_metadata &&
|
1015
|
+
fetchData.image_with_metadata.preview.uri
|
1016
|
+
}
|
1017
|
+
});
|
1018
|
+
})();
|
1019
|
+
break;
|
1020
|
+
case "UserMessage":
|
1021
|
+
log.info("ff-Return", {
|
1022
|
+
type: "message",
|
1023
|
+
senderID: utils.formatID(fetchData.message_sender.id),
|
1024
|
+
body: fetchData.message.text || "",
|
1025
|
+
threadID: utils.formatID(tid.toString()),
|
1026
|
+
messageID: fetchData.message_id,
|
1027
|
+
attachments: [
|
1028
|
+
{
|
1029
|
+
type: "share",
|
1030
|
+
ID:
|
1031
|
+
fetchData.extensible_attachment.legacy_attachment_id,
|
1032
|
+
url:
|
1033
|
+
fetchData.extensible_attachment.story_attachment.url,
|
1034
|
+
|
1035
|
+
title:
|
1036
|
+
fetchData.extensible_attachment.story_attachment
|
1037
|
+
.title_with_entities.text,
|
1038
|
+
description:
|
1039
|
+
fetchData.extensible_attachment.story_attachment
|
1040
|
+
.description.text,
|
1041
|
+
source:
|
1042
|
+
fetchData.extensible_attachment.story_attachment
|
1043
|
+
.source,
|
1044
|
+
|
1045
|
+
image: (
|
1046
|
+
(
|
1047
|
+
fetchData.extensible_attachment.story_attachment
|
1048
|
+
.media || {}
|
1049
|
+
).image || {}
|
1050
|
+
).uri,
|
1051
|
+
width: (
|
1052
|
+
(
|
1053
|
+
fetchData.extensible_attachment.story_attachment
|
1054
|
+
.media || {}
|
1055
|
+
).image || {}
|
1056
|
+
).width,
|
1057
|
+
height: (
|
1058
|
+
(
|
1059
|
+
fetchData.extensible_attachment.story_attachment
|
1060
|
+
.media || {}
|
1061
|
+
).image || {}
|
1062
|
+
).height,
|
1063
|
+
playable:
|
1064
|
+
(
|
1065
|
+
fetchData.extensible_attachment.story_attachment
|
1066
|
+
.media || {}
|
1067
|
+
).is_playable || false,
|
1068
|
+
duration:
|
1069
|
+
(
|
1070
|
+
fetchData.extensible_attachment.story_attachment
|
1071
|
+
.media || {}
|
1072
|
+
).playable_duration_in_ms || 0,
|
1073
|
+
|
1074
|
+
subattachments:
|
1075
|
+
fetchData.extensible_attachment.subattachments,
|
1076
|
+
properties:
|
1077
|
+
fetchData.extensible_attachment.story_attachment
|
1078
|
+
.properties
|
1079
|
+
}
|
1080
|
+
],
|
1081
|
+
mentions: {},
|
1082
|
+
timestamp: parseInt(fetchData.timestamp_precise),
|
1083
|
+
isGroup: fetchData.message_sender.id != tid.toString()
|
1084
|
+
});
|
1085
|
+
globalCallback(null, {
|
1086
|
+
type: "message",
|
1087
|
+
senderID: utils.formatID(fetchData.message_sender.id),
|
1088
|
+
body: fetchData.message.text || "",
|
1089
|
+
threadID: utils.formatID(tid.toString()),
|
1090
|
+
messageID: fetchData.message_id,
|
1091
|
+
attachments: [
|
1092
|
+
{
|
1093
|
+
type: "share",
|
1094
|
+
ID:
|
1095
|
+
fetchData.extensible_attachment.legacy_attachment_id,
|
1096
|
+
url:
|
1097
|
+
fetchData.extensible_attachment.story_attachment.url,
|
1098
|
+
|
1099
|
+
title:
|
1100
|
+
fetchData.extensible_attachment.story_attachment
|
1101
|
+
.title_with_entities.text,
|
1102
|
+
description:
|
1103
|
+
fetchData.extensible_attachment.story_attachment
|
1104
|
+
.description.text,
|
1105
|
+
source:
|
1106
|
+
fetchData.extensible_attachment.story_attachment
|
1107
|
+
.source,
|
1108
|
+
|
1109
|
+
image: (
|
1110
|
+
(
|
1111
|
+
fetchData.extensible_attachment.story_attachment
|
1112
|
+
.media || {}
|
1113
|
+
).image || {}
|
1114
|
+
).uri,
|
1115
|
+
width: (
|
1116
|
+
(
|
1117
|
+
fetchData.extensible_attachment.story_attachment
|
1118
|
+
.media || {}
|
1119
|
+
).image || {}
|
1120
|
+
).width,
|
1121
|
+
height: (
|
1122
|
+
(
|
1123
|
+
fetchData.extensible_attachment.story_attachment
|
1124
|
+
.media || {}
|
1125
|
+
).image || {}
|
1126
|
+
).height,
|
1127
|
+
playable:
|
1128
|
+
(
|
1129
|
+
fetchData.extensible_attachment.story_attachment
|
1130
|
+
.media || {}
|
1131
|
+
).is_playable || false,
|
1132
|
+
duration:
|
1133
|
+
(
|
1134
|
+
fetchData.extensible_attachment.story_attachment
|
1135
|
+
.media || {}
|
1136
|
+
).playable_duration_in_ms || 0,
|
1137
|
+
|
1138
|
+
subattachments:
|
1139
|
+
fetchData.extensible_attachment.subattachments,
|
1140
|
+
properties:
|
1141
|
+
fetchData.extensible_attachment.story_attachment
|
1142
|
+
.properties
|
1143
|
+
}
|
1144
|
+
],
|
1145
|
+
mentions: {},
|
1146
|
+
timestamp: parseInt(fetchData.timestamp_precise),
|
1147
|
+
isGroup: fetchData.message_sender.id != tid.toString()
|
1148
|
+
});
|
1149
|
+
}
|
1150
|
+
} else log.error("forcedFetch", fetchData);
|
1151
|
+
})
|
1152
|
+
.catch(err => log.error("forcedFetch", err));
|
1153
|
+
}
|
1154
|
+
break;
|
1155
|
+
case "ThreadName":
|
1156
|
+
case "ParticipantsAddedToGroupThread":
|
1157
|
+
case "ParticipantLeftGroupThread":
|
1158
|
+
var formattedEvent;
|
1159
|
+
try {
|
1160
|
+
formattedEvent = utils.formatDeltaEvent(v.delta);
|
1161
|
+
} catch (err) {
|
1162
|
+
return log.error("Lỗi Nhẹ", err);
|
1163
|
+
}
|
1164
|
+
return (!ctx.globalOptions.selfListen &&
|
1165
|
+
formattedEvent.author.toString() === ctx.userID) ||
|
1166
|
+
!ctx.loggedIn
|
1167
|
+
? undefined
|
1168
|
+
: (function() {
|
1169
|
+
globalCallback(null, formattedEvent);
|
1170
|
+
})();
|
1171
|
+
}
|
1172
|
+
}
|
543
1173
|
|
544
1174
|
function markDelivery(ctx, api, threadID, messageID) {
|
545
|
-
|
546
|
-
|
1175
|
+
if (threadID && messageID) {
|
1176
|
+
api.markAsDelivered(threadID, messageID, err => {
|
1177
|
+
if (err) log.error("markAsDelivered", err);
|
1178
|
+
else {
|
1179
|
+
if (ctx.globalOptions.autoMarkRead) {
|
1180
|
+
api.markAsRead(threadID, err => {
|
547
1181
|
if (err) log.error("markAsDelivered", err);
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
}
|
554
|
-
}
|
555
|
-
});
|
556
|
-
}
|
1182
|
+
});
|
1183
|
+
}
|
1184
|
+
}
|
1185
|
+
});
|
1186
|
+
}
|
557
1187
|
}
|
558
1188
|
|
559
|
-
module.exports = function
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
1189
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
1190
|
+
var globalCallback = identity;
|
1191
|
+
getSeqID = function getSeqID() {
|
1192
|
+
ctx.t_mqttCalled = false;
|
1193
|
+
defaultFuncs
|
1194
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
1195
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
1196
|
+
.then(resData => {
|
1197
|
+
if (utils.getType(resData) != "Array")
|
1198
|
+
throw {
|
1199
|
+
error: "Chưa Đăng Nhập Được - Appstate Đã Bị Lỗi",
|
1200
|
+
res: resData
|
1201
|
+
};
|
1202
|
+
if (resData && resData[resData.length - 1].error_results > 0)
|
1203
|
+
throw resData[0].o0.errors;
|
1204
|
+
if (resData[resData.length - 1].successful_results === 0)
|
1205
|
+
throw {
|
1206
|
+
error: "getSeqId: there was no successful_results",
|
1207
|
+
res: resData
|
1208
|
+
};
|
1209
|
+
if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
|
1210
|
+
ctx.lastSeqId =
|
1211
|
+
resData[0].o0.data.viewer.message_threads.sync_sequence_id;
|
1212
|
+
listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
1213
|
+
} else
|
1214
|
+
throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
|
1215
|
+
})
|
1216
|
+
.catch(err => {
|
1217
|
+
log.error("getSeqId", err);
|
1218
|
+
if (
|
1219
|
+
utils.getType(err) == "Object" &&
|
1220
|
+
err.error === "Chưa Đăng Nhập Được - Appstate Đã Bị Lỗi"
|
1221
|
+
)
|
1222
|
+
ctx.loggedIn = false;
|
1223
|
+
return globalCallback(err);
|
1224
|
+
});
|
1225
|
+
};
|
581
1226
|
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
}
|
597
|
-
}
|
1227
|
+
return function(callback) {
|
1228
|
+
class MessageEmitter extends EventEmitter {
|
1229
|
+
stopListening(callback) {
|
1230
|
+
callback = callback || (() => {});
|
1231
|
+
globalCallback = identity;
|
1232
|
+
if (ctx.mqttClient) {
|
1233
|
+
ctx.mqttClient.unsubscribe("/webrtc");
|
1234
|
+
ctx.mqttClient.unsubscribe("/rtc_multi");
|
1235
|
+
ctx.mqttClient.unsubscribe("/onevc");
|
1236
|
+
ctx.mqttClient.publish("/browser_close", "{}");
|
1237
|
+
ctx.mqttClient.end(false, function(...data) {
|
1238
|
+
callback(data);
|
1239
|
+
ctx.mqttClient = undefined;
|
1240
|
+
});
|
598
1241
|
}
|
1242
|
+
}
|
1243
|
+
}
|
599
1244
|
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
if (!ctx.firstListen) ctx.lastSeqId = null;
|
608
|
-
ctx.syncToken = undefined;
|
609
|
-
ctx.t_mqttCalled = false;
|
610
|
-
|
611
|
-
//Same request as getThreadList
|
612
|
-
form = {
|
613
|
-
"av": ctx.globalOptions.pageID,
|
614
|
-
"queries": JSON.stringify({
|
615
|
-
"o0": {
|
616
|
-
"doc_id": "3336396659757871",
|
617
|
-
"query_params": {
|
618
|
-
"limit": 1,
|
619
|
-
"before": null,
|
620
|
-
"tags": ["INBOX"],
|
621
|
-
"includeDeliveryReceipts": false,
|
622
|
-
"includeSeqID": true
|
623
|
-
}
|
624
|
-
}
|
625
|
-
})
|
626
|
-
};
|
1245
|
+
var msgEmitter = new MessageEmitter();
|
1246
|
+
globalCallback =
|
1247
|
+
callback ||
|
1248
|
+
function(error, message) {
|
1249
|
+
if (error) return msgEmitter.emit("error", error);
|
1250
|
+
msgEmitter.emit("message", message);
|
1251
|
+
};
|
627
1252
|
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
1253
|
+
//Reset some stuff
|
1254
|
+
if (!ctx.firstListen) ctx.lastSeqId = null;
|
1255
|
+
ctx.syncToken = undefined;
|
1256
|
+
ctx.t_mqttCalled = false;
|
1257
|
+
|
1258
|
+
//Same request as getThreadList
|
1259
|
+
form = {
|
1260
|
+
av: ctx.globalOptions.pageID,
|
1261
|
+
queries: JSON.stringify({
|
1262
|
+
o0: {
|
1263
|
+
doc_id: "3336396659757871",
|
1264
|
+
query_params: {
|
1265
|
+
limit: 1,
|
1266
|
+
before: null,
|
1267
|
+
tags: ["INBOX"],
|
1268
|
+
includeDeliveryReceipts: false,
|
1269
|
+
includeSeqID: true
|
1270
|
+
}
|
1271
|
+
}
|
1272
|
+
})
|
632
1273
|
};
|
633
|
-
|
1274
|
+
|
1275
|
+
if (!ctx.firstListen || !ctx.lastSeqId) getSeqID();
|
1276
|
+
else listenMqtt(defaultFuncs, api, ctx, globalCallback);
|
1277
|
+
ctx.firstListen = false;
|
1278
|
+
return msgEmitter;
|
1279
|
+
};
|
1280
|
+
};
|