stfca 1.0.12 → 1.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stfca",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Unofficial Facebook Chat API for Node.js with Auto-Update System - Enhanced by ST | Sheikh Tamim",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -0,0 +1,92 @@
1
+
2
+ "use strict";
3
+
4
+ const utils = require("../utils");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function friendList(callback) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ callback = function (err, friendList) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(friendList);
21
+ };
22
+ }
23
+
24
+ const form = {
25
+ av: ctx.userID,
26
+ __user: ctx.userID,
27
+ __a: 1,
28
+ __req: utils.getSignatureID(),
29
+ __hs: "20353.HYP:comet_pkg.2.1...0",
30
+ dpr: 1,
31
+ __ccg: "EXCELLENT",
32
+ __rev: "1027407131",
33
+ __s: utils.getSignatureID(),
34
+ __hsi: "7552796416884228248",
35
+ __comet_req: 15,
36
+ fb_dtsg: ctx.fb_dtsg,
37
+ jazoest: ctx.ttstamp,
38
+ lsd: ctx.fb_dtsg,
39
+ __spin_r: "1027407131",
40
+ __spin_b: "trunk",
41
+ __spin_t: Date.now(),
42
+ fb_api_caller_class: "RelayModern",
43
+ fb_api_req_friendly_name: "FriendingCometAllFriendsRootQuery",
44
+ variables: JSON.stringify({ scale: 2 }),
45
+ server_timestamps: true,
46
+ doc_id: "24426868700236815"
47
+ };
48
+
49
+ defaultFuncs
50
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
51
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
52
+ .then(function (resData) {
53
+ if (!resData || !resData.data) {
54
+ throw { error: "friendList returned empty object." };
55
+ }
56
+ if (resData.error) {
57
+ throw resData;
58
+ }
59
+
60
+ const friendsData = resData.data.viewer?.all_friends?.edges || [];
61
+ const formattedFriends = friendsData.map(edge => {
62
+ const friend = edge.node;
63
+ return {
64
+ userID: friend.id,
65
+ name: friend.name,
66
+ shortName: friend.short_name,
67
+ gender: friend.gender,
68
+ profilePicture: friend.profile_picture?.uri || null,
69
+ profileUrl: friend.url,
70
+ friendshipStatus: friend.friendship_status,
71
+ socialContext: friend.social_context?.text || "",
72
+ isSecureThread: friend.is_secure_thread,
73
+ subscribeStatus: friend.subscribe_status
74
+ };
75
+ });
76
+
77
+ const result = {
78
+ totalCount: resData.data.viewer?.all_friends_data?.count || 0,
79
+ friendCount: resData.data.viewer?.all_friends_data?.friend_count || 0,
80
+ friends: formattedFriends
81
+ };
82
+
83
+ callback(null, result);
84
+ })
85
+ .catch(function (err) {
86
+ console.error("friendList", err);
87
+ return callback(err);
88
+ });
89
+
90
+ return returnPromise;
91
+ };
92
+ };