alicezetion 1.0.2 → 1.0.4
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/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/index.js +488 -560
- package/package.json +25 -25
- package/replit.nix +5 -0
- package/src/addExternalModule.js +15 -0
- package/{alice → src}/addUserToGroup.js +16 -52
- package/src/changeAdminStatus.js +47 -0
- package/src/changeArchivedStatus.js +41 -0
- package/{alice → src}/changeBio.js +6 -19
- package/{alice → src}/changeBlockedStatus.js +3 -14
- package/{alice → src}/changeGroupImage.js +16 -40
- package/src/changeNickname.js +43 -0
- package/{alice → src}/changeThreadColor.js +10 -20
- package/src/changeThreadEmoji.js +41 -0
- package/src/chat.js +315 -0
- package/{alice → src}/createNewGroup.js +12 -28
- package/{alice → src}/createPoll.js +13 -25
- package/src/deleteMessage.js +44 -0
- package/src/deleteThread.js +42 -0
- package/src/forwardAttachment.js +47 -0
- package/src/forwardMessage.js +0 -0
- package/{alice → src}/getCurrentUserID.js +1 -1
- package/{alice → src}/getEmojiUrl.js +2 -4
- package/{alice → src}/getFriendsList.js +10 -21
- package/{alice → src}/getThreadHistory.js +58 -166
- package/{alice → src}/getThreadHistoryDeprecated.js +20 -42
- package/{alice → src}/getThreadInfo.js +25 -60
- package/src/getThreadInfoDeprecated.js +56 -0
- package/{alice → src}/getThreadList.js +41 -66
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/{alice → src}/getUserID.js +9 -14
- package/{alice → src}/getUserInfo.js +13 -19
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/{alice → src}/httpGet.js +12 -17
- package/{alice → src}/httpPost.js +12 -17
- package/src/listen.js +553 -0
- package/src/listenMqtt-Test.js +687 -0
- package/src/listenMqtt.js +677 -0
- package/{alice → src}/logout.js +13 -20
- package/{alice → src}/markAsDelivered.js +11 -22
- package/{alice → src}/markAsRead.js +11 -21
- package/{alice → src}/markAsReadAll.js +10 -20
- package/{alice → src}/markAsSeen.js +7 -18
- package/{alice → src}/muteThread.js +11 -18
- package/src/removeUserFromGroup.js +45 -0
- package/{alice → src}/resolvePhotoUrl.js +8 -17
- package/{alice → src}/searchForThread.js +10 -21
- package/{alice → src}/sendTypingIndicator.js +14 -47
- package/{alice → src}/setMessageReaction.js +12 -26
- package/{alice → src}/setPostReaction.js +13 -26
- package/{alice → src}/setTitle.js +13 -29
- package/src/threadColors.js +41 -0
- package/{alice → src}/unfriend.js +9 -19
- package/{alice → src}/unsendMessage.js +9 -19
- package/utils.js +1021 -1190
- package/alice/addExternalModule.js +0 -19
- package/alice/changeAdminStatus.js +0 -79
- package/alice/changeArchivedStatus.js +0 -55
- package/alice/changeNickname.js +0 -59
- package/alice/changeThreadEmoji.js +0 -55
- package/alice/deleteMessage.js +0 -56
- package/alice/deleteThread.js +0 -56
- package/alice/forwardAttachment.js +0 -60
- package/alice/getThreadInfoDeprecated.js +0 -80
- package/alice/getThreadListDeprecated.js +0 -75
- package/alice/getThreadPictures.js +0 -79
- package/alice/handleFriendRequest.js +0 -61
- package/alice/handleMessageRequest.js +0 -65
- package/alice/listenMqtt.js +0 -789
- package/alice/removeUserFromGroup.js +0 -79
- package/alice/sendMessage.js +0 -459
- package/alice/threadColors.js +0 -57
@@ -21,7 +21,7 @@ var GENDERS = {
|
|
21
21
|
};
|
22
22
|
|
23
23
|
function formatData(obj) {
|
24
|
-
return Object.keys(obj).map(function(key) {
|
24
|
+
return Object.keys(obj).map(function (key) {
|
25
25
|
var user = obj[key];
|
26
26
|
return {
|
27
27
|
alternateName: user.alternateName,
|
@@ -39,10 +39,10 @@ function formatData(obj) {
|
|
39
39
|
});
|
40
40
|
}
|
41
41
|
|
42
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
42
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
43
43
|
return function getFriendsList(callback) {
|
44
|
-
var resolveFunc = function(){};
|
45
|
-
var rejectFunc = function(){};
|
44
|
+
var resolveFunc = function () { };
|
45
|
+
var rejectFunc = function () { };
|
46
46
|
var returnPromise = new Promise(function (resolve, reject) {
|
47
47
|
resolveFunc = resolve;
|
48
48
|
rejectFunc = reject;
|
@@ -50,31 +50,20 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
50
50
|
|
51
51
|
if (!callback) {
|
52
52
|
callback = function (err, friendList) {
|
53
|
-
if (err)
|
54
|
-
return rejectFunc(err);
|
55
|
-
}
|
53
|
+
if (err) return rejectFunc(err);
|
56
54
|
resolveFunc(friendList);
|
57
55
|
};
|
58
56
|
}
|
59
57
|
|
60
58
|
defaultFuncs
|
61
|
-
.postFormData(
|
62
|
-
"https://www.facebook.com/chat/user_info_all",
|
63
|
-
ctx.jar,
|
64
|
-
{},
|
65
|
-
{ viewer: ctx.userID }
|
66
|
-
)
|
59
|
+
.postFormData("https://www.facebook.com/chat/user_info_all", ctx.jar, {}, { viewer: ctx.userID })
|
67
60
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
68
|
-
.then(function(resData) {
|
69
|
-
if (!resData) {
|
70
|
-
|
71
|
-
}
|
72
|
-
if (resData.error) {
|
73
|
-
throw resData;
|
74
|
-
}
|
61
|
+
.then(function (resData) {
|
62
|
+
if (!resData) throw { error: "getFriendsList returned empty object." };
|
63
|
+
if (resData.error) throw resData;
|
75
64
|
callback(null, formatData(resData.payload));
|
76
65
|
})
|
77
|
-
.catch(function(err) {
|
66
|
+
.catch(function (err) {
|
78
67
|
log.error("getFriendsList", err);
|
79
68
|
return callback(err);
|
80
69
|
});
|
@@ -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,56 +144,15 @@ 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
|
-
|
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,
|
147
|
+
description: attachment.story_attachment.description && attachment.story_attachment.description.text,
|
148
|
+
source: attachment.story_attachment.source == null ? null : attachment.story_attachment.source.text,
|
149
|
+
|
150
|
+
image: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).uri,
|
151
|
+
width: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).width,
|
152
|
+
height: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).height,
|
153
|
+
playable: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.is_playable,
|
154
|
+
duration: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.playable_duration_in_ms,
|
155
|
+
playableUrl: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.playable_url,
|
197
156
|
|
198
157
|
subattachments: attachment.story_attachment.subattachments,
|
199
158
|
|
@@ -210,54 +169,22 @@ function formatExtensibleAttachment(attachment) {
|
|
210
169
|
// width: "1280"
|
211
170
|
// }
|
212
171
|
//
|
213
|
-
properties: attachment.story_attachment.properties.reduce(function(
|
214
|
-
obj,
|
215
|
-
cur
|
216
|
-
) {
|
172
|
+
properties: attachment.story_attachment.properties.reduce(function (obj, cur) {
|
217
173
|
obj[cur.key] = cur.value.text;
|
218
174
|
return obj;
|
219
|
-
},
|
220
|
-
{}),
|
175
|
+
}, {}),
|
221
176
|
|
222
177
|
// Deprecated fields
|
223
178
|
animatedImageSize: "", // @Legacy
|
224
179
|
facebookUrl: "", // @Legacy
|
225
180
|
styleList: "", // @Legacy
|
226
181
|
target: "", // @Legacy
|
227
|
-
thumbnailUrl:
|
228
|
-
|
229
|
-
|
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
|
182
|
+
thumbnailUrl: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).uri, // @Legacy
|
183
|
+
thumbnailWidth: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).width, // @Legacy
|
184
|
+
thumbnailHeight: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).height // @Legacy
|
257
185
|
};
|
258
|
-
} else {
|
259
|
-
return { error: "Don't know what to do with extensible_attachment." };
|
260
186
|
}
|
187
|
+
else return { error: "Don't know what to do with extensible_attachment." };
|
261
188
|
}
|
262
189
|
|
263
190
|
function formatReactionsGraphQL(reaction) {
|
@@ -268,24 +195,18 @@ function formatReactionsGraphQL(reaction) {
|
|
268
195
|
}
|
269
196
|
|
270
197
|
function formatEventData(event) {
|
271
|
-
if (event == null) {
|
272
|
-
return {};
|
273
|
-
}
|
198
|
+
if (event == null) return {}
|
274
199
|
|
275
200
|
switch (event.__typename) {
|
276
201
|
case "ThemeColorExtensibleMessageAdminText":
|
277
|
-
return {
|
278
|
-
color: event.theme_color
|
279
|
-
};
|
202
|
+
return { color: event.theme_color };
|
280
203
|
case "ThreadNicknameExtensibleMessageAdminText":
|
281
204
|
return {
|
282
205
|
nickname: event.nickname,
|
283
206
|
participantID: event.participant_id
|
284
207
|
};
|
285
208
|
case "ThreadIconExtensibleMessageAdminText":
|
286
|
-
return {
|
287
|
-
threadIcon: event.thread_icon
|
288
|
-
};
|
209
|
+
return { threadIcon: event.thread_icon };
|
289
210
|
case "InstantGameUpdateExtensibleMessageAdminText":
|
290
211
|
return {
|
291
212
|
gameID: (event.game == null ? null : event.game.id),
|
@@ -295,9 +216,7 @@ function formatEventData(event) {
|
|
295
216
|
instant_game_update_data: event.instant_game_update_data
|
296
217
|
};
|
297
218
|
case "GameScoreExtensibleMessageAdminText":
|
298
|
-
return {
|
299
|
-
game_type: event.game_type
|
300
|
-
};
|
219
|
+
return { game_type: event.game_type };
|
301
220
|
case "RtcCallLogExtensibleMessageAdminText":
|
302
221
|
return {
|
303
222
|
event: event.event,
|
@@ -345,19 +264,15 @@ function formatEventData(event) {
|
|
345
264
|
case "LightweightEventDeleteExtensibleMessageAdminText":
|
346
265
|
return {};
|
347
266
|
default:
|
348
|
-
return {
|
349
|
-
error: "Don't know what to with event data type " + event.__typename
|
350
|
-
};
|
267
|
+
return { error: "Don't know what to with event data type " + event.__typename };
|
351
268
|
}
|
352
269
|
}
|
353
270
|
|
354
271
|
function formatMessagesGraphQLResponse(data) {
|
355
272
|
var messageThread = data.o0.data.message_thread;
|
356
|
-
var threadID = messageThread.thread_key.thread_fbid
|
357
|
-
? messageThread.thread_key.thread_fbid
|
358
|
-
: messageThread.thread_key.other_user_id;
|
273
|
+
var threadID = messageThread.thread_key.thread_fbid ? messageThread.thread_key.thread_fbid : messageThread.thread_key.other_user_id;
|
359
274
|
|
360
|
-
var messages = messageThread.messages.nodes.map(function(d) {
|
275
|
+
var messages = messageThread.messages.nodes.map(function (d) {
|
361
276
|
switch (d.__typename) {
|
362
277
|
case "UserMessage":
|
363
278
|
// Give priority to stickers. They're seen as normal messages but we've
|
@@ -393,9 +308,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
393
308
|
|
394
309
|
var mentionsObj = {};
|
395
310
|
if (d.message !== null) {
|
396
|
-
d.message.ranges.forEach(e =>
|
397
|
-
mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length);
|
398
|
-
});
|
311
|
+
d.message.ranges.forEach(e => mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length));
|
399
312
|
}
|
400
313
|
|
401
314
|
return {
|
@@ -418,9 +331,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
418
331
|
isUnread: d.unread,
|
419
332
|
|
420
333
|
// New
|
421
|
-
messageReactions: d.message_reactions
|
422
|
-
? d.message_reactions.map(formatReactionsGraphQL)
|
423
|
-
: null,
|
334
|
+
messageReactions: d.message_reactions ? d.message_reactions.map(formatReactionsGraphQL) : null,
|
424
335
|
isSponsored: d.is_sponsored,
|
425
336
|
snippet: d.snippet
|
426
337
|
};
|
@@ -434,9 +345,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
434
345
|
timestamp: d.timestamp_precise,
|
435
346
|
eventType: "change_thread_name",
|
436
347
|
snippet: d.snippet,
|
437
|
-
eventData: {
|
438
|
-
threadName: d.thread_name
|
439
|
-
},
|
348
|
+
eventData: { threadName: d.thread_name },
|
440
349
|
|
441
350
|
// @Legacy
|
442
351
|
author: d.message_sender.id,
|
@@ -453,26 +362,21 @@ function formatMessagesGraphQLResponse(data) {
|
|
453
362
|
timestamp: d.timestamp_precise,
|
454
363
|
eventType: "change_thread_image",
|
455
364
|
snippet: d.snippet,
|
456
|
-
eventData:
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
},
|
365
|
+
eventData: d.image_with_metadata == null
|
366
|
+
? {} /* removed image */
|
367
|
+
: {
|
368
|
+
/* image added */
|
369
|
+
threadImage: {
|
370
|
+
attachmentID: d.image_with_metadata.legacy_attachment_id,
|
371
|
+
width: d.image_with_metadata.original_dimensions.x,
|
372
|
+
height: d.image_with_metadata.original_dimensions.y,
|
373
|
+
url: d.image_with_metadata.preview.uri
|
374
|
+
}
|
375
|
+
},
|
468
376
|
|
469
377
|
// @Legacy
|
470
378
|
logMessageType: "log:thread-icon",
|
471
|
-
logMessageData: {
|
472
|
-
thread_icon: d.image_with_metadata
|
473
|
-
? d.image_with_metadata.preview.uri
|
474
|
-
: null
|
475
|
-
}
|
379
|
+
logMessageData: { thread_icon: d.image_with_metadata ? d.image_with_metadata.preview.uri : null }
|
476
380
|
};
|
477
381
|
case "ParticipantLeftMessage":
|
478
382
|
return {
|
@@ -486,7 +390,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
486
390
|
snippet: d.snippet,
|
487
391
|
eventData: {
|
488
392
|
// Array of IDs.
|
489
|
-
participantsRemoved: d.participants_removed.map(function(p) {
|
393
|
+
participantsRemoved: d.participants_removed.map(function (p) {
|
490
394
|
return p.id;
|
491
395
|
})
|
492
396
|
},
|
@@ -494,7 +398,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
494
398
|
// @Legacy
|
495
399
|
logMessageType: "log:unsubscribe",
|
496
400
|
logMessageData: {
|
497
|
-
leftParticipantFbId: d.participants_removed.map(function(p) {
|
401
|
+
leftParticipantFbId: d.participants_removed.map(function (p) {
|
498
402
|
return p.id;
|
499
403
|
})
|
500
404
|
}
|
@@ -511,7 +415,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
511
415
|
snippet: d.snippet,
|
512
416
|
eventData: {
|
513
417
|
// Array of IDs.
|
514
|
-
participantsAdded: d.participants_added.map(function(p) {
|
418
|
+
participantsAdded: d.participants_added.map(function (p) {
|
515
419
|
return p.id;
|
516
420
|
})
|
517
421
|
},
|
@@ -519,7 +423,7 @@ function formatMessagesGraphQLResponse(data) {
|
|
519
423
|
// @Legacy
|
520
424
|
logMessageType: "log:subscribe",
|
521
425
|
logMessageData: {
|
522
|
-
addedParticipants: d.participants_added.map(function(p) {
|
426
|
+
addedParticipants: d.participants_added.map(function (p) {
|
523
427
|
return p.id;
|
524
428
|
})
|
525
429
|
}
|
@@ -577,15 +481,10 @@ function formatMessagesGraphQLResponse(data) {
|
|
577
481
|
return messages;
|
578
482
|
}
|
579
483
|
|
580
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
581
|
-
return function getThreadHistoryGraphQL(
|
582
|
-
|
583
|
-
|
584
|
-
timestamp,
|
585
|
-
callback
|
586
|
-
) {
|
587
|
-
var resolveFunc = function(){};
|
588
|
-
var rejectFunc = function(){};
|
484
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
485
|
+
return function getThreadHistoryGraphQL(threadID, amount, timestamp, callback) {
|
486
|
+
var resolveFunc = function () { };
|
487
|
+
var rejectFunc = function () { };
|
589
488
|
var returnPromise = new Promise(function (resolve, reject) {
|
590
489
|
resolveFunc = resolve;
|
591
490
|
rejectFunc = reject;
|
@@ -593,9 +492,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
593
492
|
|
594
493
|
if (!callback) {
|
595
494
|
callback = function (err, data) {
|
596
|
-
if (err)
|
597
|
-
return rejectFunc(err);
|
598
|
-
}
|
495
|
+
if (err) return rejectFunc(err);
|
599
496
|
resolveFunc(data);
|
600
497
|
};
|
601
498
|
}
|
@@ -622,20 +519,15 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
622
519
|
defaultFuncs
|
623
520
|
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
624
521
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
625
|
-
.then(function(resData) {
|
626
|
-
if (resData.error)
|
627
|
-
throw resData;
|
628
|
-
}
|
522
|
+
.then(function (resData) {
|
523
|
+
if (resData.error) throw resData;
|
629
524
|
// This returns us an array of things. The last one is the success /
|
630
525
|
// failure one.
|
631
526
|
// @TODO What do we do in this case?
|
632
|
-
if (resData[resData.length - 1].error_results !== 0)
|
633
|
-
throw new Error("There was an error_result.");
|
634
|
-
}
|
635
|
-
|
527
|
+
if (resData[resData.length - 1].error_results !== 0) throw new Error("There was an error_result.");
|
636
528
|
callback(null, formatMessagesGraphQLResponse(resData[0]));
|
637
529
|
})
|
638
|
-
.catch(function(err) {
|
530
|
+
.catch(function (err) {
|
639
531
|
log.error("getThreadHistoryGraphQL", err);
|
640
532
|
return callback(err);
|
641
533
|
});
|
@@ -3,73 +3,54 @@
|
|
3
3
|
var utils = require("../utils");
|
4
4
|
var log = require("npmlog");
|
5
5
|
|
6
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
7
|
return function getThreadHistory(threadID, amount, timestamp, callback) {
|
8
|
-
var resolveFunc = function(){};
|
9
|
-
var rejectFunc = function(){};
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
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 (err,
|
17
|
-
if (err)
|
18
|
-
|
19
|
-
}
|
20
|
-
resolveFunc(friendList);
|
16
|
+
callback = function (err, threadInfo) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc(threadInfo);
|
21
19
|
};
|
22
20
|
}
|
23
21
|
|
24
|
-
if (!callback) {
|
25
|
-
throw { error: "getThreadHistory: need callback" };
|
26
|
-
}
|
27
|
-
|
22
|
+
if (!callback) throw { error: "getThreadHistory: need callback" };
|
28
23
|
var form = {
|
29
24
|
client: "mercury"
|
30
25
|
};
|
31
26
|
|
32
|
-
api.getUserInfo(threadID, function(err, res) {
|
33
|
-
if (err)
|
34
|
-
return callback(err);
|
35
|
-
}
|
27
|
+
api.getUserInfo(threadID, function (err, res) {
|
28
|
+
if (err) return callback(err);
|
36
29
|
var key = Object.keys(res).length > 0 ? "user_ids" : "thread_fbids";
|
37
30
|
form["messages[" + key + "][" + threadID + "][offset]"] = 0;
|
38
31
|
form["messages[" + key + "][" + threadID + "][timestamp]"] = timestamp;
|
39
32
|
form["messages[" + key + "][" + threadID + "][limit]"] = amount;
|
40
33
|
|
41
|
-
if (ctx.globalOptions.pageID)
|
42
|
-
form.request_user_id = ctx.globalOptions.pageID;
|
34
|
+
if (ctx.globalOptions.pageID) form.request_user_id = ctx.globalOptions.pageID;
|
43
35
|
|
44
36
|
defaultFuncs
|
45
|
-
.post(
|
46
|
-
"https://www.facebook.com/ajax/mercury/thread_info.php",
|
47
|
-
ctx.jar,
|
48
|
-
form
|
49
|
-
)
|
37
|
+
.post("https://www.facebook.com/ajax/mercury/thread_info.php", ctx.jar, form)
|
50
38
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
51
|
-
.then(function(resData) {
|
52
|
-
if (resData.error)
|
53
|
-
|
54
|
-
} else if (!resData.payload) {
|
55
|
-
throw { error: "Could not retrieve thread history." };
|
56
|
-
}
|
39
|
+
.then(function (resData) {
|
40
|
+
if (resData.error) throw resData;
|
41
|
+
else if (!resData.payload) throw { error: "Could not retrieve thread history." };
|
57
42
|
|
58
43
|
// Asking for message history from a thread with no message history
|
59
44
|
// will return undefined for actions here
|
60
|
-
if (!resData.payload.actions)
|
61
|
-
resData.payload.actions = [];
|
62
|
-
}
|
45
|
+
if (!resData.payload.actions) resData.payload.actions = [];
|
63
46
|
|
64
47
|
var userIDs = {};
|
65
|
-
resData.payload.actions.forEach(
|
66
|
-
userIDs[v.author.split(":").pop()] = "";
|
67
|
-
});
|
48
|
+
resData.payload.actions.forEach(v => userIDs[v.author.split(":").pop()] = "");
|
68
49
|
|
69
|
-
api.getUserInfo(Object.keys(userIDs), function(err, data) {
|
50
|
+
api.getUserInfo(Object.keys(userIDs), function (err, data) {
|
70
51
|
if (err) return callback(err); //callback({error: "Could not retrieve user information in getThreadHistory."});
|
71
52
|
|
72
|
-
resData.payload.actions.forEach(function(v) {
|
53
|
+
resData.payload.actions.forEach(function (v) {
|
73
54
|
var sender = data[v.author.split(":").pop()];
|
74
55
|
if (sender) v.sender_name = sender.name;
|
75
56
|
else v.sender_name = "Facebook User";
|
@@ -77,13 +58,10 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
77
58
|
delete v.author;
|
78
59
|
});
|
79
60
|
|
80
|
-
callback(
|
81
|
-
null,
|
82
|
-
resData.payload.actions.map(utils.formatHistoryMessage)
|
83
|
-
);
|
61
|
+
callback(null, resData.payload.actions.map(utils.formatHistoryMessage));
|
84
62
|
});
|
85
63
|
})
|
86
|
-
.catch(function(err) {
|
64
|
+
.catch(function (err) {
|
87
65
|
log.error("getThreadHistory", err);
|
88
66
|
return callback(err);
|
89
67
|
});
|