@skyzopedia/baileys-mod 3.0.2
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 +21 -0
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +94091 -0
- package/lib/Defaults/index.js +123 -0
- 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/lib/Signal/Group/sender-key-name.js +52 -0
- 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 +324 -0
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/business.js +377 -0
- package/lib/Socket/chats.js +881 -0
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +312 -0
- package/lib/Socket/index.js +16 -0
- package/lib/Socket/messages-recv.js +1163 -0
- package/lib/Socket/messages-send.js +1082 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +259 -0
- package/lib/Socket/socket.js +781 -0
- package/lib/Store/index.js +6 -0
- package/lib/Store/make-cache-manager-store.js +75 -0
- package/lib/Store/make-in-memory-store.js +290 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.js +25 -0
- package/lib/Types/Auth.js +3 -0
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -0
- package/lib/Types/Chat.js +9 -0
- package/lib/Types/Contact.js +3 -0
- package/lib/Types/Events.js +3 -0
- package/lib/Types/GroupMetadata.js +3 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +12 -0
- package/lib/Types/Newsletter.js +33 -0
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -0
- package/lib/Types/Signal.js +3 -0
- package/lib/Types/Socket.js +4 -0
- package/lib/Types/State.js +11 -0
- package/lib/Types/USync.js +3 -0
- package/lib/Types/index.js +28 -0
- package/lib/Utils/auth-utils.js +219 -0
- package/lib/Utils/baileys-event-stream.js +44 -0
- package/lib/Utils/browser-utils.js +17 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +752 -0
- package/lib/Utils/crypto.js +130 -0
- package/lib/Utils/decode-wa-message.js +267 -0
- package/lib/Utils/event-buffer.js +528 -0
- package/lib/Utils/generics.js +355 -0
- package/lib/Utils/history.js +87 -0
- package/lib/Utils/index.js +21 -0
- package/lib/Utils/link-preview.js +81 -0
- package/lib/Utils/logger.js +5 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +36 -0
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +601 -0
- package/lib/Utils/messages.js +776 -0
- package/lib/Utils/noise-handler.js +144 -0
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +341 -0
- package/lib/Utils/signal.js +161 -0
- package/lib/Utils/use-multi-file-auth-state.js +111 -0
- package/lib/Utils/validate-connection.js +200 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +240 -0
- package/lib/WABinary/encode.js +218 -0
- package/lib/WABinary/generic-utils.js +113 -0
- package/lib/WABinary/index.js +7 -0
- package/lib/WABinary/jid-utils.js +93 -0
- package/lib/WABinary/types.js +3 -0
- package/lib/WAM/BinaryInfo.js +11 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +154 -0
- package/lib/WAM/index.js +5 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.js +90 -0
- package/lib/WAUSync/USyncUser.js +24 -0
- package/lib/WAUSync/index.js +5 -0
- package/lib/index.js +15 -0
- package/package.json +102 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//===================================//
|
|
2
|
+
import { BufferJSON, initAuthCreds } from "../Utils/index.js";
|
|
3
|
+
import { proto } from "../../WAProto/index.js";
|
|
4
|
+
import { createCache } from "cache-manager";
|
|
5
|
+
import logger from "../Utils/logger.js";
|
|
6
|
+
//===================================//
|
|
7
|
+
export async function makeCacheManagerAuthState(store, sessionKey) {
|
|
8
|
+
const defaultKey = (file) => `${sessionKey}:${file}`
|
|
9
|
+
const databaseConn = await caching(store);
|
|
10
|
+
const writeData = async (file, data) => {
|
|
11
|
+
let ttl
|
|
12
|
+
if (file === "creds") {
|
|
13
|
+
ttl = 63115200
|
|
14
|
+
}
|
|
15
|
+
await databaseConn.set(defaultKey(file), JSON.stringify(data, BufferJSON.replacer), ttl)
|
|
16
|
+
}
|
|
17
|
+
const readData = async (file) => {
|
|
18
|
+
try {
|
|
19
|
+
const data = await databaseConn.get(defaultKey(file))
|
|
20
|
+
if (data) return JSON.parse(data, BufferJSON.reviver)
|
|
21
|
+
return null
|
|
22
|
+
} catch (error) {
|
|
23
|
+
logger.error(error)
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const removeData = async (file) => {
|
|
28
|
+
try {
|
|
29
|
+
return await databaseConn.del(defaultKey(file))
|
|
30
|
+
} catch (err) {
|
|
31
|
+
logger.error(`Error removing ${file} from session ${sessionKey}`)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const clearState = async () => {
|
|
35
|
+
try {
|
|
36
|
+
const keys = await databaseConn.store.keys(`${sessionKey}*`)
|
|
37
|
+
await Promise.all(keys.map((key) => databaseConn.del(key)))
|
|
38
|
+
} catch (err) {}
|
|
39
|
+
}
|
|
40
|
+
const creds = (await readData("creds")) || initAuthCreds()
|
|
41
|
+
return {
|
|
42
|
+
clearState,
|
|
43
|
+
saveCreds: () => writeData("creds", creds),
|
|
44
|
+
state: {
|
|
45
|
+
creds,
|
|
46
|
+
keys: {
|
|
47
|
+
get: async (type, ids) => {
|
|
48
|
+
const data = {}
|
|
49
|
+
await Promise.all(
|
|
50
|
+
ids.map(async (id) => {
|
|
51
|
+
let value = await readData(`${type}-${id}`)
|
|
52
|
+
if (type === "app-state-sync-key" && value) {
|
|
53
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value)
|
|
54
|
+
}
|
|
55
|
+
data[id] = value
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
return data
|
|
59
|
+
},
|
|
60
|
+
set: async (data) => {
|
|
61
|
+
const tasks = []
|
|
62
|
+
for (const category in data) {
|
|
63
|
+
for (const id in data[category]) {
|
|
64
|
+
const value = data[category][id]
|
|
65
|
+
const key = `${category}-${id}`
|
|
66
|
+
tasks.push(value ? writeData(key, value) : removeData(key))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
await Promise.all(tasks)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//===================================//
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
//===================================//
|
|
2
|
+
import { md5, toNumber, updateMessageWithReceipt, updateMessageWithReaction } from "../Utils/index.js"
|
|
3
|
+
import { DEFAULT_CONNECTION_CONFIG } from "../Defaults/index.js"
|
|
4
|
+
import { makeOrderedDictionary } from "./make-ordered-dictionary.js"
|
|
5
|
+
import { LabelAssociationType } from "../Types/LabelAssociation.js"
|
|
6
|
+
import { jidDecode, jidNormalizedUser } from "../WABinary/index.js"
|
|
7
|
+
import { proto } from "../../WAProto/index.js";
|
|
8
|
+
import { ObjectRepository } from "./object-repository.js"
|
|
9
|
+
import KeyedDB from "../KeyDB/KeyedDB.js"
|
|
10
|
+
//===================================//
|
|
11
|
+
export const waChatKey = (pin) => ({
|
|
12
|
+
key: (c) => (pin ? (c.pinned ? "1" : "0") : "") + (c.archived ? "0" : "1") + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, "0") : "") + c.id,
|
|
13
|
+
compare: (k1, k2) => k2.localeCompare(k1)
|
|
14
|
+
})
|
|
15
|
+
//===================================//
|
|
16
|
+
export const waMessageID = (m) => m.key.id || ""
|
|
17
|
+
//===================================//
|
|
18
|
+
export const waLabelAssociationKey = {
|
|
19
|
+
key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
20
|
+
compare: (k1, k2) => k2.localeCompare(k1)
|
|
21
|
+
}
|
|
22
|
+
//===================================//
|
|
23
|
+
const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID)
|
|
24
|
+
//===================================//
|
|
25
|
+
export const makeInMemoryStore = (config) => {
|
|
26
|
+
const socket = config.socket
|
|
27
|
+
const chatKey = config.chatKey || waChatKey(true)
|
|
28
|
+
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey
|
|
29
|
+
const logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: "in-mem-store" })
|
|
30
|
+
const chats = new KeyedDB(chatKey, c => c.id)
|
|
31
|
+
const messages = {}
|
|
32
|
+
const contacts = {}
|
|
33
|
+
const groupMetadata = {}
|
|
34
|
+
const presences = {}
|
|
35
|
+
const state = { connection: "close" }
|
|
36
|
+
const labels = new ObjectRepository()
|
|
37
|
+
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key)
|
|
38
|
+
const assertMessageList = (jid) => {
|
|
39
|
+
if (!messages[jid]) messages[jid] = makeMessagesDictionary()
|
|
40
|
+
return messages[jid]
|
|
41
|
+
}
|
|
42
|
+
const contactsUpsert = (newContacts) => {
|
|
43
|
+
const oldContacts = new Set(Object.keys(contacts))
|
|
44
|
+
for (const contact of newContacts) {
|
|
45
|
+
oldContacts.delete(contact.id)
|
|
46
|
+
contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact)
|
|
47
|
+
}
|
|
48
|
+
return oldContacts
|
|
49
|
+
}
|
|
50
|
+
const labelsUpsert = (newLabels) => {
|
|
51
|
+
for (const label of newLabels) labels.upsertById(label.id, label)
|
|
52
|
+
}
|
|
53
|
+
const bind = (ev) => {
|
|
54
|
+
ev.on("connection.update", update => Object.assign(state, update))
|
|
55
|
+
ev.on("messaging-history.set", ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
56
|
+
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) return
|
|
57
|
+
if (isLatest) {
|
|
58
|
+
chats.clear()
|
|
59
|
+
for (const id in messages) delete messages[id]
|
|
60
|
+
}
|
|
61
|
+
const chatsAdded = chats.insertIfAbsent(...newChats).length
|
|
62
|
+
logger.debug({ chatsAdded }, "synced chats")
|
|
63
|
+
const oldContacts = contactsUpsert(newContacts)
|
|
64
|
+
if (isLatest) for (const jid of oldContacts) delete contacts[jid]
|
|
65
|
+
logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, "synced contacts")
|
|
66
|
+
for (const msg of newMessages) {
|
|
67
|
+
const jid = msg.key.remoteJid
|
|
68
|
+
const list = assertMessageList(jid)
|
|
69
|
+
list.upsert(msg, "prepend")
|
|
70
|
+
}
|
|
71
|
+
logger.debug({ messages: newMessages.length }, "synced messages")
|
|
72
|
+
})
|
|
73
|
+
ev.on("contacts.upsert", contacts => contactsUpsert(contacts))
|
|
74
|
+
ev.on("contacts.update", async (updates) => {
|
|
75
|
+
for (const update of updates) {
|
|
76
|
+
let contact = contacts[update.id]
|
|
77
|
+
if (!contact) {
|
|
78
|
+
const contactHashes = await Promise.all(
|
|
79
|
+
Object.keys(contacts).map(async (contactId) => {
|
|
80
|
+
const { user } = jidDecode(contactId)
|
|
81
|
+
return [contactId, (await md5(Buffer.from(user + "WA_ADD_NOTIF", "utf8"))).toString("base64").slice(0, 3)]
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || ""]
|
|
85
|
+
}
|
|
86
|
+
if (contact) {
|
|
87
|
+
if (update.imgUrl === "changed") contact.imgUrl = socket ? await socket.profilePictureUrl(contact.id) : undefined
|
|
88
|
+
else if (update.imgUrl === "removed") delete contact.imgUrl
|
|
89
|
+
} else return logger.debug({ update }, "got update for non-existant contact")
|
|
90
|
+
|
|
91
|
+
Object.assign(contacts[contact.id], contact)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
ev.on("chats.upsert", newChats => chats.upsert(...newChats))
|
|
95
|
+
ev.on("chats.update", updates => {
|
|
96
|
+
for (let update of updates) {
|
|
97
|
+
const result = chats.update(update.id, chat => {
|
|
98
|
+
if (update.unreadCount > 0) {
|
|
99
|
+
update = { ...update }
|
|
100
|
+
update.unreadCount = (chat.unreadCount || 0) + update.unreadCount
|
|
101
|
+
}
|
|
102
|
+
Object.assign(chat, update)
|
|
103
|
+
})
|
|
104
|
+
if (!result) logger.debug({ update }, "got update for non-existant chat")
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
ev.on("labels.edit", (label) => {
|
|
108
|
+
if (label.deleted) return labels.deleteById(label.id)
|
|
109
|
+
if (labels.count() < 20) return labels.upsertById(label.id, label)
|
|
110
|
+
logger.error("Labels count exceed")
|
|
111
|
+
})
|
|
112
|
+
ev.on("labels.association", ({ type, association }) => {
|
|
113
|
+
switch (type) {
|
|
114
|
+
case "add": labelAssociations.upsert(association); break
|
|
115
|
+
case "remove": labelAssociations.delete(association); break
|
|
116
|
+
default: console.error(`unknown operation type [${type}]`)
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
ev.on("presence.update", ({ id, presences: update }) => {
|
|
120
|
+
presences[id] = presences[id] || {}
|
|
121
|
+
Object.assign(presences[id], update)
|
|
122
|
+
})
|
|
123
|
+
ev.on("chats.delete", deletions => {
|
|
124
|
+
for (const item of deletions) if (chats.get(item)) chats.deleteById(item)
|
|
125
|
+
})
|
|
126
|
+
ev.on("messages.upsert", ({ messages: newMessages, type }) => {
|
|
127
|
+
switch (type) {
|
|
128
|
+
case "append":
|
|
129
|
+
case "notify":
|
|
130
|
+
for (const msg of newMessages) {
|
|
131
|
+
const jid = jidNormalizedUser(msg.key.remoteJid)
|
|
132
|
+
const list = assertMessageList(jid)
|
|
133
|
+
list.upsert(msg, "append")
|
|
134
|
+
if (type === "notify" && !chats.get(jid)) {
|
|
135
|
+
ev.emit("chats.upsert", [{
|
|
136
|
+
id: jid,
|
|
137
|
+
conversationTimestamp: toNumber(msg.messageTimestamp),
|
|
138
|
+
unreadCount: 1
|
|
139
|
+
}])
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
ev.on("messages.update", updates => {
|
|
146
|
+
for (const { update, key } of updates) {
|
|
147
|
+
const list = assertMessageList(jidNormalizedUser(key.remoteJid))
|
|
148
|
+
if (update?.status) {
|
|
149
|
+
const listStatus = list.get(key.id)?.status
|
|
150
|
+
if (listStatus && update.status <= listStatus) {
|
|
151
|
+
logger.debug({ update, storedStatus: listStatus }, "status stored newer then update")
|
|
152
|
+
delete update.status
|
|
153
|
+
logger.debug({ update }, "new update object")
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const result = list.updateAssign(key.id, update)
|
|
157
|
+
if (!result) logger.debug({ update }, "got update for non-existent message")
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
ev.on("messages.delete", item => {
|
|
161
|
+
if ("all" in item) messages[item.jid]?.clear()
|
|
162
|
+
else {
|
|
163
|
+
const jid = item.keys[0].remoteJid
|
|
164
|
+
const list = messages[jid]
|
|
165
|
+
if (list) {
|
|
166
|
+
const idSet = new Set(item.keys.map(k => k.id))
|
|
167
|
+
list.filter(m => !idSet.has(m.key.id))
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
ev.on("groups.update", updates => {
|
|
172
|
+
for (const update of updates) {
|
|
173
|
+
const id = update.id
|
|
174
|
+
if (groupMetadata[id]) Object.assign(groupMetadata[id], update)
|
|
175
|
+
else logger.debug({ update }, "got update for non-existant group metadata")
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
ev.on("group-participants.update", ({ id, participants, action }) => {
|
|
179
|
+
const metadata = groupMetadata[id]
|
|
180
|
+
if (!metadata) return
|
|
181
|
+
switch (action) {
|
|
182
|
+
case "add":
|
|
183
|
+
metadata.participants.push(...participants.map(id => ({ id, isAdmin: false, isSuperAdmin: false })))
|
|
184
|
+
break
|
|
185
|
+
case "promote":
|
|
186
|
+
case "demote":
|
|
187
|
+
for (const participant of metadata.participants) {
|
|
188
|
+
if (participants.includes(participant.id)) participant.isAdmin = action === "promote"
|
|
189
|
+
}
|
|
190
|
+
break
|
|
191
|
+
case "remove":
|
|
192
|
+
metadata.participants = metadata.participants.filter(p => !participants.includes(p.id))
|
|
193
|
+
break
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
ev.on("message-receipt.update", updates => {
|
|
197
|
+
for (const { key, receipt } of updates) {
|
|
198
|
+
const obj = messages[key.remoteJid]
|
|
199
|
+
const msg = obj?.get(key.id)
|
|
200
|
+
if (msg) updateMessageWithReceipt(msg, receipt)
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
ev.on("messages.reaction", reactions => {
|
|
204
|
+
for (const { key, reaction } of reactions) {
|
|
205
|
+
const obj = messages[key.remoteJid]
|
|
206
|
+
const msg = obj?.get(key.id)
|
|
207
|
+
if (msg) updateMessageWithReaction(msg, reaction)
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
const toJSON = () => ({ chats, contacts, messages, labels, labelAssociations })
|
|
212
|
+
const fromJSON = (json) => {
|
|
213
|
+
chats.upsert(...json.chats)
|
|
214
|
+
labelAssociations.upsert(...json.labelAssociations || [])
|
|
215
|
+
contactsUpsert(Object.values(json.contacts))
|
|
216
|
+
labelsUpsert(Object.values(json.labels || {}))
|
|
217
|
+
for (const jid in json.messages) {
|
|
218
|
+
const list = assertMessageList(jid)
|
|
219
|
+
for (const msg of json.messages[jid]) list.upsert(proto.WebMessageInfo.fromObject(msg), "append")
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
chats,
|
|
224
|
+
contacts,
|
|
225
|
+
messages,
|
|
226
|
+
groupMetadata,
|
|
227
|
+
state,
|
|
228
|
+
presences,
|
|
229
|
+
labels,
|
|
230
|
+
labelAssociations,
|
|
231
|
+
bind,
|
|
232
|
+
loadMessages: async (jid, count, cursor) => {
|
|
233
|
+
const list = assertMessageList(jid)
|
|
234
|
+
const mode = !cursor || "before" in cursor ? "before" : "after"
|
|
235
|
+
const cursorKey = cursor ? ("before" in cursor ? cursor.before : cursor.after) : undefined
|
|
236
|
+
const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined
|
|
237
|
+
let msgs
|
|
238
|
+
if (list && mode === "before" && (!cursorKey || cursorValue)) {
|
|
239
|
+
if (cursorValue) {
|
|
240
|
+
const idx = list.array.findIndex(m => m.key.id === cursorKey?.id)
|
|
241
|
+
msgs = list.array.slice(0, idx)
|
|
242
|
+
} else msgs = list.array
|
|
243
|
+
const diff = count - msgs.length
|
|
244
|
+
if (diff < 0) msgs = msgs.slice(-count)
|
|
245
|
+
} else msgs = []
|
|
246
|
+
return msgs
|
|
247
|
+
},
|
|
248
|
+
getLabels: () => labels,
|
|
249
|
+
getChatLabels: (chatId) => labelAssociations.filter(la => la.chatId === chatId).all(),
|
|
250
|
+
getMessageLabels: (messageId) => labelAssociations.filter(la => la.messageId === messageId).all().map(l => l.labelId),
|
|
251
|
+
loadMessage: async (jid, id) => messages[jid]?.get(id),
|
|
252
|
+
mostRecentMessage: async (jid) => messages[jid]?.array.slice(-1)[0],
|
|
253
|
+
fetchImageUrl: async (jid, baron) => {
|
|
254
|
+
const contact = contacts[jid]
|
|
255
|
+
if (!contact) return baron?.profilePictureUrl?.(jid)
|
|
256
|
+
if (typeof contact.imgUrl === "undefined") {
|
|
257
|
+
contact.imgUrl = await baron?.profilePictureUrl?.(jid)
|
|
258
|
+
}
|
|
259
|
+
return contact.imgUrl
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
fetchGroupMetadata: async (jid, baron) => {
|
|
263
|
+
if (!groupMetadata[jid]) {
|
|
264
|
+
const metadata = await baron?.groupMetadata(jid)
|
|
265
|
+
if (metadata) groupMetadata[jid] = metadata
|
|
266
|
+
}
|
|
267
|
+
return groupMetadata[jid]
|
|
268
|
+
},
|
|
269
|
+
fetchMessageReceipts: async ({ remoteJid, id }) => {
|
|
270
|
+
const list = messages[remoteJid]
|
|
271
|
+
const msg = list?.get(id)
|
|
272
|
+
return msg?.userReceipt
|
|
273
|
+
},
|
|
274
|
+
toJSON,
|
|
275
|
+
fromJSON,
|
|
276
|
+
writeToFile: (path) => {
|
|
277
|
+
import("fs").then(fs => fs.writeFileSync(path, JSON.stringify(toJSON())))
|
|
278
|
+
},
|
|
279
|
+
readFromFile: async (path) => {
|
|
280
|
+
const fs = await import("fs")
|
|
281
|
+
if (fs.existsSync(path)) {
|
|
282
|
+
logger.debug({ path }, "reading from file")
|
|
283
|
+
const jsonStr = fs.readFileSync(path, { encoding: "utf-8" })
|
|
284
|
+
const json = JSON.parse(jsonStr)
|
|
285
|
+
fromJSON(json)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//===================================//
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//===================================//
|
|
2
|
+
export function makeOrderedDictionary(idGetter) {
|
|
3
|
+
const array = []
|
|
4
|
+
const dict = {}
|
|
5
|
+
const get = (id) => dict[id]
|
|
6
|
+
const update = (item) => {
|
|
7
|
+
const id = idGetter(item)
|
|
8
|
+
const idx = array.findIndex(i => idGetter(i) === id)
|
|
9
|
+
if (idx >= 0) {
|
|
10
|
+
array[idx] = item
|
|
11
|
+
dict[id] = item
|
|
12
|
+
}
|
|
13
|
+
return false
|
|
14
|
+
}
|
|
15
|
+
const upsert = (item, mode) => {
|
|
16
|
+
const id = idGetter(item)
|
|
17
|
+
if (get(id)) {
|
|
18
|
+
update(item)
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (mode === "append") {
|
|
22
|
+
array.push(item)
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
array.splice(0, 0, item)
|
|
26
|
+
}
|
|
27
|
+
dict[id] = item
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const remove = (item) => {
|
|
31
|
+
const id = idGetter(item)
|
|
32
|
+
const idx = array.findIndex(i => idGetter(i) === id)
|
|
33
|
+
if (idx >= 0) {
|
|
34
|
+
array.splice(idx, 1)
|
|
35
|
+
delete dict[id]
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
array,
|
|
42
|
+
get,
|
|
43
|
+
upsert,
|
|
44
|
+
update,
|
|
45
|
+
remove,
|
|
46
|
+
updateAssign: (id, update) => {
|
|
47
|
+
const item = get(id)
|
|
48
|
+
if (item) {
|
|
49
|
+
Object.assign(item, update)
|
|
50
|
+
delete dict[id]
|
|
51
|
+
dict[idGetter(item)] = item
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
return false
|
|
55
|
+
},
|
|
56
|
+
clear: () => {
|
|
57
|
+
array.splice(0, array.length)
|
|
58
|
+
for (const key of Object.keys(dict)) {
|
|
59
|
+
delete dict[key]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
filter: (contain) => {
|
|
63
|
+
let i = 0
|
|
64
|
+
while (i < array.length) {
|
|
65
|
+
if (!contain(array[i])) {
|
|
66
|
+
delete dict[idGetter(array[i])]
|
|
67
|
+
array.splice(i, 1)
|
|
68
|
+
} else {
|
|
69
|
+
i += 1
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
toJSON: () => array,
|
|
74
|
+
fromJSON: (newItems) => {
|
|
75
|
+
array.splice(0, array.length, ...newItems)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//===================================//
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//===================================//
|
|
2
|
+
export class ObjectRepository {
|
|
3
|
+
constructor(entities = {}) {
|
|
4
|
+
this.entityMap = new Map(Object.entries(entities))
|
|
5
|
+
}
|
|
6
|
+
findById(id) {
|
|
7
|
+
return this.entityMap.get(id)
|
|
8
|
+
}
|
|
9
|
+
findAll() {
|
|
10
|
+
return Array.from(this.entityMap.values())
|
|
11
|
+
}
|
|
12
|
+
upsertById(id, entity) {
|
|
13
|
+
return this.entityMap.set(id, { ...entity })
|
|
14
|
+
}
|
|
15
|
+
deleteById(id) {
|
|
16
|
+
return this.entityMap.delete(id)
|
|
17
|
+
}
|
|
18
|
+
count() {
|
|
19
|
+
return this.entityMap.size
|
|
20
|
+
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
return this.findAll()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//===================================//
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
export var LabelColor;
|
|
3
|
+
(function (LabelColor) {
|
|
4
|
+
LabelColor[LabelColor["Color1"] = 0] = "Color1";
|
|
5
|
+
LabelColor[LabelColor["Color2"] = 1] = "Color2";
|
|
6
|
+
LabelColor[LabelColor["Color3"] = 2] = "Color3";
|
|
7
|
+
LabelColor[LabelColor["Color4"] = 3] = "Color4";
|
|
8
|
+
LabelColor[LabelColor["Color5"] = 4] = "Color5";
|
|
9
|
+
LabelColor[LabelColor["Color6"] = 5] = "Color6";
|
|
10
|
+
LabelColor[LabelColor["Color7"] = 6] = "Color7";
|
|
11
|
+
LabelColor[LabelColor["Color8"] = 7] = "Color8";
|
|
12
|
+
LabelColor[LabelColor["Color9"] = 8] = "Color9";
|
|
13
|
+
LabelColor[LabelColor["Color10"] = 9] = "Color10";
|
|
14
|
+
LabelColor[LabelColor["Color11"] = 10] = "Color11";
|
|
15
|
+
LabelColor[LabelColor["Color12"] = 11] = "Color12";
|
|
16
|
+
LabelColor[LabelColor["Color13"] = 12] = "Color13";
|
|
17
|
+
LabelColor[LabelColor["Color14"] = 13] = "Color14";
|
|
18
|
+
LabelColor[LabelColor["Color15"] = 14] = "Color15";
|
|
19
|
+
LabelColor[LabelColor["Color16"] = 15] = "Color16";
|
|
20
|
+
LabelColor[LabelColor["Color17"] = 16] = "Color17";
|
|
21
|
+
LabelColor[LabelColor["Color18"] = 17] = "Color18";
|
|
22
|
+
LabelColor[LabelColor["Color19"] = 18] = "Color19";
|
|
23
|
+
LabelColor[LabelColor["Color20"] = 19] = "Color20";
|
|
24
|
+
})(LabelColor || (LabelColor = {}));
|
|
25
|
+
//=======================================================//
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
export var LabelAssociationType;
|
|
3
|
+
(function (LabelAssociationType) {
|
|
4
|
+
LabelAssociationType["Chat"] = "label_jid";
|
|
5
|
+
LabelAssociationType["Message"] = "label_message";
|
|
6
|
+
})(LabelAssociationType || (LabelAssociationType = {}));
|
|
7
|
+
//=======================================================//
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { proto } from "../../WAProto/index.js";
|
|
3
|
+
//=======================================================//
|
|
4
|
+
export { proto as WAProto };
|
|
5
|
+
export const WAMessageStubType = proto.WebMessageInfo.StubType;
|
|
6
|
+
export const WAMessageStatus = proto.WebMessageInfo.Status;
|
|
7
|
+
export var WAMessageAddressingMode;
|
|
8
|
+
(function (WAMessageAddressingMode) {
|
|
9
|
+
WAMessageAddressingMode["PN"] = "pn";
|
|
10
|
+
WAMessageAddressingMode["LID"] = "lid";
|
|
11
|
+
})(WAMessageAddressingMode || (WAMessageAddressingMode = {}));
|
|
12
|
+
//=======================================================//
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
export var XWAPaths;
|
|
3
|
+
(function (XWAPaths) {
|
|
4
|
+
XWAPaths["xwa2_newsletter_create"] = "xwa2_newsletter_create";
|
|
5
|
+
XWAPaths["xwa2_newsletter_subscribers"] = "xwa2_newsletter_subscribers";
|
|
6
|
+
XWAPaths["xwa2_newsletter_view"] = "xwa2_newsletter_view";
|
|
7
|
+
XWAPaths["xwa2_newsletter_metadata"] = "xwa2_newsletter";
|
|
8
|
+
XWAPaths["xwa2_newsletter_admin_count"] = "xwa2_newsletter_admin";
|
|
9
|
+
XWAPaths["xwa2_newsletter_mute_v2"] = "xwa2_newsletter_mute_v2";
|
|
10
|
+
XWAPaths["xwa2_newsletter_unmute_v2"] = "xwa2_newsletter_unmute_v2";
|
|
11
|
+
XWAPaths["xwa2_newsletter_follow"] = "xwa2_newsletter_follow";
|
|
12
|
+
XWAPaths["xwa2_newsletter_unfollow"] = "xwa2_newsletter_unfollow";
|
|
13
|
+
XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
|
|
14
|
+
XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_demote";
|
|
15
|
+
XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
|
|
16
|
+
})(XWAPaths || (XWAPaths = {}));
|
|
17
|
+
//=======================================================//
|
|
18
|
+
export var QueryIds;
|
|
19
|
+
(function (QueryIds) {
|
|
20
|
+
QueryIds["CREATE"] = "8823471724422422";
|
|
21
|
+
QueryIds["UPDATE_METADATA"] = "24250201037901610";
|
|
22
|
+
QueryIds["METADATA"] = "6620195908089573";
|
|
23
|
+
QueryIds["SUBSCRIBERS"] = "6388546374527196";
|
|
24
|
+
QueryIds["FOLLOW"] = "7871414976211147";
|
|
25
|
+
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
26
|
+
QueryIds["MUTE"] = "29766401636284406";
|
|
27
|
+
QueryIds["UNMUTE"] = "9864994326891137";
|
|
28
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
29
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
30
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
|
31
|
+
QueryIds["DELETE"] = "30062808666639665";
|
|
32
|
+
})(QueryIds || (QueryIds = {}));
|
|
33
|
+
//=======================================================//
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
export var XWAPaths;
|
|
3
|
+
(function (XWAPaths) {
|
|
4
|
+
XWAPaths["xwa2_newsletter_create"] = "xwa2_newsletter_create";
|
|
5
|
+
XWAPaths["xwa2_newsletter_subscribers"] = "xwa2_newsletter_subscribers";
|
|
6
|
+
XWAPaths["xwa2_newsletter_view"] = "xwa2_newsletter_view";
|
|
7
|
+
XWAPaths["xwa2_newsletter_metadata"] = "xwa2_newsletter";
|
|
8
|
+
XWAPaths["xwa2_newsletter_admin_count"] = "xwa2_newsletter_admin";
|
|
9
|
+
XWAPaths["xwa2_newsletter_mute_v2"] = "xwa2_newsletter_mute_v2";
|
|
10
|
+
XWAPaths["xwa2_newsletter_unmute_v2"] = "xwa2_newsletter_unmute_v2";
|
|
11
|
+
XWAPaths["xwa2_newsletter_follow"] = "xwa2_newsletter_follow";
|
|
12
|
+
XWAPaths["xwa2_newsletter_unfollow"] = "xwa2_newsletter_unfollow";
|
|
13
|
+
XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
|
|
14
|
+
XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_demote";
|
|
15
|
+
XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
|
|
16
|
+
})(XWAPaths || (XWAPaths = {}));
|
|
17
|
+
//=======================================================//
|
|
18
|
+
export var QueryIds;
|
|
19
|
+
(function (QueryIds) {
|
|
20
|
+
QueryIds["CREATE"] = "8823471724422422";
|
|
21
|
+
QueryIds["UPDATE_METADATA"] = "24250201037901610";
|
|
22
|
+
QueryIds["METADATA"] = "6563316087068696";
|
|
23
|
+
QueryIds["SUBSCRIBERS"] = "6388546374527196";
|
|
24
|
+
QueryIds["FOLLOW"] = "7871414976211147";
|
|
25
|
+
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
26
|
+
QueryIds["MUTE"] = "29766401636284406";
|
|
27
|
+
QueryIds["UNMUTE"] = "9864994326891137";
|
|
28
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
29
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
30
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
|
31
|
+
QueryIds["DELETE"] = "30062808666639665";
|
|
32
|
+
})(QueryIds || (QueryIds = {}));
|
|
33
|
+
//=======================================================//
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { Boom } from "@hapi/boom";
|
|
3
|
+
//=======================================================//
|
|
4
|
+
export var SyncState;
|
|
5
|
+
(function (SyncState) {
|
|
6
|
+
SyncState[SyncState["Connecting"] = 0] = "Connecting";
|
|
7
|
+
SyncState[SyncState["AwaitingInitialSync"] = 1] = "AwaitingInitialSync";
|
|
8
|
+
SyncState[SyncState["Syncing"] = 2] = "Syncing";
|
|
9
|
+
SyncState[SyncState["Online"] = 3] = "Online";
|
|
10
|
+
})(SyncState || (SyncState = {}));
|
|
11
|
+
//=======================================================//
|