@baileys-md/baileys 11.2.4 → 12.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.
- package/LICENSE +1 -1
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +70084 -131686
- package/lib/Defaults/index.js +118 -117
- package/lib/KeyDB/BinarySearch.js +20 -0
- package/lib/KeyDB/KeyedDB.js +167 -0
- package/lib/KeyDB/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.js +13 -0
- package/lib/Signal/Group/group-session-builder.js +32 -0
- package/lib/Signal/Group/group_cipher.js +84 -0
- package/lib/Signal/Group/index.js +13 -0
- package/lib/Signal/Group/keyhelper.js +20 -0
- package/lib/Signal/Group/sender-chain-key.js +28 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +65 -0
- package/lib/Signal/Group/sender-key-message.js +68 -0
- package/{WASignalGroup/sender_key_name.js → lib/Signal/Group/sender-key-name.js} +10 -28
- package/lib/Signal/Group/sender-key-record.js +43 -0
- package/lib/Signal/Group/sender-key-state.js +86 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +314 -151
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -19
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +847 -844
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -319
- package/lib/Socket/index.js +15 -9
- package/lib/Socket/messages-recv.js +1109 -989
- package/lib/Socket/messages-send.js +611 -347
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +230 -231
- package/lib/Socket/socket.js +795 -616
- package/lib/Store/index.js +6 -8
- package/lib/Store/make-cache-manager-store.js +73 -81
- package/lib/Store/make-in-memory-store.js +286 -427
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +9 -4
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +12 -7
- package/lib/Types/Newsletter.js +32 -17
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -2
- package/lib/Types/State.js +11 -2
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +27 -41
- package/lib/Utils/auth-utils.js +211 -198
- package/lib/Utils/baileys-event-stream.js +42 -61
- package/lib/Utils/browser-utils.js +25 -0
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +711 -689
- package/lib/Utils/crypto.js +112 -133
- package/lib/Utils/decode-wa-message.js +254 -186
- package/lib/Utils/event-buffer.js +510 -502
- package/lib/Utils/generics.js +318 -408
- package/lib/Utils/history.js +83 -90
- package/lib/Utils/index.js +21 -33
- package/lib/Utils/link-preview.js +71 -116
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +575 -671
- package/lib/Utils/messages.js +354 -462
- package/lib/Utils/noise-handler.js +138 -149
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +323 -354
- package/lib/Utils/signal.js +148 -130
- package/lib/Utils/use-multi-file-auth-state.js +109 -91
- package/lib/Utils/validate-connection.js +183 -190
- package/lib/WABinary/constants.js +1298 -35
- package/lib/WABinary/decode.js +231 -256
- package/lib/WABinary/encode.js +207 -239
- package/lib/WABinary/generic-utils.js +119 -40
- package/lib/WABinary/index.js +7 -21
- package/lib/WABinary/jid-utils.js +88 -64
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.js +10 -12
- package/lib/WAM/constants.js +22851 -15348
- package/lib/WAM/encode.js +135 -136
- package/lib/WAM/index.js +5 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +86 -85
- package/lib/WAUSync/USyncUser.js +23 -25
- package/lib/WAUSync/index.js +5 -19
- package/lib/index.js +18 -33
- package/package.json +52 -57
- package/README.md +0 -2
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/WASignalGroup/sender_message_key.js +0 -39
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/make-mongo-store.js +0 -567
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { getBinaryNodeChild, S_WHATSAPP_NET } from "../WABinary/index.js";
|
|
3
|
+
import { Boom } from "@hapi/boom";
|
|
4
|
+
//=======================================================//
|
|
5
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
6
|
+
return query({
|
|
7
|
+
tag: "iq",
|
|
8
|
+
attrs: {
|
|
9
|
+
id: generateMessageTag(),
|
|
10
|
+
type: "get",
|
|
11
|
+
to: S_WHATSAPP_NET,
|
|
12
|
+
xmlns: "w:mex"
|
|
13
|
+
},
|
|
14
|
+
content: [
|
|
15
|
+
{
|
|
16
|
+
tag: "query",
|
|
17
|
+
attrs: { query_id: queryId },
|
|
18
|
+
content: Buffer.from(JSON.stringify({ variables }), "utf-8")
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
//=======================================================//
|
|
24
|
+
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
25
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
26
|
+
const child = getBinaryNodeChild(result, "result");
|
|
27
|
+
if (child?.content) {
|
|
28
|
+
const data = JSON.parse(child.content.toString());
|
|
29
|
+
if (data.errors && data.errors.length > 0) {
|
|
30
|
+
const errorMessages = data.errors.map((err) => err.message || "Unknown error").join(", ");
|
|
31
|
+
const firstError = data.errors[0];
|
|
32
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
33
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
34
|
+
}
|
|
35
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
36
|
+
if (typeof response !== "undefined") {
|
|
37
|
+
return response;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const action = (dataPath || "").startsWith("xwa2_")
|
|
41
|
+
? dataPath.substring(5).replace(/_/g, " ")
|
|
42
|
+
: dataPath?.replace(/_/g, " ");
|
|
43
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
44
|
+
};
|
|
45
|
+
//=======================================================//
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,248 +1,247 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from "./mex.js";
|
|
3
|
+
import { generateProfilePicture, loadBase } from "../Utils/messages-media.js";
|
|
4
|
+
import { getBinaryNodeChild } from "../WABinary/index.js";
|
|
5
|
+
import { QueryIds, XWAPaths } from "../Types/index.js";
|
|
6
|
+
import { makeGroupsSocket } from "./groups.js";
|
|
7
|
+
//=======================================================//
|
|
8
|
+
|
|
9
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
10
|
+
const result = getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
11
|
+
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.xwa2_newsletter_create : "xwa2_newsletter"]
|
|
12
|
+
|
|
13
|
+
const metadata = {
|
|
14
|
+
id: metadataPath?.id,
|
|
15
|
+
state: metadataPath?.state?.type,
|
|
16
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
17
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
18
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
19
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
20
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
21
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
22
|
+
handle: metadataPath?.thread_metadata?.handle,
|
|
23
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
24
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
25
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
26
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
27
|
+
}
|
|
28
|
+
return metadata
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
32
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
33
|
+
return {
|
|
34
|
+
id: id,
|
|
35
|
+
owner: undefined,
|
|
36
|
+
name: thread.name.text,
|
|
37
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
38
|
+
description: thread.description.text,
|
|
39
|
+
invite: thread.invite,
|
|
40
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
41
|
+
verification: thread.verification,
|
|
42
|
+
picture: {
|
|
43
|
+
id: thread?.picture?.id || null,
|
|
44
|
+
directPath: thread?.picture?.direct_path || null
|
|
45
|
+
},
|
|
46
|
+
mute_state: viewer.mute
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const parseNewsletterMetadata = (result) => {
|
|
50
|
+
if (typeof result !== "object" || result === null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if ("id" in result && typeof result.id === "string") {
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
if ("result" in result && typeof result.result === "object" && result.result !== null && "id" in result.result) {
|
|
57
|
+
return result.result;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const makeNewsletterSocket = (config) => {
|
|
63
|
+
const sock = makeGroupsSocket(config);
|
|
64
|
+
const { delay, query, generateMessageTag } = sock;
|
|
65
|
+
const encoder = new TextEncoder()
|
|
66
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
37
67
|
tag: 'iq',
|
|
38
68
|
attrs: {
|
|
39
69
|
id: generateMessageTag(),
|
|
40
70
|
type: 'get',
|
|
41
71
|
xmlns: 'w:mex',
|
|
42
|
-
to:
|
|
72
|
+
to: "@s.whatsapp.net",
|
|
43
73
|
},
|
|
44
74
|
content: [
|
|
45
75
|
{
|
|
46
76
|
tag: 'query',
|
|
47
|
-
attrs: { query_id },
|
|
48
|
-
content: encoder.encode(JSON.stringify({
|
|
77
|
+
attrs: { 'query_id': queryId },
|
|
78
|
+
content: encoder.encode(JSON.stringify({
|
|
79
|
+
variables: {
|
|
80
|
+
'newsletter_id': jid,
|
|
81
|
+
...content
|
|
82
|
+
}
|
|
83
|
+
}))
|
|
49
84
|
}
|
|
50
85
|
]
|
|
51
|
-
}))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
return data;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
data = {
|
|
81
|
-
server_id: messageNode.attrs.server_id,
|
|
82
|
-
views: views ? +views : undefined,
|
|
83
|
-
reactions
|
|
84
|
-
};
|
|
85
|
-
return data;
|
|
86
|
-
}
|
|
87
|
-
}));
|
|
86
|
+
}))
|
|
87
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
88
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
89
|
+
};
|
|
90
|
+
const newsletterMetadata = async (type, key, role) => {
|
|
91
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
92
|
+
input: {
|
|
93
|
+
key,
|
|
94
|
+
type: type.toUpperCase(),
|
|
95
|
+
view_role: role || 'GUEST'
|
|
96
|
+
},
|
|
97
|
+
fetch_viewer_metadata: true,
|
|
98
|
+
fetch_full_image: true,
|
|
99
|
+
fetch_creation_time: true
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
return extractNewsletterMetadata(result)
|
|
103
|
+
}
|
|
104
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
105
|
+
const variables = {
|
|
106
|
+
newsletter_id: jid,
|
|
107
|
+
updates: {
|
|
108
|
+
...updates,
|
|
109
|
+
settings: null
|
|
110
|
+
}
|
|
88
111
|
};
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, "xwa2_newsletter_update");
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
loadBase(newsletterWMexQuery, QueryIds)
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
...sock,
|
|
119
|
+
newsletterCreate: async (name, description) => {
|
|
120
|
+
const variables = {
|
|
121
|
+
input: {
|
|
122
|
+
name,
|
|
123
|
+
description: description ?? null
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
127
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
128
|
+
},
|
|
129
|
+
newsletterUpdate,
|
|
130
|
+
newsletterMetadata,
|
|
131
|
+
newsletterFetchAllParticipating: async () => {
|
|
132
|
+
const data = {}
|
|
133
|
+
|
|
134
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBERS)
|
|
135
|
+
const child = JSON.parse(getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
136
|
+
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
137
|
+
|
|
138
|
+
for (const i of newsletters) {
|
|
139
|
+
if (i.id == null) continue
|
|
140
|
+
|
|
141
|
+
const metadata = await newsletterMetadata('JID', i.id)
|
|
142
|
+
if (metadata.id !== null) data[metadata.id] = metadata
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return data
|
|
146
|
+
},
|
|
147
|
+
newsletterUnfollow: async (jid) => {
|
|
148
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW)
|
|
124
149
|
},
|
|
125
150
|
newsletterFollow: async (jid) => {
|
|
126
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW)
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
158
|
-
},
|
|
159
|
-
newsletterMetadata: async (type, key, role) => {
|
|
160
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
161
|
-
input: {
|
|
162
|
-
key,
|
|
163
|
-
type: type.toUpperCase(),
|
|
164
|
-
view_role: role || 'GUEST'
|
|
165
|
-
},
|
|
166
|
-
fetch_viewer_metadata: true,
|
|
167
|
-
fetch_full_image: true,
|
|
168
|
-
fetch_creation_time: true
|
|
169
|
-
});
|
|
170
|
-
return (0, exports.extractNewsletterMetadata)(result);
|
|
171
|
-
},
|
|
172
|
-
newsletterAdminCount: async (jid) => {
|
|
173
|
-
var _a, _b;
|
|
174
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
175
|
-
const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
176
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
177
|
-
},
|
|
178
|
-
/**user is Lid, not Jid */
|
|
179
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
180
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
181
|
-
user_id: user
|
|
182
|
-
});
|
|
183
|
-
},
|
|
184
|
-
/**user is Lid, not Jid */
|
|
185
|
-
newsletterDemote: async (jid, user) => {
|
|
186
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
187
|
-
user_id: user
|
|
188
|
-
});
|
|
189
|
-
},
|
|
190
|
-
newsletterDelete: async (jid) => {
|
|
191
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
192
|
-
},
|
|
193
|
-
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
194
|
-
newsletterReactMessage: async (jid, server_id, code) => {
|
|
195
|
-
await query({
|
|
196
|
-
tag: 'message',
|
|
197
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
198
|
-
content: [{
|
|
199
|
-
tag: 'reaction',
|
|
200
|
-
attrs: code ? { code } : {}
|
|
201
|
-
}]
|
|
202
|
-
});
|
|
151
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW)
|
|
152
|
+
},
|
|
153
|
+
newsletterMute: (jid) => {
|
|
154
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
155
|
+
},
|
|
156
|
+
newsletterUnmute: (jid) => {
|
|
157
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
158
|
+
},
|
|
159
|
+
newsletterUpdateName: async (jid, name) => {
|
|
160
|
+
return await newsletterUpdate(jid, { name });
|
|
161
|
+
},
|
|
162
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
163
|
+
return await newsletterUpdate(jid, { description });
|
|
164
|
+
},
|
|
165
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
166
|
+
const { img } = await generateProfilePicture(content);
|
|
167
|
+
return await newsletterUpdate(jid, { picture: img.toString("base64") });
|
|
168
|
+
},
|
|
169
|
+
newsletterRemovePicture: async (jid) => {
|
|
170
|
+
return await newsletterUpdate(jid, { picture: "" });
|
|
171
|
+
},
|
|
172
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
173
|
+
await query({
|
|
174
|
+
tag: "message",
|
|
175
|
+
attrs: {
|
|
176
|
+
to: jid,
|
|
177
|
+
...(reaction ? {} : { edit: "7" }),
|
|
178
|
+
type: "reaction",
|
|
179
|
+
server_id: serverId,
|
|
180
|
+
id: generateMessageTag()
|
|
203
181
|
},
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
182
|
+
content: [
|
|
183
|
+
{
|
|
184
|
+
tag: "reaction",
|
|
185
|
+
attrs: reaction ? { code: reaction } : {}
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
191
|
+
const messageUpdateAttrs = {
|
|
192
|
+
count: count.toString()
|
|
193
|
+
};
|
|
194
|
+
if (typeof since === "number") {
|
|
195
|
+
messageUpdateAttrs.since = since.toString();
|
|
196
|
+
}
|
|
197
|
+
if (after) {
|
|
198
|
+
messageUpdateAttrs.after = after.toString();
|
|
199
|
+
}
|
|
200
|
+
const result = await query({
|
|
201
|
+
tag: "iq",
|
|
202
|
+
attrs: {
|
|
203
|
+
id: generateMessageTag(),
|
|
204
|
+
type: "get",
|
|
205
|
+
xmlns: "newsletter",
|
|
206
|
+
to: jid
|
|
212
207
|
},
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
208
|
+
content: [
|
|
209
|
+
{
|
|
210
|
+
tag: "message_updates",
|
|
211
|
+
attrs: messageUpdateAttrs
|
|
212
|
+
}
|
|
213
|
+
]
|
|
214
|
+
});
|
|
215
|
+
return result;
|
|
216
|
+
},
|
|
217
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
218
|
+
const result = await query({
|
|
219
|
+
tag: "iq",
|
|
220
|
+
attrs: {
|
|
221
|
+
id: generateMessageTag(),
|
|
222
|
+
type: "set",
|
|
223
|
+
xmlns: "newsletter",
|
|
224
|
+
to: jid
|
|
225
|
+
},
|
|
226
|
+
content: [{ tag: "live_updates", attrs: {}, content: [] }]
|
|
227
|
+
});
|
|
228
|
+
const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
|
|
229
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
230
|
+
return duration ? { duration: duration } : null;
|
|
231
|
+
},
|
|
232
|
+
newsletterAdminCount: async (jid) => {
|
|
233
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
234
|
+
return response.admin_count;
|
|
235
|
+
},
|
|
236
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
237
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
238
|
+
},
|
|
239
|
+
newsletterDemote: async (jid, userJid) => {
|
|
240
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
241
|
+
},
|
|
242
|
+
newsletterDelete: async (jid) => {
|
|
243
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
247
246
|
};
|
|
248
|
-
|
|
247
|
+
//=======================================================//
|