@cexy/hoonfca 1.0.6 → 2.0.1
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/LICENSE +3 -0
- package/examples/login-with-cookies.js +102 -0
- package/examples/verify.js +70 -0
- package/index.js +2 -8
- package/package.json +82 -61
- package/src/{api/action → apis}/addExternalModule.js +24 -25
- package/src/apis/addUserToGroup.js +108 -0
- package/src/apis/changeAdminStatus.js +148 -0
- package/src/apis/changeArchivedStatus.js +61 -0
- package/src/apis/changeAvatar.js +103 -0
- package/src/apis/changeBio.js +69 -0
- package/src/apis/changeBlockedStatus.js +54 -0
- package/src/apis/changeGroupImage.js +136 -0
- package/src/apis/changeThreadColor.js +116 -0
- package/src/apis/changeThreadEmoji.js +53 -0
- package/src/apis/comment.js +207 -0
- package/src/apis/createAITheme.js +129 -0
- package/src/apis/createNewGroup.js +79 -0
- package/src/apis/createPoll.js +73 -0
- package/src/apis/deleteMessage.js +44 -0
- package/src/apis/deleteThread.js +52 -0
- package/src/apis/e2ee.js +17 -0
- package/src/apis/editMessage.js +70 -0
- package/src/apis/emoji.js +124 -0
- package/src/apis/fetchThemeData.js +82 -0
- package/src/apis/follow.js +81 -0
- package/src/apis/forwardMessage.js +52 -0
- package/src/apis/friend.js +243 -0
- package/src/apis/gcmember.js +122 -0
- package/src/apis/gcname.js +123 -0
- package/src/apis/gcrule.js +119 -0
- package/src/apis/getAccess.js +111 -0
- package/src/apis/getBotInfo.js +88 -0
- package/src/apis/getBotInitialData.js +43 -0
- package/src/apis/getFriendsList.js +79 -0
- package/src/apis/getMessage.js +423 -0
- package/src/apis/getTheme.js +95 -0
- package/src/apis/getThemeInfo.js +116 -0
- package/src/apis/getThreadHistory.js +239 -0
- package/src/apis/getThreadInfo.js +267 -0
- package/src/apis/getThreadList.js +232 -0
- package/src/apis/getThreadPictures.js +58 -0
- package/src/apis/getUserID.js +117 -0
- package/src/apis/getUserInfo.js +513 -0
- package/src/{api/users → apis}/getUserInfoV2.js +146 -134
- package/src/apis/handleMessageRequest.js +50 -0
- package/src/apis/httpGet.js +63 -0
- package/src/apis/httpPost.js +89 -0
- package/src/apis/httpPostFormData.js +69 -0
- package/src/apis/listenMqtt.js +1236 -0
- package/src/apis/listenSpeed.js +179 -0
- package/src/apis/logout.js +87 -0
- package/src/apis/markAsDelivered.js +47 -0
- package/src/{api/messaging → apis}/markAsRead.js +99 -88
- package/src/apis/markAsReadAll.js +40 -0
- package/src/apis/markAsSeen.js +70 -0
- package/src/apis/mqttDeltaValue.js +278 -0
- package/src/apis/muteThread.js +45 -0
- package/src/apis/nickname.js +132 -0
- package/src/apis/notes.js +163 -0
- package/src/apis/pinMessage.js +150 -0
- package/src/apis/produceMetaTheme.js +180 -0
- package/src/apis/realtime.js +182 -0
- package/src/apis/removeUserFromGroup.js +117 -0
- package/src/apis/resolvePhotoUrl.js +58 -0
- package/src/apis/searchForThread.js +154 -0
- package/src/apis/sendMessage.js +354 -0
- package/src/apis/sendMessageMqtt.js +249 -0
- package/src/apis/sendTypingIndicator.js +91 -0
- package/src/apis/setMessageReaction.js +27 -0
- package/src/apis/setMessageReactionMqtt.js +61 -0
- package/src/apis/setThreadTheme.js +260 -0
- package/src/apis/setThreadThemeMqtt.js +94 -0
- package/src/apis/share.js +107 -0
- package/src/apis/shareContact.js +66 -0
- package/src/apis/stickers.js +257 -0
- package/src/apis/story.js +181 -0
- package/src/apis/theme.js +233 -0
- package/src/apis/unfriend.js +47 -0
- package/src/apis/unsendMessage.js +17 -0
- package/src/engine/client.js +92 -0
- package/src/engine/models/buildAPI.js +152 -0
- package/src/engine/models/loginHelper.js +519 -0
- package/src/engine/models/setOptions.js +88 -0
- package/src/security/e2ee.js +109 -0
- package/src/types/index.d.ts +498 -0
- package/src/utils/antiSuspension.js +506 -0
- package/src/utils/auth-helpers.js +149 -0
- package/src/utils/autoReLogin.js +336 -0
- package/src/utils/axios.js +436 -0
- package/src/utils/cache.js +54 -0
- package/src/utils/clients.js +282 -0
- package/src/utils/constants.js +410 -23
- package/src/utils/formatters/data/formatAttachment.js +370 -0
- package/src/utils/formatters/data/formatDelta.js +109 -0
- package/src/utils/formatters/index.js +159 -0
- package/src/utils/formatters/value/formatCookie.js +91 -0
- package/src/utils/formatters/value/formatDate.js +36 -0
- package/src/utils/formatters/value/formatID.js +16 -0
- package/src/utils/formatters.js +1373 -0
- package/src/utils/headers.js +214 -99
- package/src/utils/index.js +153 -0
- package/src/utils/monitoring.js +333 -0
- package/src/utils/rateLimiter.js +319 -0
- package/src/utils/tokenRefresh.js +657 -0
- package/src/utils/user-agents.js +238 -0
- package/src/utils/validation.js +157 -0
- package/CHANGELOG.md +0 -181
- package/DOCS.md +0 -2636
- package/LICENSE-MIT +0 -21
- package/README.md +0 -632
- package/func/checkUpdate.js +0 -231
- package/func/logger.js +0 -48
- package/index.d.ts +0 -746
- package/module/config.js +0 -67
- package/module/login.js +0 -154
- package/module/loginHelper.js +0 -1034
- package/module/options.js +0 -54
- package/src/api/action/changeAvatar.js +0 -137
- package/src/api/action/changeBio.js +0 -75
- package/src/api/action/enableAutoSaveAppState.js +0 -73
- package/src/api/action/getCurrentUserID.js +0 -7
- package/src/api/action/handleFriendRequest.js +0 -57
- package/src/api/action/logout.js +0 -76
- package/src/api/action/refreshFb_dtsg.js +0 -48
- package/src/api/action/setPostReaction.js +0 -106
- package/src/api/action/unfriend.js +0 -54
- package/src/api/http/httpGet.js +0 -46
- package/src/api/http/httpPost.js +0 -52
- package/src/api/http/postFormData.js +0 -47
- package/src/api/messaging/addUserToGroup.js +0 -68
- package/src/api/messaging/changeAdminStatus.js +0 -122
- package/src/api/messaging/changeArchivedStatus.js +0 -55
- package/src/api/messaging/changeBlockedStatus.js +0 -48
- package/src/api/messaging/changeGroupImage.js +0 -90
- package/src/api/messaging/changeNickname.js +0 -70
- package/src/api/messaging/changeThreadColor.js +0 -79
- package/src/api/messaging/changeThreadEmoji.js +0 -106
- package/src/api/messaging/createNewGroup.js +0 -88
- package/src/api/messaging/createPoll.js +0 -43
- package/src/api/messaging/createThemeAI.js +0 -98
- package/src/api/messaging/deleteMessage.js +0 -56
- package/src/api/messaging/deleteThread.js +0 -56
- package/src/api/messaging/editMessage.js +0 -68
- package/src/api/messaging/forwardAttachment.js +0 -51
- package/src/api/messaging/getEmojiUrl.js +0 -29
- package/src/api/messaging/getFriendsList.js +0 -82
- package/src/api/messaging/getMessage.js +0 -829
- package/src/api/messaging/getThemePictures.js +0 -62
- package/src/api/messaging/handleMessageRequest.js +0 -65
- package/src/api/messaging/markAsDelivered.js +0 -57
- package/src/api/messaging/markAsReadAll.js +0 -49
- package/src/api/messaging/markAsSeen.js +0 -61
- package/src/api/messaging/muteThread.js +0 -50
- package/src/api/messaging/removeUserFromGroup.js +0 -106
- package/src/api/messaging/resolvePhotoUrl.js +0 -43
- package/src/api/messaging/scheduler.js +0 -264
- package/src/api/messaging/searchForThread.js +0 -52
- package/src/api/messaging/sendMessage.js +0 -272
- package/src/api/messaging/sendTypingIndicator.js +0 -67
- package/src/api/messaging/setMessageReaction.js +0 -76
- package/src/api/messaging/setTitle.js +0 -119
- package/src/api/messaging/shareContact.js +0 -49
- package/src/api/messaging/threadColors.js +0 -128
- package/src/api/messaging/unsendMessage.js +0 -81
- package/src/api/messaging/uploadAttachment.js +0 -94
- package/src/api/socket/core/connectMqtt.js +0 -255
- package/src/api/socket/core/emitAuth.js +0 -106
- package/src/api/socket/core/getSeqID.js +0 -40
- package/src/api/socket/core/getTaskResponseData.js +0 -22
- package/src/api/socket/core/markDelivery.js +0 -12
- package/src/api/socket/core/parseDelta.js +0 -391
- package/src/api/socket/detail/buildStream.js +0 -208
- package/src/api/socket/detail/constants.js +0 -24
- package/src/api/socket/listenMqtt.js +0 -364
- package/src/api/socket/middleware/index.js +0 -216
- package/src/api/threads/getThreadHistory.js +0 -664
- package/src/api/threads/getThreadInfo.js +0 -438
- package/src/api/threads/getThreadList.js +0 -293
- package/src/api/threads/getThreadPictures.js +0 -78
- package/src/api/users/getUserID.js +0 -65
- package/src/api/users/getUserInfo.js +0 -327
- package/src/core/sendReqMqtt.js +0 -96
- package/src/database/models/index.js +0 -87
- package/src/database/models/thread.js +0 -45
- package/src/database/models/user.js +0 -46
- package/src/database/threadData.js +0 -98
- package/src/database/userData.js +0 -89
- package/src/utils/client.js +0 -320
- package/src/utils/format.js +0 -1115
- package/src/utils/request.js +0 -305
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const log = require("npmlog");
|
|
4
|
-
const { parseAndCheckLogin } = require("../../utils/client");
|
|
5
|
-
const { formatID, getType } = require("../../utils/format");
|
|
6
|
-
function createProfileUrl(url, username, id) {
|
|
7
|
-
if (url) return url;
|
|
8
|
-
return (
|
|
9
|
-
"https://www.facebook.com/" + (username || formatID(id.toString()))
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function formatParticipants(participants) {
|
|
14
|
-
return participants.edges.map(p => {
|
|
15
|
-
p = p.node.messaging_actor;
|
|
16
|
-
switch (p["__typename"]) {
|
|
17
|
-
case "User":
|
|
18
|
-
return {
|
|
19
|
-
accountType: p["__typename"],
|
|
20
|
-
userID: formatID(p.id.toString()), // do we need .toString()? when it is not a string?
|
|
21
|
-
name: p.name,
|
|
22
|
-
shortName: p.short_name,
|
|
23
|
-
gender: p.gender,
|
|
24
|
-
url: p.url, // how about making it profileURL
|
|
25
|
-
profilePicture: p.big_image_src.uri,
|
|
26
|
-
username: p.username || null,
|
|
27
|
-
// TODO: maybe better names for these?
|
|
28
|
-
isViewerFriend: p.is_viewer_friend, // true/false
|
|
29
|
-
isMessengerUser: p.is_messenger_user, // true/false
|
|
30
|
-
isVerified: p.is_verified, // true/false
|
|
31
|
-
isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
|
|
32
|
-
isViewerCoworker: p.is_viewer_coworker, // true/false
|
|
33
|
-
isEmployee: p.is_employee // null? when it is something other? can someone check?
|
|
34
|
-
};
|
|
35
|
-
case "Page":
|
|
36
|
-
return {
|
|
37
|
-
accountType: p["__typename"],
|
|
38
|
-
userID: formatID(p.id.toString()), // or maybe... pageID?
|
|
39
|
-
name: p.name,
|
|
40
|
-
url: p.url,
|
|
41
|
-
profilePicture: p.big_image_src.uri,
|
|
42
|
-
username: p.username || null,
|
|
43
|
-
// uhm... better names maybe?
|
|
44
|
-
acceptsMessengerUserFeedback: p.accepts_messenger_user_feedback, // true/false
|
|
45
|
-
isMessengerUser: p.is_messenger_user, // true/false
|
|
46
|
-
isVerified: p.is_verified, // true/false
|
|
47
|
-
isMessengerPlatformBot: p.is_messenger_platform_bot, // true/false
|
|
48
|
-
isMessageBlockedByViewer: p.is_message_blocked_by_viewer // true/false
|
|
49
|
-
};
|
|
50
|
-
case "ReducedMessagingActor":
|
|
51
|
-
case "UnavailableMessagingActor":
|
|
52
|
-
return {
|
|
53
|
-
accountType: p["__typename"],
|
|
54
|
-
userID: formatID(p.id.toString()),
|
|
55
|
-
name: p.name,
|
|
56
|
-
url: createProfileUrl(p.url, p.username, p.id), // in this case p.url is null all the time
|
|
57
|
-
profilePicture: p.big_image_src.uri, // in this case it is default facebook photo, we could determine gender using it
|
|
58
|
-
username: p.username || null, // maybe we could use it to generate profile URL?
|
|
59
|
-
isMessageBlockedByViewer: p.is_message_blocked_by_viewer // true/false
|
|
60
|
-
};
|
|
61
|
-
default:
|
|
62
|
-
log.warn(
|
|
63
|
-
"getThreadList",
|
|
64
|
-
"Found participant with unsupported typename. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues\n" +
|
|
65
|
-
JSON.stringify(p, null, 2)
|
|
66
|
-
);
|
|
67
|
-
return {
|
|
68
|
-
accountType: p["__typename"],
|
|
69
|
-
userID: formatID(p.id.toString()),
|
|
70
|
-
name: p.name || `[unknown ${p["__typename"]}]` // probably it will always be something... but fallback to [unknown], just in case
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// "FF8C0077" -> "8C0077"
|
|
77
|
-
function formatColor(color) {
|
|
78
|
-
if (color && color.match(/^(?:[0-9a-fA-F]{8})$/g)) return color.slice(2);
|
|
79
|
-
return color;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function getThreadName(t) {
|
|
83
|
-
if (t.name || t.thread_key.thread_fbid) return t.name;
|
|
84
|
-
|
|
85
|
-
for (let po of t.all_participants.edges) {
|
|
86
|
-
let p = po.node;
|
|
87
|
-
if (p.messaging_actor.id === t.thread_key.other_user_id)
|
|
88
|
-
return p.messaging_actor.name;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function mapNicknames(customizationInfo) {
|
|
93
|
-
return customizationInfo && customizationInfo.participant_customizations
|
|
94
|
-
? customizationInfo.participant_customizations.map(u => {
|
|
95
|
-
return {
|
|
96
|
-
userID: u.participant_id,
|
|
97
|
-
nickname: u.nickname
|
|
98
|
-
};
|
|
99
|
-
})
|
|
100
|
-
: [];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function formatThreadList(data) {
|
|
104
|
-
return data.map(t => {
|
|
105
|
-
let lastMessageNode =
|
|
106
|
-
t.last_message && t.last_message.nodes && t.last_message.nodes.length > 0
|
|
107
|
-
? t.last_message.nodes[0]
|
|
108
|
-
: null;
|
|
109
|
-
return {
|
|
110
|
-
threadID: t.thread_key
|
|
111
|
-
? formatID(t.thread_key.thread_fbid || t.thread_key.other_user_id)
|
|
112
|
-
: null, // shall never be null
|
|
113
|
-
name: getThreadName(t),
|
|
114
|
-
unreadCount: t.unread_count,
|
|
115
|
-
messageCount: t.messages_count,
|
|
116
|
-
imageSrc: t.image ? t.image.uri : null,
|
|
117
|
-
emoji: t.customization_info ? t.customization_info.emoji : null,
|
|
118
|
-
color: formatColor(
|
|
119
|
-
t.customization_info ? t.customization_info.outgoing_bubble_color : null
|
|
120
|
-
),
|
|
121
|
-
threadTheme: t.thread_theme,
|
|
122
|
-
nicknames: mapNicknames(t.customization_info),
|
|
123
|
-
muteUntil: t.mute_until,
|
|
124
|
-
participants: formatParticipants(t.all_participants),
|
|
125
|
-
adminIDs: t.thread_admins.map(a => a.id),
|
|
126
|
-
folder: t.folder,
|
|
127
|
-
isGroup: t.thread_type === "GROUP",
|
|
128
|
-
customizationEnabled: t.customization_enabled, // false for ONE_TO_ONE with Page or ReducedMessagingActor
|
|
129
|
-
participantAddMode: t.participant_add_mode_as_string, // "ADD" if "GROUP" and null if "ONE_TO_ONE"
|
|
130
|
-
montageThread: t.montage_thread
|
|
131
|
-
? Buffer.from(t.montage_thread.id, "base64").toString()
|
|
132
|
-
: null, // base64 encoded string "message_thread:0000000000000000"
|
|
133
|
-
reactionsMuteMode: t.reactions_mute_mode,
|
|
134
|
-
mentionsMuteMode: t.mentions_mute_mode,
|
|
135
|
-
isArchived: t.has_viewer_archived,
|
|
136
|
-
isSubscribed: t.is_viewer_subscribed,
|
|
137
|
-
timestamp: t.updated_time_precise, // in miliseconds
|
|
138
|
-
snippet: lastMessageNode ? lastMessageNode.snippet : null,
|
|
139
|
-
snippetAttachments: lastMessageNode
|
|
140
|
-
? lastMessageNode.extensible_attachment
|
|
141
|
-
: null, // TODO: not sure if it works
|
|
142
|
-
snippetSender: lastMessageNode
|
|
143
|
-
? formatID(
|
|
144
|
-
(lastMessageNode.message_sender.messaging_actor.id || "").toString()
|
|
145
|
-
)
|
|
146
|
-
: null,
|
|
147
|
-
lastMessageTimestamp: lastMessageNode
|
|
148
|
-
? lastMessageNode.timestamp_precise
|
|
149
|
-
: null, // timestamp in miliseconds
|
|
150
|
-
lastReadTimestamp:
|
|
151
|
-
t.last_read_receipt && t.last_read_receipt.nodes.length > 0
|
|
152
|
-
? t.last_read_receipt.nodes[0]
|
|
153
|
-
? t.last_read_receipt.nodes[0].timestamp_precise
|
|
154
|
-
: null
|
|
155
|
-
: null,
|
|
156
|
-
cannotReplyReason: t.cannot_reply_reason,
|
|
157
|
-
approvalMode: Boolean(t.approval_mode),
|
|
158
|
-
participantIDs: formatParticipants(t.all_participants).map(
|
|
159
|
-
participant => participant.userID
|
|
160
|
-
),
|
|
161
|
-
threadType: t.thread_type === "GROUP" ? 2 : 1, // "GROUP" or "ONE_TO_ONE"
|
|
162
|
-
inviteLink: {
|
|
163
|
-
enable: t.joinable_mode ? t.joinable_mode.mode == 1 : false,
|
|
164
|
-
link: t.joinable_mode ? t.joinable_mode.link : null
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
171
|
-
return function getThreadList(limit, timestamp, tags, callback) {
|
|
172
|
-
if (
|
|
173
|
-
!callback &&
|
|
174
|
-
(getType(tags) === "Function" ||
|
|
175
|
-
getType(tags) === "AsyncFunction")
|
|
176
|
-
) {
|
|
177
|
-
callback = tags;
|
|
178
|
-
tags = [""];
|
|
179
|
-
}
|
|
180
|
-
if (
|
|
181
|
-
getType(limit) !== "Number" ||
|
|
182
|
-
!Number.isInteger(limit) ||
|
|
183
|
-
limit <= 0
|
|
184
|
-
)
|
|
185
|
-
throw { error: "getThreadList: limit must be a positive integer" };
|
|
186
|
-
if (
|
|
187
|
-
getType(timestamp) !== "Null" &&
|
|
188
|
-
(getType(timestamp) !== "Number" || !Number.isInteger(timestamp))
|
|
189
|
-
)
|
|
190
|
-
throw { error: "getThreadList: timestamp must be an integer or null" };
|
|
191
|
-
if (getType(tags) === "String") tags = [tags];
|
|
192
|
-
if (getType(tags) !== "Array")
|
|
193
|
-
throw { error: "getThreadList: tags must be an array" };
|
|
194
|
-
var resolveFunc = function() {};
|
|
195
|
-
var rejectFunc = function() {};
|
|
196
|
-
var returnPromise = new Promise(function(resolve, reject) {
|
|
197
|
-
resolveFunc = resolve;
|
|
198
|
-
rejectFunc = reject;
|
|
199
|
-
});
|
|
200
|
-
if (
|
|
201
|
-
getType(callback) !== "Function" &&
|
|
202
|
-
getType(callback) !== "AsyncFunction"
|
|
203
|
-
) {
|
|
204
|
-
callback = function(err, data) {
|
|
205
|
-
if (err) return rejectFunc(err);
|
|
206
|
-
resolveFunc(data);
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
const form = {
|
|
210
|
-
av: ctx.userID,
|
|
211
|
-
queries: JSON.stringify({
|
|
212
|
-
o0: {
|
|
213
|
-
doc_id: "3336396659757871",
|
|
214
|
-
query_params: {
|
|
215
|
-
limit: limit + (timestamp ? 1 : 0),
|
|
216
|
-
before: timestamp,
|
|
217
|
-
tags: tags,
|
|
218
|
-
includeDeliveryReceipts: true,
|
|
219
|
-
includeSeqID: false
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}),
|
|
223
|
-
batch_name: "MessengerGraphQLThreadlistFetcher"
|
|
224
|
-
};
|
|
225
|
-
defaultFuncs
|
|
226
|
-
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
|
227
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
228
|
-
.then(resData => {
|
|
229
|
-
// Validate resData is an array and has elements
|
|
230
|
-
if (!resData || !Array.isArray(resData) || resData.length === 0) {
|
|
231
|
-
throw {
|
|
232
|
-
error: "getThreadList: Invalid response data - resData is not a valid array",
|
|
233
|
-
res: resData
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Validate last element exists and has required properties
|
|
238
|
-
const lastElement = resData[resData.length - 1];
|
|
239
|
-
if (!lastElement || typeof lastElement !== "object") {
|
|
240
|
-
throw {
|
|
241
|
-
error: "getThreadList: Invalid response data - last element is missing or invalid",
|
|
242
|
-
res: resData
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (lastElement.error_results > 0) {
|
|
247
|
-
// Check if first element and o0 exist before accessing errors
|
|
248
|
-
if (resData[0] && resData[0].o0 && resData[0].o0.errors) {
|
|
249
|
-
throw resData[0].o0.errors;
|
|
250
|
-
} else {
|
|
251
|
-
throw {
|
|
252
|
-
error: "getThreadList: Error results > 0 but error details not available",
|
|
253
|
-
res: resData
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (lastElement.successful_results === 0) {
|
|
259
|
-
throw {
|
|
260
|
-
error: "getThreadList: there was no successful_results",
|
|
261
|
-
res: resData
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Validate first element and nested data structure
|
|
266
|
-
if (!resData[0] || !resData[0].o0 || !resData[0].o0.data ||
|
|
267
|
-
!resData[0].o0.data.viewer || !resData[0].o0.data.viewer.message_threads ||
|
|
268
|
-
!Array.isArray(resData[0].o0.data.viewer.message_threads.nodes)) {
|
|
269
|
-
throw {
|
|
270
|
-
error: "getThreadList: Invalid response data structure - missing required fields",
|
|
271
|
-
res: resData
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (timestamp) {
|
|
276
|
-
const nodes = resData[0].o0.data.viewer.message_threads.nodes;
|
|
277
|
-
if (Array.isArray(nodes) && nodes.length > 0) {
|
|
278
|
-
nodes.shift();
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
callback(
|
|
283
|
-
null,
|
|
284
|
-
formatThreadList(resData[0].o0.data.viewer.message_threads.nodes)
|
|
285
|
-
);
|
|
286
|
-
})
|
|
287
|
-
.catch(err => {
|
|
288
|
-
log.error("getThreadList", err);
|
|
289
|
-
return callback(err);
|
|
290
|
-
});
|
|
291
|
-
return returnPromise;
|
|
292
|
-
};
|
|
293
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const log = require("npmlog");
|
|
4
|
-
const { parseAndCheckLogin } = require("../../utils/client");
|
|
5
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
6
|
-
return function getThreadPictures(threadID, offset, limit, callback) {
|
|
7
|
-
let resolveFunc = function() {};
|
|
8
|
-
let rejectFunc = function() {};
|
|
9
|
-
const returnPromise = new Promise(function(resolve, reject) {
|
|
10
|
-
resolveFunc = resolve;
|
|
11
|
-
rejectFunc = reject;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
if (!callback) {
|
|
15
|
-
callback = function(err, friendList) {
|
|
16
|
-
if (err) {
|
|
17
|
-
return rejectFunc(err);
|
|
18
|
-
}
|
|
19
|
-
resolveFunc(friendList);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let form = {
|
|
24
|
-
thread_id: threadID,
|
|
25
|
-
offset: offset,
|
|
26
|
-
limit: limit
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
defaultFuncs
|
|
30
|
-
.post(
|
|
31
|
-
"https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
|
|
32
|
-
ctx.jar,
|
|
33
|
-
form
|
|
34
|
-
)
|
|
35
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
36
|
-
.then(function(resData) {
|
|
37
|
-
if (resData.error) {
|
|
38
|
-
throw resData;
|
|
39
|
-
}
|
|
40
|
-
return Promise.all(
|
|
41
|
-
resData.payload.imagesData.map(function(image) {
|
|
42
|
-
form = {
|
|
43
|
-
thread_id: threadID,
|
|
44
|
-
image_id: image.fbid
|
|
45
|
-
};
|
|
46
|
-
return defaultFuncs
|
|
47
|
-
.post(
|
|
48
|
-
"https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
|
|
49
|
-
ctx.jar,
|
|
50
|
-
form
|
|
51
|
-
)
|
|
52
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
53
|
-
.then(function(resData) {
|
|
54
|
-
if (resData.error) {
|
|
55
|
-
throw resData;
|
|
56
|
-
}
|
|
57
|
-
// the response is pretty messy
|
|
58
|
-
const queryThreadID =
|
|
59
|
-
resData.jsmods.require[0][3][1].query_metadata.query_path[0]
|
|
60
|
-
.message_thread;
|
|
61
|
-
const imageData =
|
|
62
|
-
resData.jsmods.require[0][3][1].query_results[queryThreadID]
|
|
63
|
-
.message_images.edges[0].node.image2;
|
|
64
|
-
return imageData;
|
|
65
|
-
});
|
|
66
|
-
})
|
|
67
|
-
);
|
|
68
|
-
})
|
|
69
|
-
.then(function(resData) {
|
|
70
|
-
callback(null, resData);
|
|
71
|
-
})
|
|
72
|
-
.catch(function(err) {
|
|
73
|
-
log.error("Error in getThreadPictures", err);
|
|
74
|
-
callback(err);
|
|
75
|
-
});
|
|
76
|
-
return returnPromise;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const log = require("npmlog");
|
|
4
|
-
const { formatID } = require("../../utils/format");
|
|
5
|
-
function formatData(data) {
|
|
6
|
-
return {
|
|
7
|
-
userID: formatID(data.uid.toString()),
|
|
8
|
-
photoUrl: data.photo,
|
|
9
|
-
indexRank: data.index_rank,
|
|
10
|
-
name: data.text,
|
|
11
|
-
isVerified: data.is_verified,
|
|
12
|
-
profileUrl: data.path,
|
|
13
|
-
category: data.category,
|
|
14
|
-
score: data.score,
|
|
15
|
-
type: data.type
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
20
|
-
return function getUserID(name, callback) {
|
|
21
|
-
let resolveFunc = function() {};
|
|
22
|
-
let rejectFunc = function() {};
|
|
23
|
-
const returnPromise = new Promise(function(resolve, reject) {
|
|
24
|
-
resolveFunc = resolve;
|
|
25
|
-
rejectFunc = reject;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (!callback) {
|
|
29
|
-
callback = function(err, friendList) {
|
|
30
|
-
if (err) {
|
|
31
|
-
return rejectFunc(err);
|
|
32
|
-
}
|
|
33
|
-
resolveFunc(friendList);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const form = {
|
|
38
|
-
value: name.toLowerCase(),
|
|
39
|
-
viewer: ctx.userID,
|
|
40
|
-
rsp: "search",
|
|
41
|
-
context: "search",
|
|
42
|
-
path: "/home.php",
|
|
43
|
-
request_id: ctx.clientId
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
defaultFuncs
|
|
47
|
-
.get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
|
|
48
|
-
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
49
|
-
.then(function(resData) {
|
|
50
|
-
if (resData.error) {
|
|
51
|
-
throw resData;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const data = resData.payload.entries;
|
|
55
|
-
|
|
56
|
-
callback(null, data.map(formatData));
|
|
57
|
-
})
|
|
58
|
-
.catch(function(err) {
|
|
59
|
-
log.error("getUserID", err);
|
|
60
|
-
return callback(err);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return returnPromise;
|
|
64
|
-
};
|
|
65
|
-
};
|