bb-fca 2.0.9 → 2.0.10
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/dist/deltas/apis/messaging/editMessage.js +13 -24
- package/dist/deltas/apis/messaging/editMessage.js.map +1 -1
- package/dist/deltas/apis/messaging/emoji.js +34 -88
- package/dist/deltas/apis/messaging/emoji.js.map +1 -1
- package/dist/deltas/apis/messaging/gcmember.js +48 -101
- package/dist/deltas/apis/messaging/gcmember.js.map +1 -1
- package/dist/deltas/apis/messaging/gcname.js +28 -79
- package/dist/deltas/apis/messaging/gcname.js.map +1 -1
- package/dist/deltas/apis/messaging/gcrule.js +47 -105
- package/dist/deltas/apis/messaging/gcrule.js.map +1 -1
- package/dist/deltas/apis/messaging/markAsDelivered.js +10 -12
- package/dist/deltas/apis/messaging/markAsDelivered.js.map +1 -1
- package/dist/deltas/apis/messaging/markAsRead.js +25 -60
- package/dist/deltas/apis/messaging/markAsRead.js.map +1 -1
- package/dist/deltas/apis/messaging/markAsReadAll.js +9 -11
- package/dist/deltas/apis/messaging/markAsReadAll.js.map +1 -1
- package/dist/deltas/apis/messaging/markAsSeen.js +10 -37
- package/dist/deltas/apis/messaging/markAsSeen.js.map +1 -1
- package/dist/deltas/apis/messaging/nickname.js +38 -98
- package/dist/deltas/apis/messaging/nickname.js.map +1 -1
- package/dist/deltas/apis/messaging/notes.js +52 -90
- package/dist/deltas/apis/messaging/notes.js.map +1 -1
- package/dist/deltas/apis/messaging/resolvePhotoUrl.js +17 -42
- package/dist/deltas/apis/messaging/resolvePhotoUrl.js.map +1 -1
- package/dist/deltas/apis/messaging/sendMessage.js +14 -15
- package/dist/deltas/apis/messaging/sendMessage.js.map +1 -1
- package/dist/deltas/apis/messaging/sendTypingIndicator.js +7 -13
- package/dist/deltas/apis/messaging/sendTypingIndicator.js.map +1 -1
- package/dist/deltas/apis/messaging/setMessageReaction.js +24 -14
- package/dist/deltas/apis/messaging/setMessageReaction.js.map +1 -1
- package/dist/deltas/apis/messaging/shareContact.js +14 -12
- package/dist/deltas/apis/messaging/shareContact.js.map +1 -1
- package/dist/deltas/apis/messaging/stickers.js +4 -5
- package/dist/deltas/apis/messaging/stickers.js.map +1 -1
- package/dist/deltas/apis/messaging/theme.js +142 -213
- package/dist/deltas/apis/messaging/theme.js.map +1 -1
- package/dist/deltas/apis/messaging/unsendMessage.js +14 -7
- package/dist/deltas/apis/messaging/unsendMessage.js.map +1 -1
- package/dist/deltas/apis/posting/group.js +33 -11
- package/dist/deltas/apis/posting/group.js.map +1 -1
- package/dist/types/deltas/apis/messaging/editMessage.d.ts +4 -5
- package/dist/types/deltas/apis/messaging/emoji.d.ts +7 -1
- package/dist/types/deltas/apis/messaging/gcmember.d.ts +7 -1
- package/dist/types/deltas/apis/messaging/gcname.d.ts +9 -1
- package/dist/types/deltas/apis/messaging/gcrule.d.ts +7 -1
- package/dist/types/deltas/apis/messaging/markAsDelivered.d.ts +1 -2
- package/dist/types/deltas/apis/messaging/markAsRead.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/markAsReadAll.d.ts +1 -2
- package/dist/types/deltas/apis/messaging/markAsSeen.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/nickname.d.ts +7 -1
- package/dist/types/deltas/apis/messaging/notes.d.ts +13 -11
- package/dist/types/deltas/apis/messaging/resolvePhotoUrl.d.ts +4 -6
- package/dist/types/deltas/apis/messaging/sendMessage.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/sendTypingIndicator.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/setMessageReaction.d.ts +6 -1
- package/dist/types/deltas/apis/messaging/shareContact.d.ts +1 -2
- package/dist/types/deltas/apis/messaging/stickers.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/theme.d.ts +8 -1
- package/dist/types/deltas/apis/messaging/unsendMessage.d.ts +6 -1
- package/package.json +1 -1
- package/src/deltas/apis/messaging/editMessage.ts +16 -26
- package/src/deltas/apis/messaging/emoji.ts +45 -97
- package/src/deltas/apis/messaging/gcmember.ts +68 -113
- package/src/deltas/apis/messaging/gcname.ts +42 -91
- package/src/deltas/apis/messaging/gcrule.ts +61 -111
- package/src/deltas/apis/messaging/markAsDelivered.ts +19 -14
- package/src/deltas/apis/messaging/markAsRead.ts +45 -72
- package/src/deltas/apis/messaging/markAsReadAll.ts +17 -17
- package/src/deltas/apis/messaging/markAsSeen.ts +17 -41
- package/src/deltas/apis/messaging/nickname.ts +50 -116
- package/src/deltas/apis/messaging/notes.ts +59 -95
- package/src/deltas/apis/messaging/resolvePhotoUrl.ts +27 -50
- package/src/deltas/apis/messaging/sendMessage.ts +28 -26
- package/src/deltas/apis/messaging/sendTypingIndicator.ts +13 -12
- package/src/deltas/apis/messaging/setMessageReaction.ts +45 -20
- package/src/deltas/apis/messaging/shareContact.ts +25 -15
- package/src/deltas/apis/messaging/stickers.ts +4 -4
- package/src/deltas/apis/messaging/theme.ts +172 -259
- package/src/deltas/apis/messaging/unsendMessage.ts +23 -7
- package/src/deltas/apis/posting/group.ts +36 -11
- package/request.txt +0 -60
|
@@ -1,87 +1,45 @@
|
|
|
1
1
|
import utils = require('../../../utils');
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Made by Choru Official
|
|
5
|
+
* Sets the name of a group chat thread via MQTT.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} defaultFuncs
|
|
8
|
+
* @param {Object} api
|
|
9
|
+
* @param {Object} ctx
|
|
10
|
+
*/
|
|
11
|
+
export default function gcname(
|
|
12
|
+
defaultFuncs: any,
|
|
13
|
+
api: any,
|
|
14
|
+
ctx: any,
|
|
15
|
+
): Function {
|
|
4
16
|
/**
|
|
5
|
-
* Made by Choru Official
|
|
6
|
-
* Mqtt
|
|
7
17
|
* Sets the name of a group chat thread via MQTT.
|
|
8
|
-
*
|
|
9
|
-
* @param {string}
|
|
10
|
-
* @param {string}
|
|
11
|
-
* @
|
|
12
|
-
* @param {string} [initiatorID] The ID of the user who initiated the group name change (e.g., from event.senderID).
|
|
13
|
-
* @returns {Promise<object>} A promise that resolves with a structured event object on success or rejects on error.
|
|
18
|
+
* @param {string} newName - The new name for the group chat.
|
|
19
|
+
* @param {string} threadID - The ID of the group chat thread.
|
|
20
|
+
* @param {string} [initiatorID] - The ID of the user who initiated the change.
|
|
21
|
+
* @returns {Promise<object>}
|
|
14
22
|
*/
|
|
15
|
-
return function gcname(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let _rejectPromise;
|
|
21
|
-
const returnPromise = new Promise<any>((resolve, reject) => {
|
|
22
|
-
_resolvePromise = resolve;
|
|
23
|
-
_rejectPromise = reject;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
utils.getType(callback) === 'Function' ||
|
|
28
|
-
utils.getType(callback) === 'AsyncFunction'
|
|
29
|
-
) {
|
|
30
|
-
_callback = callback;
|
|
31
|
-
_initiatorID = initiatorID;
|
|
32
|
-
} else if (
|
|
33
|
-
utils.getType(threadID) === 'Function' ||
|
|
34
|
-
utils.getType(threadID) === 'AsyncFunction'
|
|
35
|
-
) {
|
|
36
|
-
_callback = threadID;
|
|
37
|
-
threadID = null;
|
|
38
|
-
_initiatorID = callback;
|
|
39
|
-
} else if (utils.getType(callback) === 'string') {
|
|
40
|
-
_initiatorID = callback;
|
|
41
|
-
_callback = undefined;
|
|
42
|
-
} else {
|
|
43
|
-
_callback = undefined;
|
|
44
|
-
_initiatorID = undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!_callback) {
|
|
48
|
-
_callback = function(__err, __data) {
|
|
49
|
-
if (__err) _rejectPromise(__err);
|
|
50
|
-
else _resolvePromise(__data);
|
|
51
|
-
};
|
|
52
|
-
} else {
|
|
53
|
-
const originalCallback = _callback;
|
|
54
|
-
_callback = function(__err, __data) {
|
|
55
|
-
if (__err) {
|
|
56
|
-
originalCallback(__err);
|
|
57
|
-
_rejectPromise(__err);
|
|
58
|
-
} else {
|
|
59
|
-
originalCallback(null, __data);
|
|
60
|
-
_resolvePromise(__data);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
_initiatorID = _initiatorID || ctx.userID;
|
|
66
|
-
|
|
67
|
-
threadID = threadID || ctx.threadID;
|
|
68
|
-
|
|
23
|
+
return async function gcname(
|
|
24
|
+
newName: string,
|
|
25
|
+
threadID: string,
|
|
26
|
+
initiatorID?: string,
|
|
27
|
+
): Promise<any> {
|
|
69
28
|
if (!threadID) {
|
|
70
|
-
|
|
71
|
-
new Error('threadID is required to change the group chat name.'),
|
|
72
|
-
);
|
|
29
|
+
throw new Error('threadID is required to change the group chat name.');
|
|
73
30
|
}
|
|
74
31
|
if (typeof newName !== 'string') {
|
|
75
|
-
|
|
32
|
+
throw new Error('newName must be a string.');
|
|
76
33
|
}
|
|
77
|
-
|
|
78
34
|
if (!ctx.mqttClient) {
|
|
79
|
-
|
|
35
|
+
throw new Error('Not connected to MQTT');
|
|
80
36
|
}
|
|
81
37
|
|
|
82
38
|
ctx.wsReqNumber += 1;
|
|
83
39
|
ctx.wsTaskNumber += 1;
|
|
84
40
|
|
|
41
|
+
const _initiatorID = initiatorID || ctx.userID;
|
|
42
|
+
|
|
85
43
|
const queryPayload = {
|
|
86
44
|
thread_key: threadID.toString(),
|
|
87
45
|
thread_name: newName,
|
|
@@ -108,29 +66,22 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
108
66
|
};
|
|
109
67
|
context.payload = JSON.stringify(context.payload);
|
|
110
68
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
new Error(`MQTT publish failed for gcname: ${err.message || err}`),
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const gcnameChangeEvent = {
|
|
123
|
-
type: 'thread_name_update',
|
|
124
|
-
threadID: threadID,
|
|
125
|
-
newName: newName,
|
|
126
|
-
senderID: _initiatorID,
|
|
127
|
-
BotID: ctx.userID,
|
|
128
|
-
timestamp: Date.now(),
|
|
129
|
-
};
|
|
130
|
-
_callback(null, gcnameChangeEvent);
|
|
131
|
-
},
|
|
69
|
+
await new Promise<void>((resolve, reject) =>
|
|
70
|
+
ctx.mqttClient.publish(
|
|
71
|
+
'/ls_req',
|
|
72
|
+
JSON.stringify(context),
|
|
73
|
+
{ qos: 1, retain: false },
|
|
74
|
+
(err) => (err ? reject(new Error(`MQTT publish failed for gcname: ${err.message || err}`)) : resolve()),
|
|
75
|
+
),
|
|
132
76
|
);
|
|
133
77
|
|
|
134
|
-
return
|
|
78
|
+
return {
|
|
79
|
+
type: 'thread_name_update',
|
|
80
|
+
threadID,
|
|
81
|
+
newName,
|
|
82
|
+
senderID: _initiatorID,
|
|
83
|
+
BotID: ctx.userID,
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
};
|
|
135
86
|
};
|
|
136
87
|
}
|
|
@@ -1,108 +1,62 @@
|
|
|
1
1
|
import utils = require('../../../utils');
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @module gcrule
|
|
5
|
+
* @param {Object} defaultFuncs
|
|
6
|
+
* @param {Object} api
|
|
7
|
+
* @param {Object} ctx
|
|
8
|
+
*/
|
|
9
|
+
export default function gcrule(
|
|
10
|
+
defaultFuncs: any,
|
|
11
|
+
api: any,
|
|
12
|
+
ctx: any,
|
|
13
|
+
): Function {
|
|
4
14
|
/**
|
|
5
|
-
* Made by ChoruOfficial
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
* @param {string} userID The ID of the user to promote or demote.
|
|
11
|
-
* @param {string} threadID The ID of the group chat.
|
|
12
|
-
* @param {Function} [callback] Optional callback function.
|
|
13
|
-
* @returns {Promise<object>} A promise that resolves with information about the action.
|
|
15
|
+
* Made by ChoruOfficial — Promotes or demotes a group chat member admin status via MQTT.
|
|
16
|
+
* @param {"admin" | "unadmin"} action - The action to perform.
|
|
17
|
+
* @param {string} userID - The user ID to promote or demote.
|
|
18
|
+
* @param {string} threadID - The ID of the group chat.
|
|
19
|
+
* @returns {Promise<object>}
|
|
14
20
|
*/
|
|
15
|
-
return async function gcrule(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let resolvePromise, rejectPromise;
|
|
25
|
-
const returnPromise = new Promise<any>((resolve, reject) => {
|
|
26
|
-
resolvePromise = resolve;
|
|
27
|
-
rejectPromise = reject;
|
|
28
|
-
});
|
|
21
|
+
return async function gcrule(
|
|
22
|
+
action: 'admin' | 'unadmin',
|
|
23
|
+
userID: string,
|
|
24
|
+
threadID: string,
|
|
25
|
+
): Promise<any> {
|
|
26
|
+
const validActions = ['admin', 'unadmin'];
|
|
27
|
+
const normalizedAction = (action || '').toLowerCase() as 'admin' | 'unadmin';
|
|
29
28
|
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
if (err) return rejectPromise(err);
|
|
33
|
-
resolvePromise(data);
|
|
34
|
-
};
|
|
29
|
+
if (!validActions.includes(normalizedAction)) {
|
|
30
|
+
return { type: 'error_gc_rule', error: `Invalid action. Must be one of: ${validActions.join(', ')}` };
|
|
35
31
|
}
|
|
32
|
+
if (!userID) return { type: 'error_gc_rule', error: 'userID is required.' };
|
|
33
|
+
if (!threadID) return { type: 'error_gc_rule', error: 'threadID is required.' };
|
|
34
|
+
if (!ctx.mqttClient) return { type: 'error_gc_rule', error: 'Not connected to MQTT' };
|
|
36
35
|
|
|
37
36
|
try {
|
|
38
|
-
const validActions = ['admin', 'unadmin'];
|
|
39
|
-
action = action ? action.toLowerCase() : '';
|
|
40
|
-
|
|
41
|
-
if (!validActions.includes(action)) {
|
|
42
|
-
return _callback(null, {
|
|
43
|
-
type: 'error_gc_rule',
|
|
44
|
-
error: `Invalid action. Must be one of: ${validActions.join(', ')}`,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
if (!userID)
|
|
48
|
-
return _callback(null, {
|
|
49
|
-
type: 'error_gc_rule',
|
|
50
|
-
error: 'userID is required.',
|
|
51
|
-
});
|
|
52
|
-
if (!threadID)
|
|
53
|
-
return _callback(null, {
|
|
54
|
-
type: 'error_gc_rule',
|
|
55
|
-
error: 'threadID is required.',
|
|
56
|
-
});
|
|
57
|
-
if (!ctx.mqttClient)
|
|
58
|
-
return _callback(null, {
|
|
59
|
-
type: 'error_gc_rule',
|
|
60
|
-
error: 'Not connected to MQTT',
|
|
61
|
-
});
|
|
62
|
-
|
|
63
37
|
const threadInfo = await api.getThreadInfo(threadID);
|
|
64
|
-
if (!threadInfo) {
|
|
65
|
-
|
|
66
|
-
type: 'error_gc_rule',
|
|
67
|
-
error: 'Could not retrieve thread information.',
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (threadInfo.isGroup === false) {
|
|
71
|
-
return _callback(null, {
|
|
72
|
-
type: 'error_gc_rule',
|
|
73
|
-
error: 'This feature is only for group chats.',
|
|
74
|
-
});
|
|
75
|
-
}
|
|
38
|
+
if (!threadInfo) return { type: 'error_gc_rule', error: 'Could not retrieve thread information.' };
|
|
39
|
+
if (threadInfo.isGroup === false) return { type: 'error_gc_rule', error: 'This feature is only for group chats.' };
|
|
76
40
|
|
|
77
|
-
const adminIDs = threadInfo.adminIDs || [];
|
|
41
|
+
const adminIDs: { id: string }[] = threadInfo.adminIDs || [];
|
|
78
42
|
const isCurrentlyAdmin = adminIDs.some((admin) => admin.id === userID);
|
|
79
43
|
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
// action is 'unadmin'
|
|
89
|
-
if (!isCurrentlyAdmin) {
|
|
90
|
-
return _callback(null, {
|
|
91
|
-
type: 'error_gc_rule',
|
|
92
|
-
error: `User is not an admin.`,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
44
|
+
if (normalizedAction === 'admin' && isCurrentlyAdmin) {
|
|
45
|
+
return { type: 'error_gc_rule', error: 'User is already an admin.' };
|
|
46
|
+
}
|
|
47
|
+
if (normalizedAction === 'unadmin' && !isCurrentlyAdmin) {
|
|
48
|
+
return { type: 'error_gc_rule', error: 'User is not an admin.' };
|
|
95
49
|
}
|
|
96
50
|
|
|
97
|
-
const isAdminStatus = action === 'admin' ? 1 : 0;
|
|
98
51
|
ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
|
|
99
52
|
ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
|
|
100
53
|
|
|
101
54
|
const queryPayload = {
|
|
102
|
-
thread_key: parseInt(threadID),
|
|
103
|
-
contact_id: parseInt(userID),
|
|
104
|
-
is_admin:
|
|
55
|
+
thread_key: Number.parseInt(threadID),
|
|
56
|
+
contact_id: Number.parseInt(userID),
|
|
57
|
+
is_admin: normalizedAction === 'admin' ? 1 : 0,
|
|
105
58
|
};
|
|
59
|
+
|
|
106
60
|
const query = {
|
|
107
61
|
failure_count: null,
|
|
108
62
|
label: '25',
|
|
@@ -110,10 +64,11 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
110
64
|
queue_name: 'admin_status',
|
|
111
65
|
task_id: ctx.wsTaskNumber,
|
|
112
66
|
};
|
|
67
|
+
|
|
113
68
|
const context: any = {
|
|
114
69
|
app_id: ctx.appID,
|
|
115
70
|
payload: {
|
|
116
|
-
epoch_id: parseInt(utils.generateOfflineThreadingID()),
|
|
71
|
+
epoch_id: Number.parseInt(utils.generateOfflineThreadingID()),
|
|
117
72
|
tasks: [query],
|
|
118
73
|
version_id: '24631415369801570',
|
|
119
74
|
},
|
|
@@ -122,31 +77,26 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
122
77
|
};
|
|
123
78
|
context.payload = JSON.stringify(context.payload);
|
|
124
79
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
type: 'gc_rule_update',
|
|
133
|
-
threadID: threadID,
|
|
134
|
-
userID: userID,
|
|
135
|
-
action: action,
|
|
136
|
-
senderID: ctx.userID,
|
|
137
|
-
BotID: ctx.userID,
|
|
138
|
-
timestamp: Date.now(),
|
|
139
|
-
};
|
|
140
|
-
return _callback(null, gcruleInfo);
|
|
141
|
-
},
|
|
80
|
+
await new Promise<void>((resolve, reject) =>
|
|
81
|
+
ctx.mqttClient.publish(
|
|
82
|
+
'/ls_req',
|
|
83
|
+
JSON.stringify(context),
|
|
84
|
+
{ qos: 1, retain: false },
|
|
85
|
+
(err) => (err ? reject(err) : resolve()),
|
|
86
|
+
),
|
|
142
87
|
);
|
|
143
|
-
} catch (err) {
|
|
144
|
-
return _callback(null, {
|
|
145
|
-
type: 'error_gc_rule',
|
|
146
|
-
error: err.message || 'An unknown error occurred.',
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
88
|
|
|
150
|
-
|
|
89
|
+
return {
|
|
90
|
+
type: 'gc_rule_update',
|
|
91
|
+
threadID,
|
|
92
|
+
userID,
|
|
93
|
+
action: normalizedAction,
|
|
94
|
+
senderID: ctx.userID,
|
|
95
|
+
BotID: ctx.userID,
|
|
96
|
+
timestamp: Date.now(),
|
|
97
|
+
};
|
|
98
|
+
} catch (err: any) {
|
|
99
|
+
return { type: 'error_gc_rule', error: err.message || 'An unknown error occurred.' };
|
|
100
|
+
}
|
|
151
101
|
};
|
|
152
102
|
}
|
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
// @ChoruOfficial
|
|
2
|
-
|
|
2
|
+
import utils = require('../../../utils');
|
|
3
3
|
|
|
4
|
-
import utils = require("../../../utils");
|
|
5
4
|
/**
|
|
6
5
|
* @param {Object} defaultFuncs
|
|
7
6
|
* @param {Object} api
|
|
8
7
|
* @param {Object} ctx
|
|
9
|
-
* @returns {function(threadID: string, messageID: string): Promise<void>}
|
|
10
8
|
*/
|
|
11
|
-
export default function(
|
|
9
|
+
export default function markAsDelivered(
|
|
10
|
+
defaultFuncs: any,
|
|
11
|
+
api: any,
|
|
12
|
+
ctx: any,
|
|
13
|
+
): Function {
|
|
12
14
|
/**
|
|
13
15
|
* Marks a message as delivered.
|
|
14
16
|
* @param {string} threadID - The ID of the thread.
|
|
15
17
|
* @param {string} messageID - The ID of the message to mark as delivered.
|
|
16
|
-
* @returns {Promise<void>}
|
|
18
|
+
* @returns {Promise<void>}
|
|
17
19
|
*/
|
|
18
|
-
return async function markAsDelivered(
|
|
20
|
+
return async function markAsDelivered(
|
|
21
|
+
threadID: string,
|
|
22
|
+
messageID: string,
|
|
23
|
+
): Promise<void> {
|
|
19
24
|
if (!threadID || !messageID) {
|
|
20
|
-
const err =
|
|
21
|
-
utils.error(
|
|
25
|
+
const err = 'Error: messageID or threadID is not defined';
|
|
26
|
+
utils.error('markAsDelivered', err);
|
|
22
27
|
throw new Error(err);
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
const form = {};
|
|
26
|
-
form[
|
|
27
|
-
form[
|
|
30
|
+
const form: Record<string, any> = {};
|
|
31
|
+
form['message_ids[0]'] = messageID;
|
|
32
|
+
form['thread_ids[' + threadID + '][0]'] = messageID;
|
|
28
33
|
|
|
29
34
|
try {
|
|
30
35
|
const resData = await defaultFuncs
|
|
31
36
|
.post(
|
|
32
|
-
|
|
37
|
+
'https://www.facebook.com/ajax/mercury/delivery_receipts.php',
|
|
33
38
|
ctx.jar,
|
|
34
39
|
form,
|
|
35
40
|
)
|
|
@@ -40,8 +45,8 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
40
45
|
throw resData;
|
|
41
46
|
}
|
|
42
47
|
} catch (err) {
|
|
43
|
-
utils.error(
|
|
48
|
+
utils.error('markAsDelivered', err);
|
|
44
49
|
throw err;
|
|
45
50
|
}
|
|
46
51
|
};
|
|
47
|
-
}
|
|
52
|
+
}
|
|
@@ -1,94 +1,67 @@
|
|
|
1
1
|
// @ChoruOfficial
|
|
2
|
-
import utils = require(
|
|
2
|
+
import utils = require('../../../utils');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @param {Object} defaultFuncs
|
|
6
6
|
* @param {Object} api
|
|
7
7
|
* @param {Object} ctx
|
|
8
8
|
*/
|
|
9
|
-
export default function(
|
|
9
|
+
export default function markAsRead(
|
|
10
|
+
defaultFuncs: any,
|
|
11
|
+
api: any,
|
|
12
|
+
ctx: any,
|
|
13
|
+
): Function {
|
|
10
14
|
/**
|
|
11
|
-
* Marks a thread as read.
|
|
15
|
+
* Marks a thread as read or unread.
|
|
12
16
|
* @param {string} threadID - The ID of the thread to mark as read.
|
|
13
|
-
* @param {boolean} [read=true] - Whether to mark as read (true) or unread (false).
|
|
14
|
-
* @
|
|
15
|
-
* @returns {Promise<null|Error>} A Promise that resolves with null on success, or rejects with an Error.
|
|
17
|
+
* @param {boolean} [read=true] - Whether to mark as read (true) or unread (false).
|
|
18
|
+
* @returns {Promise<null>}
|
|
16
19
|
*/
|
|
17
|
-
return async function markAsRead(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
callback = read;
|
|
23
|
-
read = true;
|
|
24
|
-
}
|
|
25
|
-
if (read == undefined) {
|
|
26
|
-
read = true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!callback) {
|
|
30
|
-
callback = () => {};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const form = {};
|
|
20
|
+
return async function markAsRead(
|
|
21
|
+
threadID: string,
|
|
22
|
+
read: boolean = true,
|
|
23
|
+
): Promise<null> {
|
|
24
|
+
const form: Record<string, any> = {};
|
|
34
25
|
|
|
35
|
-
if (typeof ctx.globalOptions.pageID !==
|
|
36
|
-
form[
|
|
37
|
-
form[
|
|
38
|
-
form[
|
|
39
|
-
form[
|
|
40
|
-
form[
|
|
41
|
-
form[
|
|
26
|
+
if (typeof ctx.globalOptions.pageID !== 'undefined') {
|
|
27
|
+
form['source'] = 'PagesManagerMessagesInterface';
|
|
28
|
+
form['request_user_id'] = ctx.globalOptions.pageID;
|
|
29
|
+
form['ids[' + threadID + ']'] = read;
|
|
30
|
+
form['watermarkTimestamp'] = new Date().getTime();
|
|
31
|
+
form['shouldSendReadReceipt'] = true;
|
|
32
|
+
form['commerce_last_message_type'] = '';
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.then(utils.saveCookies(ctx.jar))
|
|
52
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
53
|
-
} catch (e) {
|
|
54
|
-
callback(e);
|
|
55
|
-
return e;
|
|
56
|
-
}
|
|
34
|
+
const resData = await defaultFuncs
|
|
35
|
+
.post(
|
|
36
|
+
'https://www.facebook.com/ajax/mercury/change_read_status.php',
|
|
37
|
+
ctx.jar,
|
|
38
|
+
form,
|
|
39
|
+
)
|
|
40
|
+
.then(utils.saveCookies(ctx.jar))
|
|
41
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
57
42
|
|
|
58
43
|
if (resData.error) {
|
|
59
44
|
const err = resData.error;
|
|
60
|
-
utils.error(
|
|
61
|
-
|
|
62
|
-
return err;
|
|
45
|
+
utils.error('markAsRead', err);
|
|
46
|
+
throw new Error(err);
|
|
63
47
|
}
|
|
64
48
|
|
|
65
|
-
callback();
|
|
66
49
|
return null;
|
|
67
50
|
} else {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"/mark_thread",
|
|
73
|
-
JSON.stringify({
|
|
74
|
-
threadID,
|
|
75
|
-
mark: "read",
|
|
76
|
-
state: read,
|
|
77
|
-
}),
|
|
78
|
-
{ qos: 1, retain: false },
|
|
79
|
-
r,
|
|
80
|
-
),
|
|
81
|
-
);
|
|
82
|
-
if (err) throw err;
|
|
83
|
-
} else {
|
|
84
|
-
throw {
|
|
85
|
-
error: "You can only use this function after you start listening.",
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
} catch (e) {
|
|
89
|
-
callback(e);
|
|
90
|
-
return e;
|
|
51
|
+
if (!ctx.mqttClient) {
|
|
52
|
+
throw {
|
|
53
|
+
error: 'You can only use this function after you start listening.',
|
|
54
|
+
};
|
|
91
55
|
}
|
|
56
|
+
await new Promise<void>((resolve, reject) =>
|
|
57
|
+
ctx.mqttClient.publish(
|
|
58
|
+
'/mark_thread',
|
|
59
|
+
JSON.stringify({ threadID, mark: 'read', state: read }),
|
|
60
|
+
{ qos: 1, retain: false },
|
|
61
|
+
(err) => (err ? reject(err) : resolve()),
|
|
62
|
+
),
|
|
63
|
+
);
|
|
92
64
|
}
|
|
65
|
+
return null;
|
|
93
66
|
};
|
|
94
|
-
}
|
|
67
|
+
}
|
|
@@ -5,31 +5,31 @@ import utils = require('../../../utils');
|
|
|
5
5
|
* @param {Object} defaultFuncs
|
|
6
6
|
* @param {Object} api
|
|
7
7
|
* @param {Object} ctx
|
|
8
|
-
* @returns {function(): Promise<void>}
|
|
9
8
|
*/
|
|
10
|
-
export default function(
|
|
9
|
+
export default function markAsReadAll(
|
|
10
|
+
defaultFuncs: any,
|
|
11
|
+
api: any,
|
|
12
|
+
ctx: any,
|
|
13
|
+
): Function {
|
|
11
14
|
/**
|
|
15
|
+
* Marks all messages in the inbox as read.
|
|
12
16
|
* @returns {Promise<void>}
|
|
13
17
|
*/
|
|
14
|
-
return async function markAsReadAll() {
|
|
15
|
-
const form = {
|
|
16
|
-
folder: 'inbox',
|
|
17
|
-
};
|
|
18
|
+
return async function markAsReadAll(): Promise<void> {
|
|
19
|
+
const form = { folder: 'inbox' };
|
|
18
20
|
|
|
19
21
|
try {
|
|
20
|
-
const resData = await defaultFuncs
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const resData = await defaultFuncs
|
|
23
|
+
.post(
|
|
24
|
+
'https://www.facebook.com/ajax/mercury/mark_folder_as_read.php',
|
|
25
|
+
ctx.jar,
|
|
26
|
+
form,
|
|
27
|
+
)
|
|
28
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (parsedData.error) {
|
|
29
|
-
throw parsedData;
|
|
30
|
+
if (resData.error) {
|
|
31
|
+
throw resData;
|
|
30
32
|
}
|
|
31
|
-
|
|
32
|
-
return;
|
|
33
33
|
} catch (err) {
|
|
34
34
|
utils.error('markAsReadAll', err);
|
|
35
35
|
throw err;
|