stfca 1.0.12 → 1.0.14

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