fca-nx 6.6.6 → 6.6.8
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/package.json +1 -1
- package/src/api/action/addfriend.js +109 -0
- package/src/api/action/changeCover.js +106 -221
- package/src/api/http/httpGet.js +33 -13
- package/src/api/http/httpPost.js +32 -14
- package/src/api/messaging/editMessage.js +50 -34
- package/src/api/messaging/sendMessage.js +19 -8
- package/src/api/socket/listenMqtt.js +52 -33
- package/src/api/users/getUserInfoV2.js +145 -786
- package/src/app/createFcaClient.js +0 -1
- package/src/api/action/addFriend.js +0 -145
- /package/{LICENCE → LICENSE} +0 -0
|
@@ -1,84 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
const { parseAndCheckLogin } = require("../../utils/client.js");
|
|
4
3
|
const logger = require("../../../func/logger");
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
{
|
|
8
|
-
id: "2399631849267992",
|
|
9
|
-
name: "CometUserProfileCoverPhotoQuery",
|
|
10
|
-
hasCover: true
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
id: "5009315269112105",
|
|
14
|
-
name: "CometProfilePhotoGridQuery",
|
|
15
|
-
hasCover: true
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: "24418640587785718",
|
|
19
|
-
name: "CometHovercardQueryRendererQuery",
|
|
20
|
-
hasCover: false
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: "6003371686559437",
|
|
24
|
-
name: "CometProfileInfoRendererQuery",
|
|
25
|
-
hasCover: true
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
id: "6184020922587885",
|
|
29
|
-
name: "CometProfilePageQuery",
|
|
30
|
-
hasCover: true
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
id: "5069749766627730",
|
|
34
|
-
name: "CometActorProfilePictureQuery",
|
|
35
|
-
hasCover: false
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
|
|
4
|
+
const DOC_ID = "24418640587785718";
|
|
5
|
+
const FRIENDLY_NAME = "CometHovercardQueryRendererQuery";
|
|
39
6
|
const CALLER_CLASS = "RelayModern";
|
|
40
7
|
|
|
41
8
|
function toJSONMaybe(data) {
|
|
42
9
|
if (!data) return null;
|
|
43
|
-
|
|
44
10
|
if (typeof data === "string") {
|
|
45
|
-
const text = data
|
|
46
|
-
.trim()
|
|
47
|
-
.replace(/^for\s*\(\s*;\s*;\s*\)\s*;/, "");
|
|
48
|
-
|
|
11
|
+
const text = data.trim().replace(/^for\s*\(\s*;\s*;\s*\)\s*;/, "");
|
|
49
12
|
try {
|
|
50
13
|
return JSON.parse(text);
|
|
51
14
|
} catch {
|
|
52
15
|
return null;
|
|
53
16
|
}
|
|
54
17
|
}
|
|
55
|
-
|
|
56
18
|
return data;
|
|
57
19
|
}
|
|
58
20
|
|
|
59
21
|
function usernameFromUrl(raw) {
|
|
60
22
|
if (!raw) return null;
|
|
61
|
-
|
|
62
23
|
try {
|
|
63
24
|
const url = new URL(raw);
|
|
64
|
-
|
|
65
25
|
if (!/^www\.facebook\.com$/i.test(url.hostname)) {
|
|
66
26
|
return null;
|
|
67
27
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.replace(/^\/+/, "")
|
|
71
|
-
.replace(/\/+$/, "");
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
path &&
|
|
75
|
-
!/^profile\.php$/i.test(path) &&
|
|
76
|
-
!path.includes("/")
|
|
77
|
-
) {
|
|
28
|
+
const path = url.pathname.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
29
|
+
if (path &&!/^profile\.php$/i.test(path) &&!path.includes("/")) {
|
|
78
30
|
return path;
|
|
79
31
|
}
|
|
80
32
|
} catch {}
|
|
81
|
-
|
|
82
33
|
return null;
|
|
83
34
|
}
|
|
84
35
|
|
|
@@ -86,242 +37,71 @@ function pickMeta(user) {
|
|
|
86
37
|
let friendshipStatus = null;
|
|
87
38
|
let gender = null;
|
|
88
39
|
let shortName = user?.short_name || null;
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const secondaryActions = Array.isArray(user?.secondaryActions)
|
|
95
|
-
? user.secondaryActions
|
|
96
|
-
: [];
|
|
97
|
-
|
|
98
|
-
const friendAction = primaryActions.find(
|
|
99
|
-
item => item?.profile_action_type === "FRIEND"
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const owner =
|
|
103
|
-
friendAction?.client_handler?.profile_action
|
|
104
|
-
?.restrictable_profile_owner;
|
|
105
|
-
|
|
40
|
+
const primaryActions = Array.isArray(user?.primaryActions)? user.primaryActions : [];
|
|
41
|
+
const secondaryActions = Array.isArray(user?.secondaryActions)? user.secondaryActions : [];
|
|
42
|
+
const friendAction = primaryActions.find(item => item?.profile_action_type === "FRIEND");
|
|
43
|
+
const owner = friendAction?.client_handler?.profile_action?.restrictable_profile_owner;
|
|
106
44
|
if (owner) {
|
|
107
|
-
friendshipStatus =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
gender =
|
|
111
|
-
owner.gender || gender;
|
|
112
|
-
|
|
113
|
-
shortName =
|
|
114
|
-
owner.short_name || shortName;
|
|
45
|
+
friendshipStatus = owner.friendship_status || null;
|
|
46
|
+
gender = owner.gender || gender;
|
|
47
|
+
shortName = owner.short_name || shortName;
|
|
115
48
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
item => item?.profile_action_type === "BLOCK"
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const blockOwner =
|
|
123
|
-
blockAction?.client_handler
|
|
124
|
-
?.profile_action
|
|
125
|
-
?.profile_owner;
|
|
126
|
-
|
|
49
|
+
if (!gender ||!shortName) {
|
|
50
|
+
const blockAction = secondaryActions.find(item => item?.profile_action_type === "BLOCK");
|
|
51
|
+
const blockOwner = blockAction?.client_handler?.profile_action?.profile_owner;
|
|
127
52
|
if (blockOwner) {
|
|
128
|
-
gender =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
shortName =
|
|
132
|
-
blockOwner.short_name || shortName;
|
|
53
|
+
gender = blockOwner.gender || gender;
|
|
54
|
+
shortName = blockOwner.short_name || shortName;
|
|
133
55
|
}
|
|
134
56
|
}
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
friendshipStatus,
|
|
138
|
-
gender,
|
|
139
|
-
shortName
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function extractCoverPhoto(user) {
|
|
144
|
-
if (!user) return null;
|
|
145
|
-
|
|
146
|
-
const cover = user.cover_photo;
|
|
147
|
-
|
|
148
|
-
if (!cover) return null;
|
|
149
|
-
|
|
150
|
-
if (typeof cover === "string") {
|
|
151
|
-
return cover;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return (
|
|
155
|
-
cover?.source?.uri ||
|
|
156
|
-
cover?.source ||
|
|
157
|
-
cover?.uri ||
|
|
158
|
-
cover?.photo?.image?.uri ||
|
|
159
|
-
cover?.photo?.image?.url ||
|
|
160
|
-
cover?.image?.uri ||
|
|
161
|
-
cover?.image?.url ||
|
|
162
|
-
null
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function extractProfilePicture(user) {
|
|
167
|
-
if (!user) return null;
|
|
168
|
-
|
|
169
|
-
return (
|
|
170
|
-
user.profile_picture?.uri ||
|
|
171
|
-
user.profilePicture?.uri ||
|
|
172
|
-
user.profile_picture?.source?.uri ||
|
|
173
|
-
user.profile_picture?.source ||
|
|
174
|
-
null
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function findUser(root) {
|
|
179
|
-
if (!root) return null;
|
|
180
|
-
|
|
181
|
-
return (
|
|
182
|
-
root?.data?.node?.comet_hovercard_renderer?.user ||
|
|
183
|
-
root?.data?.node?.user ||
|
|
184
|
-
root?.data?.node ||
|
|
185
|
-
root?.data?.user ||
|
|
186
|
-
root?.data?.viewer ||
|
|
187
|
-
null
|
|
188
|
-
);
|
|
57
|
+
return { friendshipStatus, gender, shortName };
|
|
189
58
|
}
|
|
190
59
|
|
|
191
|
-
function normalizeUser(user
|
|
60
|
+
function normalizeUser(user) {
|
|
192
61
|
if (!user) return null;
|
|
193
|
-
|
|
194
62
|
const meta = pickMeta(user);
|
|
195
|
-
|
|
196
|
-
const profileUrl =
|
|
197
|
-
user.profile_url ||
|
|
198
|
-
user.profileUrl ||
|
|
199
|
-
user.url ||
|
|
200
|
-
null;
|
|
201
|
-
|
|
202
|
-
const vanity =
|
|
203
|
-
usernameFromUrl(profileUrl) ||
|
|
204
|
-
user.username_for_profile ||
|
|
205
|
-
user.username ||
|
|
206
|
-
user.vanity ||
|
|
207
|
-
null;
|
|
208
|
-
|
|
209
|
-
let coverPhoto = null;
|
|
210
|
-
|
|
211
|
-
if (doc?.hasCover) {
|
|
212
|
-
coverPhoto = extractCoverPhoto(user);
|
|
213
|
-
}
|
|
214
|
-
|
|
63
|
+
const vanity = usernameFromUrl(user.profile_url || user.url) || user.username_for_profile || null;
|
|
215
64
|
return {
|
|
216
65
|
id: user.id || null,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
user.name ||
|
|
220
|
-
null,
|
|
221
|
-
|
|
222
|
-
firstName:
|
|
223
|
-
meta.shortName ||
|
|
224
|
-
user.first_name ||
|
|
225
|
-
null,
|
|
226
|
-
|
|
66
|
+
name: user.name || null,
|
|
67
|
+
firstName: meta.shortName || null,
|
|
227
68
|
vanity,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
: null
|
|
242
|
-
),
|
|
243
|
-
|
|
244
|
-
type:
|
|
245
|
-
user.__typename ||
|
|
246
|
-
user.type ||
|
|
247
|
-
"User",
|
|
248
|
-
|
|
249
|
-
isFriend:
|
|
250
|
-
meta.friendshipStatus === "ARE_FRIENDS",
|
|
251
|
-
|
|
252
|
-
isBirthday:
|
|
253
|
-
!!user.is_birthday,
|
|
254
|
-
|
|
255
|
-
isVerified:
|
|
256
|
-
!!user.is_verified,
|
|
257
|
-
|
|
258
|
-
isMemorialized:
|
|
259
|
-
!!user.is_visibly_memorialized,
|
|
260
|
-
|
|
261
|
-
isMessengerUser:
|
|
262
|
-
typeof user.is_messenger_user === "boolean"
|
|
263
|
-
? user.is_messenger_user
|
|
264
|
-
: null,
|
|
265
|
-
|
|
266
|
-
isMessageBlockedByViewer:
|
|
267
|
-
typeof user.is_message_blocked_by_viewer === "boolean"
|
|
268
|
-
? user.is_message_blocked_by_viewer
|
|
269
|
-
: false,
|
|
270
|
-
|
|
271
|
-
workInfo:
|
|
272
|
-
user.work_info ||
|
|
273
|
-
null,
|
|
274
|
-
|
|
275
|
-
messengerStatus:
|
|
276
|
-
user.messenger_account_status_category ||
|
|
277
|
-
null
|
|
69
|
+
thumbSrc: user.profile_picture?.uri || null,
|
|
70
|
+
coverPhoto: user.cover_photo?.source || user.cover_photo?.uri || null,
|
|
71
|
+
profileUrl: user.profile_url || user.url || null,
|
|
72
|
+
gender: meta.gender || null,
|
|
73
|
+
type: user.__typename || "User",
|
|
74
|
+
isFriend: meta.friendshipStatus === "ARE_FRIENDS",
|
|
75
|
+
isBirthday:!!user.is_birthday,
|
|
76
|
+
isVerified:!!user.is_verified,
|
|
77
|
+
isMemorialized:!!user.is_visibly_memorialized,
|
|
78
|
+
isMessengerUser: typeof user.is_messenger_user === "boolean"? user.is_messenger_user : null,
|
|
79
|
+
isMessageBlockedByViewer: typeof user.is_message_blocked_by_viewer === "boolean"? user.is_message_blocked_by_viewer : false,
|
|
80
|
+
workInfo: user.work_info || null,
|
|
81
|
+
messengerStatus: user.messenger_account_status_category || null
|
|
278
82
|
};
|
|
279
83
|
}
|
|
280
84
|
|
|
281
85
|
function createDefaultUser(id) {
|
|
282
|
-
const userID = String(id);
|
|
283
|
-
|
|
284
|
-
const picture =
|
|
285
|
-
`https://graph.facebook.com/${userID}/picture?width=720&height=720`;
|
|
286
|
-
|
|
287
86
|
return {
|
|
288
|
-
id:
|
|
289
|
-
|
|
87
|
+
id: String(id),
|
|
290
88
|
name: "Facebook User",
|
|
291
|
-
|
|
292
89
|
firstName: "Facebook",
|
|
293
|
-
|
|
294
90
|
lastName: null,
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
profilePicUrl: picture,
|
|
301
|
-
|
|
302
|
-
coverPhoto: null,
|
|
303
|
-
|
|
304
|
-
profileUrl:
|
|
305
|
-
`https://www.facebook.com/profile.php?id=${userID}`,
|
|
306
|
-
|
|
91
|
+
vanity: String(id),
|
|
92
|
+
thumbSrc: `https://graph.facebook.com/${id}/picture?width=720&height=720`,
|
|
93
|
+
profilePicUrl: `https://graph.facebook.com/${id}/picture?width=720&height=720`,
|
|
94
|
+
coverPhoto: null, // FIX: default e null
|
|
95
|
+
profileUrl: `https://www.facebook.com/profile.php?id=${id}`,
|
|
307
96
|
gender: "no specific gender",
|
|
308
|
-
|
|
309
97
|
type: "User",
|
|
310
|
-
|
|
311
98
|
isFriend: false,
|
|
312
|
-
|
|
313
99
|
isBirthday: false,
|
|
314
|
-
|
|
315
100
|
isVerified: false,
|
|
316
|
-
|
|
317
101
|
isMemorialized: false,
|
|
318
|
-
|
|
319
102
|
isMessengerUser: null,
|
|
320
|
-
|
|
321
103
|
isMessageBlockedByViewer: false,
|
|
322
|
-
|
|
323
104
|
workInfo: null,
|
|
324
|
-
|
|
325
105
|
messengerStatus: null
|
|
326
106
|
};
|
|
327
107
|
}
|
|
@@ -330,582 +110,161 @@ function formatUser(user, id) {
|
|
|
330
110
|
if (!user) {
|
|
331
111
|
return createDefaultUser(id);
|
|
332
112
|
}
|
|
333
|
-
|
|
334
|
-
const nameParts = user.name
|
|
335
|
-
? String(user.name)
|
|
336
|
-
.trim()
|
|
337
|
-
.split(/\s+/)
|
|
338
|
-
: [];
|
|
339
|
-
|
|
340
|
-
const profilePicUrl =
|
|
341
|
-
user.thumbSrc ||
|
|
342
|
-
user.profilePicUrl ||
|
|
343
|
-
`https://graph.facebook.com/${id}/picture?width=720&height=720`;
|
|
344
|
-
|
|
113
|
+
const nameParts = user.name? String(user.name).trim().split(/\s+/) : [];
|
|
345
114
|
return {
|
|
346
|
-
id:
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
: null
|
|
365
|
-
),
|
|
366
|
-
|
|
367
|
-
vanity:
|
|
368
|
-
user.vanity ||
|
|
369
|
-
String(id),
|
|
370
|
-
|
|
371
|
-
thumbSrc:
|
|
372
|
-
user.thumbSrc ||
|
|
373
|
-
profilePicUrl,
|
|
374
|
-
|
|
375
|
-
profilePicUrl,
|
|
376
|
-
|
|
377
|
-
coverPhoto:
|
|
378
|
-
user.coverPhoto ||
|
|
379
|
-
null,
|
|
380
|
-
|
|
381
|
-
profileUrl:
|
|
382
|
-
user.profileUrl ||
|
|
383
|
-
`https://www.facebook.com/profile.php?id=${id}`,
|
|
384
|
-
|
|
385
|
-
gender:
|
|
386
|
-
user.gender ||
|
|
387
|
-
"no specific gender",
|
|
388
|
-
|
|
389
|
-
type:
|
|
390
|
-
user.type ||
|
|
391
|
-
"User",
|
|
392
|
-
|
|
393
|
-
isFriend:
|
|
394
|
-
typeof user.isFriend === "boolean"
|
|
395
|
-
? user.isFriend
|
|
396
|
-
: false,
|
|
397
|
-
|
|
398
|
-
isBirthday:
|
|
399
|
-
!!user.isBirthday,
|
|
400
|
-
|
|
401
|
-
isVerified:
|
|
402
|
-
!!user.isVerified,
|
|
403
|
-
|
|
404
|
-
isMemorialized:
|
|
405
|
-
!!user.isMemorialized,
|
|
406
|
-
|
|
407
|
-
isMessengerUser:
|
|
408
|
-
typeof user.isMessengerUser === "boolean"
|
|
409
|
-
? user.isMessengerUser
|
|
410
|
-
: null,
|
|
411
|
-
|
|
412
|
-
isMessageBlockedByViewer:
|
|
413
|
-
typeof user.isMessageBlockedByViewer === "boolean"
|
|
414
|
-
? user.isMessageBlockedByViewer
|
|
415
|
-
: false,
|
|
416
|
-
|
|
417
|
-
workInfo:
|
|
418
|
-
user.workInfo ||
|
|
419
|
-
null,
|
|
420
|
-
|
|
421
|
-
messengerStatus:
|
|
422
|
-
user.messengerStatus ||
|
|
423
|
-
null
|
|
115
|
+
id: user.id || String(id),
|
|
116
|
+
name: user.name || null,
|
|
117
|
+
firstName: user.firstName || nameParts[0] || "Facebook",
|
|
118
|
+
lastName: nameParts.length > 1? nameParts.slice(1).join(" ") : null,
|
|
119
|
+
vanity: user.vanity || String(id),
|
|
120
|
+
profilePicUrl: user.thumbSrc || `https://graph.facebook.com/${id}/picture?width=720&height=720`,
|
|
121
|
+
coverPhoto: user.coverPhoto || null, // FIX: cover photo pass
|
|
122
|
+
profileUrl: user.profileUrl || `https://www.facebook.com/profile.php?id=${id}`,
|
|
123
|
+
gender: user.gender || "no specific gender",
|
|
124
|
+
type: user.type || "User",
|
|
125
|
+
isFriend: typeof user.isFriend === "boolean"? user.isFriend : false,
|
|
126
|
+
isBirthday:!!user.isBirthday,
|
|
127
|
+
isVerified:!!user.isVerified,
|
|
128
|
+
isMemorialized:!!user.isMemorialized,
|
|
129
|
+
isMessengerUser: typeof user.isMessengerUser === "boolean"? user.isMessengerUser : null,
|
|
130
|
+
isMessageBlockedByViewer: typeof user.isMessageBlockedByViewer === "boolean"? user.isMessageBlockedByViewer : false,
|
|
131
|
+
workInfo: user.workInfo || null,
|
|
132
|
+
messengerStatus: user.messengerStatus || null
|
|
424
133
|
};
|
|
425
134
|
}
|
|
426
135
|
|
|
427
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
136
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
428
137
|
async function fetchOne(userID) {
|
|
429
138
|
const id = String(userID);
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
__relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider:
|
|
451
|
-
false
|
|
452
|
-
}
|
|
453
|
-
: {
|
|
454
|
-
userID: id,
|
|
455
|
-
scale: 1
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
const form = {
|
|
459
|
-
av:
|
|
460
|
-
String(ctx?.userID || ""),
|
|
461
|
-
|
|
462
|
-
fb_api_caller_class:
|
|
463
|
-
CALLER_CLASS,
|
|
464
|
-
|
|
465
|
-
fb_api_req_friendly_name:
|
|
466
|
-
doc.name,
|
|
467
|
-
|
|
468
|
-
server_timestamps:
|
|
469
|
-
true,
|
|
470
|
-
|
|
471
|
-
doc_id:
|
|
472
|
-
doc.id,
|
|
473
|
-
|
|
474
|
-
variables:
|
|
475
|
-
JSON.stringify(variables)
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
const response =
|
|
479
|
-
await defaultFuncs
|
|
480
|
-
.post(
|
|
481
|
-
"https://www.facebook.com/api/graphql/",
|
|
482
|
-
ctx.jar,
|
|
483
|
-
form
|
|
484
|
-
)
|
|
485
|
-
.then(
|
|
486
|
-
parseAndCheckLogin(
|
|
487
|
-
ctx,
|
|
488
|
-
defaultFuncs
|
|
489
|
-
)
|
|
490
|
-
);
|
|
491
|
-
|
|
492
|
-
const parsed =
|
|
493
|
-
toJSONMaybe(response) ||
|
|
494
|
-
response;
|
|
495
|
-
|
|
496
|
-
const root =
|
|
497
|
-
Array.isArray(parsed)
|
|
498
|
-
? parsed[0]
|
|
499
|
-
: parsed;
|
|
500
|
-
|
|
501
|
-
const user =
|
|
502
|
-
findUser(root);
|
|
503
|
-
|
|
504
|
-
if (!user) {
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
const normalized =
|
|
509
|
-
normalizeUser(
|
|
510
|
-
user,
|
|
511
|
-
doc
|
|
512
|
-
);
|
|
513
|
-
|
|
514
|
-
if (!normalized?.id) {
|
|
515
|
-
continue;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (!bestUser) {
|
|
519
|
-
bestUser = normalized;
|
|
520
|
-
} else {
|
|
521
|
-
if (
|
|
522
|
-
!bestUser.thumbSrc &&
|
|
523
|
-
normalized.thumbSrc
|
|
524
|
-
) {
|
|
525
|
-
bestUser.thumbSrc =
|
|
526
|
-
normalized.thumbSrc;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
if (
|
|
530
|
-
!bestUser.profileUrl &&
|
|
531
|
-
normalized.profileUrl
|
|
532
|
-
) {
|
|
533
|
-
bestUser.profileUrl =
|
|
534
|
-
normalized.profileUrl;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
if (
|
|
538
|
-
!bestUser.vanity &&
|
|
539
|
-
normalized.vanity
|
|
540
|
-
) {
|
|
541
|
-
bestUser.vanity =
|
|
542
|
-
normalized.vanity;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
if (
|
|
546
|
-
!bestUser.coverPhoto &&
|
|
547
|
-
normalized.coverPhoto
|
|
548
|
-
) {
|
|
549
|
-
bestUser.coverPhoto =
|
|
550
|
-
normalized.coverPhoto;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
if (
|
|
554
|
-
!bestUser.firstName &&
|
|
555
|
-
normalized.firstName
|
|
556
|
-
) {
|
|
557
|
-
bestUser.firstName =
|
|
558
|
-
normalized.firstName;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
if (
|
|
562
|
-
!bestUser.gender &&
|
|
563
|
-
normalized.gender
|
|
564
|
-
) {
|
|
565
|
-
bestUser.gender =
|
|
566
|
-
normalized.gender;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
if (
|
|
570
|
-
normalized.isVerified
|
|
571
|
-
) {
|
|
572
|
-
bestUser.isVerified = true;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
if (
|
|
576
|
-
normalized.isFriend
|
|
577
|
-
) {
|
|
578
|
-
bestUser.isFriend = true;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
if (normalized.coverPhoto) {
|
|
583
|
-
break;
|
|
584
|
-
}
|
|
585
|
-
} catch (error) {
|
|
586
|
-
logger(
|
|
587
|
-
`getUserInfoV2 ${doc.id}: ${error.message || error}`,
|
|
588
|
-
"warn"
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
return bestUser;
|
|
139
|
+
const variables = {
|
|
140
|
+
actionBarRenderLocation: "WWW_COMET_HOVERCARD",
|
|
141
|
+
context: "DEFAULT",
|
|
142
|
+
entityID: id,
|
|
143
|
+
scale: 1,
|
|
144
|
+
__relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false
|
|
145
|
+
};
|
|
146
|
+
const form = {
|
|
147
|
+
av: String(ctx?.userID || ""),
|
|
148
|
+
fb_api_caller_class: CALLER_CLASS,
|
|
149
|
+
fb_api_req_friendly_name: FRIENDLY_NAME,
|
|
150
|
+
server_timestamps: true,
|
|
151
|
+
doc_id: DOC_ID,
|
|
152
|
+
variables: JSON.stringify(variables)
|
|
153
|
+
};
|
|
154
|
+
const response = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form).then(parseAndCheckLogin(ctx, defaultFuncs));
|
|
155
|
+
const parsed = toJSONMaybe(response) || response;
|
|
156
|
+
const root = Array.isArray(parsed)? parsed[0] : parsed;
|
|
157
|
+
const user = root?.data?.node?.comet_hovercard_renderer?.user || null;
|
|
158
|
+
return normalizeUser(user);
|
|
594
159
|
}
|
|
595
160
|
|
|
596
161
|
async function fetchLegacy(userIDs) {
|
|
597
162
|
const form = {};
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
604
|
-
);
|
|
605
|
-
|
|
606
|
-
const response =
|
|
607
|
-
await defaultFuncs
|
|
608
|
-
.post(
|
|
609
|
-
"https://www.facebook.com/chat/user_info/",
|
|
610
|
-
ctx.jar,
|
|
611
|
-
form
|
|
612
|
-
)
|
|
613
|
-
.then(
|
|
614
|
-
parseAndCheckLogin(
|
|
615
|
-
ctx,
|
|
616
|
-
defaultFuncs
|
|
617
|
-
)
|
|
618
|
-
);
|
|
619
|
-
|
|
620
|
-
if (
|
|
621
|
-
!response ||
|
|
622
|
-
response.error
|
|
623
|
-
) {
|
|
163
|
+
userIDs.forEach((id, index) => {
|
|
164
|
+
form[`ids[${index}]`] = String(id);
|
|
165
|
+
});
|
|
166
|
+
const response = await defaultFuncs.post("https://www.facebook.com/chat/user_info/", ctx.jar, form).then(parseAndCheckLogin(ctx, defaultFuncs));
|
|
167
|
+
if (response?.error) {
|
|
624
168
|
return {};
|
|
625
169
|
}
|
|
626
|
-
|
|
627
|
-
const profiles =
|
|
628
|
-
response?.payload?.profiles ||
|
|
629
|
-
{};
|
|
630
|
-
|
|
170
|
+
const profiles = response?.payload?.profiles || {};
|
|
631
171
|
const result = {};
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const profile =
|
|
637
|
-
profiles[id];
|
|
638
|
-
|
|
639
|
-
if (!profile) {
|
|
640
|
-
continue;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
const nameParts =
|
|
644
|
-
profile.name
|
|
645
|
-
? String(profile.name)
|
|
646
|
-
.trim()
|
|
647
|
-
.split(/\s+/)
|
|
648
|
-
: [];
|
|
649
|
-
|
|
172
|
+
for (const id of Object.keys(profiles)) {
|
|
173
|
+
const profile = profiles[id];
|
|
174
|
+
if (!profile) continue;
|
|
175
|
+
const nameParts = profile.name? String(profile.name).trim().split(/\s+/) : [];
|
|
650
176
|
result[id] = {
|
|
651
177
|
id,
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
.join(" ")
|
|
669
|
-
: null
|
|
670
|
-
),
|
|
671
|
-
|
|
672
|
-
vanity:
|
|
673
|
-
profile.vanity ||
|
|
674
|
-
null,
|
|
675
|
-
|
|
676
|
-
thumbSrc:
|
|
677
|
-
profile.thumbSrc ||
|
|
678
|
-
profile.profile_pic_url ||
|
|
679
|
-
null,
|
|
680
|
-
|
|
681
|
-
coverPhoto:
|
|
682
|
-
profile.cover_photo ||
|
|
683
|
-
profile.coverPhoto ||
|
|
684
|
-
null,
|
|
685
|
-
|
|
686
|
-
profileUrl:
|
|
687
|
-
profile.uri ||
|
|
688
|
-
profile.profile_url ||
|
|
689
|
-
`https://www.facebook.com/profile.php?id=${id}`,
|
|
690
|
-
|
|
691
|
-
gender:
|
|
692
|
-
profile.gender === 1
|
|
693
|
-
? "male"
|
|
694
|
-
: profile.gender === 2
|
|
695
|
-
? "female"
|
|
696
|
-
: "no specific gender",
|
|
697
|
-
|
|
698
|
-
type:
|
|
699
|
-
profile.type ||
|
|
700
|
-
"User",
|
|
701
|
-
|
|
702
|
-
isFriend:
|
|
703
|
-
!!profile.is_friend,
|
|
704
|
-
|
|
705
|
-
isBirthday:
|
|
706
|
-
!!profile.is_birthday,
|
|
707
|
-
|
|
708
|
-
isVerified:
|
|
709
|
-
!!profile.is_verified,
|
|
710
|
-
|
|
711
|
-
isMemorialized:
|
|
712
|
-
!!profile.is_memorialized,
|
|
713
|
-
|
|
714
|
-
isMessengerUser:
|
|
715
|
-
typeof profile.is_messenger_user === "boolean"
|
|
716
|
-
? profile.is_messenger_user
|
|
717
|
-
: null,
|
|
718
|
-
|
|
719
|
-
isMessageBlockedByViewer:
|
|
720
|
-
false,
|
|
721
|
-
|
|
722
|
-
workInfo:
|
|
723
|
-
null,
|
|
724
|
-
|
|
725
|
-
messengerStatus:
|
|
726
|
-
null
|
|
178
|
+
name: profile.name || null,
|
|
179
|
+
firstName: profile.firstName || nameParts[0] || null,
|
|
180
|
+
lastName: nameParts.length > 1? nameParts.slice(1).join(" ") : null,
|
|
181
|
+
vanity: profile.vanity || null,
|
|
182
|
+
thumbSrc: null,
|
|
183
|
+
coverPhoto: profile.cover_photo || null, // FIX: legacy teo add
|
|
184
|
+
profileUrl: profile.uri || `https://www.facebook.com/profile.php?id=${id}`,
|
|
185
|
+
gender: profile.gender === 1? "male" : profile.gender === 2? "female" : "no specific gender",
|
|
186
|
+
type: profile.type || "User",
|
|
187
|
+
isFriend:!!profile.is_friend,
|
|
188
|
+
isBirthday:!!profile.is_birthday,
|
|
189
|
+
isVerified: false,
|
|
190
|
+
isMessengerUser: null,
|
|
191
|
+
isMessageBlockedByViewer: false,
|
|
192
|
+
workInfo: null,
|
|
193
|
+
messengerStatus: null
|
|
727
194
|
};
|
|
728
195
|
}
|
|
729
|
-
|
|
730
196
|
return result;
|
|
731
197
|
}
|
|
732
198
|
|
|
733
|
-
return function getUserInfoV2(
|
|
734
|
-
idOrList,
|
|
735
|
-
callback
|
|
736
|
-
) {
|
|
199
|
+
return function getUserInfoV2(idOrList, callback) {
|
|
737
200
|
let resolveFunc;
|
|
738
201
|
let rejectFunc;
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
202
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
203
|
+
resolveFunc = resolve;
|
|
204
|
+
rejectFunc = reject;
|
|
205
|
+
});
|
|
206
|
+
if (typeof callback!== "function") {
|
|
207
|
+
callback = (error, data) => {
|
|
208
|
+
if (error) {
|
|
209
|
+
rejectFunc(error);
|
|
210
|
+
return;
|
|
745
211
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
if (
|
|
749
|
-
typeof callback !== "function"
|
|
750
|
-
) {
|
|
751
|
-
callback =
|
|
752
|
-
(error, data) => {
|
|
753
|
-
if (error) {
|
|
754
|
-
rejectFunc(error);
|
|
755
|
-
} else {
|
|
756
|
-
resolveFunc(data);
|
|
757
|
-
}
|
|
758
|
-
};
|
|
212
|
+
resolveFunc(data);
|
|
213
|
+
};
|
|
759
214
|
}
|
|
760
|
-
|
|
761
|
-
const ids =
|
|
762
|
-
(
|
|
763
|
-
Array.isArray(idOrList)
|
|
764
|
-
? idOrList
|
|
765
|
-
: [idOrList]
|
|
766
|
-
)
|
|
767
|
-
.filter(
|
|
768
|
-
id =>
|
|
769
|
-
id !== null &&
|
|
770
|
-
typeof id !== "undefined"
|
|
771
|
-
)
|
|
772
|
-
.map(
|
|
773
|
-
id => String(id).trim()
|
|
774
|
-
)
|
|
775
|
-
.filter(Boolean);
|
|
776
|
-
|
|
215
|
+
const originalIsArray = Array.isArray(idOrList);
|
|
216
|
+
const ids = (originalIsArray? idOrList : [idOrList]).map(id => String(id)).filter(Boolean);
|
|
777
217
|
if (!ids.length) {
|
|
778
|
-
const error =
|
|
779
|
-
new Error(
|
|
780
|
-
"Invalid user ID(s)"
|
|
781
|
-
);
|
|
782
|
-
|
|
218
|
+
const error = new Error("Invalid user ID(s)");
|
|
783
219
|
callback(error);
|
|
784
|
-
|
|
785
|
-
return returnPromise;
|
|
220
|
+
returnPromise;
|
|
786
221
|
}
|
|
787
|
-
|
|
788
222
|
(async () => {
|
|
789
223
|
try {
|
|
790
224
|
const retObj = {};
|
|
791
|
-
|
|
792
|
-
const results =
|
|
793
|
-
await Promise.allSettled(
|
|
794
|
-
ids.map(fetchOne)
|
|
795
|
-
);
|
|
796
|
-
|
|
225
|
+
const results = await Promise.allSettled(ids.map(fetchOne));
|
|
797
226
|
const needFallback = [];
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
i++
|
|
803
|
-
) {
|
|
804
|
-
const id =
|
|
805
|
-
ids[i];
|
|
806
|
-
|
|
807
|
-
const result =
|
|
808
|
-
results[i];
|
|
809
|
-
|
|
810
|
-
if (
|
|
811
|
-
result.status === "fulfilled" &&
|
|
812
|
-
result.value?.id
|
|
813
|
-
) {
|
|
814
|
-
retObj[id] =
|
|
815
|
-
formatUser(
|
|
816
|
-
result.value,
|
|
817
|
-
id
|
|
818
|
-
);
|
|
227
|
+
for (let i = 0; i < ids.length; i++) {
|
|
228
|
+
const id = ids[i];
|
|
229
|
+
if (results[i].status === "fulfilled" && results[i].value?.id) {
|
|
230
|
+
retObj[id] = formatUser(results[i].value, id);
|
|
819
231
|
} else {
|
|
820
232
|
needFallback.push(id);
|
|
821
233
|
}
|
|
822
234
|
}
|
|
823
|
-
|
|
824
|
-
if (
|
|
825
|
-
needFallback.length
|
|
826
|
-
) {
|
|
235
|
+
if (needFallback.length) {
|
|
827
236
|
try {
|
|
828
|
-
const legacy =
|
|
829
|
-
|
|
830
|
-
needFallback
|
|
831
|
-
);
|
|
832
|
-
|
|
833
|
-
for (
|
|
834
|
-
const id of needFallback
|
|
835
|
-
) {
|
|
237
|
+
const legacy = await fetchLegacy(needFallback);
|
|
238
|
+
for (const id of needFallback) {
|
|
836
239
|
if (legacy[id]) {
|
|
837
|
-
retObj[id] =
|
|
838
|
-
formatUser(
|
|
839
|
-
legacy[id],
|
|
840
|
-
id
|
|
841
|
-
);
|
|
240
|
+
retObj[id] = formatUser(legacy[id], id);
|
|
842
241
|
}
|
|
843
242
|
}
|
|
844
243
|
} catch (error) {
|
|
845
|
-
logger(
|
|
846
|
-
`getUserInfoV2 legacy fallback: ${error.message || error}`,
|
|
847
|
-
"warn"
|
|
848
|
-
);
|
|
244
|
+
logger(`getUserInfoV2 legacy fallback: ${error.message || error}`, "warn");
|
|
849
245
|
}
|
|
850
246
|
}
|
|
851
|
-
|
|
852
|
-
for (
|
|
853
|
-
const id of ids
|
|
854
|
-
) {
|
|
247
|
+
for (const id of ids) {
|
|
855
248
|
if (!retObj[id]) {
|
|
856
|
-
retObj[id] =
|
|
857
|
-
createDefaultUser(id);
|
|
249
|
+
retObj[id] = createDefaultUser(id);
|
|
858
250
|
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
ctx?.cache?.set
|
|
862
|
-
) {
|
|
863
|
-
ctx.cache.set(
|
|
864
|
-
`user_${id}`,
|
|
865
|
-
retObj[id]
|
|
866
|
-
);
|
|
251
|
+
if (ctx?.cache?.set) {
|
|
252
|
+
ctx.cache.set(`user_${id}`, retObj[id]);
|
|
867
253
|
}
|
|
868
254
|
}
|
|
869
|
-
|
|
870
|
-
return callback(
|
|
871
|
-
null,
|
|
872
|
-
Array.isArray(idOrList)
|
|
873
|
-
? retObj
|
|
874
|
-
: retObj[ids[0]]
|
|
875
|
-
);
|
|
255
|
+
return callback(null, retObj);
|
|
876
256
|
} catch (error) {
|
|
877
|
-
logger(
|
|
878
|
-
`getUserInfoV2: ${error.message || error}`,
|
|
879
|
-
"error"
|
|
880
|
-
);
|
|
881
|
-
|
|
257
|
+
logger(`getUserInfoV2: ${error.message || error}`, "error");
|
|
882
258
|
const retObj = {};
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
retObj[id] =
|
|
888
|
-
createDefaultUser(id);
|
|
889
|
-
|
|
890
|
-
if (
|
|
891
|
-
ctx?.cache?.set
|
|
892
|
-
) {
|
|
893
|
-
ctx.cache.set(
|
|
894
|
-
`user_${id}`,
|
|
895
|
-
retObj[id]
|
|
896
|
-
);
|
|
259
|
+
for (const id of ids) {
|
|
260
|
+
retObj[id] = createDefaultUser(id);
|
|
261
|
+
if (ctx?.cache?.set) {
|
|
262
|
+
ctx.cache.set(`user_${id}`, retObj[id]);
|
|
897
263
|
}
|
|
898
264
|
}
|
|
899
|
-
|
|
900
|
-
return callback(
|
|
901
|
-
null,
|
|
902
|
-
Array.isArray(idOrList)
|
|
903
|
-
? retObj
|
|
904
|
-
: retObj[ids[0]]
|
|
905
|
-
);
|
|
265
|
+
return callback(null, retObj);
|
|
906
266
|
}
|
|
907
267
|
})();
|
|
908
|
-
|
|
909
|
-
return returnPromise;
|
|
268
|
+
returnPromise;
|
|
910
269
|
};
|
|
911
270
|
};
|