alicezetion 1.7.0 → 1.7.1
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 +182 -495
- package/package.json +10 -8
- package/replit.nix +4 -6
- package/src/addExternalModule.js +15 -0
- package/{leiamnash → src}/addUserToGroup.js +16 -52
- package/src/changeAdminStatus.js +47 -0
- package/src/changeArchivedStatus.js +41 -0
- package/{leiamnash → src}/changeBio.js +6 -19
- package/{leiamnash → src}/changeBlockedStatus.js +3 -14
- package/{leiamnash → src}/changeGroupImage.js +16 -40
- package/src/changeNickname.js +43 -0
- package/{leiamnash → src}/changeThreadColor.js +10 -20
- package/src/changeThreadEmoji.js +41 -0
- package/src/chat.js +315 -0
- package/{leiamnash → src}/createNewGroup.js +12 -28
- package/{leiamnash → src}/createPoll.js +13 -25
- package/src/deleteMessage.js +44 -0
- package/src/deleteThread.js +42 -0
- package/src/forwardAttachment.js +47 -0
- package/src/forwardMessage.js +0 -0
- package/{leiamnash → src}/getCurrentUserID.js +1 -1
- package/{leiamnash → src}/getEmojiUrl.js +2 -4
- package/{leiamnash → src}/getFriendsList.js +10 -21
- package/{leiamnash → src}/getThreadHistory.js +58 -166
- package/{leiamnash → src}/getThreadHistoryDeprecated.js +20 -42
- package/src/getThreadInfo.js +171 -0
- package/src/getThreadInfoDeprecated.js +56 -0
- package/{leiamnash → src}/getThreadList.js +41 -66
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/{leiamnash → src}/getUserID.js +9 -14
- package/{leiamnash → src}/getUserInfo.js +12 -18
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/{leiamnash → src}/httpGet.js +12 -17
- package/{leiamnash → src}/httpPost.js +12 -17
- package/src/listen.js +553 -0
- package/src/listenMqtt-Test.js +687 -0
- package/src/listenMqtt.js +677 -0
- package/{leiamnash → src}/logout.js +13 -20
- package/{leiamnash → src}/markAsDelivered.js +11 -22
- package/{leiamnash → src}/markAsRead.js +11 -21
- package/{leiamnash → src}/markAsReadAll.js +10 -20
- package/{leiamnash → src}/markAsSeen.js +7 -18
- package/{leiamnash → src}/muteThread.js +11 -18
- package/src/removeUserFromGroup.js +45 -0
- package/{leiamnash → src}/resolvePhotoUrl.js +8 -17
- package/{leiamnash → src}/searchForThread.js +10 -21
- package/src/sendMessage.js +315 -0
- package/{leiamnash → src}/sendTypingIndicator.js +14 -47
- package/{leiamnash → src}/setMessageReaction.js +12 -26
- package/{leiamnash → src}/setPostReaction.js +13 -26
- package/{leiamnash → src}/setTitle.js +13 -29
- package/src/threadColors.js +41 -0
- package/{leiamnash → src}/unfriend.js +9 -19
- package/{leiamnash → src}/unsendMessage.js +9 -19
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +7 -0
- package/test/example-config.json +18 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/utils.js +1021 -1238
- package/leiamnash/addExternalModule.js +0 -19
- package/leiamnash/changeAdminStatus.js +0 -79
- package/leiamnash/changeApprovalMode.js +0 -80
- package/leiamnash/changeArchivedStatus.js +0 -55
- package/leiamnash/changeNickname.js +0 -59
- package/leiamnash/changeThreadEmoji.js +0 -55
- package/leiamnash/chat.js +0 -447
- package/leiamnash/deleteMessage.js +0 -56
- package/leiamnash/deleteThread.js +0 -56
- package/leiamnash/forwardAttachment.js +0 -60
- package/leiamnash/getThreadInfo.js +0 -212
- package/leiamnash/getThreadInfoDeprecated.js +0 -80
- package/leiamnash/getThreadListDeprecated.js +0 -75
- package/leiamnash/getThreadPictures.js +0 -79
- package/leiamnash/handleFriendRequest.js +0 -61
- package/leiamnash/handleMessageRequest.js +0 -65
- package/leiamnash/listenMqtt.js +0 -1129
- package/leiamnash/removeUserFromGroup.js +0 -79
- package/leiamnash/threadColors.js +0 -57
package/leiamnash/chat.js
DELETED
@@ -1,447 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
var bluebird = require("bluebird");
|
6
|
-
|
7
|
-
var allowedProperties = {
|
8
|
-
attachment: true,
|
9
|
-
url: true,
|
10
|
-
sticker: true,
|
11
|
-
emoji: true,
|
12
|
-
emojiSize: true,
|
13
|
-
body: true,
|
14
|
-
mentions: true,
|
15
|
-
location: true,
|
16
|
-
};
|
17
|
-
|
18
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
19
|
-
function uploadAttachment(attachments, callback) {
|
20
|
-
var uploads = [];
|
21
|
-
|
22
|
-
// create an array of promises
|
23
|
-
for (var i = 0; i < attachments.length; i++) {
|
24
|
-
if (!utils.isReadableStream(attachments[i])) {
|
25
|
-
throw {
|
26
|
-
error:
|
27
|
-
"Attachment should be a readable stream and not " +
|
28
|
-
utils.getType(attachments[i]) +
|
29
|
-
"."
|
30
|
-
};
|
31
|
-
}
|
32
|
-
|
33
|
-
var form = {
|
34
|
-
upload_1024: attachments[i],
|
35
|
-
voice_clip: "true"
|
36
|
-
};
|
37
|
-
|
38
|
-
uploads.push(
|
39
|
-
defaultFuncs
|
40
|
-
.postFormData(
|
41
|
-
"https://upload.facebook.com/ajax/mercury/upload.php",
|
42
|
-
ctx.jar,
|
43
|
-
form,
|
44
|
-
{}
|
45
|
-
)
|
46
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
47
|
-
.then(function (resData) {
|
48
|
-
if (resData.error) {
|
49
|
-
throw resData;
|
50
|
-
}
|
51
|
-
|
52
|
-
// We have to return the data unformatted unless we want to change it
|
53
|
-
// back in sendMessage.
|
54
|
-
return resData.payload.metadata[0];
|
55
|
-
})
|
56
|
-
);
|
57
|
-
}
|
58
|
-
|
59
|
-
// resolve all promises
|
60
|
-
bluebird
|
61
|
-
.all(uploads)
|
62
|
-
.then(function (resData) {
|
63
|
-
callback(null, resData);
|
64
|
-
})
|
65
|
-
.catch(function (err) {
|
66
|
-
log.error("uploadAttachment", err);
|
67
|
-
return callback(err);
|
68
|
-
});
|
69
|
-
}
|
70
|
-
|
71
|
-
function getUrl(url, callback) {
|
72
|
-
var form = {
|
73
|
-
image_height: 960,
|
74
|
-
image_width: 960,
|
75
|
-
uri: url
|
76
|
-
};
|
77
|
-
|
78
|
-
defaultFuncs
|
79
|
-
.post(
|
80
|
-
"https://www.facebook.com/message_share_attachment/fromURI/",
|
81
|
-
ctx.jar,
|
82
|
-
form
|
83
|
-
)
|
84
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
85
|
-
.then(function (resData) {
|
86
|
-
if (resData.error) {
|
87
|
-
return callback(resData);
|
88
|
-
}
|
89
|
-
|
90
|
-
if (!resData.payload) {
|
91
|
-
return callback({ error: "Invalid url" });
|
92
|
-
}
|
93
|
-
|
94
|
-
callback(null, resData.payload.share_data.share_params);
|
95
|
-
})
|
96
|
-
.catch(function (err) {
|
97
|
-
log.error("getUrl", err);
|
98
|
-
return callback(err);
|
99
|
-
});
|
100
|
-
}
|
101
|
-
|
102
|
-
function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
|
103
|
-
// There are three cases here:
|
104
|
-
// 1. threadID is of type array, where we're starting a new group chat with users
|
105
|
-
// specified in the array.
|
106
|
-
// 2. User is sending a message to a specific user.
|
107
|
-
// 3. No additional form params and the message goes to an existing group chat.
|
108
|
-
if (utils.getType(threadID) === "Array") {
|
109
|
-
for (var i = 0; i < threadID.length; i++) {
|
110
|
-
form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
111
|
-
}
|
112
|
-
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
113
|
-
form["client_thread_id"] = "root:" + messageAndOTID;
|
114
|
-
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
115
|
-
} else {
|
116
|
-
// This means that threadID is the id of a user, and the chat
|
117
|
-
// is a single person chat
|
118
|
-
if (isSingleUser) {
|
119
|
-
form["specific_to_list[0]"] = "fbid:" + threadID;
|
120
|
-
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
121
|
-
form["other_user_fbid"] = threadID;
|
122
|
-
} else {
|
123
|
-
form["thread_fbid"] = threadID;
|
124
|
-
}
|
125
|
-
}
|
126
|
-
|
127
|
-
if (ctx.globalOptions.pageID) {
|
128
|
-
form["author"] = "fbid:" + ctx.globalOptions.pageID;
|
129
|
-
form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
|
130
|
-
form["creator_info[creatorID]"] = ctx.userID;
|
131
|
-
form["creator_info[creatorType]"] = "direct_admin";
|
132
|
-
form["creator_info[labelType]"] = "sent_message";
|
133
|
-
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
134
|
-
form["request_user_id"] = ctx.globalOptions.pageID;
|
135
|
-
form["creator_info[profileURI]"] =
|
136
|
-
"https://www.facebook.com/profile.php?id=" + ctx.userID;
|
137
|
-
}
|
138
|
-
|
139
|
-
defaultFuncs
|
140
|
-
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
141
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
142
|
-
.then(function (resData) {
|
143
|
-
if (!resData) {
|
144
|
-
return callback({ error: "Send message failed." });
|
145
|
-
}
|
146
|
-
|
147
|
-
if (resData.error) {
|
148
|
-
if (resData.error === 1545012) {
|
149
|
-
log.warn(
|
150
|
-
"sendMessage",
|
151
|
-
"Got error 1545012. This might mean that you're not part of the conversation " +
|
152
|
-
threadID
|
153
|
-
);
|
154
|
-
}
|
155
|
-
return callback(resData);
|
156
|
-
}
|
157
|
-
|
158
|
-
var messageInfo = resData.payload.actions.reduce(function (p, v) {
|
159
|
-
return (
|
160
|
-
{
|
161
|
-
threadID: v.thread_fbid,
|
162
|
-
messageID: v.message_id,
|
163
|
-
timestamp: v.timestamp
|
164
|
-
} || p
|
165
|
-
);
|
166
|
-
}, null);
|
167
|
-
|
168
|
-
return callback(null, messageInfo);
|
169
|
-
})
|
170
|
-
.catch(function (err) {
|
171
|
-
log.error("sendMessage", err);
|
172
|
-
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
173
|
-
ctx.loggedIn = false;
|
174
|
-
}
|
175
|
-
return callback(err);
|
176
|
-
});
|
177
|
-
}
|
178
|
-
|
179
|
-
function send(form, threadID, messageAndOTID, callback, isGroup) {
|
180
|
-
// We're doing a query to this to check if the given id is the id of
|
181
|
-
// a user or of a group chat. The form will be different depending
|
182
|
-
// on that.
|
183
|
-
if (utils.getType(threadID) === "Array") {
|
184
|
-
sendContent(form, threadID, false, messageAndOTID, callback);
|
185
|
-
} else {
|
186
|
-
if (utils.getType(isGroup) != "Boolean")
|
187
|
-
sendContent(form, threadID, threadID.length <= 15, messageAndOTID, callback);
|
188
|
-
else
|
189
|
-
sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
190
|
-
}
|
191
|
-
}
|
192
|
-
|
193
|
-
function handleUrl(msg, form, callback, cb) {
|
194
|
-
if (msg.url) {
|
195
|
-
form["shareable_attachment[share_type]"] = "100";
|
196
|
-
getUrl(msg.url, function (err, params) {
|
197
|
-
if (err) {
|
198
|
-
return callback(err);
|
199
|
-
}
|
200
|
-
|
201
|
-
form["shareable_attachment[share_params]"] = params;
|
202
|
-
cb();
|
203
|
-
});
|
204
|
-
} else {
|
205
|
-
cb();
|
206
|
-
}
|
207
|
-
}
|
208
|
-
|
209
|
-
function handleLocation(msg, form, callback, cb) {
|
210
|
-
if (msg.location) {
|
211
|
-
if (msg.location.latitude == null || msg.location.longitude == null) {
|
212
|
-
return callback({ error: "location property needs both latitude and longitude" });
|
213
|
-
}
|
214
|
-
|
215
|
-
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
216
|
-
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
217
|
-
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
218
|
-
}
|
219
|
-
|
220
|
-
cb();
|
221
|
-
}
|
222
|
-
|
223
|
-
function handleSticker(msg, form, callback, cb) {
|
224
|
-
if (msg.sticker) {
|
225
|
-
form["sticker_id"] = msg.sticker;
|
226
|
-
}
|
227
|
-
cb();
|
228
|
-
}
|
229
|
-
|
230
|
-
function handleEmoji(msg, form, callback, cb) {
|
231
|
-
if (msg.emojiSize != null && msg.emoji == null) {
|
232
|
-
return callback({ error: "emoji property is empty" });
|
233
|
-
}
|
234
|
-
if (msg.emoji) {
|
235
|
-
if (msg.emojiSize == null) {
|
236
|
-
msg.emojiSize = "medium";
|
237
|
-
}
|
238
|
-
if (
|
239
|
-
msg.emojiSize != "small" &&
|
240
|
-
msg.emojiSize != "medium" &&
|
241
|
-
msg.emojiSize != "large"
|
242
|
-
) {
|
243
|
-
return callback({ error: "emojiSize property is invalid" });
|
244
|
-
}
|
245
|
-
if (form["body"] != null && form["body"] != "") {
|
246
|
-
return callback({ error: "body is not empty" });
|
247
|
-
}
|
248
|
-
form["body"] = msg.emoji;
|
249
|
-
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
250
|
-
}
|
251
|
-
cb();
|
252
|
-
}
|
253
|
-
|
254
|
-
function handleAttachment(msg, form, callback, cb) {
|
255
|
-
if (msg.attachment) {
|
256
|
-
form["image_ids"] = [];
|
257
|
-
form["gif_ids"] = [];
|
258
|
-
form["file_ids"] = [];
|
259
|
-
form["video_ids"] = [];
|
260
|
-
form["audio_ids"] = [];
|
261
|
-
|
262
|
-
if (utils.getType(msg.attachment) !== "Array") {
|
263
|
-
msg.attachment = [msg.attachment];
|
264
|
-
}
|
265
|
-
|
266
|
-
uploadAttachment(msg.attachment, function (err, files) {
|
267
|
-
if (err) {
|
268
|
-
return callback(err);
|
269
|
-
}
|
270
|
-
|
271
|
-
files.forEach(function (file) {
|
272
|
-
var key = Object.keys(file);
|
273
|
-
var type = key[0]; // image_id, file_id, etc
|
274
|
-
form["" + type + "s"].push(file[type]); // push the id
|
275
|
-
});
|
276
|
-
cb();
|
277
|
-
});
|
278
|
-
} else {
|
279
|
-
cb();
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
function handleMention(msg, form, callback, cb) {
|
284
|
-
if (msg.mentions) {
|
285
|
-
for (let i = 0; i < msg.mentions.length; i++) {
|
286
|
-
const mention = msg.mentions[i];
|
287
|
-
|
288
|
-
const tag = mention.tag;
|
289
|
-
if (typeof tag !== "string") {
|
290
|
-
return callback({ error: "Mention tags must be strings." });
|
291
|
-
}
|
292
|
-
|
293
|
-
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
294
|
-
|
295
|
-
if (offset < 0) {
|
296
|
-
log.warn(
|
297
|
-
"handleMention",
|
298
|
-
'Mention for "' + tag + '" not found in message string.'
|
299
|
-
);
|
300
|
-
}
|
301
|
-
|
302
|
-
if (mention.id == null) {
|
303
|
-
log.warn("handleMention", "Mention id should be non-null.");
|
304
|
-
}
|
305
|
-
|
306
|
-
const id = mention.id || 0;
|
307
|
-
const emptyChar = '\u200E';
|
308
|
-
form["body"] = emptyChar + msg.body;
|
309
|
-
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
310
|
-
form["profile_xmd[" + i + "][length]"] = tag.length;
|
311
|
-
form["profile_xmd[" + i + "][id]"] = id;
|
312
|
-
form["profile_xmd[" + i + "][type]"] = "p";
|
313
|
-
}
|
314
|
-
}
|
315
|
-
cb();
|
316
|
-
}
|
317
|
-
|
318
|
-
return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
|
319
|
-
typeof isGroup == "undefined" ? isGroup = null : "";
|
320
|
-
if (
|
321
|
-
!callback &&
|
322
|
-
(utils.getType(threadID) === "Function" ||
|
323
|
-
utils.getType(threadID) === "AsyncFunction")
|
324
|
-
) {
|
325
|
-
return threadID({ error: "Pass a threadID as a second argument." });
|
326
|
-
}
|
327
|
-
if (
|
328
|
-
!replyToMessage &&
|
329
|
-
utils.getType(callback) === "String"
|
330
|
-
) {
|
331
|
-
replyToMessage = callback;
|
332
|
-
callback = undefined;
|
333
|
-
}
|
334
|
-
|
335
|
-
var resolveFunc = function () { };
|
336
|
-
var rejectFunc = function () { };
|
337
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
338
|
-
resolveFunc = resolve;
|
339
|
-
rejectFunc = reject;
|
340
|
-
});
|
341
|
-
|
342
|
-
if (!callback) {
|
343
|
-
callback = function (err, data) {
|
344
|
-
if (err) return rejectFunc(err);
|
345
|
-
resolveFunc(data);
|
346
|
-
};
|
347
|
-
}
|
348
|
-
|
349
|
-
var msgType = utils.getType(msg);
|
350
|
-
var threadIDType = utils.getType(threadID);
|
351
|
-
var messageIDType = utils.getType(replyToMessage);
|
352
|
-
|
353
|
-
if (msgType !== "String" && msgType !== "Object") {
|
354
|
-
return callback({
|
355
|
-
error:
|
356
|
-
"Message should be of type string or object and not " + msgType + "."
|
357
|
-
});
|
358
|
-
}
|
359
|
-
|
360
|
-
// Changing this to accomodate an array of users
|
361
|
-
if (
|
362
|
-
threadIDType !== "Array" &&
|
363
|
-
threadIDType !== "Number" &&
|
364
|
-
threadIDType !== "String"
|
365
|
-
) {
|
366
|
-
return callback({
|
367
|
-
error:
|
368
|
-
"ThreadID should be of type number, string, or array and not " +
|
369
|
-
threadIDType +
|
370
|
-
"."
|
371
|
-
});
|
372
|
-
}
|
373
|
-
|
374
|
-
if (replyToMessage && messageIDType !== 'String') {
|
375
|
-
return callback({
|
376
|
-
error:
|
377
|
-
"MessageID should be of type string and not " +
|
378
|
-
threadIDType +
|
379
|
-
"."
|
380
|
-
});
|
381
|
-
}
|
382
|
-
|
383
|
-
if (msgType === "String") {
|
384
|
-
msg = { body: msg };
|
385
|
-
}
|
386
|
-
|
387
|
-
var disallowedProperties = Object.keys(msg).filter(
|
388
|
-
prop => !allowedProperties[prop]
|
389
|
-
);
|
390
|
-
if (disallowedProperties.length > 0) {
|
391
|
-
return callback({
|
392
|
-
error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`"
|
393
|
-
});
|
394
|
-
}
|
395
|
-
|
396
|
-
var messageAndOTID = utils.generateOfflineThreadingID();
|
397
|
-
|
398
|
-
var form = {
|
399
|
-
client: "mercury",
|
400
|
-
action_type: "ma-type:user-generated-message",
|
401
|
-
author: "fbid:" + ctx.userID,
|
402
|
-
timestamp: Date.now(),
|
403
|
-
timestamp_absolute: "Today",
|
404
|
-
timestamp_relative: utils.generateTimestampRelative(),
|
405
|
-
timestamp_time_passed: "0",
|
406
|
-
is_unread: false,
|
407
|
-
is_cleared: false,
|
408
|
-
is_forward: false,
|
409
|
-
is_filtered_content: false,
|
410
|
-
is_filtered_content_bh: false,
|
411
|
-
is_filtered_content_account: false,
|
412
|
-
is_filtered_content_quasar: false,
|
413
|
-
is_filtered_content_invalid_app: false,
|
414
|
-
is_spoof_warning: false,
|
415
|
-
source: "source:chat:web",
|
416
|
-
"source_tags[0]": "source:chat",
|
417
|
-
body: msg.body ? msg.body.toString() : "",
|
418
|
-
html_body: false,
|
419
|
-
ui_push_phase: "V3",
|
420
|
-
status: "0",
|
421
|
-
offline_threading_id: messageAndOTID,
|
422
|
-
message_id: messageAndOTID,
|
423
|
-
threading_id: utils.generateThreadingID(ctx.clientID),
|
424
|
-
"ephemeral_ttl_mode:": "0",
|
425
|
-
manual_retry_cnt: "0",
|
426
|
-
has_attachment: !!(msg.attachment || msg.url || msg.sticker),
|
427
|
-
signatureID: utils.getSignatureID(),
|
428
|
-
replied_to_message_id: replyToMessage
|
429
|
-
};
|
430
|
-
|
431
|
-
handleLocation(msg, form, callback, () =>
|
432
|
-
handleSticker(msg, form, callback, () =>
|
433
|
-
handleAttachment(msg, form, callback, () =>
|
434
|
-
handleUrl(msg, form, callback, () =>
|
435
|
-
handleEmoji(msg, form, callback, () =>
|
436
|
-
handleMention(msg, form, callback, () =>
|
437
|
-
send(form, threadID, messageAndOTID, callback, isGroup)
|
438
|
-
)
|
439
|
-
)
|
440
|
-
)
|
441
|
-
)
|
442
|
-
)
|
443
|
-
);
|
444
|
-
|
445
|
-
return returnPromise;
|
446
|
-
};
|
447
|
-
};
|
@@ -1,56 +0,0 @@
|
|
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 deleteMessage(messageOrMessages, 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
|
-
if (!callback) {
|
15
|
-
callback = function(err) {
|
16
|
-
if (err) {
|
17
|
-
return rejectFunc(err);
|
18
|
-
}
|
19
|
-
resolveFunc();
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
var form = {
|
24
|
-
client: "mercury"
|
25
|
-
};
|
26
|
-
|
27
|
-
if (utils.getType(messageOrMessages) !== "Array") {
|
28
|
-
messageOrMessages = [messageOrMessages];
|
29
|
-
}
|
30
|
-
|
31
|
-
for (var i = 0; i < messageOrMessages.length; i++) {
|
32
|
-
form["message_ids[" + i + "]"] = messageOrMessages[i];
|
33
|
-
}
|
34
|
-
|
35
|
-
defaultFuncs
|
36
|
-
.post(
|
37
|
-
"https://www.facebook.com/ajax/mercury/delete_messages.php",
|
38
|
-
ctx.jar,
|
39
|
-
form
|
40
|
-
)
|
41
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
42
|
-
.then(function(resData) {
|
43
|
-
if (resData.error) {
|
44
|
-
throw resData;
|
45
|
-
}
|
46
|
-
|
47
|
-
return callback();
|
48
|
-
})
|
49
|
-
.catch(function(err) {
|
50
|
-
log.error("deleteMessage", err);
|
51
|
-
return callback(err);
|
52
|
-
});
|
53
|
-
|
54
|
-
return returnPromise;
|
55
|
-
};
|
56
|
-
};
|
@@ -1,56 +0,0 @@
|
|
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 deleteThread(threadOrThreads, 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
|
-
if (!callback) {
|
15
|
-
callback = function(err) {
|
16
|
-
if (err) {
|
17
|
-
return rejectFunc(err);
|
18
|
-
}
|
19
|
-
resolveFunc();
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
var form = {
|
24
|
-
client: "mercury"
|
25
|
-
};
|
26
|
-
|
27
|
-
if (utils.getType(threadOrThreads) !== "Array") {
|
28
|
-
threadOrThreads = [threadOrThreads];
|
29
|
-
}
|
30
|
-
|
31
|
-
for (var i = 0; i < threadOrThreads.length; i++) {
|
32
|
-
form["ids[" + i + "]"] = threadOrThreads[i];
|
33
|
-
}
|
34
|
-
|
35
|
-
defaultFuncs
|
36
|
-
.post(
|
37
|
-
"https://www.facebook.com/ajax/mercury/delete_thread.php",
|
38
|
-
ctx.jar,
|
39
|
-
form
|
40
|
-
)
|
41
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
42
|
-
.then(function(resData) {
|
43
|
-
if (resData.error) {
|
44
|
-
throw resData;
|
45
|
-
}
|
46
|
-
|
47
|
-
return callback();
|
48
|
-
})
|
49
|
-
.catch(function(err) {
|
50
|
-
log.error("deleteThread", err);
|
51
|
-
return callback(err);
|
52
|
-
});
|
53
|
-
|
54
|
-
return returnPromise;
|
55
|
-
};
|
56
|
-
};
|
@@ -1,60 +0,0 @@
|
|
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 forwardAttachment(attachmentID, userOrUsers, 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
|
-
if (!callback) {
|
15
|
-
callback = function(err) {
|
16
|
-
if (err) {
|
17
|
-
return rejectFunc(err);
|
18
|
-
}
|
19
|
-
resolveFunc();
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
var form = {
|
24
|
-
attachment_id: attachmentID
|
25
|
-
};
|
26
|
-
|
27
|
-
if (utils.getType(userOrUsers) !== "Array") {
|
28
|
-
userOrUsers = [userOrUsers];
|
29
|
-
}
|
30
|
-
|
31
|
-
var timestamp = Math.floor(Date.now() / 1000);
|
32
|
-
|
33
|
-
for (var i = 0; i < userOrUsers.length; i++) {
|
34
|
-
//That's good, the key of the array is really timestmap in seconds + index
|
35
|
-
//Probably time when the attachment will be sent?
|
36
|
-
form["recipient_map[" + (timestamp + i) + "]"] = userOrUsers[i];
|
37
|
-
}
|
38
|
-
|
39
|
-
defaultFuncs
|
40
|
-
.post(
|
41
|
-
"https://www.facebook.com/mercury/attachments/forward/",
|
42
|
-
ctx.jar,
|
43
|
-
form
|
44
|
-
)
|
45
|
-
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
46
|
-
.then(function(resData) {
|
47
|
-
if (resData.error) {
|
48
|
-
throw resData;
|
49
|
-
}
|
50
|
-
|
51
|
-
return callback();
|
52
|
-
})
|
53
|
-
.catch(function(err) {
|
54
|
-
log.error("forwardAttachment", err);
|
55
|
-
return callback(err);
|
56
|
-
});
|
57
|
-
|
58
|
-
return returnPromise;
|
59
|
-
};
|
60
|
-
};
|