@dongdev/fca-unofficial 3.0.30 → 3.0.31
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/CHANGELOG.md +3 -0
- package/package.json +2 -1
- package/src/api/http/httpGet.js +2 -2
- package/src/api/messaging/addUserToGroup.js +1 -1
- package/src/api/messaging/changeGroupImage.js +1 -1
- package/src/api/messaging/changeNickname.js +1 -1
- package/src/api/messaging/changeThreadColor.js +1 -1
- package/src/api/messaging/editMessage.js +1 -1
- package/src/api/messaging/searchForThread.js +2 -1
- package/src/api/messaging/sendTypingIndicator.js +1 -1
- package/src/api/messaging/setMessageReaction.js +3 -4
- package/src/api/messaging/unsendMessage.js +1 -1
- package/src/api/threads/getThreadInfo.js +2 -1
- package/src/api/users/getUserInfo.js +7 -4
- package/src/database/helpers.js +53 -0
- package/src/database/models/index.js +2 -1
- package/src/database/threadData.js +49 -53
- package/src/database/userData.js +46 -37
- package/src/utils/format/attachment.js +357 -0
- package/src/utils/format/cookie.js +9 -0
- package/src/utils/format/date.js +50 -0
- package/src/utils/format/decode.js +44 -0
- package/src/utils/format/delta.js +194 -0
- package/src/utils/format/ids.js +64 -0
- package/src/utils/format/index.js +64 -0
- package/src/utils/format/message.js +88 -0
- package/src/utils/format/presence.js +132 -0
- package/src/utils/format/readTyp.js +44 -0
- package/src/utils/format/thread.js +42 -0
- package/src/utils/format/utils.js +141 -0
- package/src/utils/loginParser/autoLogin.js +125 -0
- package/src/utils/loginParser/helpers.js +43 -0
- package/src/utils/loginParser/index.js +10 -0
- package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
- package/src/utils/loginParser/textUtils.js +28 -0
- package/src/utils/request/client.js +26 -0
- package/src/utils/request/config.js +23 -0
- package/src/utils/request/defaults.js +46 -0
- package/src/utils/request/helpers.js +46 -0
- package/src/utils/request/index.js +17 -0
- package/src/utils/request/methods.js +163 -0
- package/src/utils/request/proxy.js +21 -0
- package/src/utils/request/retry.js +77 -0
- package/src/utils/request/sanitize.js +49 -0
- package/src/utils/format.js +0 -1174
- package/src/utils/loginParser.js +0 -365
- package/src/utils/messageFormat.js +0 -1173
- package/src/utils/request.js +0 -332
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var url = require("url");
|
|
4
|
+
const querystring = require("querystring");
|
|
5
|
+
|
|
6
|
+
function _formatAttachment(attachment1, attachment2) {
|
|
7
|
+
attachment2 = attachment2 || { id: "", image_data: {} };
|
|
8
|
+
attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
|
|
9
|
+
var blob = attachment1.blob_attachment;
|
|
10
|
+
var type =
|
|
11
|
+
blob && blob.__typename ? blob.__typename : attachment1.attach_type;
|
|
12
|
+
if (!type && attachment1.sticker_attachment) {
|
|
13
|
+
type = "StickerAttachment";
|
|
14
|
+
blob = attachment1.sticker_attachment;
|
|
15
|
+
} else if (!type && attachment1.extensible_attachment) {
|
|
16
|
+
if (
|
|
17
|
+
attachment1.extensible_attachment.story_attachment &&
|
|
18
|
+
attachment1.extensible_attachment.story_attachment.target &&
|
|
19
|
+
attachment1.extensible_attachment.story_attachment.target.__typename &&
|
|
20
|
+
attachment1.extensible_attachment.story_attachment.target.__typename ===
|
|
21
|
+
"MessageLocation"
|
|
22
|
+
)
|
|
23
|
+
type = "MessageLocation";
|
|
24
|
+
else type = "ExtensibleAttachment";
|
|
25
|
+
|
|
26
|
+
blob = attachment1.extensible_attachment;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (blob && blob.real_metadata) {
|
|
30
|
+
const realMetadata = blob.real_metadata;
|
|
31
|
+
if (realMetadata.Src) {
|
|
32
|
+
attachment2.src = realMetadata.Src;
|
|
33
|
+
}
|
|
34
|
+
if (realMetadata.ThumbnailSrc) {
|
|
35
|
+
attachment2.thumbnailSrc = realMetadata.ThumbnailSrc;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
switch (type) {
|
|
40
|
+
case "sticker":
|
|
41
|
+
return {
|
|
42
|
+
type: "sticker",
|
|
43
|
+
ID: attachment1.metadata.stickerID.toString(),
|
|
44
|
+
url: attachment1.url,
|
|
45
|
+
packID: attachment1.metadata.packID.toString(),
|
|
46
|
+
spriteUrl: attachment1.metadata.spriteURI,
|
|
47
|
+
spriteUrl2x: attachment1.metadata.spriteURI2x,
|
|
48
|
+
width: attachment1.metadata.width,
|
|
49
|
+
height: attachment1.metadata.height,
|
|
50
|
+
caption: attachment2.caption,
|
|
51
|
+
description: attachment2.description,
|
|
52
|
+
frameCount: attachment1.metadata.frameCount,
|
|
53
|
+
frameRate: attachment1.metadata.frameRate,
|
|
54
|
+
framesPerRow: attachment1.metadata.framesPerRow,
|
|
55
|
+
framesPerCol: attachment1.metadata.framesPerCol,
|
|
56
|
+
stickerID: attachment1.metadata.stickerID.toString(),
|
|
57
|
+
spriteURI: attachment1.metadata.spriteURI,
|
|
58
|
+
spriteURI2x: attachment1.metadata.spriteURI2x,
|
|
59
|
+
};
|
|
60
|
+
case "file":
|
|
61
|
+
return {
|
|
62
|
+
type: "file",
|
|
63
|
+
filename: attachment1.name,
|
|
64
|
+
ID: attachment2.id.toString(),
|
|
65
|
+
url: attachment1.url,
|
|
66
|
+
isMalicious: attachment2.is_malicious,
|
|
67
|
+
contentType: attachment2.mime_type,
|
|
68
|
+
name: attachment1.name,
|
|
69
|
+
mimeType: attachment2.mime_type,
|
|
70
|
+
fileSize: attachment2.file_size,
|
|
71
|
+
};
|
|
72
|
+
case "photo":
|
|
73
|
+
return {
|
|
74
|
+
type: "photo",
|
|
75
|
+
ID: attachment1.metadata.fbid.toString(),
|
|
76
|
+
filename: attachment1.fileName,
|
|
77
|
+
thumbnailUrl: attachment1.thumbnail_url,
|
|
78
|
+
previewUrl: attachment1.preview_url,
|
|
79
|
+
previewWidth: attachment1.preview_width,
|
|
80
|
+
previewHeight: attachment1.preview_height,
|
|
81
|
+
largePreviewUrl: attachment1.large_preview_url,
|
|
82
|
+
largePreviewWidth: attachment1.large_preview_width,
|
|
83
|
+
largePreviewHeight: attachment1.large_preview_height,
|
|
84
|
+
url: attachment1.metadata.url,
|
|
85
|
+
width: attachment1.metadata.dimensions.split(",")[0],
|
|
86
|
+
height: attachment1.metadata.dimensions.split(",")[1],
|
|
87
|
+
name: attachment1.fileName,
|
|
88
|
+
};
|
|
89
|
+
case "animated_image":
|
|
90
|
+
return {
|
|
91
|
+
type: "animated_image",
|
|
92
|
+
ID: attachment2.id.toString(),
|
|
93
|
+
filename: attachment2.filename,
|
|
94
|
+
previewUrl: attachment1.preview_url,
|
|
95
|
+
previewWidth: attachment1.preview_width,
|
|
96
|
+
previewHeight: attachment1.preview_height,
|
|
97
|
+
url: attachment2.image_data.url,
|
|
98
|
+
width: attachment2.image_data.width,
|
|
99
|
+
height: attachment2.image_data.height,
|
|
100
|
+
name: attachment1.name,
|
|
101
|
+
facebookUrl: attachment1.url,
|
|
102
|
+
thumbnailUrl: attachment1.thumbnail_url,
|
|
103
|
+
mimeType: attachment2.mime_type,
|
|
104
|
+
rawGifImage: attachment2.image_data.raw_gif_image,
|
|
105
|
+
rawWebpImage: attachment2.image_data.raw_webp_image,
|
|
106
|
+
animatedGifUrl: attachment2.image_data.animated_gif_url,
|
|
107
|
+
animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url,
|
|
108
|
+
animatedWebpUrl: attachment2.image_data.animated_webp_url,
|
|
109
|
+
animatedWebpPreviewUrl:
|
|
110
|
+
attachment2.image_data.animated_webp_preview_url,
|
|
111
|
+
};
|
|
112
|
+
case "share":
|
|
113
|
+
return {
|
|
114
|
+
type: "share",
|
|
115
|
+
ID: attachment1.share.share_id.toString(),
|
|
116
|
+
url: attachment2.href,
|
|
117
|
+
title: attachment1.share.title,
|
|
118
|
+
description: attachment1.share.description,
|
|
119
|
+
source: attachment1.share.source,
|
|
120
|
+
image: attachment1.share.media.image,
|
|
121
|
+
width: attachment1.share.media.image_size.width,
|
|
122
|
+
height: attachment1.share.media.image_size.height,
|
|
123
|
+
playable: attachment1.share.media.playable,
|
|
124
|
+
duration: attachment1.share.media.duration,
|
|
125
|
+
subattachments: attachment1.share.subattachments,
|
|
126
|
+
properties: {},
|
|
127
|
+
animatedImageSize: attachment1.share.media.animated_image_size,
|
|
128
|
+
facebookUrl: attachment1.share.uri,
|
|
129
|
+
target: attachment1.share.target,
|
|
130
|
+
styleList: attachment1.share.style_list,
|
|
131
|
+
};
|
|
132
|
+
case "video":
|
|
133
|
+
return {
|
|
134
|
+
type: "video",
|
|
135
|
+
ID: attachment1.metadata.fbid.toString(),
|
|
136
|
+
filename: attachment1.name,
|
|
137
|
+
previewUrl: attachment1.preview_url,
|
|
138
|
+
previewWidth: attachment1.preview_width,
|
|
139
|
+
previewHeight: attachment1.preview_height,
|
|
140
|
+
url: attachment1.url,
|
|
141
|
+
width: attachment1.metadata.dimensions.width,
|
|
142
|
+
height: attachment1.metadata.dimensions.height,
|
|
143
|
+
duration: attachment1.metadata.duration,
|
|
144
|
+
videoType: "unknown",
|
|
145
|
+
thumbnailUrl: attachment1.thumbnail_url,
|
|
146
|
+
};
|
|
147
|
+
case "error":
|
|
148
|
+
return {
|
|
149
|
+
type: "error",
|
|
150
|
+
attachment1: attachment1,
|
|
151
|
+
attachment2: attachment2,
|
|
152
|
+
};
|
|
153
|
+
case "MessageImage":
|
|
154
|
+
return {
|
|
155
|
+
type: "photo",
|
|
156
|
+
ID: blob.legacy_attachment_id,
|
|
157
|
+
filename: blob.filename,
|
|
158
|
+
thumbnailUrl: blob.thumbnail.uri,
|
|
159
|
+
previewUrl: blob.preview.uri,
|
|
160
|
+
previewWidth: blob.preview.width,
|
|
161
|
+
previewHeight: blob.preview.height,
|
|
162
|
+
largePreviewUrl: blob.large_preview.uri,
|
|
163
|
+
largePreviewWidth: blob.large_preview.width,
|
|
164
|
+
largePreviewHeight: blob.large_preview.height,
|
|
165
|
+
url: blob.large_preview.uri,
|
|
166
|
+
width: blob.original_dimensions.x,
|
|
167
|
+
height: blob.original_dimensions.y,
|
|
168
|
+
name: blob.filename,
|
|
169
|
+
};
|
|
170
|
+
case "MessageAnimatedImage":
|
|
171
|
+
return {
|
|
172
|
+
type: "animated_image",
|
|
173
|
+
ID: blob.legacy_attachment_id,
|
|
174
|
+
filename: blob.filename,
|
|
175
|
+
previewUrl: blob.preview_image.uri,
|
|
176
|
+
previewWidth: blob.preview_image.width,
|
|
177
|
+
previewHeight: blob.preview_image.height,
|
|
178
|
+
url: blob.animated_image.uri,
|
|
179
|
+
width: blob.animated_image.width,
|
|
180
|
+
height: blob.animated_image.height,
|
|
181
|
+
thumbnailUrl: blob.preview_image.uri,
|
|
182
|
+
name: blob.filename,
|
|
183
|
+
facebookUrl: blob.animated_image.uri,
|
|
184
|
+
rawGifImage: blob.animated_image.uri,
|
|
185
|
+
animatedGifUrl: blob.animated_image.uri,
|
|
186
|
+
animatedGifPreviewUrl: blob.preview_image.uri,
|
|
187
|
+
animatedWebpUrl: blob.animated_image.uri,
|
|
188
|
+
animatedWebpPreviewUrl: blob.preview_image.uri,
|
|
189
|
+
};
|
|
190
|
+
case "MessageVideo":
|
|
191
|
+
return {
|
|
192
|
+
type: "video",
|
|
193
|
+
filename: blob.filename,
|
|
194
|
+
ID: blob.legacy_attachment_id,
|
|
195
|
+
previewUrl: blob.large_image.uri,
|
|
196
|
+
previewWidth: blob.large_image.width,
|
|
197
|
+
previewHeight: blob.large_image.height,
|
|
198
|
+
url: blob.playable_url,
|
|
199
|
+
width: blob.original_dimensions.x,
|
|
200
|
+
height: blob.original_dimensions.y,
|
|
201
|
+
duration: blob.playable_duration_in_ms,
|
|
202
|
+
videoType: blob.video_type.toLowerCase(),
|
|
203
|
+
thumbnailUrl: blob.large_image.uri,
|
|
204
|
+
};
|
|
205
|
+
case "MessageAudio":
|
|
206
|
+
return {
|
|
207
|
+
type: "audio",
|
|
208
|
+
filename: blob.filename,
|
|
209
|
+
ID: blob.url_shimhash,
|
|
210
|
+
audioType: blob.audio_type,
|
|
211
|
+
duration: blob.playable_duration_in_ms,
|
|
212
|
+
url: blob.playable_url,
|
|
213
|
+
isVoiceMail: blob.is_voicemail,
|
|
214
|
+
};
|
|
215
|
+
case "StickerAttachment":
|
|
216
|
+
return {
|
|
217
|
+
type: "sticker",
|
|
218
|
+
ID: blob.id,
|
|
219
|
+
url: blob.url,
|
|
220
|
+
packID: blob.pack ? blob.pack.id : null,
|
|
221
|
+
spriteUrl: blob.sprite_image,
|
|
222
|
+
spriteUrl2x: blob.sprite_image_2x,
|
|
223
|
+
width: blob.width,
|
|
224
|
+
height: blob.height,
|
|
225
|
+
caption: blob.label,
|
|
226
|
+
description: blob.label,
|
|
227
|
+
frameCount: blob.frame_count,
|
|
228
|
+
frameRate: blob.frame_rate,
|
|
229
|
+
framesPerRow: blob.frames_per_row,
|
|
230
|
+
framesPerCol: blob.frames_per_column,
|
|
231
|
+
stickerID: blob.id,
|
|
232
|
+
spriteURI: blob.sprite_image,
|
|
233
|
+
spriteURI2x: blob.sprite_image_2x,
|
|
234
|
+
};
|
|
235
|
+
case "MessageLocation": {
|
|
236
|
+
var urlAttach = blob.story_attachment.url;
|
|
237
|
+
var mediaAttach = blob.story_attachment.media;
|
|
238
|
+
var u = querystring.parse(url.parse(urlAttach).query).u;
|
|
239
|
+
var where1 = querystring.parse(url.parse(u).query).where1;
|
|
240
|
+
var address = where1.split(", ");
|
|
241
|
+
var latitude;
|
|
242
|
+
var longitude;
|
|
243
|
+
try {
|
|
244
|
+
latitude = Number.parseFloat(address[0]);
|
|
245
|
+
longitude = Number.parseFloat(address[1]);
|
|
246
|
+
} catch (err) {}
|
|
247
|
+
var imageUrl;
|
|
248
|
+
var width;
|
|
249
|
+
var height;
|
|
250
|
+
if (mediaAttach && mediaAttach.image) {
|
|
251
|
+
imageUrl = mediaAttach.image.uri;
|
|
252
|
+
width = mediaAttach.image.width;
|
|
253
|
+
height = mediaAttach.image.height;
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
type: "location",
|
|
257
|
+
ID: blob.legacy_attachment_id,
|
|
258
|
+
latitude: latitude,
|
|
259
|
+
longitude: longitude,
|
|
260
|
+
image: imageUrl,
|
|
261
|
+
width: width,
|
|
262
|
+
height: height,
|
|
263
|
+
url: u || urlAttach,
|
|
264
|
+
address: where1,
|
|
265
|
+
facebookUrl: blob.story_attachment.url,
|
|
266
|
+
target: blob.story_attachment.target,
|
|
267
|
+
styleList: blob.story_attachment.style_list,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
case "ExtensibleAttachment":
|
|
271
|
+
return {
|
|
272
|
+
type: "share",
|
|
273
|
+
ID: blob.legacy_attachment_id,
|
|
274
|
+
url: blob.story_attachment.url,
|
|
275
|
+
title: blob.story_attachment.title_with_entities.text,
|
|
276
|
+
description:
|
|
277
|
+
blob.story_attachment.description &&
|
|
278
|
+
blob.story_attachment.description.text,
|
|
279
|
+
source: blob.story_attachment.source
|
|
280
|
+
? blob.story_attachment.source.text
|
|
281
|
+
: null,
|
|
282
|
+
image:
|
|
283
|
+
blob.story_attachment.media &&
|
|
284
|
+
blob.story_attachment.media.image &&
|
|
285
|
+
blob.story_attachment.media.image.uri,
|
|
286
|
+
width:
|
|
287
|
+
blob.story_attachment.media &&
|
|
288
|
+
blob.story_attachment.media.image &&
|
|
289
|
+
blob.story_attachment.media.image.width,
|
|
290
|
+
height:
|
|
291
|
+
blob.story_attachment.media &&
|
|
292
|
+
blob.story_attachment.media.image &&
|
|
293
|
+
blob.story_attachment.media.image.height,
|
|
294
|
+
playable:
|
|
295
|
+
blob.story_attachment.media &&
|
|
296
|
+
blob.story_attachment.media.is_playable,
|
|
297
|
+
duration:
|
|
298
|
+
blob.story_attachment.media &&
|
|
299
|
+
blob.story_attachment.media.playable_duration_in_ms,
|
|
300
|
+
playableUrl:
|
|
301
|
+
blob.story_attachment.media == null
|
|
302
|
+
? null
|
|
303
|
+
: blob.story_attachment.media.playable_url,
|
|
304
|
+
subattachments: blob.story_attachment.subattachments,
|
|
305
|
+
properties: blob.story_attachment.properties.reduce(function (obj, cur) {
|
|
306
|
+
obj[cur.key] = cur.value.text;
|
|
307
|
+
return obj;
|
|
308
|
+
}, {}),
|
|
309
|
+
facebookUrl: blob.story_attachment.url,
|
|
310
|
+
target: blob.story_attachment.target,
|
|
311
|
+
styleList: blob.story_attachment.style_list,
|
|
312
|
+
};
|
|
313
|
+
case "MessageFile":
|
|
314
|
+
return {
|
|
315
|
+
type: "file",
|
|
316
|
+
filename: blob.filename,
|
|
317
|
+
ID: blob.message_file_fbid,
|
|
318
|
+
url: blob.url,
|
|
319
|
+
isMalicious: blob.is_malicious,
|
|
320
|
+
contentType: blob.content_type,
|
|
321
|
+
name: blob.filename,
|
|
322
|
+
mimeType: "",
|
|
323
|
+
fileSize: -1,
|
|
324
|
+
};
|
|
325
|
+
default:
|
|
326
|
+
throw new Error(
|
|
327
|
+
"unrecognized attach_file of type " +
|
|
328
|
+
type +
|
|
329
|
+
"`" +
|
|
330
|
+
JSON.stringify(attachment1, null, 4) +
|
|
331
|
+
" attachment2: " +
|
|
332
|
+
JSON.stringify(attachment2, null, 4) +
|
|
333
|
+
"`",
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
|
|
339
|
+
attachmentMap = shareMap || attachmentMap;
|
|
340
|
+
return attachments
|
|
341
|
+
? attachments.map(function (att, idx) {
|
|
342
|
+
if (
|
|
343
|
+
!attachmentMap ||
|
|
344
|
+
!attachmentIds ||
|
|
345
|
+
!attachmentMap[attachmentIds[idx]]
|
|
346
|
+
) {
|
|
347
|
+
return _formatAttachment(att);
|
|
348
|
+
}
|
|
349
|
+
return _formatAttachment(att, attachmentMap[attachmentIds[idx]]);
|
|
350
|
+
})
|
|
351
|
+
: [];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
module.exports = {
|
|
355
|
+
_formatAttachment,
|
|
356
|
+
formatAttachment,
|
|
357
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var NUM_TO_MONTH = [
|
|
4
|
+
"Jan",
|
|
5
|
+
"Feb",
|
|
6
|
+
"Mar",
|
|
7
|
+
"Apr",
|
|
8
|
+
"May",
|
|
9
|
+
"Jun",
|
|
10
|
+
"Jul",
|
|
11
|
+
"Aug",
|
|
12
|
+
"Sep",
|
|
13
|
+
"Oct",
|
|
14
|
+
"Nov",
|
|
15
|
+
"Dec",
|
|
16
|
+
];
|
|
17
|
+
var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
18
|
+
|
|
19
|
+
function formatDate(date) {
|
|
20
|
+
var d = date.getUTCDate();
|
|
21
|
+
d = d >= 10 ? d : "0" + d;
|
|
22
|
+
var h = date.getUTCHours();
|
|
23
|
+
h = h >= 10 ? h : "0" + h;
|
|
24
|
+
var m = date.getUTCMinutes();
|
|
25
|
+
m = m >= 10 ? m : "0" + m;
|
|
26
|
+
var s = date.getUTCSeconds();
|
|
27
|
+
s = s >= 10 ? s : "0" + s;
|
|
28
|
+
return (
|
|
29
|
+
NUM_TO_DAY[date.getUTCDay()] +
|
|
30
|
+
", " +
|
|
31
|
+
d +
|
|
32
|
+
" " +
|
|
33
|
+
NUM_TO_MONTH[date.getUTCMonth()] +
|
|
34
|
+
" " +
|
|
35
|
+
date.getUTCFullYear() +
|
|
36
|
+
" " +
|
|
37
|
+
h +
|
|
38
|
+
":" +
|
|
39
|
+
m +
|
|
40
|
+
":" +
|
|
41
|
+
s +
|
|
42
|
+
" GMT"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
NUM_TO_MONTH,
|
|
48
|
+
NUM_TO_DAY,
|
|
49
|
+
formatDate,
|
|
50
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function decodeClientPayload(payload) {
|
|
4
|
+
function Utf8ArrayToStr(array) {
|
|
5
|
+
var out, i, len, c;
|
|
6
|
+
var char2, char3;
|
|
7
|
+
out = "";
|
|
8
|
+
len = array.length;
|
|
9
|
+
i = 0;
|
|
10
|
+
while (i < len) {
|
|
11
|
+
c = array[i++];
|
|
12
|
+
switch (c >> 4) {
|
|
13
|
+
case 0:
|
|
14
|
+
case 1:
|
|
15
|
+
case 2:
|
|
16
|
+
case 3:
|
|
17
|
+
case 4:
|
|
18
|
+
case 5:
|
|
19
|
+
case 6:
|
|
20
|
+
case 7:
|
|
21
|
+
out += String.fromCharCode(c);
|
|
22
|
+
break;
|
|
23
|
+
case 12:
|
|
24
|
+
case 13:
|
|
25
|
+
char2 = array[i++];
|
|
26
|
+
out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
|
|
27
|
+
break;
|
|
28
|
+
case 14:
|
|
29
|
+
char2 = array[i++];
|
|
30
|
+
char3 = array[i++];
|
|
31
|
+
out += String.fromCharCode(
|
|
32
|
+
((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0),
|
|
33
|
+
);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
return JSON.parse(Utf8ArrayToStr(payload));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
decodeClientPayload,
|
|
44
|
+
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { formatID } = require("./utils");
|
|
4
|
+
const { _formatAttachment } = require("./attachment");
|
|
5
|
+
|
|
6
|
+
function getAdminTextMessageType(m) {
|
|
7
|
+
const type = m && (m.type || m);
|
|
8
|
+
switch (type) {
|
|
9
|
+
case "joinable_group_link_mode_change":
|
|
10
|
+
return "log:link-status";
|
|
11
|
+
case "magic_words":
|
|
12
|
+
return "log:magic-words";
|
|
13
|
+
case "change_thread_theme":
|
|
14
|
+
return "log:thread-color";
|
|
15
|
+
case "change_thread_icon":
|
|
16
|
+
case "change_thread_quick_reaction":
|
|
17
|
+
return "log:thread-icon";
|
|
18
|
+
case "change_thread_nickname":
|
|
19
|
+
return "log:user-nickname";
|
|
20
|
+
case "change_thread_admins":
|
|
21
|
+
return "log:thread-admins";
|
|
22
|
+
case "group_poll":
|
|
23
|
+
return "log:thread-poll";
|
|
24
|
+
case "change_thread_approval_mode":
|
|
25
|
+
return "log:thread-approval-mode";
|
|
26
|
+
case "messenger_call_log":
|
|
27
|
+
case "participant_joined_group_call":
|
|
28
|
+
return "log:thread-call";
|
|
29
|
+
case "pin_messages_v2":
|
|
30
|
+
return "log:thread-pinned";
|
|
31
|
+
case "unpin_messages_v2":
|
|
32
|
+
return "log:unpin-message";
|
|
33
|
+
default:
|
|
34
|
+
return m && m.type != null ? m.type : type;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function formatDeltaEvent(m) {
|
|
39
|
+
var logMessageType;
|
|
40
|
+
var logMessageData;
|
|
41
|
+
switch (m.class) {
|
|
42
|
+
case "AdminTextMessage":
|
|
43
|
+
logMessageType = getAdminTextMessageType(m);
|
|
44
|
+
logMessageData = m.untypedData;
|
|
45
|
+
break;
|
|
46
|
+
case "ThreadName":
|
|
47
|
+
logMessageType = "log:thread-name";
|
|
48
|
+
logMessageData = { name: m.name };
|
|
49
|
+
break;
|
|
50
|
+
case "ParticipantsAddedToGroupThread":
|
|
51
|
+
logMessageType = "log:subscribe";
|
|
52
|
+
logMessageData = { addedParticipants: m.addedParticipants };
|
|
53
|
+
break;
|
|
54
|
+
case "ParticipantLeftGroupThread":
|
|
55
|
+
logMessageType = "log:unsubscribe";
|
|
56
|
+
logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
|
|
57
|
+
break;
|
|
58
|
+
case "UserLocation": {
|
|
59
|
+
logMessageType = "log:user-location";
|
|
60
|
+
logMessageData = {
|
|
61
|
+
Image:
|
|
62
|
+
m.attachments[0].mercury.extensible_attachment.story_attachment.media
|
|
63
|
+
.image,
|
|
64
|
+
Location:
|
|
65
|
+
m.attachments[0].mercury.extensible_attachment.story_attachment.target
|
|
66
|
+
.location_title,
|
|
67
|
+
coordinates:
|
|
68
|
+
m.attachments[0].mercury.extensible_attachment.story_attachment.target
|
|
69
|
+
.coordinate,
|
|
70
|
+
url: m.attachments[0].mercury.extensible_attachment.story_attachment
|
|
71
|
+
.url,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
case "ApprovalQueue":
|
|
75
|
+
logMessageType = "log:approval-queue";
|
|
76
|
+
logMessageData = {
|
|
77
|
+
approvalQueue: {
|
|
78
|
+
action: m.action,
|
|
79
|
+
recipientFbId: m.recipientFbId,
|
|
80
|
+
requestSource: m.requestSource,
|
|
81
|
+
...m.messageMetadata,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
type: "event",
|
|
87
|
+
threadID: formatID(
|
|
88
|
+
(
|
|
89
|
+
m.messageMetadata.threadKey.threadFbId ||
|
|
90
|
+
m.messageMetadata.threadKey.otherUserFbId
|
|
91
|
+
).toString(),
|
|
92
|
+
),
|
|
93
|
+
logMessageType: logMessageType,
|
|
94
|
+
logMessageData: logMessageData,
|
|
95
|
+
logMessageBody: m.messageMetadata.adminText,
|
|
96
|
+
author: m.messageMetadata.actorFbId,
|
|
97
|
+
participantIDs: (m?.participants || []).map((e) => e.toString()),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getMentionsFromDeltaMessage(m) {
|
|
102
|
+
var body = m.body || "";
|
|
103
|
+
var mentions = {};
|
|
104
|
+
var mdata = [];
|
|
105
|
+
if (m.data && m.data.prng) {
|
|
106
|
+
try {
|
|
107
|
+
mdata = JSON.parse(m.data.prng);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
mdata = [];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (mdata.length > 0) {
|
|
113
|
+
for (var i = 0; i < mdata.length; i++) {
|
|
114
|
+
var id = mdata[i].i;
|
|
115
|
+
var o = parseInt(mdata[i].o, 10) || 0;
|
|
116
|
+
var l = parseInt(mdata[i].l, 10) || 0;
|
|
117
|
+
mentions[String(id)] = body.substring(o, o + l);
|
|
118
|
+
}
|
|
119
|
+
return mentions;
|
|
120
|
+
}
|
|
121
|
+
var md = m.messageMetadata;
|
|
122
|
+
if (
|
|
123
|
+
md &&
|
|
124
|
+
md.data &&
|
|
125
|
+
md.data.data &&
|
|
126
|
+
md.data.data.Gb &&
|
|
127
|
+
md.data.data.Gb.asMap &&
|
|
128
|
+
md.data.data.Gb.asMap.data
|
|
129
|
+
) {
|
|
130
|
+
var gbData = md.data.data.Gb.asMap.data;
|
|
131
|
+
for (var key in gbData) {
|
|
132
|
+
if (!Object.prototype.hasOwnProperty.call(gbData, key)) continue;
|
|
133
|
+
var entry = gbData[key];
|
|
134
|
+
if (entry && entry.asMap && entry.asMap.data) {
|
|
135
|
+
var d = entry.asMap.data;
|
|
136
|
+
var id = d.id && d.id.asLong ? String(d.id.asLong) : null;
|
|
137
|
+
var offset = parseInt(
|
|
138
|
+
d.offset && d.offset.asLong ? d.offset.asLong : 0,
|
|
139
|
+
10,
|
|
140
|
+
);
|
|
141
|
+
var len = parseInt(
|
|
142
|
+
d.length && d.length.asLong ? d.length.asLong : 0,
|
|
143
|
+
10,
|
|
144
|
+
);
|
|
145
|
+
if (id != null) {
|
|
146
|
+
mentions[id] = body.substring(offset, offset + len);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return mentions;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function formatDeltaMessage(m) {
|
|
155
|
+
var md = m.messageMetadata;
|
|
156
|
+
var body = m.body || "";
|
|
157
|
+
var mentions = getMentionsFromDeltaMessage(m);
|
|
158
|
+
var args = body === "" ? [] : body.trim().split(/\s+/);
|
|
159
|
+
return {
|
|
160
|
+
type: "message",
|
|
161
|
+
senderID: formatID(md.actorFbId.toString()),
|
|
162
|
+
threadID: formatID(
|
|
163
|
+
(md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString(),
|
|
164
|
+
),
|
|
165
|
+
messageID: md.messageId,
|
|
166
|
+
args: args,
|
|
167
|
+
body: body,
|
|
168
|
+
attachments: (m.attachments || []).map((v) => _formatAttachment(v)),
|
|
169
|
+
mentions: mentions,
|
|
170
|
+
timestamp: md.timestamp,
|
|
171
|
+
isGroup: !!md.threadKey.threadFbId,
|
|
172
|
+
participantIDs: (m.participants || []).map((p) => formatID(p.toString())),
|
|
173
|
+
isUnread: md.isUnread !== undefined ? md.isUnread : false,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function formatDeltaReadReceipt(delta) {
|
|
178
|
+
return {
|
|
179
|
+
reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
|
|
180
|
+
time: delta.actionTimestampMs,
|
|
181
|
+
threadID: formatID(
|
|
182
|
+
(delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString(),
|
|
183
|
+
),
|
|
184
|
+
type: "read_receipt",
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = {
|
|
189
|
+
getAdminTextMessageType,
|
|
190
|
+
formatDeltaEvent,
|
|
191
|
+
formatDeltaMessage,
|
|
192
|
+
getMentionsFromDeltaMessage,
|
|
193
|
+
formatDeltaReadReceipt,
|
|
194
|
+
};
|