alicezetion 1.2.8 → 1.2.9
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 +5 -2
- package/leiamnash/addExternalModule.js +6 -10
- package/leiamnash/addUserToGroup.js +16 -52
- package/leiamnash/changeAdminStatus.js +37 -69
- package/leiamnash/changeArchivedStatus.js +12 -26
- package/leiamnash/changeBio.js +6 -19
- package/leiamnash/changeBlockedStatus.js +3 -14
- package/leiamnash/changeGroupImage.js +16 -40
- package/leiamnash/changeNickname.js +11 -27
- package/leiamnash/changeThreadColor.js +10 -20
- package/leiamnash/changeThreadEmoji.js +10 -24
- package/leiamnash/chat.js +279 -414
- package/leiamnash/createNewGroup.js +12 -28
- package/leiamnash/createPoll.js +13 -25
- package/leiamnash/deleteMessage.js +12 -24
- package/leiamnash/deleteThread.js +11 -25
- package/leiamnash/forwardAttachment.js +13 -26
- package/leiamnash/forwardMessage.js +0 -0
- package/leiamnash/getCurrentUserID.js +1 -1
- package/leiamnash/getEmojiUrl.js +2 -4
- package/leiamnash/getFriendsList.js +10 -21
- package/leiamnash/getThreadHistory.js +58 -166
- package/leiamnash/getThreadHistoryDeprecated.js +20 -42
- package/leiamnash/getThreadInfo.js +25 -60
- package/leiamnash/getThreadInfoDeprecated.js +18 -42
- package/leiamnash/getThreadList.js +41 -66
- package/leiamnash/getThreadListDeprecated.js +14 -43
- package/leiamnash/getThreadPictures.js +17 -37
- package/leiamnash/getUserID.js +9 -14
- package/leiamnash/getUserInfo.js +12 -18
- package/leiamnash/handleFriendRequest.js +37 -52
- package/leiamnash/handleMessageRequest.js +14 -32
- package/leiamnash/httpGet.js +12 -17
- package/leiamnash/httpPost.js +12 -17
- package/leiamnash/listen.js +553 -0
- package/leiamnash/listenMqtt-Test.js +687 -0
- package/leiamnash/listenMqtt.js +1 -2
- package/leiamnash/logout.js +13 -20
- package/leiamnash/markAsDelivered.js +11 -22
- package/leiamnash/markAsRead.js +11 -21
- package/leiamnash/markAsReadAll.js +10 -20
- package/leiamnash/markAsSeen.js +7 -18
- package/leiamnash/muteThread.js +11 -18
- package/leiamnash/removeUserFromGroup.js +14 -48
- package/leiamnash/resolvePhotoUrl.js +8 -17
- package/leiamnash/searchForThread.js +10 -21
- package/leiamnash/sendTypingIndicator.js +14 -47
- package/leiamnash/setMessageReaction.js +12 -26
- package/leiamnash/setPostReaction.js +13 -26
- package/leiamnash/setTitle.js +13 -29
- package/leiamnash/threadColors.js +28 -44
- package/leiamnash/unfriend.js +9 -19
- package/leiamnash/unsendMessage.js +9 -19
- package/package.json +1 -1
- package/replit.nix +1 -3
- package/utils.js +0 -0
@@ -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
|
});
|
@@ -21,7 +21,7 @@ function formatEventReminders(reminder) {
|
|
21
21
|
secondsToNotifyBefore: reminder.seconds_to_notify_before,
|
22
22
|
allowsRsvp: reminder.allows_rsvp,
|
23
23
|
relatedEvent: reminder.related_event,
|
24
|
-
members: reminder.event_reminder_members.edges.map(function(member) {
|
24
|
+
members: reminder.event_reminder_members.edges.map(function (member) {
|
25
25
|
return {
|
26
26
|
memberID: member.node.id,
|
27
27
|
state: member.guest_list_state.toLowerCase()
|
@@ -31,33 +31,15 @@ function formatEventReminders(reminder) {
|
|
31
31
|
}
|
32
32
|
|
33
33
|
function formatThreadGraphQLResponse(data) {
|
34
|
-
|
35
|
-
|
36
|
-
} catch (err){
|
37
|
-
console.error("GetThreadInfoGraphQL", "Can't get this thread info!");
|
38
|
-
return {err: err};
|
39
|
-
}
|
40
|
-
var threadID = messageThread.thread_key.thread_fbid
|
41
|
-
? messageThread.thread_key.thread_fbid
|
42
|
-
: messageThread.thread_key.other_user_id;
|
34
|
+
var messageThread = data.o0.data.message_thread;
|
35
|
+
var threadID = messageThread.thread_key.thread_fbid ? messageThread.thread_key.thread_fbid : messageThread.thread_key.other_user_id;
|
43
36
|
|
44
37
|
// Remove me
|
45
38
|
var lastM = messageThread.last_message;
|
46
|
-
var snippetID =
|
47
|
-
|
48
|
-
lastM.nodes &&
|
49
|
-
lastM.nodes[0] &&
|
50
|
-
lastM.nodes[0].message_sender &&
|
51
|
-
lastM.nodes[0].message_sender.messaging_actor
|
52
|
-
? lastM.nodes[0].message_sender.messaging_actor.id
|
53
|
-
: null;
|
54
|
-
var snippetText =
|
55
|
-
lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
|
39
|
+
var snippetID = lastM && lastM.nodes && lastM.nodes[0] && lastM.nodes[0].message_sender && lastM.nodes[0].message_sender.messaging_actor ? lastM.nodes[0].message_sender.messaging_actor.id : null;
|
40
|
+
var snippetText = lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
|
56
41
|
var lastR = messageThread.last_read_receipt;
|
57
|
-
var lastReadTimestamp =
|
58
|
-
lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise
|
59
|
-
? lastR.nodes[0].timestamp_precise
|
60
|
-
: null;
|
42
|
+
var lastReadTimestamp = lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise ? lastR.nodes[0].timestamp_precise : null;
|
61
43
|
|
62
44
|
return {
|
63
45
|
threadID: threadID,
|
@@ -84,27 +66,16 @@ function formatThreadGraphQLResponse(data) {
|
|
84
66
|
isArchived: messageThread.has_viewer_archived,
|
85
67
|
folder: messageThread.folder,
|
86
68
|
cannotReplyReason: messageThread.cannot_reply_reason,
|
87
|
-
eventReminders: messageThread.event_reminders
|
88
|
-
|
89
|
-
|
90
|
-
emoji: messageThread.customization_info
|
91
|
-
? messageThread.customization_info.emoji
|
92
|
-
: null,
|
93
|
-
color:
|
94
|
-
messageThread.customization_info &&
|
95
|
-
messageThread.customization_info.outgoing_bubble_color
|
96
|
-
? messageThread.customization_info.outgoing_bubble_color.slice(2)
|
97
|
-
: null,
|
69
|
+
eventReminders: messageThread.event_reminders ? messageThread.event_reminders.nodes.map(formatEventReminders) : null,
|
70
|
+
emoji: messageThread.customization_info ? messageThread.customization_info.emoji : null,
|
71
|
+
color: messageThread.customization_info && messageThread.customization_info.outgoing_bubble_color ? messageThread.customization_info.outgoing_bubble_color.slice(2) : null,
|
98
72
|
nicknames:
|
99
73
|
messageThread.customization_info &&
|
100
|
-
|
101
|
-
? messageThread.customization_info.participant_customizations.reduce(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
},
|
106
|
-
{}
|
107
|
-
)
|
74
|
+
messageThread.customization_info.participant_customizations
|
75
|
+
? messageThread.customization_info.participant_customizations.reduce(function (res, val) {
|
76
|
+
if (val.nickname) res[val.participant_id] = val.nickname;
|
77
|
+
return res;
|
78
|
+
}, {})
|
108
79
|
: {},
|
109
80
|
adminIDs: messageThread.thread_admins,
|
110
81
|
approvalMode: Boolean(messageThread.approval_mode),
|
@@ -134,19 +105,17 @@ function formatThreadGraphQLResponse(data) {
|
|
134
105
|
hasEmailParticipant: false,
|
135
106
|
readOnly: false,
|
136
107
|
canReply: messageThread.cannot_reply_reason == null,
|
137
|
-
lastMessageTimestamp: messageThread.last_message
|
138
|
-
? messageThread.last_message.timestamp_precise
|
139
|
-
: null,
|
108
|
+
lastMessageTimestamp: messageThread.last_message ? messageThread.last_message.timestamp_precise : null,
|
140
109
|
lastMessageType: "message",
|
141
110
|
lastReadTimestamp: lastReadTimestamp,
|
142
111
|
threadType: messageThread.thread_type == "GROUP" ? 2 : 1
|
143
112
|
};
|
144
113
|
}
|
145
114
|
|
146
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
115
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
147
116
|
return function getThreadInfoGraphQL(threadID, callback) {
|
148
|
-
var resolveFunc = function(){};
|
149
|
-
var rejectFunc = function(){};
|
117
|
+
var resolveFunc = function () { };
|
118
|
+
var rejectFunc = function () { };
|
150
119
|
var returnPromise = new Promise(function (resolve, reject) {
|
151
120
|
resolveFunc = resolve;
|
152
121
|
rejectFunc = reject;
|
@@ -154,9 +123,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
154
123
|
|
155
124
|
if (utils.getType(callback) != "Function" && utils.getType(callback) != "AsyncFunction") {
|
156
125
|
callback = function (err, data) {
|
157
|
-
if (err)
|
158
|
-
return rejectFunc(err);
|
159
|
-
}
|
126
|
+
if (err) return rejectFunc(err);
|
160
127
|
resolveFunc(data);
|
161
128
|
};
|
162
129
|
}
|
@@ -183,21 +150,19 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
183
150
|
defaultFuncs
|
184
151
|
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
185
152
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
186
|
-
.then(function(resData) {
|
187
|
-
if (resData.error)
|
188
|
-
throw resData;
|
189
|
-
}
|
153
|
+
.then(function (resData) {
|
154
|
+
if (resData.error) throw resData;
|
190
155
|
// This returns us an array of things. The last one is the success /
|
191
156
|
// failure one.
|
192
157
|
// @TODO What do we do in this case?
|
193
158
|
if (resData[resData.length - 1].error_results !== 0) {
|
194
|
-
console.
|
159
|
+
console.log(resData); //Log more info
|
160
|
+
throw new Error("well darn there was an error_result");
|
195
161
|
}
|
196
|
-
|
197
162
|
callback(null, formatThreadGraphQLResponse(resData[0]));
|
198
163
|
})
|
199
|
-
.catch(function(err) {
|
200
|
-
log.error("getThreadInfoGraphQL",
|
164
|
+
.catch(function (err) {
|
165
|
+
log.error("getThreadInfoGraphQL", "Can't get thread info");
|
201
166
|
return callback(err);
|
202
167
|
});
|
203
168
|
|