node-ainzfb-new 1.6.0 → 1.6.30-test
Sign up to get free protection for your applications and to get access to all the features.
- package/.gitattributes +0 -0
- package/.github/dependabot.yml +0 -0
- package/.github/workflows/nodejs.yml +0 -0
- package/.github/workflows/npmpublish.yml +0 -0
- package/DOCS.md +0 -0
- package/Extra/Database/index.js +0 -0
- package/Extra/Database/methods.js +0 -0
- package/Extra/ExtraAddons.js +0 -0
- package/Extra/ExtraGetThread.js +0 -0
- package/Extra/ExtraUptimeRobot.js +0 -0
- package/Extra/PM2/ecosystem.config.js +0 -0
- package/Extra/Src/Last-Run.js +0 -0
- package/LICENSE-MIT +0 -0
- package/Language/index.json +0 -0
- package/README.md +0 -0
- package/StateCrypt.js +0 -0
- package/broadcast.js +0 -0
- package/index.js +0 -0
- package/logger.js +0 -0
- package/package.json +2 -4
- 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/getAccessToken.js +0 -0
- 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/getThreadInfo.js +0 -0
- 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/getUserInfoV2.js +0 -0
- 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 +12 -13
- package/CHANGELOG.md +0 -2
package/src/getThreadHistory.js
CHANGED
@@ -29,10 +29,10 @@ function formatAttachmentsGraphQLResponse(attachment) {
|
|
29
29
|
// @Undocumented
|
30
30
|
attributionApp: attachment.attribution_app
|
31
31
|
? {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
attributionAppID: attachment.attribution_app.id,
|
33
|
+
name: attachment.attribution_app.name,
|
34
|
+
logo: attachment.attribution_app.square_logo
|
35
|
+
}
|
36
36
|
: null
|
37
37
|
|
38
38
|
// @TODO No idea what this is, should we expose it?
|
@@ -78,10 +78,10 @@ function formatAttachmentsGraphQLResponse(attachment) {
|
|
78
78
|
// @Undocumented
|
79
79
|
attributionApp: attachment.attribution_app
|
80
80
|
? {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
attributionAppID: attachment.attribution_app.id,
|
82
|
+
name: attachment.attribution_app.name,
|
83
|
+
logo: attachment.attribution_app.square_logo
|
84
|
+
}
|
85
85
|
: null
|
86
86
|
};
|
87
87
|
case "MessageVideo":
|
@@ -144,15 +144,56 @@ function formatExtensibleAttachment(attachment) {
|
|
144
144
|
url: attachment.story_attachment.url,
|
145
145
|
|
146
146
|
title: attachment.story_attachment.title_with_entities.text,
|
147
|
-
description:
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
147
|
+
description:
|
148
|
+
attachment.story_attachment.description &&
|
149
|
+
attachment.story_attachment.description.text,
|
150
|
+
source:
|
151
|
+
attachment.story_attachment.source == null
|
152
|
+
? null
|
153
|
+
: attachment.story_attachment.source.text,
|
154
|
+
|
155
|
+
image:
|
156
|
+
attachment.story_attachment.media == null
|
157
|
+
? null
|
158
|
+
: attachment.story_attachment.media.animated_image == null &&
|
159
|
+
attachment.story_attachment.media.image == null
|
160
|
+
? null
|
161
|
+
: (
|
162
|
+
attachment.story_attachment.media.animated_image ||
|
163
|
+
attachment.story_attachment.media.image
|
164
|
+
).uri,
|
165
|
+
width:
|
166
|
+
attachment.story_attachment.media == null
|
167
|
+
? null
|
168
|
+
: attachment.story_attachment.media.animated_image == null &&
|
169
|
+
attachment.story_attachment.media.image == null
|
170
|
+
? null
|
171
|
+
: (
|
172
|
+
attachment.story_attachment.media.animated_image ||
|
173
|
+
attachment.story_attachment.media.image
|
174
|
+
).width,
|
175
|
+
height:
|
176
|
+
attachment.story_attachment.media == null
|
177
|
+
? null
|
178
|
+
: attachment.story_attachment.media.animated_image == null &&
|
179
|
+
attachment.story_attachment.media.image == null
|
180
|
+
? null
|
181
|
+
: (
|
182
|
+
attachment.story_attachment.media.animated_image ||
|
183
|
+
attachment.story_attachment.media.image
|
184
|
+
).height,
|
185
|
+
playable:
|
186
|
+
attachment.story_attachment.media == null
|
187
|
+
? null
|
188
|
+
: attachment.story_attachment.media.is_playable,
|
189
|
+
duration:
|
190
|
+
attachment.story_attachment.media == null
|
191
|
+
? null
|
192
|
+
: attachment.story_attachment.media.playable_duration_in_ms,
|
193
|
+
playableUrl:
|
194
|
+
attachment.story_attachment.media == null
|
195
|
+
? null
|
196
|
+
: attachment.story_attachment.media.playable_url,
|
156
197
|
|
157
198
|
subattachments: attachment.story_attachment.subattachments,
|
158
199
|
|
@@ -169,22 +210,52 @@ function formatExtensibleAttachment(attachment) {
|
|
169
210
|
// width: "1280"
|
170
211
|
// }
|
171
212
|
//
|
172
|
-
properties: attachment.story_attachment.properties.reduce(function
|
213
|
+
properties: attachment.story_attachment.properties.reduce(function(
|
214
|
+
obj,
|
215
|
+
cur
|
216
|
+
) {
|
173
217
|
obj[cur.key] = cur.value.text;
|
174
218
|
return obj;
|
175
|
-
},
|
219
|
+
},
|
220
|
+
{}),
|
176
221
|
|
177
222
|
// Deprecated fields
|
178
223
|
animatedImageSize: "", // @Legacy
|
179
224
|
facebookUrl: "", // @Legacy
|
180
225
|
styleList: "", // @Legacy
|
181
226
|
target: "", // @Legacy
|
182
|
-
thumbnailUrl:
|
183
|
-
|
184
|
-
|
227
|
+
thumbnailUrl:
|
228
|
+
attachment.story_attachment.media == null
|
229
|
+
? null
|
230
|
+
: attachment.story_attachment.media.animated_image == null &&
|
231
|
+
attachment.story_attachment.media.image == null
|
232
|
+
? null
|
233
|
+
: (
|
234
|
+
attachment.story_attachment.media.animated_image ||
|
235
|
+
attachment.story_attachment.media.image
|
236
|
+
).uri, // @Legacy
|
237
|
+
thumbnailWidth:
|
238
|
+
attachment.story_attachment.media == null
|
239
|
+
? null
|
240
|
+
: attachment.story_attachment.media.animated_image == null &&
|
241
|
+
attachment.story_attachment.media.image == null
|
242
|
+
? null
|
243
|
+
: (
|
244
|
+
attachment.story_attachment.media.animated_image ||
|
245
|
+
attachment.story_attachment.media.image
|
246
|
+
).width, // @Legacy
|
247
|
+
thumbnailHeight:
|
248
|
+
attachment.story_attachment.media == null
|
249
|
+
? null
|
250
|
+
: attachment.story_attachment.media.animated_image == null &&
|
251
|
+
attachment.story_attachment.media.image == null
|
252
|
+
? null
|
253
|
+
: (
|
254
|
+
attachment.story_attachment.media.animated_image ||
|
255
|
+
attachment.story_attachment.media.image
|
256
|
+
).height // @Legacy
|
185
257
|
};
|
186
|
-
}
|
187
|
-
else return { error: "Don't know what to do with extensible_attachment." };
|
258
|
+
} else return { error: "Don't know what to do with extensible_attachment." };
|
188
259
|
}
|
189
260
|
|
190
261
|
function formatReactionsGraphQL(reaction) {
|
@@ -195,7 +266,7 @@ function formatReactionsGraphQL(reaction) {
|
|
195
266
|
}
|
196
267
|
|
197
268
|
function formatEventData(event) {
|
198
|
-
if (event == null) return {}
|
269
|
+
if (event == null) return {};
|
199
270
|
|
200
271
|
switch (event.__typename) {
|
201
272
|
case "ThemeColorExtensibleMessageAdminText":
|
@@ -209,7 +280,7 @@ function formatEventData(event) {
|
|
209
280
|
return { threadIcon: event.thread_icon };
|
210
281
|
case "InstantGameUpdateExtensibleMessageAdminText":
|
211
282
|
return {
|
212
|
-
gameID:
|
283
|
+
gameID: event.game == null ? null : event.game.id,
|
213
284
|
update_type: event.update_type,
|
214
285
|
collapsed_text: event.collapsed_text,
|
215
286
|
expanded_text: event.expanded_text,
|
@@ -264,15 +335,19 @@ function formatEventData(event) {
|
|
264
335
|
case "LightweightEventDeleteExtensibleMessageAdminText":
|
265
336
|
return {};
|
266
337
|
default:
|
267
|
-
return {
|
338
|
+
return {
|
339
|
+
error: "Don't know what to with event data type " + event.__typename
|
340
|
+
};
|
268
341
|
}
|
269
342
|
}
|
270
343
|
|
271
344
|
function formatMessagesGraphQLResponse(data) {
|
272
345
|
var messageThread = data.o0.data.message_thread;
|
273
|
-
var threadID = messageThread.thread_key.thread_fbid
|
346
|
+
var threadID = messageThread.thread_key.thread_fbid
|
347
|
+
? messageThread.thread_key.thread_fbid
|
348
|
+
: messageThread.thread_key.other_user_id;
|
274
349
|
|
275
|
-
var messages = messageThread.messages.nodes.map(function
|
350
|
+
var messages = messageThread.messages.nodes.map(function(d) {
|
276
351
|
switch (d.__typename) {
|
277
352
|
case "UserMessage":
|
278
353
|
// Give priority to stickers. They're seen as normal messages but we've
|
@@ -308,7 +383,13 @@ function formatMessagesGraphQLResponse(data) {
|
|
308
383
|
|
309
384
|
var mentionsObj = {};
|
310
385
|
if (d.message !== null) {
|
311
|
-
d.message.ranges.forEach(
|
386
|
+
d.message.ranges.forEach(
|
387
|
+
e =>
|
388
|
+
(mentionsObj[e.entity.id] = d.message.text.substr(
|
389
|
+
e.offset,
|
390
|
+
e.length
|
391
|
+
))
|
392
|
+
);
|
312
393
|
}
|
313
394
|
|
314
395
|
return {
|
@@ -320,7 +401,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
320
401
|
: d.extensible_attachment
|
321
402
|
? [formatExtensibleAttachment(d.extensible_attachment)]
|
322
403
|
: [],
|
323
|
-
body: d.message !== null ? d.message.text :
|
404
|
+
body: d.message !== null ? d.message.text : "",
|
324
405
|
isGroup: messageThread.thread_type === "GROUP",
|
325
406
|
messageID: d.message_id,
|
326
407
|
senderID: d.message_sender.id,
|
@@ -331,7 +412,9 @@ function formatMessagesGraphQLResponse(data) {
|
|
331
412
|
isUnread: d.unread,
|
332
413
|
|
333
414
|
// New
|
334
|
-
messageReactions: d.message_reactions
|
415
|
+
messageReactions: d.message_reactions
|
416
|
+
? d.message_reactions.map(formatReactionsGraphQL)
|
417
|
+
: null,
|
335
418
|
isSponsored: d.is_sponsored,
|
336
419
|
snippet: d.snippet
|
337
420
|
};
|
@@ -362,21 +445,26 @@ function formatMessagesGraphQLResponse(data) {
|
|
362
445
|
timestamp: d.timestamp_precise,
|
363
446
|
eventType: "change_thread_image",
|
364
447
|
snippet: d.snippet,
|
365
|
-
eventData:
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
448
|
+
eventData:
|
449
|
+
d.image_with_metadata == null
|
450
|
+
? {} /* removed image */
|
451
|
+
: {
|
452
|
+
/* image added */
|
453
|
+
threadImage: {
|
454
|
+
attachmentID: d.image_with_metadata.legacy_attachment_id,
|
455
|
+
width: d.image_with_metadata.original_dimensions.x,
|
456
|
+
height: d.image_with_metadata.original_dimensions.y,
|
457
|
+
url: d.image_with_metadata.preview.uri
|
458
|
+
}
|
459
|
+
},
|
376
460
|
|
377
461
|
// @Legacy
|
378
462
|
logMessageType: "log:thread-icon",
|
379
|
-
logMessageData: {
|
463
|
+
logMessageData: {
|
464
|
+
thread_icon: d.image_with_metadata
|
465
|
+
? d.image_with_metadata.preview.uri
|
466
|
+
: null
|
467
|
+
}
|
380
468
|
};
|
381
469
|
case "ParticipantLeftMessage":
|
382
470
|
return {
|
@@ -390,7 +478,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
390
478
|
snippet: d.snippet,
|
391
479
|
eventData: {
|
392
480
|
// Array of IDs.
|
393
|
-
participantsRemoved: d.participants_removed.map(function
|
481
|
+
participantsRemoved: d.participants_removed.map(function(p) {
|
394
482
|
return p.id;
|
395
483
|
})
|
396
484
|
},
|
@@ -398,7 +486,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
398
486
|
// @Legacy
|
399
487
|
logMessageType: "log:unsubscribe",
|
400
488
|
logMessageData: {
|
401
|
-
leftParticipantFbId: d.participants_removed.map(function
|
489
|
+
leftParticipantFbId: d.participants_removed.map(function(p) {
|
402
490
|
return p.id;
|
403
491
|
})
|
404
492
|
}
|
@@ -415,7 +503,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
415
503
|
snippet: d.snippet,
|
416
504
|
eventData: {
|
417
505
|
// Array of IDs.
|
418
|
-
participantsAdded: d.participants_added.map(function
|
506
|
+
participantsAdded: d.participants_added.map(function(p) {
|
419
507
|
return p.id;
|
420
508
|
})
|
421
509
|
},
|
@@ -423,7 +511,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
423
511
|
// @Legacy
|
424
512
|
logMessageType: "log:subscribe",
|
425
513
|
logMessageData: {
|
426
|
-
addedParticipants: d.participants_added.map(function
|
514
|
+
addedParticipants: d.participants_added.map(function(p) {
|
427
515
|
return p.id;
|
428
516
|
})
|
429
517
|
}
|
@@ -481,17 +569,22 @@ function formatMessagesGraphQLResponse(data) {
|
|
481
569
|
return messages;
|
482
570
|
}
|
483
571
|
|
484
|
-
module.exports = function
|
485
|
-
return function getThreadHistoryGraphQL(
|
486
|
-
|
487
|
-
|
488
|
-
|
572
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
573
|
+
return function getThreadHistoryGraphQL(
|
574
|
+
threadID,
|
575
|
+
amount,
|
576
|
+
timestamp,
|
577
|
+
callback
|
578
|
+
) {
|
579
|
+
var resolveFunc = function() {};
|
580
|
+
var rejectFunc = function() {};
|
581
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
489
582
|
resolveFunc = resolve;
|
490
583
|
rejectFunc = reject;
|
491
584
|
});
|
492
585
|
|
493
586
|
if (!callback) {
|
494
|
-
callback = function
|
587
|
+
callback = function(err, data) {
|
495
588
|
if (err) return rejectFunc(err);
|
496
589
|
resolveFunc(data);
|
497
590
|
};
|
@@ -500,7 +593,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
500
593
|
// `queries` has to be a string. I couldn't tell from the dev console. This
|
501
594
|
// took me a really long time to figure out. I deserve a cookie for this.
|
502
595
|
var form = {
|
503
|
-
|
596
|
+
av: ctx.globalOptions.pageID,
|
504
597
|
queries: JSON.stringify({
|
505
598
|
o0: {
|
506
599
|
// This doc_id was valid on February 2nd 2017.
|
@@ -519,16 +612,20 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
519
612
|
defaultFuncs
|
520
613
|
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
521
614
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
522
|
-
.then(function
|
615
|
+
.then(function(resData) {
|
523
616
|
if (resData.error) throw resData;
|
524
617
|
// This returns us an array of things. The last one is the success /
|
525
618
|
// failure one.
|
526
619
|
// @TODO What do we do in this case?
|
527
|
-
if (resData[resData.length - 1].error_results !== 0)
|
620
|
+
if (resData[resData.length - 1].error_results !== 0)
|
621
|
+
throw new Error("There was an error_result.");
|
528
622
|
callback(null, formatMessagesGraphQLResponse(resData[0]));
|
529
623
|
})
|
530
|
-
.catch(function
|
531
|
-
log.error(
|
624
|
+
.catch(function(err) {
|
625
|
+
log.error(
|
626
|
+
"getThreadHistoryGraphQL",
|
627
|
+
"Lỗi getThreadHistoryGraphQL Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !"
|
628
|
+
);
|
532
629
|
return callback(err);
|
533
630
|
});
|
534
631
|
|
@@ -3,17 +3,17 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function getThreadHistory(threadID, amount, timestamp, callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
|
-
callback = function
|
16
|
+
callback = function(err, threadInfo) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
resolveFunc(threadInfo);
|
19
19
|
};
|
@@ -24,33 +24,41 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
24
24
|
client: "mercury"
|
25
25
|
};
|
26
26
|
|
27
|
-
api.getUserInfo(threadID, function
|
27
|
+
api.getUserInfo(threadID, function(err, res) {
|
28
28
|
if (err) return callback(err);
|
29
29
|
var key = Object.keys(res).length > 0 ? "user_ids" : "thread_fbids";
|
30
30
|
form["messages[" + key + "][" + threadID + "][offset]"] = 0;
|
31
31
|
form["messages[" + key + "][" + threadID + "][timestamp]"] = timestamp;
|
32
32
|
form["messages[" + key + "][" + threadID + "][limit]"] = amount;
|
33
33
|
|
34
|
-
if (ctx.globalOptions.pageID)
|
34
|
+
if (ctx.globalOptions.pageID)
|
35
|
+
form.request_user_id = ctx.globalOptions.pageID;
|
35
36
|
|
36
37
|
defaultFuncs
|
37
|
-
.post(
|
38
|
+
.post(
|
39
|
+
"https://www.facebook.com/ajax/mercury/thread_info.php",
|
40
|
+
ctx.jar,
|
41
|
+
form
|
42
|
+
)
|
38
43
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
39
|
-
.then(function
|
44
|
+
.then(function(resData) {
|
40
45
|
if (resData.error) throw resData;
|
41
|
-
else if (!resData.payload)
|
46
|
+
else if (!resData.payload)
|
47
|
+
throw { error: "Could not retrieve thread history." };
|
42
48
|
|
43
49
|
// Asking for message history from a thread with no message history
|
44
50
|
// will return undefined for actions here
|
45
51
|
if (!resData.payload.actions) resData.payload.actions = [];
|
46
52
|
|
47
53
|
var userIDs = {};
|
48
|
-
resData.payload.actions.forEach(
|
54
|
+
resData.payload.actions.forEach(
|
55
|
+
v => (userIDs[v.author.split(":").pop()] = "")
|
56
|
+
);
|
49
57
|
|
50
|
-
api.getUserInfo(Object.keys(userIDs), function
|
58
|
+
api.getUserInfo(Object.keys(userIDs), function(err, data) {
|
51
59
|
if (err) return callback(err); //callback({error: "Could not retrieve user information in getThreadHistory."});
|
52
60
|
|
53
|
-
resData.payload.actions.forEach(function
|
61
|
+
resData.payload.actions.forEach(function(v) {
|
54
62
|
var sender = data[v.author.split(":").pop()];
|
55
63
|
if (sender) v.sender_name = sender.name;
|
56
64
|
else v.sender_name = "Facebook User";
|
@@ -58,10 +66,13 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
58
66
|
delete v.author;
|
59
67
|
});
|
60
68
|
|
61
|
-
callback(
|
69
|
+
callback(
|
70
|
+
null,
|
71
|
+
resData.payload.actions.map(utils.formatHistoryMessage)
|
72
|
+
);
|
62
73
|
});
|
63
74
|
})
|
64
|
-
.catch(function
|
75
|
+
.catch(function(err) {
|
65
76
|
log.error("getThreadHistory", err);
|
66
77
|
return callback(err);
|
67
78
|
});
|
package/src/getThreadInfo.js
CHANGED
File without changes
|
@@ -3,17 +3,17 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function
|
6
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
7
7
|
return function getThreadInfo(threadID, callback) {
|
8
|
-
var resolveFunc = function
|
9
|
-
var rejectFunc = function
|
10
|
-
var returnPromise = new Promise(function
|
8
|
+
var resolveFunc = function() {};
|
9
|
+
var rejectFunc = function() {};
|
10
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
11
11
|
resolveFunc = resolve;
|
12
12
|
rejectFunc = reject;
|
13
13
|
});
|
14
14
|
|
15
15
|
if (!callback) {
|
16
|
-
callback = function
|
16
|
+
callback = function(err, data) {
|
17
17
|
if (err) return rejectFunc(err);
|
18
18
|
resolveFunc(data);
|
19
19
|
};
|
@@ -23,30 +23,42 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
23
23
|
client: "mercury"
|
24
24
|
};
|
25
25
|
|
26
|
-
api.getUserInfo(threadID, function
|
26
|
+
api.getUserInfo(threadID, function(err, userRes) {
|
27
27
|
if (err) return callback(err);
|
28
28
|
var key = Object.keys(userRes).length > 0 ? "user_ids" : "thread_fbids";
|
29
29
|
form["threads[" + key + "][0]"] = threadID;
|
30
30
|
|
31
|
-
if (ctx.globalOptions.pageId)
|
31
|
+
if (ctx.globalOptions.pageId)
|
32
|
+
form.request_user_id = ctx.globalOptions.pageId;
|
32
33
|
|
33
34
|
defaultFuncs
|
34
|
-
.post(
|
35
|
+
.post(
|
36
|
+
"https://www.facebook.com/ajax/mercury/thread_info.php",
|
37
|
+
ctx.jar,
|
38
|
+
form
|
39
|
+
)
|
35
40
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
-
.then(function
|
41
|
+
.then(function(resData) {
|
37
42
|
if (resData.error) throw resData;
|
38
|
-
else if (!resData.payload)
|
43
|
+
else if (!resData.payload)
|
44
|
+
throw { error: "Could not retrieve thread Info." };
|
39
45
|
|
40
46
|
var threadData = resData.payload.threads[0];
|
41
47
|
var userData = userRes[threadID];
|
42
48
|
|
43
49
|
if (threadData == null) throw { error: "ThreadData is null" };
|
44
50
|
|
45
|
-
threadData.name =
|
46
|
-
|
51
|
+
threadData.name =
|
52
|
+
userData != null && userData.name != null
|
53
|
+
? userData.name
|
54
|
+
: threadData.name;
|
55
|
+
threadData.image_src =
|
56
|
+
userData != null && userData.thumbSrc != null
|
57
|
+
? userData.thumbSrc
|
58
|
+
: threadData.image_src;
|
47
59
|
callback(null, utils.formatThread(threadData));
|
48
60
|
})
|
49
|
-
.catch(function
|
61
|
+
.catch(function(err) {
|
50
62
|
log.error("getThreadInfo", err);
|
51
63
|
return callback(err);
|
52
64
|
});
|