project: Move to ESM Modules
This commit is contained in:
+24
-20
@@ -2,8 +2,7 @@ import NodeCache from '@cacheable/node-cache'
|
||||
import { Boom } from '@hapi/boom'
|
||||
import { proto } from '../../WAProto'
|
||||
import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults'
|
||||
import {
|
||||
ALL_WA_PATCH_NAMES,
|
||||
import type {
|
||||
BotListInfo,
|
||||
ChatModification,
|
||||
ChatMutation,
|
||||
@@ -25,10 +24,11 @@ import {
|
||||
WAPrivacyValue,
|
||||
WAReadReceiptsValue
|
||||
} from '../Types'
|
||||
import { LabelActionBody } from '../Types/Label'
|
||||
import { ALL_WA_PATCH_NAMES } from '../Types'
|
||||
import type { LabelActionBody } from '../Types/Label'
|
||||
import {
|
||||
chatModificationToAppPatch,
|
||||
ChatMutationMap,
|
||||
type ChatMutationMap,
|
||||
decodePatches,
|
||||
decodeSyncdSnapshot,
|
||||
encodeSyncdPatch,
|
||||
@@ -41,7 +41,7 @@ import {
|
||||
import { makeMutex } from '../Utils/make-mutex'
|
||||
import processMessage from '../Utils/process-message'
|
||||
import {
|
||||
BinaryNode,
|
||||
type BinaryNode,
|
||||
getBinaryNodeChild,
|
||||
getBinaryNodeChildren,
|
||||
jidDecode,
|
||||
@@ -205,8 +205,8 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
if (section.attrs.type === 'all') {
|
||||
for (const bot of getBinaryNodeChildren(section, 'bot')) {
|
||||
botList.push({
|
||||
jid: bot.attrs.jid,
|
||||
personaId: bot.attrs['persona_id']
|
||||
jid: bot.attrs.jid!,
|
||||
personaId: bot.attrs['persona_id']!
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
const usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol()
|
||||
|
||||
for (const jid of jids) {
|
||||
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`
|
||||
const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`
|
||||
usyncQuery.withUser(new USyncUser().withPhone(phone))
|
||||
}
|
||||
|
||||
@@ -271,16 +271,18 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
|
||||
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me!.id)) {
|
||||
targetJid = jidNormalizedUser(jid) // in case it is someone other than us
|
||||
} else {
|
||||
targetJid = undefined
|
||||
}
|
||||
|
||||
const { img } = await generateProfilePicture(content, dimensions)
|
||||
await query({
|
||||
tag: 'iq',
|
||||
attrs: {
|
||||
target: targetJid,
|
||||
to: S_WHATSAPP_NET,
|
||||
type: 'set',
|
||||
xmlns: 'w:profile:picture'
|
||||
xmlns: 'w:profile:picture',
|
||||
...(targetJid ? { target: targetJid } : {})
|
||||
},
|
||||
content: [
|
||||
{
|
||||
@@ -303,15 +305,17 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
|
||||
if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me!.id)) {
|
||||
targetJid = jidNormalizedUser(jid) // in case it is someone other than us
|
||||
} else {
|
||||
targetJid = undefined
|
||||
}
|
||||
|
||||
await query({
|
||||
tag: 'iq',
|
||||
attrs: {
|
||||
target: targetJid,
|
||||
to: S_WHATSAPP_NET,
|
||||
type: 'set',
|
||||
xmlns: 'w:profile:picture'
|
||||
xmlns: 'w:profile:picture',
|
||||
...(targetJid ? { target: targetJid } : {})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -477,7 +481,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
const states = {} as { [T in WAPatchName]: LTHashState }
|
||||
const nodes: BinaryNode[] = []
|
||||
|
||||
for (const name of collectionsToHandle) {
|
||||
for (const name of collectionsToHandle as Set<WAPatchName>) {
|
||||
const result = await authState.keys.get('app-state-sync-version', [name])
|
||||
let state = result[name]
|
||||
|
||||
@@ -569,7 +573,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
// collection is done with sync
|
||||
collectionsToHandle.delete(name)
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
// if retry attempts overshoot
|
||||
// or key not found
|
||||
const isIrrecoverableError =
|
||||
@@ -595,7 +599,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
|
||||
const { onMutation } = newAppStateChunkHandler(isInitialSync)
|
||||
for (const key in globalMutationMap) {
|
||||
onMutation(globalMutationMap[key])
|
||||
onMutation(globalMutationMap[key]!)
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -689,7 +693,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
const jid = attrs.from
|
||||
const participant = attrs.participant || attrs.from
|
||||
|
||||
if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
|
||||
if (shouldIgnoreJid(jid!) && jid !== '@s.whatsapp.net') {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -700,12 +704,12 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
}
|
||||
} else if (Array.isArray(content)) {
|
||||
const [firstChild] = content
|
||||
let type = firstChild.tag as WAPresence
|
||||
let type = firstChild!.tag as WAPresence
|
||||
if (type === 'paused') {
|
||||
type = 'available'
|
||||
}
|
||||
|
||||
if (firstChild.attrs?.media === 'audio') {
|
||||
if (firstChild!.attrs?.media === 'audio') {
|
||||
type = 'recording'
|
||||
}
|
||||
|
||||
@@ -715,7 +719,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
if (presence) {
|
||||
ev.emit('presence.update', { id: jid, presences: { [participant]: presence } })
|
||||
ev.emit('presence.update', { id: jid!, presences: { [participant!]: presence } })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -790,7 +794,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
logger
|
||||
)
|
||||
for (const key in mutationMap) {
|
||||
onMutation(mutationMap[key])
|
||||
onMutation(mutationMap[key]!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user