socketon 1.31.2-rc → 1.51.16
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 +313 -159
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +65801 -141371
- package/lib/Defaults/index.js +117 -141
- 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 +12 -14
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +75 -87
- package/lib/Signal/Group/index.js +13 -57
- package/lib/Signal/Group/keyhelper.js +17 -52
- package/lib/Signal/Group/sender-chain-key.js +27 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -63
- package/lib/Signal/Group/sender-key-message.js +65 -66
- package/lib/Signal/Group/sender-key-name.js +45 -44
- package/lib/Signal/Group/sender-key-record.js +39 -49
- package/lib/Signal/Group/sender-key-state.js +80 -93
- package/lib/Signal/Group/sender-message-key.js +27 -28
- package/lib/Signal/libsignal.js +313 -163
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -19
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/Client/websocket.js.bak +53 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +846 -935
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -309
- package/lib/Socket/index.js +15 -10
- package/lib/Socket/messages-recv.js +1107 -1054
- package/lib/Socket/messages-send.js +639 -448
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +240 -324
- package/lib/Socket/socket.js +794 -651
- package/lib/Socket/socketon.js +402 -0
- package/lib/Store/index.js +6 -10
- package/lib/Store/make-cache-manager-store.js +73 -81
- package/lib/Store/make-in-memory-store.js +286 -423
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +9 -4
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +12 -9
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -2
- package/lib/Types/State.js +11 -2
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +27 -41
- package/lib/Utils/auth-utils.js +211 -198
- package/lib/Utils/baileys-event-stream.js +42 -61
- package/lib/Utils/browser-utils.js +25 -0
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +710 -687
- package/lib/Utils/crypto.js +112 -133
- package/lib/Utils/decode-wa-message.js +252 -183
- package/lib/Utils/decode-wa-message.js.bak +267 -0
- package/lib/Utils/event-buffer.js +510 -496
- package/lib/Utils/generics.js +319 -392
- package/lib/Utils/history.js +83 -92
- package/lib/Utils/index.js +21 -33
- package/lib/Utils/link-preview.js +71 -83
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +550 -768
- package/lib/Utils/messages.js +354 -263
- package/lib/Utils/noise-handler.js +138 -149
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +323 -303
- package/lib/Utils/signal.js +149 -141
- package/lib/Utils/use-multi-file-auth-state.js +95 -103
- package/lib/Utils/validate-connection.js +183 -214
- package/lib/WABinary/constants.js +1298 -35
- package/lib/WABinary/decode.js +237 -249
- package/lib/WABinary/encode.js +213 -260
- package/lib/WABinary/generic-utils.js +56 -65
- package/lib/WABinary/index.js +7 -21
- package/lib/WABinary/jid-utils.js +89 -58
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.js +10 -12
- package/lib/WAM/constants.js +22851 -15348
- package/lib/WAM/encode.js +135 -136
- package/lib/WAM/index.js +5 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +86 -85
- package/lib/WAUSync/USyncUser.js +23 -25
- package/lib/WAUSync/index.js +5 -19
- package/lib/index.js +27 -35
- package/package.json +85 -95
- package/engine-requirements.js +0 -10
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/dugong.d.ts +0 -254
- package/lib/Socket/dugong.js +0 -484
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/generics.js.bak +0 -433
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/Utils/validate-connection.js.bak +0 -237
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
|
@@ -1,427 +1,290 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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]) || ""]
|
|
43
85
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
}])
|
|
63
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
|
+
}
|
|
64
155
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
|
|
78
|
-
if (isLatest) {
|
|
79
|
-
chats.clear();
|
|
80
|
-
for (const id in messages) {
|
|
81
|
-
delete messages[id];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const chatsAdded = chats.insertIfAbsent(...newChats).length;
|
|
85
|
-
logger.debug({ chatsAdded }, 'synced chats');
|
|
86
|
-
const oldContacts = contactsUpsert(newContacts);
|
|
87
|
-
if (isLatest) {
|
|
88
|
-
for (const jid of oldContacts) {
|
|
89
|
-
delete contacts[jid];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
|
|
93
|
-
for (const msg of newMessages) {
|
|
94
|
-
const jid = msg.key.remoteJid;
|
|
95
|
-
const list = assertMessageList(jid);
|
|
96
|
-
list.upsert(msg, 'prepend');
|
|
97
|
-
}
|
|
98
|
-
logger.debug({ messages: newMessages.length }, 'synced messages');
|
|
99
|
-
});
|
|
100
|
-
ev.on('contacts.upsert', contacts => {
|
|
101
|
-
contactsUpsert(contacts);
|
|
102
|
-
});
|
|
103
|
-
ev.on('contacts.update', async (updates) => {
|
|
104
|
-
var _a;
|
|
105
|
-
for (const update of updates) {
|
|
106
|
-
let contact;
|
|
107
|
-
if (contacts[update.id]) {
|
|
108
|
-
contact = contacts[update.id];
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const validContacts = getValidContacts();
|
|
112
|
-
const contactHashes = validContacts.map((contactId) => {
|
|
113
|
-
const { user } = (0, WABinary_1.jidDecode)(contactId);
|
|
114
|
-
return [contactId, ((0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
|
|
115
|
-
});
|
|
116
|
-
contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
|
|
117
|
-
}
|
|
118
|
-
if (contact) {
|
|
119
|
-
if (update.imgUrl === 'changed') {
|
|
120
|
-
contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
|
|
121
|
-
}
|
|
122
|
-
else if (update.imgUrl === 'removed') {
|
|
123
|
-
delete contact.imgUrl;
|
|
124
|
-
}
|
|
125
|
-
Object.assign(contacts[contact.id], contact);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
logger.debug({ update }, 'got update for non-existant contact');
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
ev.on('chats.upsert', newChats => {
|
|
133
|
-
chats.upsert(...newChats);
|
|
134
|
-
});
|
|
135
|
-
ev.on('chats.update', updates => {
|
|
136
|
-
for (let update of updates) {
|
|
137
|
-
const result = chats.update(update.id, chat => {
|
|
138
|
-
if (update.unreadCount > 0) {
|
|
139
|
-
update = { ...update };
|
|
140
|
-
update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
|
|
141
|
-
}
|
|
142
|
-
Object.assign(chat, update);
|
|
143
|
-
});
|
|
144
|
-
if (!result) {
|
|
145
|
-
logger.debug({ update }, 'got update for non-existant chat');
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
ev.on('labels.edit', (label) => {
|
|
150
|
-
if (label.deleted) {
|
|
151
|
-
return labels.deleteById(label.id);
|
|
152
|
-
}
|
|
153
|
-
// WhatsApp can store only up to 20 labels
|
|
154
|
-
if (labels.count() < 20) {
|
|
155
|
-
return labels.upsertById(label.id, label);
|
|
156
|
-
}
|
|
157
|
-
logger.error('Labels count exceed');
|
|
158
|
-
});
|
|
159
|
-
ev.on('labels.association', ({ type, association }) => {
|
|
160
|
-
switch (type) {
|
|
161
|
-
case 'add':
|
|
162
|
-
labelAssociations.upsert(association);
|
|
163
|
-
break;
|
|
164
|
-
case 'remove':
|
|
165
|
-
labelAssociations.delete(association);
|
|
166
|
-
break;
|
|
167
|
-
default:
|
|
168
|
-
console.error(`unknown operation type [${type}]`);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
ev.on('presence.update', ({ id, presences: update }) => {
|
|
172
|
-
presences[id] = presences[id] || {};
|
|
173
|
-
Object.assign(presences[id], update);
|
|
174
|
-
});
|
|
175
|
-
ev.on('chats.delete', deletions => {
|
|
176
|
-
for (const item of deletions) {
|
|
177
|
-
if (chats.get(item)) {
|
|
178
|
-
chats.deleteById(item);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
ev.on('messages.upsert', ({ messages: newMessages, type }) => {
|
|
183
|
-
switch (type) {
|
|
184
|
-
case 'append':
|
|
185
|
-
case 'notify':
|
|
186
|
-
for (const msg of newMessages) {
|
|
187
|
-
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
188
|
-
const list = assertMessageList(jid);
|
|
189
|
-
list.upsert(msg, 'append');
|
|
190
|
-
if (type === 'notify') {
|
|
191
|
-
if (!chats.get(jid)) {
|
|
192
|
-
ev.emit('chats.upsert', [
|
|
193
|
-
{
|
|
194
|
-
id: jid,
|
|
195
|
-
conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
|
|
196
|
-
unreadCount: 1
|
|
197
|
-
}
|
|
198
|
-
]);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
ev.on('messages.update', updates => {
|
|
206
|
-
var _a;
|
|
207
|
-
for (const { update, key } of updates) {
|
|
208
|
-
const list = assertMessageList((0, WABinary_1.jidNormalizedUser)(key.remoteJid));
|
|
209
|
-
if (update === null || update === void 0 ? void 0 : update.status) {
|
|
210
|
-
const listStatus = (_a = list.get(key.id)) === null || _a === void 0 ? void 0 : _a.status;
|
|
211
|
-
if (listStatus && (update === null || update === void 0 ? void 0 : update.status) <= listStatus) {
|
|
212
|
-
logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
|
|
213
|
-
delete update.status;
|
|
214
|
-
logger.debug({ update }, 'new update object');
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
const result = list.updateAssign(key.id, update);
|
|
218
|
-
if (!result) {
|
|
219
|
-
logger.debug({ update }, 'got update for non-existent message');
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
ev.on('messages.delete', item => {
|
|
224
|
-
if ('all' in item) {
|
|
225
|
-
const list = messages[item.jid];
|
|
226
|
-
list === null || list === void 0 ? void 0 : list.clear();
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
const jid = item.keys[0].remoteJid;
|
|
230
|
-
const list = messages[jid];
|
|
231
|
-
if (list) {
|
|
232
|
-
const idSet = new Set(item.keys.map(k => k.id));
|
|
233
|
-
list.filter(m => !idSet.has(m.key.id));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
ev.on('groups.update', updates => {
|
|
238
|
-
for (const update of updates) {
|
|
239
|
-
const id = update.id;
|
|
240
|
-
if (groupMetadata[id]) {
|
|
241
|
-
Object.assign(groupMetadata[id], update);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
logger.debug({ update }, 'got update for non-existant group metadata');
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
ev.on('group-participants.update', ({ id, participants, action }) => {
|
|
249
|
-
const metadata = groupMetadata[id];
|
|
250
|
-
if (metadata) {
|
|
251
|
-
switch (action) {
|
|
252
|
-
case 'add':
|
|
253
|
-
metadata.participants.push(...participants.map(id => ({ id, isAdmin: false, isSuperAdmin: false })));
|
|
254
|
-
break;
|
|
255
|
-
case 'demote':
|
|
256
|
-
case 'promote':
|
|
257
|
-
for (const participant of metadata.participants) {
|
|
258
|
-
if (participants.includes(participant.id)) {
|
|
259
|
-
participant.isAdmin = action === 'promote';
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
break;
|
|
263
|
-
case 'remove':
|
|
264
|
-
metadata.participants = metadata.participants.filter(p => !participants.includes(p.id));
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
ev.on('message-receipt.update', updates => {
|
|
270
|
-
for (const { key, receipt } of updates) {
|
|
271
|
-
const obj = messages[key.remoteJid];
|
|
272
|
-
const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
|
|
273
|
-
if (msg) {
|
|
274
|
-
(0, Utils_1.updateMessageWithReceipt)(msg, receipt);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
ev.on('messages.reaction', (reactions) => {
|
|
279
|
-
for (const { key, reaction } of reactions) {
|
|
280
|
-
const obj = messages[key.remoteJid];
|
|
281
|
-
const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
|
|
282
|
-
if (msg) {
|
|
283
|
-
(0, Utils_1.updateMessageWithReaction)(msg, reaction);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
|
-
const toJSON = () => ({
|
|
289
|
-
chats,
|
|
290
|
-
contacts,
|
|
291
|
-
messages,
|
|
292
|
-
labels,
|
|
293
|
-
labelAssociations
|
|
294
|
-
});
|
|
295
|
-
const fromJSON = (json) => {
|
|
296
|
-
chats.upsert(...json.chats);
|
|
297
|
-
labelAssociations.upsert(...json.labelAssociations || []);
|
|
298
|
-
contactsUpsert(Object.values(json.contacts));
|
|
299
|
-
labelsUpsert(Object.values(json.labels || {}));
|
|
300
|
-
for (const jid in json.messages) {
|
|
301
|
-
const list = assertMessageList(jid);
|
|
302
|
-
for (const msg of json.messages[jid]) {
|
|
303
|
-
list.upsert(WAProto_1.proto.WebMessageInfo.fromObject(msg), 'append');
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
return {
|
|
308
|
-
chats,
|
|
309
|
-
contacts,
|
|
310
|
-
messages,
|
|
311
|
-
groupMetadata,
|
|
312
|
-
state,
|
|
313
|
-
presences,
|
|
314
|
-
labels,
|
|
315
|
-
labelAssociations,
|
|
316
|
-
bind,
|
|
317
|
-
/** loads messages from the store, if not found -- uses the legacy connection */
|
|
318
|
-
loadMessages: async (jid, count, cursor) => {
|
|
319
|
-
const list = assertMessageList(jid);
|
|
320
|
-
const mode = !cursor || 'before' in cursor ? 'before' : 'after';
|
|
321
|
-
const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
|
|
322
|
-
const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
|
|
323
|
-
let messages;
|
|
324
|
-
if (list && mode === 'before' && (!cursorKey || cursorValue)) {
|
|
325
|
-
if (cursorValue) {
|
|
326
|
-
const msgIdx = list.array.findIndex(m => m.key.id === (cursorKey === null || cursorKey === void 0 ? void 0 : cursorKey.id));
|
|
327
|
-
messages = list.array.slice(0, msgIdx);
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
messages = list.array;
|
|
331
|
-
}
|
|
332
|
-
const diff = count - messages.length;
|
|
333
|
-
if (diff < 0) {
|
|
334
|
-
messages = messages.slice(-count); // get the last X messages
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
messages = [];
|
|
339
|
-
}
|
|
340
|
-
return messages;
|
|
341
|
-
},
|
|
342
|
-
/**
|
|
343
|
-
* Get all available labels for profile
|
|
344
|
-
*
|
|
345
|
-
* Keep in mind that the list is formed from predefined tags and tags
|
|
346
|
-
* that were "caught" during their editing.
|
|
347
|
-
*/
|
|
348
|
-
getLabels: () => {
|
|
349
|
-
return labels;
|
|
350
|
-
},
|
|
351
|
-
/**
|
|
352
|
-
* Get labels for chat
|
|
353
|
-
*
|
|
354
|
-
* @returns Label IDs
|
|
355
|
-
**/
|
|
356
|
-
getChatLabels: (chatId) => {
|
|
357
|
-
return labelAssociations.filter((la) => la.chatId === chatId).all();
|
|
358
|
-
},
|
|
359
|
-
/**
|
|
360
|
-
* Get labels for message
|
|
361
|
-
*
|
|
362
|
-
* @returns Label IDs
|
|
363
|
-
**/
|
|
364
|
-
getMessageLabels: (messageId) => {
|
|
365
|
-
const associations = labelAssociations
|
|
366
|
-
.filter((la) => la.messageId === messageId)
|
|
367
|
-
.all();
|
|
368
|
-
return associations.map(({ labelId }) => labelId);
|
|
369
|
-
},
|
|
370
|
-
loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
|
|
371
|
-
mostRecentMessage: async (jid) => {
|
|
372
|
-
var _a;
|
|
373
|
-
const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
|
|
374
|
-
return message;
|
|
375
|
-
},
|
|
376
|
-
fetchImageUrl: async (jid, sock) => {
|
|
377
|
-
const contact = contacts[jid];
|
|
378
|
-
if (!contact) {
|
|
379
|
-
return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
|
|
380
|
-
}
|
|
381
|
-
if (typeof contact.imgUrl === 'undefined') {
|
|
382
|
-
contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
|
|
383
|
-
}
|
|
384
|
-
return contact.imgUrl;
|
|
385
|
-
},
|
|
386
|
-
fetchGroupMetadata: async (jid, sock) => {
|
|
387
|
-
if (!groupMetadata[jid]) {
|
|
388
|
-
const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
|
|
389
|
-
if (metadata) {
|
|
390
|
-
groupMetadata[jid] = metadata;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return groupMetadata[jid];
|
|
394
|
-
},
|
|
395
|
-
// fetchBroadcastListInfo: async(jid: string, sock: WASocket | undefined) => {
|
|
396
|
-
// if(!groupMetadata[jid]) {
|
|
397
|
-
// const metadata = await sock?.getBroadcastListInfo(jid)
|
|
398
|
-
// if(metadata) {
|
|
399
|
-
// groupMetadata[jid] = metadata
|
|
400
|
-
// }
|
|
401
|
-
// }
|
|
402
|
-
// return groupMetadata[jid]
|
|
403
|
-
// },
|
|
404
|
-
fetchMessageReceipts: async ({ remoteJid, id }) => {
|
|
405
|
-
const list = messages[remoteJid];
|
|
406
|
-
const msg = list === null || list === void 0 ? void 0 : list.get(id);
|
|
407
|
-
return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
|
|
408
|
-
},
|
|
409
|
-
toJSON,
|
|
410
|
-
fromJSON,
|
|
411
|
-
writeToFile: (path) => {
|
|
412
|
-
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
413
|
-
const { writeFileSync } = require('fs');
|
|
414
|
-
writeFileSync(path, JSON.stringify(toJSON()));
|
|
415
|
-
},
|
|
416
|
-
readFromFile: (path) => {
|
|
417
|
-
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
418
|
-
const { readFileSync, existsSync } = require('fs');
|
|
419
|
-
if (existsSync(path)) {
|
|
420
|
-
logger.debug({ path }, 'reading from file');
|
|
421
|
-
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
|
422
|
-
const json = JSON.parse(jsonStr);
|
|
423
|
-
fromJSON(json);
|
|
424
|
-
}
|
|
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))
|
|
425
168
|
}
|
|
426
|
-
|
|
427
|
-
}
|
|
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
|
+
//===================================//
|