@nexustechpro/baileys 2.0.6 → 2.1.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/README.md +72 -1
- package/lib/Defaults/index.js +3 -2
- package/lib/Signal/libsignal.js +552 -358
- package/lib/Socket/chats.js +192 -273
- package/lib/Socket/messages-recv.js +4 -2
- package/lib/Socket/messages-send.js +42 -18
- package/lib/Socket/newsletter.js +87 -36
- package/lib/Socket/nexus-handler.js +44 -42
- package/lib/Socket/socket.js +23 -10
- package/lib/Store/make-in-memory-store.js +29 -20
- package/lib/Utils/auth-utils.js +2 -2
- package/lib/Utils/chat-utils.js +319 -620
- package/lib/Utils/decode-wa-message.js +11 -26
- package/lib/Utils/key-store.js +1 -1
- package/lib/Utils/link-preview.js +134 -71
- package/lib/Utils/messages-media.js +97 -26
- package/lib/Utils/messages.js +723 -820
- package/lib/Utils/use-multi-file-auth-state.js +183 -90
- package/lib/index.js +1 -1
- package/package.json +10 -8
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import WAProto from '../../WAProto/index.js';
|
|
2
2
|
import * as Defaults from '../Defaults/index.js';
|
|
3
3
|
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import * as Utils_1 from '../Utils/index.js';
|
|
5
|
+
import * as WABinary_1 from '../WABinary/index.js';
|
|
6
6
|
import { makeOrderedDictionary } from './make-ordered-dictionary.js';
|
|
7
7
|
import { ObjectRepository } from './object-repository.js';
|
|
8
8
|
|
|
9
9
|
const waChatKey = (pin) => ({
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
11
|
+
compare: (k1, k2) => k2.localeCompare(k1)
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
const waMessageID = (m) => m.key.id || '';
|
|
15
15
|
|
|
16
16
|
const waLabelAssociationKey = {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
18
|
+
compare: (k1, k2) => k2.localeCompare(k1)
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
|
|
@@ -24,7 +24,7 @@ const makeInMemoryStore = (config) => {
|
|
|
24
24
|
const socket = config.socket
|
|
25
25
|
const chatKey = config.chatKey || waChatKey(true)
|
|
26
26
|
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey
|
|
27
|
-
const logger = config.logger ||
|
|
27
|
+
const logger = config.logger || Defaults.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
|
|
28
28
|
const KeyedDB = require('@adiwajshing/keyed-db').default
|
|
29
29
|
const chats = new KeyedDB(chatKey, c => c.id)
|
|
30
30
|
const messages = {}
|
|
@@ -32,7 +32,7 @@ const makeInMemoryStore = (config) => {
|
|
|
32
32
|
const groupMetadata = {}
|
|
33
33
|
const presences = {}
|
|
34
34
|
const state = { connection: 'close' }
|
|
35
|
-
const labels = new
|
|
35
|
+
const labels = new ObjectRepository()
|
|
36
36
|
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key)
|
|
37
37
|
const assertMessageList = (jid) => {
|
|
38
38
|
if (!messages[jid]) {
|
|
@@ -64,7 +64,7 @@ const makeInMemoryStore = (config) => {
|
|
|
64
64
|
Object.assign(state, update)
|
|
65
65
|
})
|
|
66
66
|
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
67
|
-
if (syncType ===
|
|
67
|
+
if (syncType === WAProto.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
68
68
|
return // FOR NOW,
|
|
69
69
|
//TODO: HANDLE
|
|
70
70
|
}
|
|
@@ -102,21 +102,30 @@ const makeInMemoryStore = (config) => {
|
|
|
102
102
|
else {
|
|
103
103
|
const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
|
|
104
104
|
const { user } = WABinary_1.jidDecode(contactId)
|
|
105
|
-
return [contactId, (
|
|
105
|
+
return [contactId, (Utils_1.md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)]
|
|
106
106
|
}))
|
|
107
107
|
contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || ''] // find contact by attrs.hash, when user is not saved as a contact
|
|
108
108
|
}
|
|
109
|
-
if (contact) {
|
|
110
|
-
if
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
if (!contact) {
|
|
110
|
+
// Create new contact entry if the update has meaningful data
|
|
111
|
+
if (update.notify || update.verifiedName || update.name) {
|
|
112
|
+
contacts[update.id] = { id: update.id }
|
|
113
|
+
contact = contacts[update.id]
|
|
114
|
+
} else {
|
|
115
|
+
logger.debug({ update }, 'got update for non-existant contact')
|
|
116
|
+
continue
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
if (update.imgUrl === 'changed') {
|
|
120
|
+
contact.imgUrl = socket ? await socket.profilePictureUrl(contact.id) : undefined
|
|
121
|
+
}
|
|
122
|
+
else if (update.imgUrl === 'removed') {
|
|
123
|
+
delete contact.imgUrl
|
|
119
124
|
}
|
|
125
|
+
// Persist pushName, verifiedName, and name from the update
|
|
126
|
+
if (update.notify) contact.notify = update.notify
|
|
127
|
+
if (update.verifiedName) contact.verifiedName = update.verifiedName
|
|
128
|
+
if (update.name) contact.name = update.name
|
|
120
129
|
Object.assign(contacts[contact.id], contact)
|
|
121
130
|
}
|
|
122
131
|
})
|
|
@@ -288,7 +297,7 @@ const makeInMemoryStore = (config) => {
|
|
|
288
297
|
for (const jid in json.messages) {
|
|
289
298
|
const list = assertMessageList(jid)
|
|
290
299
|
for (const msg of json.messages[jid]) {
|
|
291
|
-
list.upsert(
|
|
300
|
+
list.upsert(WAProto.proto.WebMessageInfo.fromObject(msg), 'append')
|
|
292
301
|
}
|
|
293
302
|
}
|
|
294
303
|
}
|
|
@@ -355,7 +364,7 @@ const makeInMemoryStore = (config) => {
|
|
|
355
364
|
.all()
|
|
356
365
|
return associations.map(({ labelId }) => labelId)
|
|
357
366
|
},
|
|
358
|
-
loadMessage: async (jid, id) => messages[jid]?.get(id),
|
|
367
|
+
loadMessage: async (jid, id) => messages[jid]?.get(id),
|
|
359
368
|
mostRecentMessage: async (jid) => {
|
|
360
369
|
const message = messages[jid]?.array.slice(-1)[0]
|
|
361
370
|
return message
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -128,7 +128,7 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
128
128
|
}
|
|
129
129
|
catch (error) {
|
|
130
130
|
const msg = error?.message || (typeof error === 'string' ? error : '') || ''
|
|
131
|
-
const isExpected = msg.includes('InvalidPreKeyId') || msg.includes('SessionNotFound') || msg.includes('InvalidMessage') || msg.includes('no sender key state') || msg.includes('
|
|
131
|
+
const isExpected = msg.includes('InvalidPreKeyId') || msg.includes('SessionNotFound') || msg.includes('InvalidMessage') || msg.includes('no sender key state') || msg.includes('memory access out of bounds') || msg.includes('old counter') || msg.includes('DuplicatedMessage') || msg.includes('BadMac') || msg.includes('Connection Closed')
|
|
132
132
|
if (isExpected) { logger?.debug?.({ error: msg }, 'transaction skipped — expected decrypt error, message dropped silently'); return undefined } // skip, no retry
|
|
133
133
|
logger?.error?.({ error: msg || error }, 'transaction failed, rolling back')
|
|
134
134
|
throw error
|
|
@@ -225,7 +225,7 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
225
225
|
}
|
|
226
226
|
catch (error) {
|
|
227
227
|
const msg = error?.message || (typeof error === 'string' ? error : '') || ''
|
|
228
|
-
const isExpected = msg.includes('InvalidPreKeyId') || msg.includes('SessionNotFound') || msg.includes('InvalidMessage') || msg.includes('no sender key state') || msg.includes('
|
|
228
|
+
const isExpected = msg.includes('InvalidPreKeyId') || msg.includes('SessionNotFound') || msg.includes('InvalidMessage') || msg.includes('no sender key state') || msg.includes('memory access out of bounds') || msg.includes('old counter') || msg.includes('DuplicatedMessage') || msg.includes('BadMac')
|
|
229
229
|
; (isExpected ? logger?.debug?.bind(logger) : logger?.error?.bind(logger))?.({ error: msg || error }, 'transaction failed, rolling back')
|
|
230
230
|
throw error
|
|
231
231
|
}
|