fca-neokex-fix 1.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +220 -0
  2. package/LICENSE +26 -0
  3. package/README.md +346 -0
  4. package/THEME_FEATURES.md +137 -0
  5. package/examples/README.md +131 -0
  6. package/examples/apply-ai-theme.js +127 -0
  7. package/examples/check-current-theme.js +74 -0
  8. package/examples/simple-bot.js +114 -0
  9. package/examples/test-bot.js +752 -0
  10. package/examples/test-logging.js +85 -0
  11. package/examples/theme-usage-example.js +53 -0
  12. package/index.js +2 -0
  13. package/package.json +105 -0
  14. package/src/apis/addExternalModule.js +24 -0
  15. package/src/apis/addUserToGroup.js +108 -0
  16. package/src/apis/changeAdminStatus.js +148 -0
  17. package/src/apis/changeArchivedStatus.js +61 -0
  18. package/src/apis/changeAvatar.js +103 -0
  19. package/src/apis/changeBio.js +69 -0
  20. package/src/apis/changeBlockedStatus.js +54 -0
  21. package/src/apis/changeGroupImage.js +136 -0
  22. package/src/apis/changeThreadColor.js +116 -0
  23. package/src/apis/comment.js +207 -0
  24. package/src/apis/createAITheme.js +129 -0
  25. package/src/apis/createNewGroup.js +79 -0
  26. package/src/apis/createPoll.js +73 -0
  27. package/src/apis/deleteMessage.js +44 -0
  28. package/src/apis/deleteThread.js +52 -0
  29. package/src/apis/editMessage.js +70 -0
  30. package/src/apis/emoji.js +124 -0
  31. package/src/apis/fetchThemeData.js +65 -0
  32. package/src/apis/follow.js +81 -0
  33. package/src/apis/forwardMessage.js +52 -0
  34. package/src/apis/friend.js +243 -0
  35. package/src/apis/gcmember.js +122 -0
  36. package/src/apis/gcname.js +123 -0
  37. package/src/apis/gcrule.js +119 -0
  38. package/src/apis/getAccess.js +111 -0
  39. package/src/apis/getBotInfo.js +88 -0
  40. package/src/apis/getBotInitialData.js +43 -0
  41. package/src/apis/getFriendsList.js +79 -0
  42. package/src/apis/getMessage.js +423 -0
  43. package/src/apis/getTheme.js +104 -0
  44. package/src/apis/getThemeInfo.js +96 -0
  45. package/src/apis/getThreadHistory.js +239 -0
  46. package/src/apis/getThreadInfo.js +257 -0
  47. package/src/apis/getThreadList.js +222 -0
  48. package/src/apis/getThreadPictures.js +58 -0
  49. package/src/apis/getUserID.js +83 -0
  50. package/src/apis/getUserInfo.js +495 -0
  51. package/src/apis/getUserInfoV2.js +146 -0
  52. package/src/apis/handleMessageRequest.js +50 -0
  53. package/src/apis/httpGet.js +63 -0
  54. package/src/apis/httpPost.js +89 -0
  55. package/src/apis/httpPostFormData.js +69 -0
  56. package/src/apis/listenMqtt.js +796 -0
  57. package/src/apis/listenSpeed.js +170 -0
  58. package/src/apis/logout.js +63 -0
  59. package/src/apis/markAsDelivered.js +47 -0
  60. package/src/apis/markAsRead.js +95 -0
  61. package/src/apis/markAsReadAll.js +41 -0
  62. package/src/apis/markAsSeen.js +70 -0
  63. package/src/apis/mqttDeltaValue.js +330 -0
  64. package/src/apis/muteThread.js +45 -0
  65. package/src/apis/nickname.js +132 -0
  66. package/src/apis/notes.js +163 -0
  67. package/src/apis/pinMessage.js +141 -0
  68. package/src/apis/produceMetaTheme.js +180 -0
  69. package/src/apis/realtime.js +161 -0
  70. package/src/apis/removeUserFromGroup.js +117 -0
  71. package/src/apis/resolvePhotoUrl.js +58 -0
  72. package/src/apis/searchForThread.js +154 -0
  73. package/src/apis/sendMessage.js +281 -0
  74. package/src/apis/sendMessageMqtt.js +188 -0
  75. package/src/apis/sendTypingIndicator.js +41 -0
  76. package/src/apis/setMessageReaction.js +27 -0
  77. package/src/apis/setMessageReactionMqtt.js +61 -0
  78. package/src/apis/setThreadTheme.js +260 -0
  79. package/src/apis/setThreadThemeMqtt.js +94 -0
  80. package/src/apis/share.js +107 -0
  81. package/src/apis/shareContact.js +66 -0
  82. package/src/apis/stickers.js +257 -0
  83. package/src/apis/story.js +181 -0
  84. package/src/apis/theme.js +233 -0
  85. package/src/apis/unfriend.js +47 -0
  86. package/src/apis/unsendMessage.js +17 -0
  87. package/src/database/appStateBackup.js +189 -0
  88. package/src/database/models/index.js +56 -0
  89. package/src/database/models/thread.js +31 -0
  90. package/src/database/models/user.js +32 -0
  91. package/src/database/threadData.js +101 -0
  92. package/src/database/userData.js +90 -0
  93. package/src/engine/client.js +91 -0
  94. package/src/engine/models/buildAPI.js +109 -0
  95. package/src/engine/models/loginHelper.js +326 -0
  96. package/src/engine/models/setOptions.js +53 -0
  97. package/src/utils/auth-helpers.js +149 -0
  98. package/src/utils/autoReLogin.js +169 -0
  99. package/src/utils/axios.js +290 -0
  100. package/src/utils/clients.js +270 -0
  101. package/src/utils/constants.js +396 -0
  102. package/src/utils/formatters/data/formatAttachment.js +370 -0
  103. package/src/utils/formatters/data/formatDelta.js +153 -0
  104. package/src/utils/formatters/index.js +159 -0
  105. package/src/utils/formatters/value/formatCookie.js +91 -0
  106. package/src/utils/formatters/value/formatDate.js +36 -0
  107. package/src/utils/formatters/value/formatID.js +16 -0
  108. package/src/utils/formatters.js +1067 -0
  109. package/src/utils/headers.js +199 -0
  110. package/src/utils/index.js +151 -0
  111. package/src/utils/monitoring.js +358 -0
  112. package/src/utils/rateLimiter.js +380 -0
  113. package/src/utils/tokenRefresh.js +311 -0
  114. package/src/utils/user-agents.js +238 -0
@@ -0,0 +1,423 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+ const { _formatAttachment } = require('../utils/formatters/data/formatAttachment');
5
+
6
+ const THEME_COLORS = [
7
+ { theme_color: "FF000000", theme_id: "788274591712841", theme_emoji: "🖤", gradient: '["FFF0F0F0"]', should_show_icon: "", theme_name_with_subtitle: "Monochrome" },
8
+ { theme_color: "FFFF5CA1", theme_id: "169463077092846", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Hot Pink" },
9
+ { theme_color: "FF2825B5", theme_id: "271607034185782", theme_emoji: null, gradient: '["FF5E007E","FF331290","FF2825B5"]', should_show_icon: "1", theme_name_with_subtitle: "Shadow" },
10
+ { theme_color: "FFD9A900", theme_id: "2533652183614000", theme_emoji: null, gradient: '["FF550029","FFAA3232","FFD9A900"]', should_show_icon: "1", theme_name_with_subtitle: "Maple" },
11
+ { theme_color: "FFFB45DE", theme_id: "2873642949430623", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Tulip" },
12
+ { theme_color: "FF5E007E", theme_id: "193497045377796", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Grape" },
13
+ { theme_color: "FF7AA286", theme_id: "1455149831518874", theme_emoji: "🌑", gradient: '["FF25C0E1","FFCE832A"]', should_show_icon: "", theme_name_with_subtitle: "Dune" },
14
+ { theme_color: "FFFAAF00", theme_id: "672058580051520", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Honey" },
15
+ { theme_color: "FF0084FF", theme_id: "196241301102133", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Default Blue" },
16
+ { theme_color: "FFFFC300", theme_id: "174636906462322", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Yellow" },
17
+ { theme_color: "FF44BEC7", theme_id: "1928399724138152", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Teal Blue" },
18
+ { theme_color: "FF7646FF", theme_id: "234137870477637", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Bright Purple" },
19
+ { theme_color: "FFF25C54", theme_id: "3022526817824329", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Peach" },
20
+ { theme_color: "FFF01D6A", theme_id: "724096885023603", theme_emoji: null, gradient: '["FF005FFF","FF9200FF","FFFF2E19"]', should_show_icon: "1", theme_name_with_subtitle: "Berry" },
21
+ { theme_color: "FFFF7CA8", theme_id: "624266884847972", theme_emoji: null, gradient: '["FFFF8FB2","FFA797FF","FF00E5FF"]', should_show_icon: "1", theme_name_with_subtitle: "Candy" },
22
+ { theme_color: "FF0084FF", theme_id: "196241301102133", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Classic" },
23
+ { theme_color: "FF0099FF", theme_id: "3273938616164733", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Classic" },
24
+ { theme_color: "FFFA3C4C", theme_id: "2129984390566328", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Red" },
25
+ { theme_color: "FF13CF13", theme_id: "2136751179887052", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Green" },
26
+ { theme_color: "FFFF7E29", theme_id: "175615189761153", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Orange" }
27
+ ];
28
+
29
+ function formatMessage(threadID, data) {
30
+ const baseMessage = {
31
+ threadID: threadID,
32
+ messageID: data.message_id,
33
+ timestamp: data.timestamp_precise,
34
+ author: data.message_sender ? data.message_sender.id : null
35
+ };
36
+
37
+ switch (data.__typename) {
38
+ case "ThreadNameMessage":
39
+ return {
40
+ ...baseMessage,
41
+ type: "event",
42
+ logMessageType: "log:thread-name",
43
+ logMessageData: { name: data.thread_name },
44
+ logMessageBody: data.snippet
45
+ };
46
+
47
+ case "ThreadImageMessage":
48
+ const metadata = data.image_with_metadata;
49
+ return {
50
+ ...baseMessage,
51
+ type: "event",
52
+ logMessageType: "log:thread-image",
53
+ logMessageData: metadata ? {
54
+ attachmentID: metadata.legacy_attachment_id,
55
+ width: metadata.original_dimensions.x,
56
+ height: metadata.original_dimensions.y,
57
+ url: metadata.preview.uri
58
+ } : null,
59
+ logMessageBody: data.snippet
60
+ };
61
+
62
+ case "GenericAdminTextMessage":
63
+ const adminType = data.extensible_message_admin_text_type;
64
+
65
+ if (adminType === "CHANGE_THREAD_THEME") {
66
+ const themeColor = data.extensible_message_admin_text.theme_color;
67
+ const colorMatch = THEME_COLORS.find(color => color.theme_color === themeColor);
68
+
69
+ return {
70
+ ...baseMessage,
71
+ type: "event",
72
+ logMessageType: "log:thread-color",
73
+ logMessageData: colorMatch || {
74
+ theme_color: themeColor,
75
+ theme_id: null,
76
+ theme_emoji: null,
77
+ gradient: null,
78
+ should_show_icon: null,
79
+ theme_name_with_subtitle: null
80
+ },
81
+ logMessageBody: data.snippet
82
+ };
83
+ }
84
+
85
+ if (adminType === "CHANGE_THREAD_ICON") {
86
+ const thread_icon = data.extensible_message_admin_text?.thread_icon;
87
+ let iconUrl = null;
88
+
89
+ if (thread_icon) {
90
+ try {
91
+ iconUrl = `https://static.xx.fbcdn.net/images/emoji.php/v9/t3c/1/16/${thread_icon.codePointAt(0).toString(16)}.png`;
92
+ } catch (err) {
93
+ utils.warn(`getMessage: Error generating icon URL: ${err.message}`);
94
+ }
95
+ }
96
+
97
+ return {
98
+ ...baseMessage,
99
+ type: "event",
100
+ logMessageType: "log:thread-icon",
101
+ logMessageData: {
102
+ thread_icon: thread_icon || null,
103
+ thread_icon_url: iconUrl
104
+ },
105
+ logMessageBody: data.snippet
106
+ };
107
+ }
108
+
109
+ if (adminType === "CHANGE_THREAD_NICKNAME") {
110
+ return {
111
+ ...baseMessage,
112
+ type: "event",
113
+ logMessageType: "log:user-nickname",
114
+ logMessageData: {
115
+ nickname: data.extensible_message_admin_text?.nickname || null,
116
+ participant_id: data.extensible_message_admin_text?.participant_id || null
117
+ },
118
+ logMessageBody: data.snippet
119
+ };
120
+ }
121
+
122
+ if (adminType === "GROUP_POLL") {
123
+ const question = data.extensible_message_admin_text?.question;
124
+ if (!question) {
125
+ return {
126
+ ...baseMessage,
127
+ type: "event",
128
+ logMessageType: "log:thread-poll",
129
+ logMessageData: { error: "Missing poll question data" },
130
+ logMessageBody: data.snippet
131
+ };
132
+ }
133
+
134
+ return {
135
+ ...baseMessage,
136
+ type: "event",
137
+ logMessageType: "log:thread-poll",
138
+ logMessageData: {
139
+ question_json: JSON.stringify({
140
+ id: question.id,
141
+ text: question.text,
142
+ total_count: data.extensible_message_admin_text.total_count || 0,
143
+ viewer_has_voted: question.viewer_has_voted || false,
144
+ question_type: "",
145
+ creator_id: data.message_sender ? data.message_sender.id : null,
146
+ options: (question.options?.nodes || []).map(option => ({
147
+ id: option.id,
148
+ text: option.text,
149
+ total_count: (option.voters?.nodes || []).length,
150
+ viewer_has_voted: option.viewer_has_voted || false,
151
+ voters: (option.voters?.nodes || []).map(voter => voter.id)
152
+ }))
153
+ }),
154
+ event_type: (data.extensible_message_admin_text.event_type || "").toLowerCase(),
155
+ question_id: question.id
156
+ },
157
+ logMessageBody: data.snippet
158
+ };
159
+ }
160
+
161
+ if (adminType === "CHANGE_THREAD_QUICK_REACTION") {
162
+ return {
163
+ ...baseMessage,
164
+ type: "event",
165
+ logMessageType: "log:thread-icon",
166
+ logMessageData: {
167
+ thread_quick_reaction: data.extensible_message_admin_text?.thread_quick_reaction || null
168
+ },
169
+ logMessageBody: data.snippet
170
+ };
171
+ }
172
+
173
+ if (adminType === "CHANGE_THREAD_ADMINS") {
174
+ return {
175
+ ...baseMessage,
176
+ type: "event",
177
+ logMessageType: "log:thread-admins",
178
+ logMessageData: {
179
+ admin_type: data.extensible_message_admin_text?.admin_type || null,
180
+ target_id: data.extensible_message_admin_text?.target_id || null
181
+ },
182
+ logMessageBody: data.snippet
183
+ };
184
+ }
185
+
186
+ if (adminType === "CHANGE_THREAD_APPROVAL_MODE") {
187
+ return {
188
+ ...baseMessage,
189
+ type: "event",
190
+ logMessageType: "log:thread-approval-mode",
191
+ logMessageData: {
192
+ approval_mode: data.extensible_message_admin_text?.approval_mode || null
193
+ },
194
+ logMessageBody: data.snippet
195
+ };
196
+ }
197
+
198
+ if (adminType === "MESSENGER_CALL_LOG" || adminType === "PARTICIPANT_JOINED_GROUP_CALL") {
199
+ return {
200
+ ...baseMessage,
201
+ type: "event",
202
+ logMessageType: "log:thread-call",
203
+ logMessageData: {
204
+ event_type: adminType,
205
+ call_duration: data.extensible_message_admin_text?.call_duration || 0
206
+ },
207
+ logMessageBody: data.snippet
208
+ };
209
+ }
210
+
211
+ if (adminType === "PIN_MESSAGES_V2") {
212
+ return {
213
+ ...baseMessage,
214
+ type: "event",
215
+ logMessageType: "log:thread-pinned",
216
+ logMessageData: {
217
+ pinned_message_id: data.extensible_message_admin_text?.pinned_message_id || null
218
+ },
219
+ logMessageBody: data.snippet
220
+ };
221
+ }
222
+
223
+ if (adminType === "UNPIN_MESSAGES_V2") {
224
+ return {
225
+ ...baseMessage,
226
+ type: "event",
227
+ logMessageType: "log:unpin-message",
228
+ logMessageData: {
229
+ unpinned_message_id: data.extensible_message_admin_text?.unpinned_message_id || null
230
+ },
231
+ logMessageBody: data.snippet
232
+ };
233
+ }
234
+
235
+ if (adminType === "JOINABLE_GROUP_LINK_MODE_CHANGE") {
236
+ return {
237
+ ...baseMessage,
238
+ type: "event",
239
+ logMessageType: "log:link-status",
240
+ logMessageData: {
241
+ link_status: data.extensible_message_admin_text?.joinable_mode || null
242
+ },
243
+ logMessageBody: data.snippet
244
+ };
245
+ }
246
+
247
+ if (adminType === "MAGIC_WORDS") {
248
+ return {
249
+ ...baseMessage,
250
+ type: "event",
251
+ logMessageType: "log:magic-words",
252
+ logMessageData: {
253
+ magic_word: data.extensible_message_admin_text?.magic_word || null
254
+ },
255
+ logMessageBody: data.snippet
256
+ };
257
+ }
258
+
259
+ return {
260
+ ...baseMessage,
261
+ type: "event",
262
+ logMessageType: "log:generic-admin",
263
+ logMessageData: { admin_type: adminType },
264
+ logMessageBody: data.snippet
265
+ };
266
+
267
+ case "UserMessage":
268
+ const attachments = [];
269
+
270
+ if (data.blob_attachments && data.blob_attachments.length > 0) {
271
+ data.blob_attachments.forEach(att => {
272
+ try {
273
+ const formatted = _formatAttachment(att);
274
+ attachments.push(formatted);
275
+ } catch (ex) {
276
+ attachments.push({
277
+ type: "unknown",
278
+ error: ex.message || ex,
279
+ rawAttachment: att
280
+ });
281
+ }
282
+ });
283
+ } else if (data.extensible_attachment && Object.keys(data.extensible_attachment).length > 0) {
284
+ try {
285
+ const formatted = _formatAttachment({ extensible_attachment: data.extensible_attachment });
286
+ attachments.push(formatted);
287
+ } catch (ex) {
288
+ const storyAtt = data.extensible_attachment.story_attachment || {};
289
+ attachments.push({
290
+ type: "share",
291
+ ID: data.extensible_attachment.legacy_attachment_id,
292
+ url: storyAtt.url,
293
+ title: storyAtt.title_with_entities ? storyAtt.title_with_entities.text : null,
294
+ description: storyAtt.description ? storyAtt.description.text : null,
295
+ source: storyAtt.source ? storyAtt.source.text : null,
296
+ image: storyAtt.media && storyAtt.media.image ? storyAtt.media.image.uri : null,
297
+ width: storyAtt.media && storyAtt.media.image ? storyAtt.media.image.width : null,
298
+ height: storyAtt.media && storyAtt.media.image ? storyAtt.media.image.height : null,
299
+ playable: storyAtt.media ? storyAtt.media.is_playable || false : false,
300
+ duration: storyAtt.media ? storyAtt.media.playable_duration_in_ms || 0 : 0,
301
+ playableUrl: storyAtt.media && storyAtt.media.playable_url ? storyAtt.media.playable_url : null,
302
+ subattachments: data.extensible_attachment.subattachments,
303
+ properties: storyAtt.properties || {}
304
+ });
305
+ }
306
+ }
307
+
308
+ const mentions = {};
309
+ if (data.message && data.message.ranges) {
310
+ data.message.ranges.forEach(mention => {
311
+ if (mention.entity && mention.entity.id && data.message.text) {
312
+ mentions[mention.entity.id] = data.message.text.substring(
313
+ mention.offset,
314
+ mention.offset + mention.length
315
+ );
316
+ }
317
+ });
318
+ }
319
+
320
+ return {
321
+ type: "message",
322
+ senderID: data.message_sender ? data.message_sender.id : null,
323
+ body: data.message && data.message.text ? data.message.text : "",
324
+ threadID: threadID,
325
+ messageID: data.message_id,
326
+ reactions: data.message_reactions ? data.message_reactions.map(r => ({ [r.user.id]: r.reaction })) : [],
327
+ attachments: attachments,
328
+ mentions: mentions,
329
+ timestamp: data.timestamp_precise
330
+ };
331
+
332
+ default:
333
+ utils.warn(`getMessage: Unknown message type "${data.__typename}"`);
334
+ return {
335
+ ...baseMessage,
336
+ type: "unknown",
337
+ data: data
338
+ };
339
+ }
340
+ }
341
+
342
+ function parseDelta(threadID, delta) {
343
+ if (delta.replied_to_message) {
344
+ return {
345
+ type: "message_reply",
346
+ ...formatMessage(threadID, delta),
347
+ messageReply: formatMessage(threadID, delta.replied_to_message.message)
348
+ };
349
+ } else {
350
+ return formatMessage(threadID, delta);
351
+ }
352
+ }
353
+
354
+ module.exports = function(defaultFuncs, api, ctx) {
355
+ return function getMessage(threadID, messageID, callback) {
356
+ let resolveFunc = function() {};
357
+ let rejectFunc = function() {};
358
+ const returnPromise = new Promise(function(resolve, reject) {
359
+ resolveFunc = resolve;
360
+ rejectFunc = reject;
361
+ });
362
+
363
+ if (!callback) {
364
+ callback = function(err, info) {
365
+ if (err) return rejectFunc(err);
366
+ resolveFunc(info);
367
+ };
368
+ }
369
+
370
+ if (!threadID || !messageID) {
371
+ return callback({ error: "getMessage: need threadID and messageID" });
372
+ }
373
+
374
+ const form = {
375
+ av: ctx.userID,
376
+ fb_dtsg: ctx.fb_dtsg,
377
+ queries: JSON.stringify({
378
+ o0: {
379
+ doc_id: "1768656253222505",
380
+ query_params: {
381
+ thread_and_message_id: {
382
+ thread_id: threadID,
383
+ message_id: messageID
384
+ }
385
+ }
386
+ }
387
+ })
388
+ };
389
+
390
+ defaultFuncs
391
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
392
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
393
+ .then(resData => {
394
+ if (!resData || resData.length === 0) {
395
+ throw { error: "getMessage: no response data" };
396
+ }
397
+
398
+ if (resData[resData.length - 1].error_results > 0) {
399
+ throw resData[0].o0.errors;
400
+ }
401
+
402
+ if (resData[resData.length - 1].successful_results === 0) {
403
+ throw {
404
+ error: "getMessage: there was no successful_results",
405
+ res: resData
406
+ };
407
+ }
408
+
409
+ const fetchData = resData[0].o0.data.message;
410
+ if (fetchData) {
411
+ callback(null, parseDelta(threadID, fetchData));
412
+ } else {
413
+ throw { error: "getMessage: message data not found" };
414
+ }
415
+ })
416
+ .catch(err => {
417
+ utils.error("getMessage", err);
418
+ callback(err);
419
+ });
420
+
421
+ return returnPromise;
422
+ };
423
+ };
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return async function getTheme(threadID, callback) {
7
+ if (!threadID) {
8
+ const error = new Error("threadID is required");
9
+ if (callback) return callback(error);
10
+ throw error;
11
+ }
12
+
13
+ let resolveFunc, rejectFunc;
14
+ const promise = new Promise((resolve, reject) => {
15
+ resolveFunc = resolve;
16
+ rejectFunc = reject;
17
+ });
18
+
19
+ const form = {
20
+ fb_api_caller_class: 'RelayModern',
21
+ fb_api_req_friendly_name: 'MWPThreadThemeQuery_AllThemesQuery',
22
+ variables: JSON.stringify({ version: "default" }),
23
+ server_timestamps: true,
24
+ doc_id: '24474714052117636',
25
+ };
26
+
27
+ try {
28
+ const resData = await defaultFuncs
29
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form, null, {
30
+ "x-fb-friendly-name": "MWPThreadThemeQuery_AllThemesQuery",
31
+ "x-fb-lsd": ctx.lsd,
32
+ "referer": `https://www.facebook.com/messages/t/${threadID}`
33
+ })
34
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
35
+
36
+ if (resData.errors) {
37
+ throw new Error(JSON.stringify(resData.errors));
38
+ }
39
+
40
+ if (!resData.data || !resData.data.messenger_thread_themes) {
41
+ throw new Error("Could not retrieve thread themes from response.");
42
+ }
43
+
44
+ const extractUrl = (obj) => {
45
+ if (!obj) return null;
46
+ if (typeof obj === 'string') return obj;
47
+ return obj.uri || obj.url || null;
48
+ };
49
+
50
+ const baseThemes = resData.data.messenger_thread_themes.map(themeData => {
51
+ if (!themeData || !themeData.id) return null;
52
+
53
+ return {
54
+ id: themeData.id,
55
+ name: themeData.name || '',
56
+ theme_idx: themeData.theme_idx,
57
+ accessibility_label: themeData.accessibility_label || themeData.name || ''
58
+ };
59
+ }).filter(t => t !== null);
60
+
61
+ const themesWithPreviews = await Promise.all(
62
+ baseThemes.map(async (baseTheme) => {
63
+ try {
64
+ const detailedTheme = await api.fetchThemeData(baseTheme.id);
65
+
66
+ const theme = {
67
+ ...baseTheme,
68
+ gradient_colors: detailedTheme.colors || [],
69
+ primary_color: detailedTheme.colors?.[0] || null
70
+ };
71
+
72
+ if (detailedTheme.backgroundImage) {
73
+ theme.background_image = detailedTheme.backgroundImage;
74
+ theme.preview_image_urls = {
75
+ light_mode: detailedTheme.backgroundImage,
76
+ dark_mode: detailedTheme.backgroundImage
77
+ };
78
+ }
79
+
80
+ return theme;
81
+ } catch (fetchErr) {
82
+ utils.error("getTheme - fetchThemeData", `Failed to fetch details for theme ${baseTheme.id}: ${fetchErr.message}`);
83
+ return baseTheme;
84
+ }
85
+ })
86
+ );
87
+
88
+ if (callback) {
89
+ callback(null, themesWithPreviews);
90
+ } else {
91
+ resolveFunc(themesWithPreviews);
92
+ }
93
+ } catch (err) {
94
+ utils.error("getTheme", err);
95
+ if (callback) {
96
+ callback(err);
97
+ } else {
98
+ rejectFunc(err);
99
+ }
100
+ }
101
+
102
+ return promise;
103
+ };
104
+ };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ return async function getThemeInfo(threadID, callback) {
7
+ if (!threadID) {
8
+ const error = new Error("threadID is required");
9
+ if (callback) return callback(error);
10
+ throw error;
11
+ }
12
+
13
+ let resolveFunc, rejectFunc;
14
+ const promise = new Promise((resolve, reject) => {
15
+ resolveFunc = resolve;
16
+ rejectFunc = reject;
17
+ });
18
+
19
+ try {
20
+ let threadInfo;
21
+ try {
22
+ threadInfo = await api.getThreadInfo(threadID);
23
+ } catch (getInfoErr) {
24
+ // If getThreadInfo fails, thread might not exist or access is restricted
25
+ // Return a basic theme info object with defaults
26
+ const themeInfo = {
27
+ threadID: threadID,
28
+ threadName: '',
29
+ color: null,
30
+ emoji: '👍',
31
+ theme_id: null,
32
+ theme_color: null,
33
+ gradient_colors: null,
34
+ is_default: true,
35
+ error: getInfoErr.message || 'Could not retrieve full thread info'
36
+ };
37
+
38
+ if (callback) {
39
+ return callback(null, themeInfo);
40
+ } else {
41
+ return resolveFunc(themeInfo);
42
+ }
43
+ }
44
+
45
+ if (!threadInfo || threadInfo.length === 0) {
46
+ // Thread exists but no info returned - return defaults
47
+ const themeInfo = {
48
+ threadID: threadID,
49
+ threadName: '',
50
+ color: null,
51
+ emoji: '👍',
52
+ theme_id: null,
53
+ theme_color: null,
54
+ gradient_colors: null,
55
+ is_default: true
56
+ };
57
+
58
+ if (callback) {
59
+ return callback(null, themeInfo);
60
+ } else {
61
+ return resolveFunc(themeInfo);
62
+ }
63
+ }
64
+
65
+ const info = Array.isArray(threadInfo) ? threadInfo[0] : threadInfo;
66
+
67
+ const themeInfo = {
68
+ threadID: threadID,
69
+ threadName: info.threadName || info.name || '',
70
+ color: info.color || null,
71
+ emoji: info.emoji || '👍',
72
+ theme_id: info.theme_id || info.themeID || null,
73
+ theme_color: info.theme_color || info.color || null,
74
+ gradient_colors: info.gradient_colors || null,
75
+ is_default: !info.color && !info.theme_id
76
+ };
77
+
78
+ if (callback) {
79
+ callback(null, themeInfo);
80
+ } else {
81
+ resolveFunc(themeInfo);
82
+ }
83
+ } catch (err) {
84
+ // Preserve the original error message from getThreadInfo
85
+ // Don't override with generic "Could not retrieve thread info"
86
+ utils.error("getThemeInfo", err);
87
+ if (callback) {
88
+ callback(err);
89
+ } else {
90
+ rejectFunc(err);
91
+ }
92
+ }
93
+
94
+ return promise;
95
+ };
96
+ };