@aseppxyzz12/baileys 1.1.8

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 (185) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +2579 -0
  3. package/WAProto/AICommon/AICommon.js +19396 -0
  4. package/WAProto/AICommon/AICommon.proto +820 -0
  5. package/WAProto/Adv/Adv.js +1137 -0
  6. package/WAProto/Adv/Adv.proto +42 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +8975 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +484 -0
  9. package/WAProto/Cert/Cert.js +893 -0
  10. package/WAProto/Cert/Cert.proto +30 -0
  11. package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
  13. package/WAProto/CompanionReg/CompanionReg.js +2457 -0
  14. package/WAProto/CompanionReg/CompanionReg.proto +103 -0
  15. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
  16. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
  17. package/WAProto/E2E/E2E.js +78728 -0
  18. package/WAProto/E2E/E2E.proto +1970 -0
  19. package/WAProto/Ephemeral/Ephemeral.js +143 -0
  20. package/WAProto/Ephemeral/Ephemeral.proto +7 -0
  21. package/WAProto/HistorySync/HistorySync.js +95931 -0
  22. package/WAProto/HistorySync/HistorySync.proto +229 -0
  23. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
  24. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
  25. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
  26. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
  27. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
  28. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
  29. package/WAProto/MmsRetry/MmsRetry.js +310 -0
  30. package/WAProto/MmsRetry/MmsRetry.proto +19 -0
  31. package/WAProto/Protocol/Protocol.js +399 -0
  32. package/WAProto/Protocol/Protocol.proto +22 -0
  33. package/WAProto/Reporting/Reporting.js +535 -0
  34. package/WAProto/Reporting/Reporting.proto +22 -0
  35. package/WAProto/ServerSync/ServerSync.js +1830 -0
  36. package/WAProto/ServerSync/ServerSync.proto +70 -0
  37. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
  38. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
  39. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
  40. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
  41. package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
  42. package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
  43. package/WAProto/SyncAction/SyncAction.js +17424 -0
  44. package/WAProto/SyncAction/SyncAction.proto +663 -0
  45. package/WAProto/UserPassword/UserPassword.js +544 -0
  46. package/WAProto/UserPassword/UserPassword.proto +28 -0
  47. package/WAProto/VnameCert/VnameCert.js +1466 -0
  48. package/WAProto/VnameCert/VnameCert.proto +65 -0
  49. package/WAProto/Wa6/Wa6.js +4601 -0
  50. package/WAProto/Wa6/Wa6.proto +241 -0
  51. package/WAProto/Web/Web.js +90819 -0
  52. package/WAProto/Web/Web.proto +605 -0
  53. package/WAProto/index.js +30 -0
  54. package/engine-requirements.js +9 -0
  55. package/lib/Defaults/baileys-version.json +3 -0
  56. package/lib/Defaults/connection.js +39 -0
  57. package/lib/Defaults/constants.js +50 -0
  58. package/lib/Defaults/history.js +13 -0
  59. package/lib/Defaults/index.js +36 -0
  60. package/lib/Defaults/media.js +43 -0
  61. package/lib/Defaults/phonenumber-mcc.json +223 -0
  62. package/lib/Defaults/prefix.js +12 -0
  63. package/lib/Function/Download/tiktok.js +19 -0
  64. package/lib/Function/Tools/bypass.js +19 -0
  65. package/lib/Function/index.js +13 -0
  66. package/lib/Signal/Group/ciphertext-message.js +14 -0
  67. package/lib/Signal/Group/group-session-builder.js +46 -0
  68. package/lib/Signal/Group/group_cipher.js +104 -0
  69. package/lib/Signal/Group/index.js +42 -0
  70. package/lib/Signal/Group/keyhelper.js +21 -0
  71. package/lib/Signal/Group/queue-job.js +57 -0
  72. package/lib/Signal/Group/sender-chain-key.js +34 -0
  73. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  74. package/lib/Signal/Group/sender-key-message.js +78 -0
  75. package/lib/Signal/Group/sender-key-name.js +49 -0
  76. package/lib/Signal/Group/sender-key-record.js +45 -0
  77. package/lib/Signal/Group/sender-key-state.js +100 -0
  78. package/lib/Signal/Group/sender-message-key.js +28 -0
  79. package/lib/Signal/libsignal.js +364 -0
  80. package/lib/Signal/lid-mapping.js +164 -0
  81. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  82. package/lib/Socket/Client/index.js +31 -0
  83. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  84. package/lib/Socket/Client/types.js +12 -0
  85. package/lib/Socket/Client/web-socket-client.js +62 -0
  86. package/lib/Socket/Client/websocket.js +67 -0
  87. package/lib/Socket/business.js +291 -0
  88. package/lib/Socket/chats.js +874 -0
  89. package/lib/Socket/community.js +454 -0
  90. package/lib/Socket/dugong.js +658 -0
  91. package/lib/Socket/groups.js +357 -0
  92. package/lib/Socket/index.js +13 -0
  93. package/lib/Socket/messages-recv.js +1509 -0
  94. package/lib/Socket/messages-send.js +1505 -0
  95. package/lib/Socket/mex.js +54 -0
  96. package/lib/Socket/newsletter.js +171 -0
  97. package/lib/Socket/registration.js +167 -0
  98. package/lib/Socket/rich-content.js +279 -0
  99. package/lib/Socket/socket.js +905 -0
  100. package/lib/Socket/username.js +157 -0
  101. package/lib/Socket/usync.js +70 -0
  102. package/lib/Store/index.js +37 -0
  103. package/lib/Store/keyed-db.js +114 -0
  104. package/lib/Store/make-cache-manager-store.js +77 -0
  105. package/lib/Store/make-in-memory-store.js +423 -0
  106. package/lib/Store/make-ordered-dictionary.js +78 -0
  107. package/lib/Store/object-repository.js +26 -0
  108. package/lib/Types/Auth.js +2 -0
  109. package/lib/Types/Bussines.js +2 -0
  110. package/lib/Types/Call.js +2 -0
  111. package/lib/Types/Chat.js +10 -0
  112. package/lib/Types/Contact.js +2 -0
  113. package/lib/Types/Events.js +2 -0
  114. package/lib/Types/GroupMetadata.js +2 -0
  115. package/lib/Types/Label.js +25 -0
  116. package/lib/Types/LabelAssociation.js +4 -0
  117. package/lib/Types/Message.js +11 -0
  118. package/lib/Types/Mex.js +40 -0
  119. package/lib/Types/MexUpdates.js +15 -0
  120. package/lib/Types/Newsletter.js +32 -0
  121. package/lib/Types/Product.js +2 -0
  122. package/lib/Types/Signal.js +2 -0
  123. package/lib/Types/Socket.js +2 -0
  124. package/lib/Types/State.js +9 -0
  125. package/lib/Types/USync.js +2 -0
  126. package/lib/Types/index.js +60 -0
  127. package/lib/Utils/auth-utils.js +256 -0
  128. package/lib/Utils/baileys-event-stream.js +63 -0
  129. package/lib/Utils/bot-toolkit.js +455 -0
  130. package/lib/Utils/browser-utils.js +29 -0
  131. package/lib/Utils/business.js +233 -0
  132. package/lib/Utils/chat-utils.js +904 -0
  133. package/lib/Utils/companion-reg-client-utils.js +41 -0
  134. package/lib/Utils/crypto.js +144 -0
  135. package/lib/Utils/decode-wa-message.js +305 -0
  136. package/lib/Utils/event-buffer.js +555 -0
  137. package/lib/Utils/generics.js +411 -0
  138. package/lib/Utils/history.js +100 -0
  139. package/lib/Utils/identity-change-handler.js +53 -0
  140. package/lib/Utils/index.js +57 -0
  141. package/lib/Utils/link-preview.js +76 -0
  142. package/lib/Utils/logger.js +4 -0
  143. package/lib/Utils/lt-hash.js +45 -0
  144. package/lib/Utils/make-mutex.js +33 -0
  145. package/lib/Utils/message-composer.js +289 -0
  146. package/lib/Utils/message-retry-manager.js +134 -0
  147. package/lib/Utils/messages-media.js +806 -0
  148. package/lib/Utils/messages.js +1908 -0
  149. package/lib/Utils/noise-handler.js +157 -0
  150. package/lib/Utils/offline-node-processor.js +42 -0
  151. package/lib/Utils/pre-key-manager.js +86 -0
  152. package/lib/Utils/process-message.js +814 -0
  153. package/lib/Utils/reporting-utils.js +264 -0
  154. package/lib/Utils/signal.js +183 -0
  155. package/lib/Utils/stanza-ack.js +36 -0
  156. package/lib/Utils/sync-action-utils.js +52 -0
  157. package/lib/Utils/tc-token-utils.js +167 -0
  158. package/lib/Utils/use-multi-file-auth-state.js +104 -0
  159. package/lib/Utils/validate-connection.js +229 -0
  160. package/lib/Utils/vialeys-event-stream.js +41 -0
  161. package/lib/WABinary/constants.js +1308 -0
  162. package/lib/WABinary/decode.js +233 -0
  163. package/lib/WABinary/encode.js +212 -0
  164. package/lib/WABinary/generic-utils.js +124 -0
  165. package/lib/WABinary/index.js +36 -0
  166. package/lib/WABinary/jid-utils.js +101 -0
  167. package/lib/WABinary/types.js +2 -0
  168. package/lib/WAM/BinaryInfo.js +12 -0
  169. package/lib/WAM/constants.js +20491 -0
  170. package/lib/WAM/encode.js +148 -0
  171. package/lib/WAM/index.js +34 -0
  172. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
  174. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
  175. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
  176. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
  177. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
  178. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  179. package/lib/WAUSync/Protocols/index.js +38 -0
  180. package/lib/WAUSync/USyncQuery.js +97 -0
  181. package/lib/WAUSync/USyncUser.js +33 -0
  182. package/lib/WAUSync/index.js +34 -0
  183. package/lib/index.js +113 -0
  184. package/lib/messages-send.js +1496 -0
  185. package/package.json +100 -0
@@ -0,0 +1,423 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { proto: proto } = require("../../WAProto");
4
+ const { DEFAULT_CONNECTION_CONFIG: DEFAULT_CONNECTION_CONFIG } = require("../Defaults/connection");
5
+ const { LabelAssociationType: LabelAssociationType } = require("../Types/LabelAssociation");
6
+ const {
7
+ md5: md5,
8
+ toNumber: toNumber,
9
+ updateMessageWithReceipt: updateMessageWithReceipt,
10
+ updateMessageWithReaction: updateMessageWithReaction,
11
+ } = require("../Utils");
12
+ const { jidDecode: jidDecode, jidNormalizedUser: jidNormalizedUser } = require("../WABinary");
13
+ const { makeOrderedDictionary: makeOrderedDictionary } = require("./make-ordered-dictionary");
14
+ const { ObjectRepository: ObjectRepository } = require("./object-repository");
15
+ const waChatKey = (pin) => ({
16
+ key: (c) =>
17
+ (pin ? (c.pinned ? "1" : "0") : "") +
18
+ (c.archived ? "0" : "1") +
19
+ (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, "0") : "") +
20
+ c.id,
21
+ compare: (k1, k2) => k2.localeCompare(k1),
22
+ });
23
+ const waMessageID = (m) => m.key.id || "";
24
+ const waLabelAssociationKey = {
25
+ key: (la) =>
26
+ la.type === LabelAssociationType.Chat
27
+ ? la.chatId + la.labelId
28
+ : la.chatId + la.messageId + la.labelId,
29
+ compare: (k1, k2) => k2.localeCompare(k1),
30
+ };
31
+ const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
32
+ const makeInMemoryStore = (config) => {
33
+ const socket = config.socket;
34
+ const chatKey = config.chatKey || waChatKey(true);
35
+ const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
36
+ const logger =
37
+ config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: "in-mem-store" });
38
+ const KeyedDB = require("@adiwajshing/keyed-db").default;
39
+ const chats = new KeyedDB(chatKey, (c) => c.id);
40
+ const messages = {};
41
+ const contacts = {};
42
+ const groupMetadata = {};
43
+ const presences = {};
44
+ const state = { connection: "close" };
45
+ const labels = new ObjectRepository();
46
+ const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
47
+ const assertMessageList = (jid) => {
48
+ if (!messages[jid]) {
49
+ messages[jid] = makeMessagesDictionary();
50
+ }
51
+ return messages[jid];
52
+ };
53
+ const contactsUpsert = (newContacts) => {
54
+ const oldContacts = new Set(Object.keys(contacts));
55
+ for (const contact of newContacts) {
56
+ oldContacts.delete(contact.id);
57
+ contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
58
+ }
59
+ return oldContacts;
60
+ };
61
+ const labelsUpsert = (newLabels) => {
62
+ for (const label of newLabels) {
63
+ labels.upsertById(label.id, label);
64
+ }
65
+ };
66
+ const bind = (ev) => {
67
+ ev.on("connection.update", (update) => {
68
+ Object.assign(state, update);
69
+ });
70
+ ev.on(
71
+ "messaging-history.set",
72
+ ({
73
+ chats: newChats,
74
+ contacts: newContacts,
75
+ messages: newMessages,
76
+ isLatest: isLatest,
77
+ syncType: syncType,
78
+ }) => {
79
+ if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
80
+ return;
81
+ }
82
+ if (isLatest) {
83
+ chats.clear();
84
+ for (const id in messages) {
85
+ delete messages[id];
86
+ }
87
+ }
88
+ const chatsAdded = chats.insertIfAbsent(...newChats).length;
89
+ logger.debug({ chatsAdded: chatsAdded }, "synced chats");
90
+ const oldContacts = contactsUpsert(newContacts);
91
+ if (isLatest) {
92
+ for (const jid of oldContacts) {
93
+ delete contacts[jid];
94
+ }
95
+ }
96
+ logger.debug(
97
+ {
98
+ deletedContacts: isLatest ? oldContacts.size : 0,
99
+ newContacts: newContacts,
100
+ },
101
+ "synced contacts"
102
+ );
103
+ for (const msg of newMessages) {
104
+ const jid = msg.key.remoteJid;
105
+ const list = assertMessageList(jid);
106
+ list.upsert(msg, "prepend");
107
+ }
108
+ logger.debug({ messages: newMessages.length }, "synced messages");
109
+ }
110
+ );
111
+ ev.on("contacts.upsert", (contacts) => {
112
+ contactsUpsert(contacts);
113
+ });
114
+ ev.on("contacts.update", async (updates) => {
115
+ for (const update of updates) {
116
+ let contact;
117
+ if (contacts[update.id]) {
118
+ contact = contacts[update.id];
119
+ } else {
120
+ const contactHashes = await Promise.all(
121
+ Object.keys(contacts).map(async (contactId) => {
122
+ const { user: user } = jidDecode(contactId);
123
+ return [
124
+ contactId,
125
+ (await md5(Buffer.from(user + "WA_ADD_NOTIF", "utf8")))
126
+ .toString("base64")
127
+ .slice(0, 3),
128
+ ];
129
+ })
130
+ );
131
+ contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || ""];
132
+ }
133
+ if (contact) {
134
+ if (update.imgUrl === "changed") {
135
+ contact.imgUrl = socket
136
+ ? await socket.profilePictureUrl(contact.id)
137
+ : undefined;
138
+ } else if (update.imgUrl === "removed") {
139
+ delete contact.imgUrl;
140
+ }
141
+ } else {
142
+ return logger.debug({ update: update }, "got update for non-existant contact");
143
+ }
144
+ Object.assign(contacts[contact.id], contact);
145
+ }
146
+ });
147
+ ev.on("chats.upsert", (newChats) => {
148
+ chats.upsert(...newChats);
149
+ });
150
+ ev.on("chats.update", (updates) => {
151
+ for (let update of updates) {
152
+ const result = chats.update(update.id, (chat) => {
153
+ if (update.unreadCount > 0) {
154
+ update = { ...update };
155
+ update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
156
+ }
157
+ Object.assign(chat, update);
158
+ });
159
+ if (!result) {
160
+ logger.debug({ update: update }, "got update for non-existant chat");
161
+ }
162
+ }
163
+ });
164
+ ev.on("labels.edit", (label) => {
165
+ if (label.deleted) {
166
+ return labels.deleteById(label.id);
167
+ }
168
+ if (labels.count() < 20) {
169
+ return labels.upsertById(label.id, label);
170
+ }
171
+ logger.error("Labels count exceed");
172
+ });
173
+ ev.on("labels.association", ({ type: type, association: association }) => {
174
+ switch (type) {
175
+ case "add":
176
+ labelAssociations.upsert(association);
177
+ break;
178
+ case "remove":
179
+ labelAssociations.delete(association);
180
+ break;
181
+ default:
182
+ console.error(`unknown operation type [${type}]`);
183
+ }
184
+ });
185
+ ev.on("presence.update", ({ id: id, presences: update }) => {
186
+ presences[id] = presences[id] || {};
187
+ Object.assign(presences[id], update);
188
+ });
189
+ ev.on("chats.delete", (deletions) => {
190
+ for (const item of deletions) {
191
+ if (chats.get(item)) {
192
+ chats.deleteById(item);
193
+ }
194
+ }
195
+ });
196
+ ev.on("messages.upsert", ({ messages: newMessages, type: type }) => {
197
+ switch (type) {
198
+ case "append":
199
+ case "notify":
200
+ for (const msg of newMessages) {
201
+ const jid = jidNormalizedUser(msg.key.remoteJid);
202
+ const list = assertMessageList(jid);
203
+ list.upsert(msg, "append");
204
+ if (type === "notify" && !chats.get(jid)) {
205
+ ev.emit("chats.upsert", [
206
+ {
207
+ id: jid,
208
+ conversationTimestamp: toNumber(msg.messageTimestamp),
209
+ unreadCount: 1,
210
+ },
211
+ ]);
212
+ }
213
+ }
214
+ break;
215
+ }
216
+ });
217
+ ev.on("messages.update", (updates) => {
218
+ for (const { update: update, key: key } of updates) {
219
+ const list = assertMessageList(jidNormalizedUser(key.remoteJid));
220
+ if (update?.status) {
221
+ const listStatus = list.get(key.id)?.status;
222
+ if (listStatus && update?.status <= listStatus) {
223
+ logger.debug(
224
+ { update: update, storedStatus: listStatus },
225
+ "status stored newer then update"
226
+ );
227
+ delete update.status;
228
+ logger.debug({ update: update }, "new update object");
229
+ }
230
+ }
231
+ const result = list.updateAssign(key.id, update);
232
+ if (!result) {
233
+ logger.debug({ update: update }, "got update for non-existent message");
234
+ }
235
+ }
236
+ });
237
+ ev.on("messages.delete", (item) => {
238
+ if ("all" in item) {
239
+ const list = messages[item.jid];
240
+ list?.clear();
241
+ } else {
242
+ const jid = item.keys[0].remoteJid;
243
+ const list = messages[jid];
244
+ if (list) {
245
+ const idSet = new Set(item.keys.map((k) => k.id));
246
+ list.filter((m) => !idSet.has(m.key.id));
247
+ }
248
+ }
249
+ });
250
+ ev.on("groups.update", (updates) => {
251
+ for (const update of updates) {
252
+ const id = update.id;
253
+ if (groupMetadata[id]) {
254
+ Object.assign(groupMetadata[id], update);
255
+ } else {
256
+ logger.debug({ update: update }, "got update for non-existant group metadata");
257
+ }
258
+ }
259
+ });
260
+ ev.on(
261
+ "group-participants.update",
262
+ ({ id: id, participants: participants, action: action }) => {
263
+ const metadata = groupMetadata[id];
264
+ if (metadata) {
265
+ switch (action) {
266
+ case "add":
267
+ metadata.participants.push(
268
+ ...participants.map((id) => ({
269
+ id: id,
270
+ isAdmin: false,
271
+ isSuperAdmin: false,
272
+ }))
273
+ );
274
+ break;
275
+ case "demote":
276
+ case "promote":
277
+ for (const participant of metadata.participants) {
278
+ if (participants.includes(participant.id)) {
279
+ participant.isAdmin = action === "promote";
280
+ }
281
+ }
282
+ break;
283
+ case "remove":
284
+ metadata.participants = metadata.participants.filter(
285
+ (p) => !participants.includes(p.id)
286
+ );
287
+ break;
288
+ }
289
+ }
290
+ }
291
+ );
292
+ ev.on("message-receipt.update", (updates) => {
293
+ for (const { key: key, receipt: receipt } of updates) {
294
+ const obj = messages[key.remoteJid];
295
+ const msg = obj?.get(key.id);
296
+ if (msg) {
297
+ updateMessageWithReceipt(msg, receipt);
298
+ }
299
+ }
300
+ });
301
+ ev.on("messages.reaction", (reactions) => {
302
+ for (const { key: key, reaction: reaction } of reactions) {
303
+ const obj = messages[key.remoteJid];
304
+ const msg = obj?.get(key.id);
305
+ if (msg) {
306
+ updateMessageWithReaction(msg, reaction);
307
+ }
308
+ }
309
+ });
310
+ };
311
+ const toJSON = () => ({
312
+ chats: chats,
313
+ contacts: contacts,
314
+ messages: messages,
315
+ labels: labels,
316
+ labelAssociations: labelAssociations,
317
+ });
318
+ const fromJSON = (json) => {
319
+ chats.upsert(...json.chats);
320
+ labelAssociations.upsert(...(json.labelAssociations || []));
321
+ contactsUpsert(Object.values(json.contacts));
322
+ labelsUpsert(Object.values(json.labels || {}));
323
+ for (const jid in json.messages) {
324
+ const list = assertMessageList(jid);
325
+ for (const msg of json.messages[jid]) {
326
+ list.upsert(proto.WebMessageInfo.fromObject(msg), "append");
327
+ }
328
+ }
329
+ };
330
+ return {
331
+ chats: chats,
332
+ contacts: contacts,
333
+ messages: messages,
334
+ groupMetadata: groupMetadata,
335
+ state: state,
336
+ presences: presences,
337
+ labels: labels,
338
+ labelAssociations: labelAssociations,
339
+ bind: bind,
340
+ loadMessages: async (jid, count, cursor) => {
341
+ const list = assertMessageList(jid);
342
+ const mode = !cursor || "before" in cursor ? "before" : "after";
343
+ const cursorKey = !!cursor
344
+ ? "before" in cursor
345
+ ? cursor.before
346
+ : cursor.after
347
+ : undefined;
348
+ const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
349
+ let messages;
350
+ if (list && mode === "before" && (!cursorKey || cursorValue)) {
351
+ if (cursorValue) {
352
+ const msgIdx = list.array.findIndex((m) => m.key.id === cursorKey?.id);
353
+ messages = list.array.slice(0, msgIdx);
354
+ } else {
355
+ messages = list.array;
356
+ }
357
+ const diff = count - messages.length;
358
+ if (diff < 0) {
359
+ messages = messages.slice(-count);
360
+ }
361
+ } else {
362
+ messages = [];
363
+ }
364
+ return messages;
365
+ },
366
+ getLabels: () => labels,
367
+ getChatLabels: (chatId) => labelAssociations.filter((la) => la.chatId === chatId).all(),
368
+ getMessageLabels: (messageId) => {
369
+ const associations = labelAssociations.filter((la) => la.messageId === messageId).all();
370
+ return associations.map(({ labelId: labelId }) => labelId);
371
+ },
372
+ loadMessage: async (jid, id) => messages[jid]?.get(id),
373
+ mostRecentMessage: async (jid) => {
374
+ const message = messages[jid]?.array.slice(-1)[0];
375
+ return message;
376
+ },
377
+ fetchImageUrl: async (jid, conn) => {
378
+ const contact = contacts[jid];
379
+ if (!contact) {
380
+ return conn?.profilePictureUrl(jid);
381
+ }
382
+ if (typeof contact.imgUrl === "undefined") {
383
+ contact.imgUrl = await conn?.profilePictureUrl(jid);
384
+ }
385
+ return contact.imgUrl;
386
+ },
387
+ fetchGroupMetadata: async (jid, conn) => {
388
+ if (!groupMetadata[jid]) {
389
+ const metadata = await conn?.groupMetadata(jid);
390
+ if (metadata) {
391
+ groupMetadata[jid] = metadata;
392
+ }
393
+ }
394
+ return groupMetadata[jid];
395
+ },
396
+ fetchMessageReceipts: async ({ remoteJid: remoteJid, id: id }) => {
397
+ const list = messages[remoteJid];
398
+ const msg = list?.get(id);
399
+ return msg?.userReceipt;
400
+ },
401
+ toJSON: toJSON,
402
+ fromJSON: fromJSON,
403
+ writeToFile: (path) => {
404
+ const { writeFileSync: writeFileSync } = require("fs");
405
+ writeFileSync(path, JSON.stringify(toJSON()));
406
+ },
407
+ readFromFile: (path) => {
408
+ const { readFileSync: readFileSync, existsSync: existsSync } = require("fs");
409
+ if (existsSync(path)) {
410
+ logger.debug({ path: path }, "reading from file");
411
+ const jsonStr = readFileSync(path, { encoding: "utf-8" });
412
+ const json = JSON.parse(jsonStr);
413
+ fromJSON(json);
414
+ }
415
+ },
416
+ };
417
+ };
418
+ module.exports = {
419
+ waChatKey: waChatKey,
420
+ waMessageID: waMessageID,
421
+ waLabelAssociationKey: waLabelAssociationKey,
422
+ makeInMemoryStore: makeInMemoryStore,
423
+ };
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function makeOrderedDictionary(idGetter) {
4
+ const array = [];
5
+ const dict = {};
6
+ const get = (id) => dict[id];
7
+ const update = (item) => {
8
+ const id = idGetter(item);
9
+ const idx = array.findIndex((i) => idGetter(i) === id);
10
+ if (idx >= 0) {
11
+ array[idx] = item;
12
+ dict[id] = item;
13
+ }
14
+ return false;
15
+ };
16
+ const upsert = (item, mode) => {
17
+ const id = idGetter(item);
18
+ if (get(id)) {
19
+ update(item);
20
+ } else {
21
+ if (mode === "append") {
22
+ array.push(item);
23
+ } else {
24
+ array.splice(0, 0, item);
25
+ }
26
+ dict[id] = item;
27
+ }
28
+ };
29
+ const remove = (item) => {
30
+ const id = idGetter(item);
31
+ const idx = array.findIndex((i) => idGetter(i) === id);
32
+ if (idx >= 0) {
33
+ array.splice(idx, 1);
34
+ delete dict[id];
35
+ return true;
36
+ }
37
+ return false;
38
+ };
39
+ return {
40
+ array: array,
41
+ get: get,
42
+ upsert: upsert,
43
+ update: update,
44
+ remove: remove,
45
+ updateAssign: (id, update) => {
46
+ const item = get(id);
47
+ if (item) {
48
+ Object.assign(item, update);
49
+ delete dict[id];
50
+ dict[idGetter(item)] = item;
51
+ return true;
52
+ }
53
+ return false;
54
+ },
55
+ clear: () => {
56
+ array.splice(0, array.length);
57
+ for (const key of Object.keys(dict)) {
58
+ delete dict[key];
59
+ }
60
+ },
61
+ filter: (contain) => {
62
+ let i = 0;
63
+ while (i < array.length) {
64
+ if (!contain(array[i])) {
65
+ delete dict[idGetter(array[i])];
66
+ array.splice(i, 1);
67
+ } else {
68
+ i += 1;
69
+ }
70
+ }
71
+ },
72
+ toJSON: () => array,
73
+ fromJSON: (newItems) => {
74
+ array.splice(0, array.length, ...newItems);
75
+ },
76
+ };
77
+ }
78
+ module.exports = { makeOrderedDictionary: makeOrderedDictionary };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ObjectRepository {
4
+ constructor(entities = {}) {
5
+ this.entityMap = new Map(Object.entries(entities));
6
+ }
7
+ findById(id) {
8
+ return this.entityMap.get(id);
9
+ }
10
+ findAll() {
11
+ return Array.from(this.entityMap.values());
12
+ }
13
+ upsertById(id, entity) {
14
+ return this.entityMap.set(id, { ...entity });
15
+ }
16
+ deleteById(id) {
17
+ return this.entityMap.delete(id);
18
+ }
19
+ count() {
20
+ return this.entityMap.size;
21
+ }
22
+ toJSON() {
23
+ return this.findAll();
24
+ }
25
+ }
26
+ module.exports = { ObjectRepository: ObjectRepository };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ALL_WA_PATCH_NAMES = [
4
+ "critical_block",
5
+ "critical_unblock_low",
6
+ "regular_high",
7
+ "regular_low",
8
+ "regular",
9
+ ];
10
+ module.exports = { ALL_WA_PATCH_NAMES: ALL_WA_PATCH_NAMES };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const LabelColor = {
4
+ Color1: 0,
5
+ Color2: 1,
6
+ Color3: 2,
7
+ Color4: 3,
8
+ Color5: 4,
9
+ Color6: 5,
10
+ Color7: 6,
11
+ Color8: 7,
12
+ Color9: 8,
13
+ Color10: 9,
14
+ Color11: 10,
15
+ Color12: 11,
16
+ Color13: 12,
17
+ Color14: 13,
18
+ Color15: 14,
19
+ Color16: 15,
20
+ Color17: 16,
21
+ Color18: 17,
22
+ Color19: 18,
23
+ Color20: 19,
24
+ };
25
+ module.exports = { LabelColor: LabelColor };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const LabelAssociationType = { Chat: "label_jid", Message: "label_message" };
4
+ module.exports = { LabelAssociationType: LabelAssociationType };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { proto: proto } = require("../../WAProto");
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const WAMessageAddressingMode = { PN: "pn", LID: "lid" };
6
+ module.exports = {
7
+ WAMessageAddressingMode: WAMessageAddressingMode,
8
+ WAMessageStubType: proto.WebMessageInfo.StubType,
9
+ WAMessageStatus: proto.WebMessageInfo.Status,
10
+ WAProto: proto,
11
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // Ported & adapted from PouCode fork for AsepXyz Baileys
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.QueryIds = exports.XWAPaths = void 0;
5
+ var XWAPaths;
6
+ (function (XWAPaths) {
7
+ XWAPaths["xwa2_newsletter_create"] = "xwa2_newsletter_create";
8
+ XWAPaths["xwa2_newsletter_subscribers"] = "xwa2_newsletter_subscribers";
9
+ XWAPaths["xwa2_newsletter_view"] = "xwa2_newsletter_view";
10
+ XWAPaths["xwa2_newsletter_metadata"] = "xwa2_newsletter";
11
+ XWAPaths["xwa2_newsletter_admin_count"] = "xwa2_newsletter_admin";
12
+ XWAPaths["xwa2_newsletter_mute_v2"] = "xwa2_newsletter_mute_v2";
13
+ XWAPaths["xwa2_newsletter_unmute_v2"] = "xwa2_newsletter_unmute_v2";
14
+ XWAPaths["xwa2_newsletter_follow"] = "xwa2_newsletter_follow";
15
+ XWAPaths["xwa2_newsletter_unfollow"] = "xwa2_newsletter_unfollow";
16
+ XWAPaths["xwa2_newsletter_join_v2"] = "xwa2_newsletter_join_v2";
17
+ XWAPaths["xwa2_newsletter_leave_v2"] = "xwa2_newsletter_leave_v2";
18
+ XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
19
+ XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_demote";
20
+ XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
21
+ XWAPaths["xwa2_fetch_account_reachout_timelock"] = "xwa2_fetch_account_reachout_timelock";
22
+ XWAPaths["xwa2_message_capping_info"] = "xwa2_message_capping_info";
23
+ })(XWAPaths = exports.XWAPaths || (exports.XWAPaths = {}));
24
+ var QueryIds;
25
+ (function (QueryIds) {
26
+ QueryIds["CREATE"] = "8823471724422422";
27
+ QueryIds["UPDATE_METADATA"] = "24250201037901610";
28
+ QueryIds["METADATA"] = "6563316087068696";
29
+ QueryIds["SUBSCRIBERS"] = "9783111038412085";
30
+ QueryIds["FOLLOW"] = "24404358912487870";
31
+ QueryIds["UNFOLLOW"] = "9767147403369991";
32
+ QueryIds["MUTE"] = "29766401636284406";
33
+ QueryIds["UNMUTE"] = "9864994326891137";
34
+ QueryIds["ADMIN_COUNT"] = "7130823597031706";
35
+ QueryIds["CHANGE_OWNER"] = "7341777602580933";
36
+ QueryIds["DEMOTE"] = "6551828931592903";
37
+ QueryIds["DELETE"] = "30062808666639665";
38
+ QueryIds["REACHOUT_TIMELOCK"] = "23983697327930364";
39
+ QueryIds["MESSAGE_CAPPING_INFO"] = "24503548349331633";
40
+ })(QueryIds = exports.QueryIds || (exports.QueryIds = {}));
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const MexUpdatesOperations = {
4
+ OWNER_COMMUNITY: "NotificationCommunityOwnerUpdate",
5
+ GROUP_MEMBER_LINK: "NotificationGroupMemberLinkPropertyUpdate",
6
+ GROUP_LIMIT_SHARING: "NotificationGroupLimitSharingPropertyUpdate",
7
+ };
8
+ const XWAPathsMexUpdates = {
9
+ GROUP_SHARING_CHANGE: "xwa2_notify_group_on_prop_change",
10
+ COMMUNITY_OWNER_CHANGE: "xwa2_notify_group_on_participants_roles_change",
11
+ };
12
+ module.exports = {
13
+ MexUpdatesOperations: MexUpdatesOperations,
14
+ XWAPathsMexUpdates: XWAPathsMexUpdates,
15
+ };