alicezetion 1.2.7 → 1.2.8
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/index.js +2 -5
- package/leiamnash/addExternalModule.js +10 -6
- package/leiamnash/addUserToGroup.js +52 -16
- package/leiamnash/changeAdminStatus.js +69 -37
- package/leiamnash/changeArchivedStatus.js +26 -12
- package/leiamnash/changeBio.js +19 -6
- package/leiamnash/changeBlockedStatus.js +14 -3
- package/leiamnash/changeGroupImage.js +40 -16
- package/leiamnash/changeNickname.js +27 -11
- package/leiamnash/changeThreadColor.js +20 -10
- package/leiamnash/changeThreadEmoji.js +24 -10
- package/leiamnash/chat.js +414 -279
- package/leiamnash/createNewGroup.js +28 -12
- package/leiamnash/createPoll.js +25 -13
- package/leiamnash/deleteMessage.js +24 -12
- package/leiamnash/deleteThread.js +25 -11
- package/leiamnash/forwardAttachment.js +26 -13
- package/leiamnash/getCurrentUserID.js +1 -1
- package/leiamnash/getEmojiUrl.js +4 -2
- package/leiamnash/getFriendsList.js +21 -10
- package/leiamnash/getThreadHistory.js +166 -58
- package/leiamnash/getThreadHistoryDeprecated.js +42 -20
- package/leiamnash/getThreadInfo.js +60 -25
- package/leiamnash/getThreadInfoDeprecated.js +42 -18
- package/leiamnash/getThreadList.js +66 -41
- package/leiamnash/getThreadListDeprecated.js +43 -14
- package/leiamnash/getThreadPictures.js +37 -17
- package/leiamnash/getUserID.js +14 -9
- package/leiamnash/getUserInfo.js +18 -12
- package/leiamnash/handleFriendRequest.js +52 -37
- package/leiamnash/handleMessageRequest.js +32 -14
- package/leiamnash/httpGet.js +17 -12
- package/leiamnash/httpPost.js +17 -12
- package/leiamnash/listenMqtt.js +2 -1
- package/leiamnash/logout.js +20 -13
- package/leiamnash/markAsDelivered.js +22 -11
- package/leiamnash/markAsRead.js +21 -11
- package/leiamnash/markAsReadAll.js +20 -10
- package/leiamnash/markAsSeen.js +18 -7
- package/leiamnash/muteThread.js +18 -11
- package/leiamnash/removeUserFromGroup.js +48 -14
- package/leiamnash/resolvePhotoUrl.js +17 -8
- package/leiamnash/searchForThread.js +21 -10
- package/leiamnash/sendTypingIndicator.js +47 -14
- package/leiamnash/setMessageReaction.js +26 -12
- package/leiamnash/setPostReaction.js +26 -13
- package/leiamnash/setTitle.js +29 -13
- package/leiamnash/threadColors.js +44 -28
- package/leiamnash/unfriend.js +19 -9
- package/leiamnash/unsendMessage.js +19 -9
- package/package.json +1 -1
- package/replit.nix +3 -1
- package/utils.js +0 -0
- package/leiamnash/forwardMessage.js +0 -0
- package/leiamnash/listen.js +0 -553
- package/leiamnash/listenMqtt-Test.js +0 -687
@@ -3,19 +3,21 @@
|
|
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
|
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
|
-
|
16
|
+
callback = function (err, friendList) {
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
20
|
+
resolveFunc(friendList);
|
19
21
|
};
|
20
22
|
}
|
21
23
|
|
@@ -23,30 +25,52 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
23
25
|
client: "mercury"
|
24
26
|
};
|
25
27
|
|
26
|
-
api.getUserInfo(threadID, function
|
27
|
-
if (err)
|
28
|
+
api.getUserInfo(threadID, function(err, userRes) {
|
29
|
+
if (err) {
|
30
|
+
return callback(err);
|
31
|
+
}
|
28
32
|
var key = Object.keys(userRes).length > 0 ? "user_ids" : "thread_fbids";
|
29
33
|
form["threads[" + key + "][0]"] = threadID;
|
30
34
|
|
31
|
-
if (ctx.globalOptions.pageId)
|
35
|
+
if (ctx.globalOptions.pageId)
|
36
|
+
form.request_user_id = ctx.globalOptions.pageId;
|
32
37
|
|
33
38
|
defaultFuncs
|
34
|
-
.post(
|
39
|
+
.post(
|
40
|
+
"https://www.facebook.com/ajax/mercury/thread_info.php",
|
41
|
+
ctx.jar,
|
42
|
+
form
|
43
|
+
)
|
35
44
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
-
.then(function
|
37
|
-
if (resData.error)
|
38
|
-
|
39
|
-
|
45
|
+
.then(function(resData) {
|
46
|
+
if (resData.error) {
|
47
|
+
throw resData;
|
48
|
+
} else if (!resData.payload) {
|
49
|
+
throw {
|
50
|
+
error: "Could not retrieve thread Info."
|
51
|
+
};
|
52
|
+
}
|
40
53
|
var threadData = resData.payload.threads[0];
|
41
54
|
var userData = userRes[threadID];
|
42
55
|
|
43
|
-
if (threadData == null)
|
56
|
+
if (threadData == null) {
|
57
|
+
throw {
|
58
|
+
error: "ThreadData is null"
|
59
|
+
};
|
60
|
+
}
|
61
|
+
|
62
|
+
threadData.name =
|
63
|
+
userData != null && userData.name != null
|
64
|
+
? userData.name
|
65
|
+
: threadData.name;
|
66
|
+
threadData.image_src =
|
67
|
+
userData != null && userData.thumbSrc != null
|
68
|
+
? userData.thumbSrc
|
69
|
+
: threadData.image_src;
|
44
70
|
|
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
71
|
callback(null, utils.formatThread(threadData));
|
48
72
|
})
|
49
|
-
.catch(function
|
73
|
+
.catch(function(err) {
|
50
74
|
log.error("getThreadInfo", err);
|
51
75
|
return callback(err);
|
52
76
|
});
|
@@ -9,7 +9,7 @@ function createProfileUrl(url, username, id) {
|
|
9
9
|
}
|
10
10
|
|
11
11
|
function formatParticipants(participants) {
|
12
|
-
return participants.edges.map((p)
|
12
|
+
return participants.edges.map((p)=>{
|
13
13
|
p = p.node.messaging_actor;
|
14
14
|
switch (p["__typename"]) {
|
15
15
|
case "User":
|
@@ -21,7 +21,7 @@ function formatParticipants(participants) {
|
|
21
21
|
gender: p.gender,
|
22
22
|
url: p.url, // how about making it profileURL
|
23
23
|
profilePicture: p.big_image_src.uri,
|
24
|
-
username: (p.username
|
24
|
+
username: (p.username||null),
|
25
25
|
// TODO: maybe better names for these?
|
26
26
|
isViewerFriend: p.is_viewer_friend, // true/false
|
27
27
|
isMessengerUser: p.is_messenger_user, // true/false
|
@@ -37,7 +37,7 @@ function formatParticipants(participants) {
|
|
37
37
|
name: p.name,
|
38
38
|
url: p.url,
|
39
39
|
profilePicture: p.big_image_src.uri,
|
40
|
-
username: (p.username
|
40
|
+
username: (p.username||null),
|
41
41
|
// uhm... better names maybe?
|
42
42
|
acceptsMessengerUserFeedback: p.accepts_messenger_user_feedback, // true/false
|
43
43
|
isMessengerUser: p.is_messenger_user, // true/false
|
@@ -46,18 +46,27 @@ function formatParticipants(participants) {
|
|
46
46
|
isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
|
47
47
|
};
|
48
48
|
case "ReducedMessagingActor":
|
49
|
-
case "UnavailableMessagingActor":
|
50
49
|
return {
|
51
50
|
accountType: p["__typename"],
|
52
51
|
userID: utils.formatID(p.id.toString()),
|
53
52
|
name: p.name,
|
54
53
|
url: createProfileUrl(p.url, p.username, p.id), // in this case p.url is null all the time
|
55
54
|
profilePicture: p.big_image_src.uri, // in this case it is default facebook photo, we could determine gender using it
|
56
|
-
username: (p.username
|
55
|
+
username: (p.username||null), // maybe we could use it to generate profile URL?
|
56
|
+
isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
|
57
|
+
};
|
58
|
+
case "UnavailableMessagingActor":
|
59
|
+
return {
|
60
|
+
accountType: p["__typename"],
|
61
|
+
userID: utils.formatID(p.id.toString()),
|
62
|
+
name: p.name, // "Facebook User" in user's language
|
63
|
+
url: createProfileUrl(p.url, p.username, p.id), // in this case p.url is null all the time
|
64
|
+
profilePicture: p.big_image_src.uri, // default male facebook photo
|
65
|
+
username: (p.username||null), // maybe we could use it to generate profile URL?
|
57
66
|
isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
|
58
67
|
};
|
59
68
|
default:
|
60
|
-
log.warn("getThreadList", "Found participant with unsupported typename. Please open an issue at https://github.com/Schmavery/
|
69
|
+
log.warn("getThreadList", "Found participant with unsupported typename. Please open an issue at https://github.com/Schmavery/fca-unofficial/issues\n" + JSON.stringify(p, null, 2));
|
61
70
|
return {
|
62
71
|
accountType: p["__typename"],
|
63
72
|
userID: utils.formatID(p.id.toString()),
|
@@ -69,7 +78,9 @@ function formatParticipants(participants) {
|
|
69
78
|
|
70
79
|
// "FF8C0077" -> "8C0077"
|
71
80
|
function formatColor(color) {
|
72
|
-
if (color && color.match(/^(?:[0-9a-fA-F]{8})$/g))
|
81
|
+
if (color && color.match(/^(?:[0-9a-fA-F]{8})$/g)) {
|
82
|
+
return color.slice(2);
|
83
|
+
}
|
73
84
|
return color;
|
74
85
|
}
|
75
86
|
|
@@ -84,24 +95,24 @@ function getThreadName(t) {
|
|
84
95
|
|
85
96
|
function mapNicknames(customizationInfo) {
|
86
97
|
return (customizationInfo && customizationInfo.participant_customizations) ? customizationInfo.participant_customizations.map(u => {
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
})
|
98
|
+
return {
|
99
|
+
"userID": u.participant_id,
|
100
|
+
"nickname": u.nickname
|
101
|
+
};
|
102
|
+
}):[];
|
92
103
|
}
|
93
104
|
|
94
105
|
function formatThreadList(data) {
|
95
106
|
return data.map(t => {
|
96
|
-
let lastMessageNode = (t.last_message
|
107
|
+
let lastMessageNode = (t.last_message&&t.last_message.nodes&&t.last_message.nodes.length>0)?t.last_message.nodes[0]:null;
|
97
108
|
return {
|
98
|
-
threadID: t.thread_key
|
109
|
+
threadID: t.thread_key?utils.formatID(t.thread_key.thread_fbid || t.thread_key.other_user_id):null, // shall never be null
|
99
110
|
name: getThreadName(t),
|
100
111
|
unreadCount: t.unread_count,
|
101
112
|
messageCount: t.messages_count,
|
102
|
-
imageSrc: t.image
|
103
|
-
emoji: t.customization_info
|
104
|
-
color: formatColor(t.customization_info
|
113
|
+
imageSrc: t.image?t.image.uri:null,
|
114
|
+
emoji: t.customization_info?t.customization_info.emoji:null,
|
115
|
+
color: formatColor(t.customization_info?t.customization_info.outgoing_bubble_color:null),
|
105
116
|
nicknames: mapNicknames(t.customization_info),
|
106
117
|
muteUntil: t.mute_until,
|
107
118
|
participants: formatParticipants(t.all_participants),
|
@@ -112,7 +123,7 @@ function formatThreadList(data) {
|
|
112
123
|
// isPinProtected: t.is_pin_protected, // feature from future? always false (2018-04-04)
|
113
124
|
customizationEnabled: t.customization_enabled, // false for ONE_TO_ONE with Page or ReducedMessagingActor
|
114
125
|
participantAddMode: t.participant_add_mode_as_string, // "ADD" if "GROUP" and null if "ONE_TO_ONE"
|
115
|
-
montageThread: t.montage_thread
|
126
|
+
montageThread: t.montage_thread?Buffer.from(t.montage_thread.id,"base64").toString():null, // base64 encoded string "message_thread:0000000000000000"
|
116
127
|
// it is not userID nor any other ID known to me...
|
117
128
|
// can somebody inspect it? where is it used?
|
118
129
|
// probably Messenger Day uses it
|
@@ -123,13 +134,13 @@ function formatThreadList(data) {
|
|
123
134
|
timestamp: t.updated_time_precise, // in miliseconds
|
124
135
|
// isCanonicalUser: t.is_canonical_neo_user, // is it always false?
|
125
136
|
// TODO: how about putting snippet in another object? current implementation does not handle every possibile message type etc.
|
126
|
-
snippet: lastMessageNode
|
127
|
-
snippetAttachments: lastMessageNode
|
128
|
-
snippetSender: lastMessageNode
|
129
|
-
lastMessageTimestamp: lastMessageNode
|
130
|
-
lastReadTimestamp: (t.last_read_receipt
|
131
|
-
|
132
|
-
|
137
|
+
snippet: lastMessageNode?lastMessageNode.snippet:null,
|
138
|
+
snippetAttachments: lastMessageNode?lastMessageNode.extensible_attachment:null, // TODO: not sure if it works
|
139
|
+
snippetSender: lastMessageNode?utils.formatID((lastMessageNode.message_sender.messaging_actor.id || "").toString()):null,
|
140
|
+
lastMessageTimestamp: lastMessageNode?lastMessageNode.timestamp_precise:null, // timestamp in miliseconds
|
141
|
+
lastReadTimestamp: (t.last_read_receipt&&t.last_read_receipt.nodes.length>0)
|
142
|
+
? (t.last_read_receipt.nodes[0]?t.last_read_receipt.nodes[0].timestamp_precise:null)
|
143
|
+
: null, // timestamp in miliseconds
|
133
144
|
cannotReplyReason: t.cannot_reply_reason, // TODO: inspect possible values
|
134
145
|
approvalMode: Boolean(t.approval_mode),
|
135
146
|
|
@@ -140,21 +151,28 @@ function formatThreadList(data) {
|
|
140
151
|
});
|
141
152
|
}
|
142
153
|
|
143
|
-
module.exports = function
|
154
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
144
155
|
return function getThreadList(limit, timestamp, tags, callback) {
|
145
156
|
if (!callback && (utils.getType(tags) === "Function" || utils.getType(tags) === "AsyncFunction")) {
|
146
157
|
callback = tags;
|
147
158
|
tags = [""];
|
148
159
|
}
|
149
|
-
if (utils.getType(limit) !== "Number" || !Number.isInteger(limit) || limit <= 0)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
160
|
+
if (utils.getType(limit) !== "Number" || !Number.isInteger(limit) || limit <= 0) {
|
161
|
+
throw {error: "getThreadList: limit must be a positive integer"};
|
162
|
+
}
|
163
|
+
if (utils.getType(timestamp) !== "Null" &&
|
164
|
+
(utils.getType(timestamp) !== "Number" || !Number.isInteger(timestamp))) {
|
165
|
+
throw {error: "getThreadList: timestamp must be an integer or null"};
|
166
|
+
}
|
167
|
+
if (utils.getType(tags) === "String") {
|
168
|
+
tags = [tags];
|
169
|
+
}
|
170
|
+
if (utils.getType(tags) !== "Array") {
|
171
|
+
throw {error: "getThreadList: tags must be an array"};
|
172
|
+
}
|
155
173
|
|
156
|
-
var resolveFunc = function
|
157
|
-
var rejectFunc = function
|
174
|
+
var resolveFunc = function(){};
|
175
|
+
var rejectFunc = function(){};
|
158
176
|
var returnPromise = new Promise(function (resolve, reject) {
|
159
177
|
resolveFunc = resolve;
|
160
178
|
rejectFunc = reject;
|
@@ -162,7 +180,9 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
162
180
|
|
163
181
|
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
164
182
|
callback = function (err, data) {
|
165
|
-
if (err)
|
183
|
+
if (err) {
|
184
|
+
return rejectFunc(err);
|
185
|
+
}
|
166
186
|
resolveFunc(data);
|
167
187
|
};
|
168
188
|
}
|
@@ -174,7 +194,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
174
194
|
// This doc_id was valid on 2020-07-20
|
175
195
|
"doc_id": "3336396659757871",
|
176
196
|
"query_params": {
|
177
|
-
"limit": limit
|
197
|
+
"limit": limit+(timestamp?1:0),
|
178
198
|
"before": timestamp,
|
179
199
|
"tags": tags,
|
180
200
|
"includeDeliveryReceipts": true,
|
@@ -189,9 +209,13 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
189
209
|
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
190
210
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
191
211
|
.then((resData) => {
|
192
|
-
if (resData[resData.length - 1].error_results > 0)
|
212
|
+
if (resData[resData.length - 1].error_results > 0) {
|
213
|
+
throw resData[0].o0.errors;
|
214
|
+
}
|
193
215
|
|
194
|
-
if (resData[resData.length - 1].successful_results === 0)
|
216
|
+
if (resData[resData.length - 1].successful_results === 0) {
|
217
|
+
throw {error: "getThreadList: there was no successful_results", res: resData};
|
218
|
+
}
|
195
219
|
|
196
220
|
// When we ask for threads using timestamp from the previous request,
|
197
221
|
// we are getting the last thread repeated as the first thread in this response.
|
@@ -199,12 +223,13 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
199
223
|
// It is also the reason for increasing limit by 1 when timestamp is set
|
200
224
|
// this way user asks for 10 threads, we are asking for 11,
|
201
225
|
// but after removing the duplicated one, it is again 10
|
202
|
-
if (timestamp)
|
203
|
-
|
226
|
+
if (timestamp) {
|
227
|
+
resData[0].o0.data.viewer.message_threads.nodes.shift();
|
228
|
+
}
|
204
229
|
callback(null, formatThreadList(resData[0].o0.data.viewer.message_threads.nodes));
|
205
230
|
})
|
206
231
|
.catch((err) => {
|
207
|
-
log.error("getThreadList",
|
232
|
+
log.error("getThreadList", err);
|
208
233
|
return callback(err);
|
209
234
|
});
|
210
235
|
|
@@ -3,21 +3,39 @@
|
|
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 getThreadList(start, end, type, callback) {
|
8
8
|
if (utils.getType(callback) === "Undefined") {
|
9
|
-
if (utils.getType(end) !== "Number")
|
10
|
-
|
9
|
+
if (utils.getType(end) !== "Number") {
|
10
|
+
throw {
|
11
|
+
error: "Please pass a number as a second argument."
|
12
|
+
};
|
13
|
+
} else if (
|
14
|
+
utils.getType(type) === "Function" ||
|
15
|
+
utils.getType(type) === "AsyncFunction"
|
16
|
+
) {
|
11
17
|
callback = type;
|
12
18
|
type = "inbox"; //default to inbox
|
19
|
+
} else if (utils.getType(type) !== "String") {
|
20
|
+
throw {
|
21
|
+
error:
|
22
|
+
"Please pass a String as a third argument. Your options are: inbox, pending, and archived"
|
23
|
+
};
|
24
|
+
} else {
|
25
|
+
throw {
|
26
|
+
error: "getThreadList: need callback"
|
27
|
+
};
|
13
28
|
}
|
14
|
-
else if (utils.getType(type) !== "String") throw { error: "Please pass a String as a third argument. Your options are: inbox, pending, and archived" };
|
15
|
-
else throw { error: "getThreadList: need callback" };
|
16
29
|
}
|
17
30
|
|
18
|
-
if (type === "archived")
|
19
|
-
|
20
|
-
|
31
|
+
if (type === "archived") {
|
32
|
+
type = "action:archived";
|
33
|
+
} else if (type !== "inbox" && type !== "pending" && type !== "other") {
|
34
|
+
throw {
|
35
|
+
error:
|
36
|
+
"type can only be one of the following: inbox, pending, archived, other"
|
37
|
+
};
|
38
|
+
}
|
21
39
|
|
22
40
|
if (end <= start) end = start + 20;
|
23
41
|
|
@@ -28,17 +46,28 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
28
46
|
form[type + "[offset]"] = start;
|
29
47
|
form[type + "[limit]"] = end - start;
|
30
48
|
|
31
|
-
if (ctx.globalOptions.pageID)
|
49
|
+
if (ctx.globalOptions.pageID) {
|
50
|
+
form.request_user_id = ctx.globalOptions.pageID;
|
51
|
+
}
|
32
52
|
|
33
53
|
defaultFuncs
|
34
|
-
.post(
|
54
|
+
.post(
|
55
|
+
"https://www.facebook.com/ajax/mercury/threadlist_info.php",
|
56
|
+
ctx.jar,
|
57
|
+
form
|
58
|
+
)
|
35
59
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
36
|
-
.then(function
|
37
|
-
if (resData.error)
|
60
|
+
.then(function(resData) {
|
61
|
+
if (resData.error) {
|
62
|
+
throw resData;
|
63
|
+
}
|
38
64
|
log.verbose("getThreadList", JSON.stringify(resData.payload.threads));
|
39
|
-
return callback(
|
65
|
+
return callback(
|
66
|
+
null,
|
67
|
+
(resData.payload.threads || []).map(utils.formatThread)
|
68
|
+
);
|
40
69
|
})
|
41
|
-
.catch(function
|
70
|
+
.catch(function(err) {
|
42
71
|
log.error("getThreadList", err);
|
43
72
|
return callback(err);
|
44
73
|
});
|
@@ -3,19 +3,21 @@
|
|
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 getThreadPictures(threadID, offset, limit, 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
|
-
|
16
|
+
callback = function (err, friendList) {
|
17
|
+
if (err) {
|
18
|
+
return rejectFunc(err);
|
19
|
+
}
|
20
|
+
resolveFunc(friendList);
|
19
21
|
};
|
20
22
|
}
|
21
23
|
|
@@ -26,31 +28,49 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
26
28
|
};
|
27
29
|
|
28
30
|
defaultFuncs
|
29
|
-
.post(
|
31
|
+
.post(
|
32
|
+
"https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
|
33
|
+
ctx.jar,
|
34
|
+
form
|
35
|
+
)
|
30
36
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
31
|
-
.then(function
|
32
|
-
if (resData.error)
|
37
|
+
.then(function(resData) {
|
38
|
+
if (resData.error) {
|
39
|
+
throw resData;
|
40
|
+
}
|
33
41
|
return Promise.all(
|
34
|
-
resData.payload.imagesData.map(function
|
42
|
+
resData.payload.imagesData.map(function(image) {
|
35
43
|
form = {
|
36
44
|
thread_id: threadID,
|
37
45
|
image_id: image.fbid
|
38
46
|
};
|
39
47
|
return defaultFuncs
|
40
|
-
.post(
|
48
|
+
.post(
|
49
|
+
"https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
|
50
|
+
ctx.jar,
|
51
|
+
form
|
52
|
+
)
|
41
53
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
42
|
-
.then(function
|
43
|
-
if (resData.error)
|
54
|
+
.then(function(resData) {
|
55
|
+
if (resData.error) {
|
56
|
+
throw resData;
|
57
|
+
}
|
44
58
|
// the response is pretty messy
|
45
|
-
var queryThreadID =
|
46
|
-
|
59
|
+
var queryThreadID =
|
60
|
+
resData.jsmods.require[0][3][1].query_metadata.query_path[0]
|
61
|
+
.message_thread;
|
62
|
+
var imageData =
|
63
|
+
resData.jsmods.require[0][3][1].query_results[queryThreadID]
|
64
|
+
.message_images.edges[0].node.image2;
|
47
65
|
return imageData;
|
48
66
|
});
|
49
67
|
})
|
50
68
|
);
|
51
69
|
})
|
52
|
-
.then(
|
53
|
-
|
70
|
+
.then(function(resData) {
|
71
|
+
callback(null, resData);
|
72
|
+
})
|
73
|
+
.catch(function(err) {
|
54
74
|
log.error("Error in getThreadPictures", err);
|
55
75
|
callback(err);
|
56
76
|
});
|
package/leiamnash/getUserID.js
CHANGED
@@ -17,19 +17,21 @@ function formatData(data) {
|
|
17
17
|
};
|
18
18
|
}
|
19
19
|
|
20
|
-
module.exports = function
|
20
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
21
21
|
return function getUserID(name, callback) {
|
22
|
-
var resolveFunc = function
|
23
|
-
var rejectFunc = function
|
22
|
+
var resolveFunc = function(){};
|
23
|
+
var rejectFunc = function(){};
|
24
24
|
var returnPromise = new Promise(function (resolve, reject) {
|
25
25
|
resolveFunc = resolve;
|
26
26
|
rejectFunc = reject;
|
27
27
|
});
|
28
28
|
|
29
29
|
if (!callback) {
|
30
|
-
callback = function (err,
|
31
|
-
if (err)
|
32
|
-
|
30
|
+
callback = function (err, friendList) {
|
31
|
+
if (err) {
|
32
|
+
return rejectFunc(err);
|
33
|
+
}
|
34
|
+
resolveFunc(friendList);
|
33
35
|
};
|
34
36
|
}
|
35
37
|
|
@@ -45,13 +47,16 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
45
47
|
defaultFuncs
|
46
48
|
.get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
|
47
49
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
48
|
-
.then(function
|
49
|
-
if (resData.error)
|
50
|
+
.then(function(resData) {
|
51
|
+
if (resData.error) {
|
52
|
+
throw resData;
|
53
|
+
}
|
50
54
|
|
51
55
|
var data = resData.payload.entries;
|
56
|
+
|
52
57
|
callback(null, data.map(formatData));
|
53
58
|
})
|
54
|
-
.catch(function
|
59
|
+
.catch(function(err) {
|
55
60
|
log.error("getUserID", err);
|
56
61
|
return callback(err);
|
57
62
|
});
|
package/leiamnash/getUserInfo.js
CHANGED
@@ -27,37 +27,43 @@ function formatData(data) {
|
|
27
27
|
return retObj;
|
28
28
|
}
|
29
29
|
|
30
|
-
module.exports = function
|
30
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
31
31
|
return function getUserInfo(id, callback) {
|
32
|
-
var resolveFunc = function
|
33
|
-
var rejectFunc = function
|
32
|
+
var resolveFunc = function(){};
|
33
|
+
var rejectFunc = function(){};
|
34
34
|
var returnPromise = new Promise(function (resolve, reject) {
|
35
35
|
resolveFunc = resolve;
|
36
36
|
rejectFunc = reject;
|
37
37
|
});
|
38
38
|
|
39
39
|
if (!callback) {
|
40
|
-
callback = function (err,
|
41
|
-
if (err)
|
42
|
-
|
40
|
+
callback = function (err, friendList) {
|
41
|
+
if (err) {
|
42
|
+
return rejectFunc(err);
|
43
|
+
}
|
44
|
+
resolveFunc(friendList);
|
43
45
|
};
|
44
46
|
}
|
45
47
|
|
46
|
-
if (utils.getType(id) !== "Array")
|
48
|
+
if (utils.getType(id) !== "Array") {
|
49
|
+
id = [id];
|
50
|
+
}
|
47
51
|
|
48
52
|
var form = {};
|
49
|
-
id.map(function
|
53
|
+
id.map(function(v, i) {
|
50
54
|
form["ids[" + i + "]"] = v;
|
51
55
|
});
|
52
56
|
defaultFuncs
|
53
57
|
.post("https://www.facebook.com/chat/user_info/", ctx.jar, form)
|
54
58
|
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
55
|
-
.then(function
|
56
|
-
if (resData.error)
|
59
|
+
.then(function(resData) {
|
60
|
+
if (resData.error) {
|
61
|
+
throw resData;
|
62
|
+
}
|
57
63
|
return callback(null, formatData(resData.payload.profiles));
|
58
64
|
})
|
59
|
-
.catch(function
|
60
|
-
log.error("getUserInfo",
|
65
|
+
.catch(function(err) {
|
66
|
+
log.error("getUserInfo", err);
|
61
67
|
return callback(err);
|
62
68
|
});
|
63
69
|
|