alicezetion 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/.travis.yml +6 -0
- package/index.js +532 -604
- package/package.json +78 -75
- package/replit.nix +5 -0
- package/src/addExternalModule.js +15 -0
- package/{alice → src}/addUserToGroup.js +77 -113
- package/src/changeAdminStatus.js +47 -0
- package/src/changeArchivedStatus.js +41 -0
- package/{alice → src}/changeBio.js +64 -77
- package/{alice → src}/changeBlockedStatus.js +36 -47
- package/{alice → src}/changeGroupImage.js +105 -129
- package/src/changeNickname.js +43 -0
- package/{alice → src}/changeThreadColor.js +61 -71
- package/src/changeThreadEmoji.js +41 -0
- package/src/chat.js +315 -0
- package/{alice → src}/createNewGroup.js +70 -86
- package/{alice → src}/createPoll.js +59 -71
- 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 +7 -7
- package/{alice → src}/getEmojiUrl.js +27 -29
- package/{alice → src}/getFriendsList.js +73 -84
- package/{alice → src}/getThreadHistory.js +537 -645
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/{alice → src}/getThreadInfo.js +171 -206
- package/src/getThreadInfoDeprecated.js +56 -0
- package/{alice → src}/getThreadList.js +213 -238
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/{alice → src}/getUserID.js +61 -66
- package/{alice → src}/getUserInfo.js +66 -72
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/{alice → src}/httpGet.js +47 -52
- package/{alice → src}/httpPost.js +47 -52
- package/src/listen.js +553 -0
- package/src/listenMqtt-Test.js +687 -0
- package/src/listenMqtt.js +677 -0
- package/{alice → src}/logout.js +68 -75
- package/{alice → src}/markAsDelivered.js +47 -58
- package/{alice → src}/markAsRead.js +70 -80
- package/{alice/seen.js → src/markAsReadAll.js} +39 -49
- package/{alice → src}/markAsSeen.js +48 -59
- package/{alice → src}/muteThread.js +45 -52
- package/src/removeUserFromGroup.js +45 -0
- package/{alice → src}/resolvePhotoUrl.js +36 -45
- package/src/searchForThread.js +42 -0
- package/{alice → src}/sendTypingIndicator.js +70 -103
- package/{alice/react.js → src/setMessageReaction.js} +103 -117
- package/{alice → src}/setPostReaction.js +63 -76
- package/{alice → src}/setTitle.js +70 -86
- package/src/threadColors.js +41 -0
- package/{alice → src}/unfriend.js +42 -52
- package/{alice → src}/unsendMessage.js +39 -49
- package/utils.js +1190 -1357
- 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/chat.js +0 -459
- package/alice/deleteMessage.js +0 -56
- package/alice/deleteThread.js +0 -56
- package/alice/forwardAttachment.js +0 -60
- package/alice/getThreadHistoryDeprecated.js +0 -93
- 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/searchForThread.js +0 -53
- package/alice/threadColors.js +0 -57
- package/test/data/shareAttach.js +0 -146
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +0 -7
- package/test/example-config.json +0 -18
- package/test/test-page.js +0 -140
- package/test/test.js +0 -385
@@ -0,0 +1,71 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
return function getThreadHistory(threadID, amount, timestamp, callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
|
15
|
+
if (!callback) {
|
16
|
+
callback = function (err, threadInfo) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc(threadInfo);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
if (!callback) throw { error: "getThreadHistory: need callback" };
|
23
|
+
var form = {
|
24
|
+
client: "mercury"
|
25
|
+
};
|
26
|
+
|
27
|
+
api.getUserInfo(threadID, function (err, res) {
|
28
|
+
if (err) return callback(err);
|
29
|
+
var key = Object.keys(res).length > 0 ? "user_ids" : "thread_fbids";
|
30
|
+
form["messages[" + key + "][" + threadID + "][offset]"] = 0;
|
31
|
+
form["messages[" + key + "][" + threadID + "][timestamp]"] = timestamp;
|
32
|
+
form["messages[" + key + "][" + threadID + "][limit]"] = amount;
|
33
|
+
|
34
|
+
if (ctx.globalOptions.pageID) form.request_user_id = ctx.globalOptions.pageID;
|
35
|
+
|
36
|
+
defaultFuncs
|
37
|
+
.post("https://www.facebook.com/ajax/mercury/thread_info.php", ctx.jar, form)
|
38
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
39
|
+
.then(function (resData) {
|
40
|
+
if (resData.error) throw resData;
|
41
|
+
else if (!resData.payload) throw { error: "Could not retrieve thread history." };
|
42
|
+
|
43
|
+
// Asking for message history from a thread with no message history
|
44
|
+
// will return undefined for actions here
|
45
|
+
if (!resData.payload.actions) resData.payload.actions = [];
|
46
|
+
|
47
|
+
var userIDs = {};
|
48
|
+
resData.payload.actions.forEach(v => userIDs[v.author.split(":").pop()] = "");
|
49
|
+
|
50
|
+
api.getUserInfo(Object.keys(userIDs), function (err, data) {
|
51
|
+
if (err) return callback(err); //callback({error: "Could not retrieve user information in getThreadHistory."});
|
52
|
+
|
53
|
+
resData.payload.actions.forEach(function (v) {
|
54
|
+
var sender = data[v.author.split(":").pop()];
|
55
|
+
if (sender) v.sender_name = sender.name;
|
56
|
+
else v.sender_name = "Facebook User";
|
57
|
+
v.sender_fbid = v.author;
|
58
|
+
delete v.author;
|
59
|
+
});
|
60
|
+
|
61
|
+
callback(null, resData.payload.actions.map(utils.formatHistoryMessage));
|
62
|
+
});
|
63
|
+
})
|
64
|
+
.catch(function (err) {
|
65
|
+
log.error("getThreadHistory", err);
|
66
|
+
return callback(err);
|
67
|
+
});
|
68
|
+
});
|
69
|
+
return returnPromise;
|
70
|
+
};
|
71
|
+
};
|
@@ -1,206 +1,171 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
function formatEventReminders(reminder) {
|
7
|
-
return {
|
8
|
-
reminderID: reminder.id,
|
9
|
-
eventCreatorID: reminder.lightweight_event_creator.id,
|
10
|
-
time: reminder.time,
|
11
|
-
eventType: reminder.lightweight_event_type.toLowerCase(),
|
12
|
-
locationName: reminder.location_name,
|
13
|
-
// @TODO verify this
|
14
|
-
locationCoordinates: reminder.location_coordinates,
|
15
|
-
locationPage: reminder.location_page,
|
16
|
-
eventStatus: reminder.lightweight_event_status.toLowerCase(),
|
17
|
-
note: reminder.note,
|
18
|
-
repeatMode: reminder.repeat_mode.toLowerCase(),
|
19
|
-
eventTitle: reminder.event_title,
|
20
|
-
triggerMessage: reminder.trigger_message,
|
21
|
-
secondsToNotifyBefore: reminder.seconds_to_notify_before,
|
22
|
-
allowsRsvp: reminder.allows_rsvp,
|
23
|
-
relatedEvent: reminder.related_event,
|
24
|
-
members: reminder.event_reminder_members.edges.map(function(member) {
|
25
|
-
return {
|
26
|
-
memberID: member.node.id,
|
27
|
-
state: member.guest_list_state.toLowerCase()
|
28
|
-
};
|
29
|
-
})
|
30
|
-
};
|
31
|
-
}
|
32
|
-
|
33
|
-
function formatThreadGraphQLResponse(data) {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
var
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
}
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
id: threadID,
|
173
|
-
message_limit: 0,
|
174
|
-
load_messages: false,
|
175
|
-
load_read_receipts: false,
|
176
|
-
before: null
|
177
|
-
}
|
178
|
-
}
|
179
|
-
}),
|
180
|
-
batch_name: "MessengerGraphQLThreadFetcher"
|
181
|
-
};
|
182
|
-
|
183
|
-
defaultFuncs
|
184
|
-
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
185
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
186
|
-
.then(function(resData) {
|
187
|
-
if (resData.error) {
|
188
|
-
throw resData;
|
189
|
-
}
|
190
|
-
// This returns us an array of things. The last one is the success /
|
191
|
-
// failure one.
|
192
|
-
// @TODO What do we do in this case?
|
193
|
-
if (resData[resData.length - 1].error_results !== 0) {
|
194
|
-
console.error("GetThreadInfo", "Well darn there was an error_result");
|
195
|
-
}
|
196
|
-
|
197
|
-
callback(null, formatThreadGraphQLResponse(resData[0]));
|
198
|
-
})
|
199
|
-
.catch(function(err) {
|
200
|
-
log.error("getThreadInfoGraphQL", err);
|
201
|
-
return callback(err);
|
202
|
-
});
|
203
|
-
|
204
|
-
return returnPromise;
|
205
|
-
};
|
206
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
function formatEventReminders(reminder) {
|
7
|
+
return {
|
8
|
+
reminderID: reminder.id,
|
9
|
+
eventCreatorID: reminder.lightweight_event_creator.id,
|
10
|
+
time: reminder.time,
|
11
|
+
eventType: reminder.lightweight_event_type.toLowerCase(),
|
12
|
+
locationName: reminder.location_name,
|
13
|
+
// @TODO verify this
|
14
|
+
locationCoordinates: reminder.location_coordinates,
|
15
|
+
locationPage: reminder.location_page,
|
16
|
+
eventStatus: reminder.lightweight_event_status.toLowerCase(),
|
17
|
+
note: reminder.note,
|
18
|
+
repeatMode: reminder.repeat_mode.toLowerCase(),
|
19
|
+
eventTitle: reminder.event_title,
|
20
|
+
triggerMessage: reminder.trigger_message,
|
21
|
+
secondsToNotifyBefore: reminder.seconds_to_notify_before,
|
22
|
+
allowsRsvp: reminder.allows_rsvp,
|
23
|
+
relatedEvent: reminder.related_event,
|
24
|
+
members: reminder.event_reminder_members.edges.map(function (member) {
|
25
|
+
return {
|
26
|
+
memberID: member.node.id,
|
27
|
+
state: member.guest_list_state.toLowerCase()
|
28
|
+
};
|
29
|
+
})
|
30
|
+
};
|
31
|
+
}
|
32
|
+
|
33
|
+
function formatThreadGraphQLResponse(data) {
|
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;
|
36
|
+
|
37
|
+
// Remove me
|
38
|
+
var lastM = messageThread.last_message;
|
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;
|
41
|
+
var lastR = messageThread.last_read_receipt;
|
42
|
+
var lastReadTimestamp = lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise ? lastR.nodes[0].timestamp_precise : null;
|
43
|
+
|
44
|
+
return {
|
45
|
+
threadID: threadID,
|
46
|
+
threadName: messageThread.name,
|
47
|
+
participantIDs: messageThread.all_participants.edges.map(d => d.node.messaging_actor.id),
|
48
|
+
userInfo: messageThread.all_participants.edges.map(d => ({
|
49
|
+
id: d.node.messaging_actor.id,
|
50
|
+
name: d.node.messaging_actor.name,
|
51
|
+
firstName: d.node.messaging_actor.short_name,
|
52
|
+
vanity: d.node.messaging_actor.username,
|
53
|
+
thumbSrc: d.node.messaging_actor.big_image_src.uri,
|
54
|
+
profileUrl: d.node.messaging_actor.big_image_src.uri,
|
55
|
+
gender: d.node.messaging_actor.gender,
|
56
|
+
type: d.node.messaging_actor.__typename,
|
57
|
+
isFriend: d.node.messaging_actor.is_viewer_friend,
|
58
|
+
isBirthday: !!d.node.messaging_actor.is_birthday //not sure?
|
59
|
+
})),
|
60
|
+
unreadCount: messageThread.unread_count,
|
61
|
+
messageCount: messageThread.messages_count,
|
62
|
+
timestamp: messageThread.updated_time_precise,
|
63
|
+
muteUntil: messageThread.mute_until,
|
64
|
+
isGroup: messageThread.thread_type == "GROUP",
|
65
|
+
isSubscribed: messageThread.is_viewer_subscribed,
|
66
|
+
isArchived: messageThread.has_viewer_archived,
|
67
|
+
folder: messageThread.folder,
|
68
|
+
cannotReplyReason: messageThread.cannot_reply_reason,
|
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,
|
72
|
+
nicknames:
|
73
|
+
messageThread.customization_info &&
|
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
|
+
}, {})
|
79
|
+
: {},
|
80
|
+
adminIDs: messageThread.thread_admins,
|
81
|
+
approvalMode: Boolean(messageThread.approval_mode),
|
82
|
+
approvalQueue: messageThread.group_approval_queue.nodes.map(a => ({
|
83
|
+
inviterID: a.inviter.id,
|
84
|
+
requesterID: a.requester.id,
|
85
|
+
timestamp: a.request_timestamp,
|
86
|
+
request_source: a.request_source // @Undocumented
|
87
|
+
})),
|
88
|
+
|
89
|
+
// @Undocumented
|
90
|
+
reactionsMuteMode: messageThread.reactions_mute_mode.toLowerCase(),
|
91
|
+
mentionsMuteMode: messageThread.mentions_mute_mode.toLowerCase(),
|
92
|
+
isPinProtected: messageThread.is_pin_protected,
|
93
|
+
relatedPageThread: messageThread.related_page_thread,
|
94
|
+
|
95
|
+
// @Legacy
|
96
|
+
name: messageThread.name,
|
97
|
+
snippet: snippetText,
|
98
|
+
snippetSender: snippetID,
|
99
|
+
snippetAttachments: [],
|
100
|
+
serverTimestamp: messageThread.updated_time_precise,
|
101
|
+
imageSrc: messageThread.image ? messageThread.image.uri : null,
|
102
|
+
isCanonicalUser: messageThread.is_canonical_neo_user,
|
103
|
+
isCanonical: messageThread.thread_type != "GROUP",
|
104
|
+
recipientsLoadable: true,
|
105
|
+
hasEmailParticipant: false,
|
106
|
+
readOnly: false,
|
107
|
+
canReply: messageThread.cannot_reply_reason == null,
|
108
|
+
lastMessageTimestamp: messageThread.last_message ? messageThread.last_message.timestamp_precise : null,
|
109
|
+
lastMessageType: "message",
|
110
|
+
lastReadTimestamp: lastReadTimestamp,
|
111
|
+
threadType: messageThread.thread_type == "GROUP" ? 2 : 1
|
112
|
+
};
|
113
|
+
}
|
114
|
+
|
115
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
116
|
+
return function getThreadInfoGraphQL(threadID, callback) {
|
117
|
+
var resolveFunc = function () { };
|
118
|
+
var rejectFunc = function () { };
|
119
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
120
|
+
resolveFunc = resolve;
|
121
|
+
rejectFunc = reject;
|
122
|
+
});
|
123
|
+
|
124
|
+
if (utils.getType(callback) != "Function" && utils.getType(callback) != "AsyncFunction") {
|
125
|
+
callback = function (err, data) {
|
126
|
+
if (err) return rejectFunc(err);
|
127
|
+
resolveFunc(data);
|
128
|
+
};
|
129
|
+
}
|
130
|
+
|
131
|
+
// `queries` has to be a string. I couldn't tell from the dev console. This
|
132
|
+
// took me a really long time to figure out. I deserve a cookie for this.
|
133
|
+
var form = {
|
134
|
+
queries: JSON.stringify({
|
135
|
+
o0: {
|
136
|
+
// This doc_id is valid as of July 20th, 2020
|
137
|
+
doc_id: "3449967031715030",
|
138
|
+
query_params: {
|
139
|
+
id: threadID,
|
140
|
+
message_limit: 0,
|
141
|
+
load_messages: false,
|
142
|
+
load_read_receipts: false,
|
143
|
+
before: null
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}),
|
147
|
+
batch_name: "MessengerGraphQLThreadFetcher"
|
148
|
+
};
|
149
|
+
|
150
|
+
defaultFuncs
|
151
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
152
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
153
|
+
.then(function (resData) {
|
154
|
+
if (resData.error) throw resData;
|
155
|
+
// This returns us an array of things. The last one is the success /
|
156
|
+
// failure one.
|
157
|
+
// @TODO What do we do in this case?
|
158
|
+
if (resData[resData.length - 1].error_results !== 0) {
|
159
|
+
console.log(resData); //Log more info
|
160
|
+
throw new Error("well darn there was an error_result");
|
161
|
+
}
|
162
|
+
callback(null, formatThreadGraphQLResponse(resData[0]));
|
163
|
+
})
|
164
|
+
.catch(function (err) {
|
165
|
+
log.error("getThreadInfoGraphQL", "Can't get thread info");
|
166
|
+
return callback(err);
|
167
|
+
});
|
168
|
+
|
169
|
+
return returnPromise;
|
170
|
+
};
|
171
|
+
};
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
return function getThreadInfo(threadID, callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
|
15
|
+
if (!callback) {
|
16
|
+
callback = function (err, data) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc(data);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
var form = {
|
23
|
+
client: "mercury"
|
24
|
+
};
|
25
|
+
|
26
|
+
api.getUserInfo(threadID, function (err, userRes) {
|
27
|
+
if (err) return callback(err);
|
28
|
+
var key = Object.keys(userRes).length > 0 ? "user_ids" : "thread_fbids";
|
29
|
+
form["threads[" + key + "][0]"] = threadID;
|
30
|
+
|
31
|
+
if (ctx.globalOptions.pageId) form.request_user_id = ctx.globalOptions.pageId;
|
32
|
+
|
33
|
+
defaultFuncs
|
34
|
+
.post("https://www.facebook.com/ajax/mercury/thread_info.php", ctx.jar, form)
|
35
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
+
.then(function (resData) {
|
37
|
+
if (resData.error) throw resData;
|
38
|
+
else if (!resData.payload) throw { error: "Could not retrieve thread Info." };
|
39
|
+
|
40
|
+
var threadData = resData.payload.threads[0];
|
41
|
+
var userData = userRes[threadID];
|
42
|
+
|
43
|
+
if (threadData == null) throw { error: "ThreadData is null" };
|
44
|
+
|
45
|
+
threadData.name = userData != null && userData.name != null ? userData.name : threadData.name;
|
46
|
+
threadData.image_src = userData != null && userData.thumbSrc != null ? userData.thumbSrc : threadData.image_src;
|
47
|
+
callback(null, utils.formatThread(threadData));
|
48
|
+
})
|
49
|
+
.catch(function (err) {
|
50
|
+
log.error("getThreadInfo", err);
|
51
|
+
return callback(err);
|
52
|
+
});
|
53
|
+
});
|
54
|
+
return returnPromise;
|
55
|
+
};
|
56
|
+
};
|