@rosyn/whats 0.0.0-stage → 0.1.0
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/README.md +352 -2
- package/dist/client/index.d.ts +96 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +224 -0
- package/dist/client/index.js.map +1 -0
- package/dist/codec/index.d.ts +8 -0
- package/dist/codec/index.d.ts.map +1 -0
- package/dist/codec/index.js +157 -0
- package/dist/codec/index.js.map +1 -0
- package/dist/compat/extensions.d.ts +219 -0
- package/dist/compat/extensions.d.ts.map +1 -0
- package/dist/compat/extensions.js +717 -0
- package/dist/compat/extensions.js.map +1 -0
- package/dist/compat/index.d.ts +41 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/index.js +2500 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/errors/index.d.ts +15 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +26 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.d.ts +12 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +48 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/media/index.d.ts +22 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +88 -0
- package/dist/media/index.js.map +1 -0
- package/dist/proto/index.d.ts +401 -0
- package/dist/proto/index.d.ts.map +1 -0
- package/dist/proto/index.js +1342 -0
- package/dist/proto/index.js.map +1 -0
- package/dist/protocol/jid.d.ts +36 -0
- package/dist/protocol/jid.d.ts.map +1 -0
- package/dist/protocol/jid.js +95 -0
- package/dist/protocol/jid.js.map +1 -0
- package/dist/protocol/tokens.d.ts +3 -0
- package/dist/protocol/tokens.d.ts.map +1 -0
- package/dist/protocol/tokens.js +4 -0
- package/dist/protocol/tokens.js.map +1 -0
- package/dist/protocol/wabin.d.ts +8 -0
- package/dist/protocol/wabin.d.ts.map +1 -0
- package/dist/protocol/wabin.js +256 -0
- package/dist/protocol/wabin.js.map +1 -0
- package/dist/signal/index.d.ts +22 -0
- package/dist/signal/index.d.ts.map +1 -0
- package/dist/signal/index.js +62 -0
- package/dist/signal/index.js.map +1 -0
- package/dist/signal/protocol.d.ts +139 -0
- package/dist/signal/protocol.d.ts.map +1 -0
- package/dist/signal/protocol.js +620 -0
- package/dist/signal/protocol.js.map +1 -0
- package/dist/storage/index.d.ts +59 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +65 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/transport/websocket.d.ts +32 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +153 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/types/index.d.ts +111 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/native/rosyn_whats_engine.node +0 -0
- package/package.json +53 -4
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
import { encodeWABinaryNode } from "../protocol/wabin.js";
|
|
3
|
+
import { generateMessageIDV2, jidNormalizedUser } from "../protocol/jid.js";
|
|
4
|
+
const NL_QUERY_IDS = {
|
|
5
|
+
CREATE: "8823471724422422",
|
|
6
|
+
UPDATE_METADATA: "24250201037901610",
|
|
7
|
+
METADATA: "6563316087068696",
|
|
8
|
+
SUBSCRIBERS: "9783111038412085",
|
|
9
|
+
FOLLOW: "24404358912487870",
|
|
10
|
+
UNFOLLOW: "9767147403369991",
|
|
11
|
+
MUTE: "29766401636284406",
|
|
12
|
+
UNMUTE: "9864994326891137",
|
|
13
|
+
ADMIN_COUNT: "7130823597031706",
|
|
14
|
+
CHANGE_OWNER: "7341777602580933",
|
|
15
|
+
DEMOTE: "6551828931592903",
|
|
16
|
+
DELETE: "30062808666639665",
|
|
17
|
+
};
|
|
18
|
+
function findChild(node, tag) {
|
|
19
|
+
return Array.isArray(node?.content) ? node.content.find((c) => c.tag === tag) : undefined;
|
|
20
|
+
}
|
|
21
|
+
function findChildren(node, tag) {
|
|
22
|
+
return Array.isArray(node?.content) ? node.content.filter((c) => c.tag === tag) : [];
|
|
23
|
+
}
|
|
24
|
+
function childText(node) {
|
|
25
|
+
if (!node?.content)
|
|
26
|
+
return "";
|
|
27
|
+
if (node.content instanceof Uint8Array)
|
|
28
|
+
return Buffer.from(node.content).toString("utf8");
|
|
29
|
+
return typeof node.content === "string" ? node.content : "";
|
|
30
|
+
}
|
|
31
|
+
export function createCompatExtensions(deps) {
|
|
32
|
+
const { sendQuery, sendEncrypted, nextTag, getAuthCreds, ev, transportReady, isOpen, signalMgr, groupCache, rememberLidPn, resolvePnJid, uploadPreKeys, getKey, setKey, } = deps;
|
|
33
|
+
const groupQuery = async (jid, type, content) => sendQuery({ tag: "iq", attrs: { to: jid, type, id: nextTag(), xmlns: "w:g2" }, content });
|
|
34
|
+
const parseGroupMeta = (grp, fallbackId = "") => {
|
|
35
|
+
const id = grp?.attrs?.id ? (grp.attrs.id.includes("@") ? grp.attrs.id : `${grp.attrs.id}@g.us`) : fallbackId;
|
|
36
|
+
const subject = grp?.attrs?.subject ?? "";
|
|
37
|
+
const addressingMode = grp?.attrs?.addressing_mode;
|
|
38
|
+
const descNode = findChild(grp, "description");
|
|
39
|
+
const desc = childText(findChild(descNode, "body"));
|
|
40
|
+
const participants = [];
|
|
41
|
+
for (const c of findChildren(grp, "participant")) {
|
|
42
|
+
if (!c.attrs?.jid)
|
|
43
|
+
continue;
|
|
44
|
+
rememberLidPn(c.attrs.jid, c.attrs.phone_number);
|
|
45
|
+
const pnId = c.attrs.phone_number ? jidNormalizedUser(c.attrs.phone_number) : resolvePnJid(c.attrs.jid);
|
|
46
|
+
const lidVal = c.attrs.lid || (c.attrs.jid.endsWith("@lid") ? c.attrs.jid : undefined);
|
|
47
|
+
participants.push({
|
|
48
|
+
id: pnId,
|
|
49
|
+
...(c.attrs.phone_number ? { phoneNumber: c.attrs.phone_number } : {}),
|
|
50
|
+
...(lidVal ? { lid: lidVal } : {}),
|
|
51
|
+
admin: c.attrs.type,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return { id, subject, addressingMode, desc, descId: descNode?.attrs?.id, participants };
|
|
55
|
+
};
|
|
56
|
+
const privacyQuery = async (name, value) => sendQuery({
|
|
57
|
+
tag: "iq",
|
|
58
|
+
attrs: { xmlns: "privacy", to: "s.whatsapp.net", type: "set", id: nextTag() },
|
|
59
|
+
content: [{ tag: "privacy", attrs: {}, content: [{ tag: "category", attrs: { name, value } }] }],
|
|
60
|
+
});
|
|
61
|
+
const mexQuery = async (queryId, variables) => {
|
|
62
|
+
const res = await sendQuery({
|
|
63
|
+
tag: "iq",
|
|
64
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "w:mex" },
|
|
65
|
+
content: [{ tag: "query", attrs: { query_id: queryId }, content: Buffer.from(JSON.stringify({ variables }), "utf8") }],
|
|
66
|
+
});
|
|
67
|
+
const resultNode = findChild(res, "result");
|
|
68
|
+
if (resultNode?.content instanceof Uint8Array) {
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(Buffer.from(resultNode.content).toString("utf8"));
|
|
71
|
+
return parsed?.data ?? parsed;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {};
|
|
77
|
+
};
|
|
78
|
+
const newsletterUpdate = async (jid, updates) => mexQuery(NL_QUERY_IDS.UPDATE_METADATA, { newsletter_id: jid, updates: { ...updates, settings: null } });
|
|
79
|
+
const appPatch = async (patchCreate) => {
|
|
80
|
+
const ts = patchCreate.timestamp ?? Date.now();
|
|
81
|
+
const collection = patchCreate.type;
|
|
82
|
+
const prevState = (await getKey("app-state-sync-version", collection)) ?? { version: 0 };
|
|
83
|
+
const nextVersion = Number(prevState.version ?? 0) + 1;
|
|
84
|
+
const payloadJson = Buffer.from(JSON.stringify({ index: patchCreate.index, value: patchCreate.syncAction, timestamp: ts }), "utf8");
|
|
85
|
+
const mac = createHmac("sha256", randomBytes(32)).update(payloadJson).digest();
|
|
86
|
+
await sendQuery({
|
|
87
|
+
tag: "iq",
|
|
88
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "w:sync:app:state" },
|
|
89
|
+
content: [
|
|
90
|
+
{
|
|
91
|
+
tag: "sync",
|
|
92
|
+
attrs: {},
|
|
93
|
+
content: [
|
|
94
|
+
{
|
|
95
|
+
tag: "collection",
|
|
96
|
+
attrs: { name: collection, version: String(nextVersion), return_snapshot: "false" },
|
|
97
|
+
content: [{ tag: "patch", attrs: {}, content: Buffer.concat([payloadJson, mac.subarray(0, 16)]) }],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
await setKey("app-state-sync-version", collection, { version: nextVersion });
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
async query(node) {
|
|
107
|
+
return sendQuery(node);
|
|
108
|
+
},
|
|
109
|
+
async waitForSocketOpen() {
|
|
110
|
+
if (isOpen())
|
|
111
|
+
return;
|
|
112
|
+
await transportReady;
|
|
113
|
+
},
|
|
114
|
+
async waitForConnectionUpdate(check, timeoutMs = 30_000) {
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
const timer = setTimeout(() => {
|
|
117
|
+
ev.off("connection.update", onUpd);
|
|
118
|
+
reject(new Error("Timed out waiting for connection.update"));
|
|
119
|
+
}, timeoutMs);
|
|
120
|
+
const onUpd = (u) => {
|
|
121
|
+
if (check(u)) {
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
ev.off("connection.update", onUpd);
|
|
124
|
+
resolve(u);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
ev.on("connection.update", onUpd);
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
async waitForMessage(msgId, timeoutMs = 30_000) {
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
const timer = setTimeout(() => {
|
|
133
|
+
ev.off("messages.upsert", onMsg);
|
|
134
|
+
reject(new Error(`Timed out waiting for message ${msgId}`));
|
|
135
|
+
}, timeoutMs);
|
|
136
|
+
const onMsg = (up) => {
|
|
137
|
+
const hit = up?.messages?.find((m) => m?.key?.id === msgId);
|
|
138
|
+
if (hit) {
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
ev.off("messages.upsert", onMsg);
|
|
141
|
+
resolve(hit);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
ev.on("messages.upsert", onMsg);
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
// --- Groups & Communities ---
|
|
148
|
+
async groupCreate(subject, participants) {
|
|
149
|
+
const key = generateMessageIDV2(getAuthCreds().me?.id);
|
|
150
|
+
const res = await groupQuery("@g.us", "set", [
|
|
151
|
+
{
|
|
152
|
+
tag: "create",
|
|
153
|
+
attrs: { subject, key },
|
|
154
|
+
content: participants.map((jid) => ({ tag: "participant", attrs: { jid } })),
|
|
155
|
+
},
|
|
156
|
+
]);
|
|
157
|
+
return parseGroupMeta(findChild(res, "group"));
|
|
158
|
+
},
|
|
159
|
+
async groupLeave(id) {
|
|
160
|
+
await groupQuery("@g.us", "set", [{ tag: "leave", attrs: {}, content: [{ tag: "group", attrs: { id } }] }]);
|
|
161
|
+
groupCache.delete(id);
|
|
162
|
+
},
|
|
163
|
+
async groupUpdateSubject(jid, subject) {
|
|
164
|
+
await groupQuery(jid, "set", [{ tag: "subject", attrs: {}, content: Buffer.from(subject, "utf8") }]);
|
|
165
|
+
groupCache.delete(jid);
|
|
166
|
+
},
|
|
167
|
+
async groupUpdateDescription(jid, description) {
|
|
168
|
+
const prev = groupCache.get(jid)?.descId;
|
|
169
|
+
await groupQuery(jid, "set", [
|
|
170
|
+
{
|
|
171
|
+
tag: "description",
|
|
172
|
+
attrs: {
|
|
173
|
+
...(description ? { id: generateMessageIDV2(getAuthCreds().me?.id) } : { delete: "true" }),
|
|
174
|
+
...(prev ? { prev } : {}),
|
|
175
|
+
},
|
|
176
|
+
...(description ? { content: [{ tag: "body", attrs: {}, content: Buffer.from(description, "utf8") }] } : {}),
|
|
177
|
+
},
|
|
178
|
+
]);
|
|
179
|
+
groupCache.delete(jid);
|
|
180
|
+
},
|
|
181
|
+
async groupInviteCode(jid) {
|
|
182
|
+
const res = await groupQuery(jid, "get", [{ tag: "invite", attrs: {} }]);
|
|
183
|
+
return findChild(res, "invite")?.attrs?.code;
|
|
184
|
+
},
|
|
185
|
+
async groupRevokeInvite(jid) {
|
|
186
|
+
const res = await groupQuery(jid, "set", [{ tag: "invite", attrs: {} }]);
|
|
187
|
+
return findChild(res, "invite")?.attrs?.code;
|
|
188
|
+
},
|
|
189
|
+
async groupAcceptInvite(code) {
|
|
190
|
+
const res = await groupQuery("@g.us", "set", [{ tag: "invite", attrs: { code } }]);
|
|
191
|
+
return findChild(res, "group")?.attrs?.jid;
|
|
192
|
+
},
|
|
193
|
+
async groupRevokeInviteV4(groupJid, invitedJid) {
|
|
194
|
+
const res = await groupQuery(groupJid, "set", [
|
|
195
|
+
{ tag: "revoke", attrs: {}, content: [{ tag: "participant", attrs: { jid: invitedJid } }] },
|
|
196
|
+
]);
|
|
197
|
+
return Boolean(res);
|
|
198
|
+
},
|
|
199
|
+
async groupGetInviteInfo(code) {
|
|
200
|
+
const res = await groupQuery("@g.us", "get", [{ tag: "invite", attrs: { code } }]);
|
|
201
|
+
return parseGroupMeta(findChild(res, "group"));
|
|
202
|
+
},
|
|
203
|
+
async groupToggleEphemeral(jid, ephemeralExpiration) {
|
|
204
|
+
await groupQuery(jid, "set", [
|
|
205
|
+
ephemeralExpiration
|
|
206
|
+
? { tag: "ephemeral", attrs: { expiration: String(ephemeralExpiration) } }
|
|
207
|
+
: { tag: "not_ephemeral", attrs: {} },
|
|
208
|
+
]);
|
|
209
|
+
},
|
|
210
|
+
async groupMemberAddMode(jid, mode) {
|
|
211
|
+
await groupQuery(jid, "set", [{ tag: "member_add_mode", attrs: {}, content: mode }]);
|
|
212
|
+
},
|
|
213
|
+
async groupJoinApprovalMode(jid, mode) {
|
|
214
|
+
await groupQuery(jid, "set", [
|
|
215
|
+
{ tag: "membership_approval_mode", attrs: {}, content: [{ tag: "group_join", attrs: { state: mode } }] },
|
|
216
|
+
]);
|
|
217
|
+
},
|
|
218
|
+
async groupRequestParticipantsList(jid) {
|
|
219
|
+
const res = await groupQuery(jid, "get", [{ tag: "membership_approval_requests", attrs: {} }]);
|
|
220
|
+
const node = findChild(res, "membership_approval_requests");
|
|
221
|
+
return findChildren(node, "membership_approval_request").map((v) => v.attrs);
|
|
222
|
+
},
|
|
223
|
+
async groupRequestParticipantsUpdate(jid, participants, action) {
|
|
224
|
+
const res = await groupQuery(jid, "set", [
|
|
225
|
+
{
|
|
226
|
+
tag: "membership_requests_action",
|
|
227
|
+
attrs: {},
|
|
228
|
+
content: [
|
|
229
|
+
{ tag: action, attrs: {}, content: participants.map((p) => ({ tag: "participant", attrs: { jid: p } })) },
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
]);
|
|
233
|
+
const actNode = findChild(findChild(res, "membership_requests_action"), action);
|
|
234
|
+
return findChildren(actNode, "participant").map((p) => ({ status: p.attrs?.error || "200", jid: p.attrs?.jid }));
|
|
235
|
+
},
|
|
236
|
+
async communityCreate(subject, body = "") {
|
|
237
|
+
const res = await groupQuery("@g.us", "set", [
|
|
238
|
+
{
|
|
239
|
+
tag: "create",
|
|
240
|
+
attrs: { subject },
|
|
241
|
+
content: [
|
|
242
|
+
{ tag: "description", attrs: {}, content: [{ tag: "body", attrs: {}, content: Buffer.from(body, "utf8") }] },
|
|
243
|
+
{ tag: "parent", attrs: { default_membership_approval_mode: "request_required" } },
|
|
244
|
+
{ tag: "allow_non_admin_sub_group_creation", attrs: {} },
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
]);
|
|
248
|
+
return parseGroupMeta(findChild(res, "group"));
|
|
249
|
+
},
|
|
250
|
+
async communityMetadata(jid) {
|
|
251
|
+
const res = await groupQuery(jid, "get", [{ tag: "query", attrs: { request: "interactive" } }]);
|
|
252
|
+
return parseGroupMeta(findChild(res, "group"), jid);
|
|
253
|
+
},
|
|
254
|
+
async communityParticipantsUpdate(jid, participants, action) {
|
|
255
|
+
const res = await groupQuery(jid, "set", [
|
|
256
|
+
{ tag: action, attrs: {}, content: participants.map((p) => ({ tag: "participant", attrs: { jid: p } })) },
|
|
257
|
+
]);
|
|
258
|
+
return findChildren(findChild(res, action), "participant").map((p) => ({ status: p.attrs?.error || "200", jid: p.attrs?.jid }));
|
|
259
|
+
},
|
|
260
|
+
async communityRequestParticipantsList(jid) {
|
|
261
|
+
const res = await groupQuery(jid, "get", [{ tag: "membership_approval_requests", attrs: {} }]);
|
|
262
|
+
return findChildren(findChild(res, "membership_approval_requests"), "membership_approval_request").map((v) => v.attrs);
|
|
263
|
+
},
|
|
264
|
+
async communityRequestParticipantsUpdate(jid, participants, action) {
|
|
265
|
+
const res = await groupQuery(jid, "set", [
|
|
266
|
+
{
|
|
267
|
+
tag: "membership_requests_action",
|
|
268
|
+
attrs: {},
|
|
269
|
+
content: [{ tag: action, attrs: {}, content: participants.map((p) => ({ tag: "participant", attrs: { jid: p } })) }],
|
|
270
|
+
},
|
|
271
|
+
]);
|
|
272
|
+
return findChildren(findChild(findChild(res, "membership_requests_action"), action), "participant").map((p) => ({
|
|
273
|
+
status: p.attrs?.error || "200",
|
|
274
|
+
jid: p.attrs?.jid,
|
|
275
|
+
}));
|
|
276
|
+
},
|
|
277
|
+
// --- Profile, USync, Presence, Blocklist, Privacy ---
|
|
278
|
+
async executeUSyncQuery(usyncQuery) {
|
|
279
|
+
return sendQuery({
|
|
280
|
+
tag: "iq",
|
|
281
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "usync" },
|
|
282
|
+
content: [
|
|
283
|
+
{
|
|
284
|
+
tag: "usync",
|
|
285
|
+
attrs: { sid: nextTag(), mode: usyncQuery.mode ?? "query", last: "true", index: "0", context: usyncQuery.context ?? "interactive" },
|
|
286
|
+
content: [
|
|
287
|
+
{ tag: "query", attrs: {}, content: usyncQuery.queryNodes },
|
|
288
|
+
{ tag: "list", attrs: {}, content: usyncQuery.userNodes },
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
async onWhatsApp(...jids) {
|
|
295
|
+
const res = await sendQuery({
|
|
296
|
+
tag: "iq",
|
|
297
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "usync" },
|
|
298
|
+
content: [
|
|
299
|
+
{
|
|
300
|
+
tag: "usync",
|
|
301
|
+
attrs: { sid: nextTag(), mode: "query", last: "true", index: "0", context: "interactive" },
|
|
302
|
+
content: [
|
|
303
|
+
{ tag: "query", attrs: {}, content: [{ tag: "contact", attrs: {} }, { tag: "lid", attrs: {} }] },
|
|
304
|
+
{
|
|
305
|
+
tag: "list",
|
|
306
|
+
attrs: {},
|
|
307
|
+
content: jids.map((j) => {
|
|
308
|
+
const clean = String(j).replace(/[^0-9]/g, "");
|
|
309
|
+
return { tag: "user", attrs: {}, content: [{ tag: "contact", attrs: {}, content: `+${clean}` }] };
|
|
310
|
+
}),
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
});
|
|
316
|
+
const list = findChild(findChild(res, "usync"), "list");
|
|
317
|
+
return findChildren(list, "user").map((u) => {
|
|
318
|
+
const contact = findChild(u, "contact");
|
|
319
|
+
const lidNode = findChild(u, "lid");
|
|
320
|
+
if (u.attrs?.jid && lidNode?.attrs?.val)
|
|
321
|
+
rememberLidPn(lidNode.attrs.val, u.attrs.jid);
|
|
322
|
+
return { exists: contact?.attrs?.type === "in", jid: u.attrs?.jid, lid: lidNode?.attrs?.val };
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
async fetchStatus(...jids) {
|
|
326
|
+
const res = await sendQuery({
|
|
327
|
+
tag: "iq",
|
|
328
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "usync" },
|
|
329
|
+
content: [
|
|
330
|
+
{
|
|
331
|
+
tag: "usync",
|
|
332
|
+
attrs: { sid: nextTag(), mode: "query", last: "true", index: "0", context: "interactive" },
|
|
333
|
+
content: [
|
|
334
|
+
{ tag: "query", attrs: {}, content: [{ tag: "status", attrs: {} }] },
|
|
335
|
+
{ tag: "list", attrs: {}, content: jids.map((j) => ({ tag: "user", attrs: { jid: jidNormalizedUser(j) } })) },
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
});
|
|
340
|
+
const list = findChild(findChild(res, "usync"), "list");
|
|
341
|
+
return findChildren(list, "user").map((u) => {
|
|
342
|
+
const st = findChild(u, "status");
|
|
343
|
+
return { id: u.attrs?.jid, status: childText(st), setAt: st?.attrs?.t ? new Date(Number(st.attrs.t) * 1000) : undefined };
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
async fetchDisappearingDuration(...jids) {
|
|
347
|
+
const res = await sendQuery({
|
|
348
|
+
tag: "iq",
|
|
349
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "usync" },
|
|
350
|
+
content: [
|
|
351
|
+
{
|
|
352
|
+
tag: "usync",
|
|
353
|
+
attrs: { sid: nextTag(), mode: "query", last: "true", index: "0", context: "interactive" },
|
|
354
|
+
content: [
|
|
355
|
+
{ tag: "query", attrs: {}, content: [{ tag: "disappearing_mode", attrs: {} }] },
|
|
356
|
+
{ tag: "list", attrs: {}, content: jids.map((j) => ({ tag: "user", attrs: { jid: jidNormalizedUser(j) } })) },
|
|
357
|
+
],
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
});
|
|
361
|
+
const list = findChild(findChild(res, "usync"), "list");
|
|
362
|
+
return findChildren(list, "user").map((u) => {
|
|
363
|
+
const dm = findChild(u, "disappearing_mode");
|
|
364
|
+
return { id: u.attrs?.jid, disappearing_mode: { duration: Number(dm?.attrs?.duration ?? 0), setAt: Number(dm?.attrs?.t ?? 0) } };
|
|
365
|
+
});
|
|
366
|
+
},
|
|
367
|
+
async updateProfileName(name) {
|
|
368
|
+
await appPatch({
|
|
369
|
+
type: "critical_block",
|
|
370
|
+
index: ["setting_pushName"],
|
|
371
|
+
syncAction: { pushNameSetting: { name } },
|
|
372
|
+
});
|
|
373
|
+
const creds = getAuthCreds();
|
|
374
|
+
if (creds.me) {
|
|
375
|
+
creds.me.name = name;
|
|
376
|
+
ev.emit("creds.update", creds);
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
async updateProfileStatus(status) {
|
|
380
|
+
await sendQuery({
|
|
381
|
+
tag: "iq",
|
|
382
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "status" },
|
|
383
|
+
content: [{ tag: "status", attrs: {}, content: Buffer.from(status, "utf8") }],
|
|
384
|
+
});
|
|
385
|
+
},
|
|
386
|
+
async updateProfilePicture(jid, content) {
|
|
387
|
+
const buf = content instanceof Uint8Array ? Buffer.from(content) : Buffer.from(await (await fetch(content.url)).arrayBuffer());
|
|
388
|
+
const target = jidNormalizedUser(jid);
|
|
389
|
+
await sendQuery({
|
|
390
|
+
tag: "iq",
|
|
391
|
+
attrs: {
|
|
392
|
+
to: "s.whatsapp.net",
|
|
393
|
+
type: "set",
|
|
394
|
+
id: nextTag(),
|
|
395
|
+
xmlns: "w:profile:picture",
|
|
396
|
+
...(target !== jidNormalizedUser(getAuthCreds().me?.id ?? "") ? { target } : {}),
|
|
397
|
+
},
|
|
398
|
+
content: [{ tag: "picture", attrs: { type: "image" }, content: buf }],
|
|
399
|
+
});
|
|
400
|
+
},
|
|
401
|
+
async removeProfilePicture(jid) {
|
|
402
|
+
const target = jidNormalizedUser(jid);
|
|
403
|
+
await sendQuery({
|
|
404
|
+
tag: "iq",
|
|
405
|
+
attrs: {
|
|
406
|
+
to: "s.whatsapp.net",
|
|
407
|
+
type: "set",
|
|
408
|
+
id: nextTag(),
|
|
409
|
+
xmlns: "w:profile:picture",
|
|
410
|
+
...(target !== jidNormalizedUser(getAuthCreds().me?.id ?? "") ? { target } : {}),
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
},
|
|
414
|
+
async presenceSubscribe(toJid) {
|
|
415
|
+
sendEncrypted(encodeWABinaryNode({ tag: "presence", attrs: { to: toJid, id: nextTag(), type: "subscribe" } }));
|
|
416
|
+
},
|
|
417
|
+
async fetchBlocklist() {
|
|
418
|
+
const res = await sendQuery({ tag: "iq", attrs: { xmlns: "blocklist", to: "s.whatsapp.net", type: "get", id: nextTag() } });
|
|
419
|
+
return findChildren(findChild(res, "list"), "item").map((i) => i.attrs?.jid).filter(Boolean);
|
|
420
|
+
},
|
|
421
|
+
async updateBlockStatus(jid, action) {
|
|
422
|
+
await sendQuery({
|
|
423
|
+
tag: "iq",
|
|
424
|
+
attrs: { xmlns: "blocklist", to: "s.whatsapp.net", type: "set", id: nextTag() },
|
|
425
|
+
content: [{ tag: "item", attrs: { action, jid } }],
|
|
426
|
+
});
|
|
427
|
+
},
|
|
428
|
+
async fetchPrivacySettings() {
|
|
429
|
+
const res = await sendQuery({
|
|
430
|
+
tag: "iq",
|
|
431
|
+
attrs: { xmlns: "privacy", to: "s.whatsapp.net", type: "get", id: nextTag() },
|
|
432
|
+
content: [{ tag: "privacy", attrs: {} }],
|
|
433
|
+
});
|
|
434
|
+
const out = {};
|
|
435
|
+
for (const c of findChildren(findChild(res, "privacy"), "category")) {
|
|
436
|
+
if (c.attrs?.name && c.attrs?.value)
|
|
437
|
+
out[c.attrs.name] = c.attrs.value;
|
|
438
|
+
}
|
|
439
|
+
return out;
|
|
440
|
+
},
|
|
441
|
+
updateLastSeenPrivacy: (value) => privacyQuery("last", value),
|
|
442
|
+
updateOnlinePrivacy: (value) => privacyQuery("online", value),
|
|
443
|
+
updateProfilePicturePrivacy: (value) => privacyQuery("profile", value),
|
|
444
|
+
updateStatusPrivacy: (value) => privacyQuery("status", value),
|
|
445
|
+
updateReadReceiptsPrivacy: (value) => privacyQuery("readreceipts", value),
|
|
446
|
+
updateGroupsAddPrivacy: (value) => privacyQuery("groupadd", value),
|
|
447
|
+
updateCallPrivacy: (value) => privacyQuery("calladd", value),
|
|
448
|
+
updateMessagesPrivacy: (value) => privacyQuery("messages", value),
|
|
449
|
+
async updateDefaultDisappearingMode(duration) {
|
|
450
|
+
await sendQuery({
|
|
451
|
+
tag: "iq",
|
|
452
|
+
attrs: { xmlns: "disappearing_mode", to: "s.whatsapp.net", type: "set", id: nextTag() },
|
|
453
|
+
content: [{ tag: "disappearing_mode", attrs: { duration: String(duration) } }],
|
|
454
|
+
});
|
|
455
|
+
},
|
|
456
|
+
async updateDisableLinkPreviewsPrivacy(isPreviewsDisabled) {
|
|
457
|
+
await appPatch({
|
|
458
|
+
type: "regular_high",
|
|
459
|
+
index: ["setting_disableLinkPreviews"],
|
|
460
|
+
syncAction: { privacySettingDisableLinkPreviewsAction: { isPreviewsDisabled } },
|
|
461
|
+
});
|
|
462
|
+
},
|
|
463
|
+
// --- Calls, History, PreKeys ---
|
|
464
|
+
async rejectCall(callId, callFrom) {
|
|
465
|
+
sendEncrypted(encodeWABinaryNode({
|
|
466
|
+
tag: "call",
|
|
467
|
+
attrs: { from: getAuthCreds().me?.id ?? "", to: callFrom },
|
|
468
|
+
content: [{ tag: "reject", attrs: { "call-id": callId, "call-creator": callFrom, count: "0" } }],
|
|
469
|
+
}));
|
|
470
|
+
},
|
|
471
|
+
async createCallLink(type, event) {
|
|
472
|
+
const res = await sendQuery({
|
|
473
|
+
tag: "call",
|
|
474
|
+
attrs: { id: nextTag(), to: "@call" },
|
|
475
|
+
content: [{ tag: "link_create", attrs: { media: type }, content: event ? [{ tag: "event", attrs: { start_time: String(event.startTime) } }] : undefined }],
|
|
476
|
+
});
|
|
477
|
+
return findChild(res, "link_create")?.attrs?.token;
|
|
478
|
+
},
|
|
479
|
+
async fetchMessageHistory(count, oldestMsgKey, oldestMsgTimestamp) {
|
|
480
|
+
const id = nextTag();
|
|
481
|
+
await sendQuery({
|
|
482
|
+
tag: "iq",
|
|
483
|
+
attrs: { to: "s.whatsapp.net", type: "set", id, xmlns: "w:m" },
|
|
484
|
+
content: [
|
|
485
|
+
{
|
|
486
|
+
tag: "history_sync_request",
|
|
487
|
+
attrs: {
|
|
488
|
+
count: String(count),
|
|
489
|
+
jid: oldestMsgKey.remoteJid,
|
|
490
|
+
msg_id: oldestMsgKey.id,
|
|
491
|
+
from_me: String(Boolean(oldestMsgKey.fromMe)),
|
|
492
|
+
timestamp: String(oldestMsgTimestamp),
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
});
|
|
497
|
+
return id;
|
|
498
|
+
},
|
|
499
|
+
async requestPlaceholderResend(messageKey) {
|
|
500
|
+
const id = nextTag();
|
|
501
|
+
await sendQuery({
|
|
502
|
+
tag: "iq",
|
|
503
|
+
attrs: { to: "s.whatsapp.net", type: "set", id, xmlns: "w:m" },
|
|
504
|
+
content: [{ tag: "placeholder_resend", attrs: { jid: messageKey.remoteJid, msg_id: messageKey.id, from_me: String(Boolean(messageKey.fromMe)) } }],
|
|
505
|
+
});
|
|
506
|
+
return id;
|
|
507
|
+
},
|
|
508
|
+
async rotateSignedPreKey() {
|
|
509
|
+
await uploadPreKeys();
|
|
510
|
+
},
|
|
511
|
+
async uploadPreKeysToServerIfRequired() {
|
|
512
|
+
await uploadPreKeys();
|
|
513
|
+
},
|
|
514
|
+
// --- Newsletter ---
|
|
515
|
+
async newsletterCreate(name, description) {
|
|
516
|
+
const data = await mexQuery(NL_QUERY_IDS.CREATE, { input: { name, description: description ?? null } });
|
|
517
|
+
return data?.xwa2_newsletter_create ?? data;
|
|
518
|
+
},
|
|
519
|
+
newsletterUpdate,
|
|
520
|
+
newsletterUpdateName: (jid, name) => newsletterUpdate(jid, { name }),
|
|
521
|
+
newsletterUpdateDescription: (jid, description) => newsletterUpdate(jid, { description }),
|
|
522
|
+
async newsletterUpdatePicture(jid, content) {
|
|
523
|
+
return newsletterUpdate(jid, { picture: Buffer.from(content).toString("base64") });
|
|
524
|
+
},
|
|
525
|
+
newsletterRemovePicture: (jid) => newsletterUpdate(jid, { picture: "" }),
|
|
526
|
+
newsletterSubscribers: (jid) => mexQuery(NL_QUERY_IDS.SUBSCRIBERS, { newsletter_id: jid }),
|
|
527
|
+
newsletterMetadata: async (type, key) => {
|
|
528
|
+
const data = await mexQuery(NL_QUERY_IDS.METADATA, {
|
|
529
|
+
fetch_creation_time: true,
|
|
530
|
+
fetch_full_image: true,
|
|
531
|
+
fetch_viewer_metadata: true,
|
|
532
|
+
input: { key, type: type.toUpperCase() },
|
|
533
|
+
});
|
|
534
|
+
return data?.xwa2_newsletter_metadata ?? data?.xwa2_newsletter ?? data;
|
|
535
|
+
},
|
|
536
|
+
newsletterFollow: (jid) => mexQuery(NL_QUERY_IDS.FOLLOW, { newsletter_id: jid }),
|
|
537
|
+
newsletterUnfollow: (jid) => mexQuery(NL_QUERY_IDS.UNFOLLOW, { newsletter_id: jid }),
|
|
538
|
+
newsletterMute: (jid) => mexQuery(NL_QUERY_IDS.MUTE, { newsletter_id: jid }),
|
|
539
|
+
newsletterUnmute: (jid) => mexQuery(NL_QUERY_IDS.UNMUTE, { newsletter_id: jid }),
|
|
540
|
+
newsletterAdminCount: (jid) => mexQuery(NL_QUERY_IDS.ADMIN_COUNT, { newsletter_id: jid }),
|
|
541
|
+
newsletterChangeOwner: (jid, newOwnerJid) => mexQuery(NL_QUERY_IDS.CHANGE_OWNER, { newsletter_id: jid, user_id: newOwnerJid }),
|
|
542
|
+
newsletterDemote: (jid, userJid) => mexQuery(NL_QUERY_IDS.DEMOTE, { newsletter_id: jid, user_id: userJid }),
|
|
543
|
+
newsletterDelete: (jid) => mexQuery(NL_QUERY_IDS.DELETE, { newsletter_id: jid }),
|
|
544
|
+
async newsletterFetchMessages(jid, count, since, after) {
|
|
545
|
+
return sendQuery({
|
|
546
|
+
tag: "iq",
|
|
547
|
+
attrs: { id: nextTag(), type: "get", xmlns: "newsletter", to: jid },
|
|
548
|
+
content: [
|
|
549
|
+
{
|
|
550
|
+
tag: "message_updates",
|
|
551
|
+
attrs: {
|
|
552
|
+
count: String(count),
|
|
553
|
+
...(typeof since === "number" ? { since: String(since) } : {}),
|
|
554
|
+
...(typeof after === "number" ? { after: String(after) } : {}),
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
],
|
|
558
|
+
});
|
|
559
|
+
},
|
|
560
|
+
async subscribeNewsletterUpdates(jid) {
|
|
561
|
+
const res = await sendQuery({
|
|
562
|
+
tag: "iq",
|
|
563
|
+
attrs: { id: nextTag(), type: "set", xmlns: "newsletter", to: jid },
|
|
564
|
+
content: [{ tag: "live_updates", attrs: {}, content: [] }],
|
|
565
|
+
});
|
|
566
|
+
return findChild(res, "live_updates")?.attrs;
|
|
567
|
+
},
|
|
568
|
+
async newsletterReactMessage(jid, serverId, reaction) {
|
|
569
|
+
sendEncrypted(encodeWABinaryNode({
|
|
570
|
+
tag: "message",
|
|
571
|
+
attrs: { to: jid, ...(reaction ? {} : { edit: "7" }), type: "reaction", server_id: serverId, id: generateMessageIDV2(jid) },
|
|
572
|
+
content: [{ tag: "reaction", attrs: reaction ? { code: reaction } : {} }],
|
|
573
|
+
}));
|
|
574
|
+
},
|
|
575
|
+
// --- Business & Catalog ---
|
|
576
|
+
async getBusinessProfile(jid) {
|
|
577
|
+
const res = await sendQuery({
|
|
578
|
+
tag: "iq",
|
|
579
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "w:biz" },
|
|
580
|
+
content: [{ tag: "business_profile", attrs: { v: "244" }, content: [{ tag: "profile", attrs: { jid } }] }],
|
|
581
|
+
});
|
|
582
|
+
return findChild(findChild(res, "business_profile"), "profile")?.attrs ?? null;
|
|
583
|
+
},
|
|
584
|
+
async updateBussinesProfile(args) {
|
|
585
|
+
await sendQuery({
|
|
586
|
+
tag: "iq",
|
|
587
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "w:biz" },
|
|
588
|
+
content: [{ tag: "business_profile", attrs: { v: "3", mutation_type: "delta" }, content: Object.entries(args).map(([k, v]) => ({ tag: k, attrs: {}, content: String(v) })) }],
|
|
589
|
+
});
|
|
590
|
+
},
|
|
591
|
+
async updateCoverPhoto(photo) {
|
|
592
|
+
const res = await sendQuery({
|
|
593
|
+
tag: "iq",
|
|
594
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "w:biz" },
|
|
595
|
+
content: [{ tag: "business_profile", attrs: { v: "3", mutation_type: "delta" }, content: [{ tag: "cover_photo", attrs: {}, content: Buffer.from(photo) }] }],
|
|
596
|
+
});
|
|
597
|
+
return findChild(findChild(res, "business_profile"), "cover_photo")?.attrs?.id;
|
|
598
|
+
},
|
|
599
|
+
async removeCoverPhoto(id) {
|
|
600
|
+
await sendQuery({
|
|
601
|
+
tag: "iq",
|
|
602
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "w:biz" },
|
|
603
|
+
content: [{ tag: "business_profile", attrs: { v: "3", mutation_type: "delta" }, content: [{ tag: "cover_photo", attrs: { op: "delete", id } }] }],
|
|
604
|
+
});
|
|
605
|
+
},
|
|
606
|
+
async getCatalog({ jid, limit = 10, cursor } = {}) {
|
|
607
|
+
const target = jid || getAuthCreds().me?.id || "";
|
|
608
|
+
return sendQuery({
|
|
609
|
+
tag: "iq",
|
|
610
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "w:biz:catalog" },
|
|
611
|
+
content: [
|
|
612
|
+
{
|
|
613
|
+
tag: "product_catalog",
|
|
614
|
+
attrs: { jid: target, allow_shop_source: "true" },
|
|
615
|
+
content: [
|
|
616
|
+
{ tag: "limit", attrs: {}, content: String(limit) },
|
|
617
|
+
...(cursor ? [{ tag: "after", attrs: {}, content: cursor }] : []),
|
|
618
|
+
],
|
|
619
|
+
},
|
|
620
|
+
],
|
|
621
|
+
});
|
|
622
|
+
},
|
|
623
|
+
async getCollections(jid, limit = 51) {
|
|
624
|
+
const target = jid || getAuthCreds().me?.id || "";
|
|
625
|
+
return sendQuery({
|
|
626
|
+
tag: "iq",
|
|
627
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "w:biz:catalog" },
|
|
628
|
+
content: [{ tag: "collections", attrs: { biz_jid: target }, content: [{ tag: "collection_limit", attrs: {}, content: String(limit) }] }],
|
|
629
|
+
});
|
|
630
|
+
},
|
|
631
|
+
async productCreate(create) {
|
|
632
|
+
return sendQuery({
|
|
633
|
+
tag: "iq",
|
|
634
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "w:biz:catalog" },
|
|
635
|
+
content: [{ tag: "product_catalog_add", attrs: { v: "1" }, content: [{ tag: "product", attrs: {}, content: [{ tag: "name", attrs: {}, content: String(create.name ?? "") }] }] }],
|
|
636
|
+
});
|
|
637
|
+
},
|
|
638
|
+
async productUpdate(productId, update) {
|
|
639
|
+
return sendQuery({
|
|
640
|
+
tag: "iq",
|
|
641
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "w:biz:catalog" },
|
|
642
|
+
content: [{ tag: "product_catalog_edit", attrs: { v: "1" }, content: [{ tag: "product", attrs: { id: productId }, content: [{ tag: "name", attrs: {}, content: String(update.name ?? "") }] }] }],
|
|
643
|
+
});
|
|
644
|
+
},
|
|
645
|
+
async productDelete(productIds) {
|
|
646
|
+
const res = await sendQuery({
|
|
647
|
+
tag: "iq",
|
|
648
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "w:biz:catalog" },
|
|
649
|
+
content: [{ tag: "product_catalog_delete", attrs: { v: "1" }, content: productIds.map((id) => ({ tag: "product", attrs: {}, content: [{ tag: "id", attrs: {}, content: id }] })) }],
|
|
650
|
+
});
|
|
651
|
+
return { deleted: Number(findChild(res, "product_catalog_delete")?.attrs?.deleted_count ?? productIds.length) };
|
|
652
|
+
},
|
|
653
|
+
async getOrderDetails(orderId, tokenBase64) {
|
|
654
|
+
return sendQuery({
|
|
655
|
+
tag: "iq",
|
|
656
|
+
attrs: { to: "s.whatsapp.net", type: "get", id: nextTag(), xmlns: "fb:thrift_iq", s_max_id: "5" },
|
|
657
|
+
content: [{ tag: "order", attrs: { op: "get", id: orderId }, content: [{ tag: "token", attrs: {}, content: tokenBase64 }] }],
|
|
658
|
+
});
|
|
659
|
+
},
|
|
660
|
+
// --- App State Sync & Chat Mutations ---
|
|
661
|
+
appPatch,
|
|
662
|
+
async resyncAppState(collections = ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"]) {
|
|
663
|
+
await sendQuery({
|
|
664
|
+
tag: "iq",
|
|
665
|
+
attrs: { to: "s.whatsapp.net", type: "set", id: nextTag(), xmlns: "w:sync:app:state" },
|
|
666
|
+
content: [{ tag: "sync", attrs: {}, content: collections.map((name) => ({ tag: "collection", attrs: { name, version: "0", return_snapshot: "true" } })) }],
|
|
667
|
+
});
|
|
668
|
+
},
|
|
669
|
+
async chatModify(mod, jid) {
|
|
670
|
+
if ("archive" in mod) {
|
|
671
|
+
return appPatch({ type: "regular_high", index: ["archive", jid], syncAction: { archiveChatAction: { archived: Boolean(mod.archive) } } });
|
|
672
|
+
}
|
|
673
|
+
if ("pin" in mod) {
|
|
674
|
+
return appPatch({ type: "regular_high", index: ["pin_v1", jid], syncAction: { pinAction: { pinned: Boolean(mod.pin) } } });
|
|
675
|
+
}
|
|
676
|
+
if ("mute" in mod) {
|
|
677
|
+
return appPatch({ type: "regular_high", index: ["mute", jid], syncAction: { muteAction: { muted: mod.mute !== null, muteEndTimestamp: mod.mute ?? 0 } } });
|
|
678
|
+
}
|
|
679
|
+
if ("markRead" in mod) {
|
|
680
|
+
return appPatch({ type: "regular_high", index: ["markChatAsRead", jid], syncAction: { markChatAsReadAction: { read: Boolean(mod.markRead) } } });
|
|
681
|
+
}
|
|
682
|
+
if ("clear" in mod) {
|
|
683
|
+
return appPatch({ type: "regular_high", index: ["clearChat", jid, "1", "0"], syncAction: { clearChatAction: { messageRange: mod.lastMessages } } });
|
|
684
|
+
}
|
|
685
|
+
if ("delete" in mod) {
|
|
686
|
+
return appPatch({ type: "regular_high", index: ["deleteChat", jid, "1"], syncAction: { deleteChatAction: { messageRange: mod.lastMessages } } });
|
|
687
|
+
}
|
|
688
|
+
if ("star" in mod) {
|
|
689
|
+
return appPatch({ type: "regular_high", index: ["star", jid, mod.star.messages?.[0]?.id ?? "", "1", "0"], syncAction: { starAction: { starred: Boolean(mod.star.star) } } });
|
|
690
|
+
}
|
|
691
|
+
},
|
|
692
|
+
async star(jid, messages, star) {
|
|
693
|
+
for (const m of messages) {
|
|
694
|
+
await appPatch({ type: "regular_high", index: ["star", jid, m.id, m.fromMe ? "1" : "0", "0"], syncAction: { starAction: { starred: star } } });
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
async addOrEditContact(jid, contact) {
|
|
698
|
+
return appPatch({ type: "critical_unblock_low", index: ["contact", jid], syncAction: { contactAction: contact } });
|
|
699
|
+
},
|
|
700
|
+
async removeContact(jid) {
|
|
701
|
+
return appPatch({ type: "critical_unblock_low", index: ["contact", jid], syncAction: {} });
|
|
702
|
+
},
|
|
703
|
+
async addChatLabel(jid, labelId) {
|
|
704
|
+
return appPatch({ type: "regular", index: ["label_jid", labelId, jid], syncAction: { labelAssociationAction: { labeled: true } } });
|
|
705
|
+
},
|
|
706
|
+
async removeChatLabel(jid, labelId) {
|
|
707
|
+
return appPatch({ type: "regular", index: ["label_jid", labelId, jid], syncAction: { labelAssociationAction: { labeled: false } } });
|
|
708
|
+
},
|
|
709
|
+
async addMessageLabel(jid, messageId, labelId) {
|
|
710
|
+
return appPatch({ type: "regular", index: ["label_message", labelId, jid, messageId, "0", "0"], syncAction: { labelAssociationAction: { labeled: true } } });
|
|
711
|
+
},
|
|
712
|
+
async removeMessageLabel(jid, messageId, labelId) {
|
|
713
|
+
return appPatch({ type: "regular", index: ["label_message", labelId, jid, messageId, "0", "0"], syncAction: { labelAssociationAction: { labeled: false } } });
|
|
714
|
+
},
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
//# sourceMappingURL=extensions.js.map
|