fix: resolve top-level await, signal sessions, and null safety improvements
fix: resolve top-level await, signal sessions, and null safety improvements
This commit is contained in:
@@ -495,6 +495,7 @@ export function makeLibSignalRepository(
|
||||
|
||||
const decoded1 = jidDecode(fromJid)
|
||||
if (!decoded1) {
|
||||
logger.warn({ fromJid }, 'bulkDeviceMigration: failed to decode fromJid, aborting migration')
|
||||
return { migrated: 0, skipped: 0, total: 0 }
|
||||
}
|
||||
|
||||
|
||||
+22
-5
@@ -754,9 +754,16 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (!toJid) return
|
||||
if (!toJid) {
|
||||
logger.warn('sendPresenceUpdate: toJid is missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
const decoded = jidDecode(toJid)
|
||||
if (!decoded) return
|
||||
if (!decoded) {
|
||||
logger.warn({ toJid }, 'sendPresenceUpdate: failed to decode toJid, skipping')
|
||||
return
|
||||
}
|
||||
const { server } = decoded
|
||||
const isLid = server === 'lid'
|
||||
|
||||
@@ -798,7 +805,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
let presence: PresenceData | undefined
|
||||
const jid = attrs.from
|
||||
const participant = attrs.participant || attrs.from
|
||||
if (!jid) return
|
||||
if (!jid) {
|
||||
logger.warn({ attrs }, 'handlePresenceUpdate: jid (attrs.from) is missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
if (shouldIgnoreJid(jid) && jid !== S_WHATSAPP_NET) {
|
||||
return
|
||||
@@ -811,7 +821,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
}
|
||||
} else if (Array.isArray(content)) {
|
||||
const [firstChild] = content
|
||||
if (!firstChild) return
|
||||
if (!firstChild) {
|
||||
logger.warn({ jid }, 'handlePresenceUpdate: firstChild content is empty, skipping')
|
||||
return
|
||||
}
|
||||
let type = firstChild.tag as WAPresence
|
||||
if (type === 'paused') {
|
||||
type = 'available'
|
||||
@@ -827,7 +840,11 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
if (presence) {
|
||||
if (!participant) return
|
||||
if (!participant) {
|
||||
logger.warn({ jid }, 'handlePresenceUpdate: participant is missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
ev.emit('presence.update', { id: jid, presences: { [participant]: presence } })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ export const makeCommunitiesSocket = (config: SocketConfig) => {
|
||||
sock.ws.on('CB:ib,,dirty', async (node: BinaryNode) => {
|
||||
const dirtyNode = getBinaryNodeChild(node, 'dirty')
|
||||
if (!dirtyNode) {
|
||||
logger.debug({ node: node.tag }, 'community dirty handler: no dirty node found, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -886,6 +886,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
if (!sessionStartTime) {
|
||||
logger.debug('TTL timer: sessionStartTime not set, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -639,6 +639,8 @@ export const makeEventBuffer = (
|
||||
if (updateId) {
|
||||
newData.chatUpdates[updateId] = update
|
||||
delete data.chatUpdates[updateId]
|
||||
} else {
|
||||
logger.debug({ update }, 'conditional chat update missing id, not carrying forward')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -979,7 +981,10 @@ function append<E extends BufferableEvent>(
|
||||
case 'chats.update':
|
||||
for (const update of eventData as ChatUpdate[]) {
|
||||
const chatId = update.id
|
||||
if (!chatId) continue
|
||||
if (!chatId) {
|
||||
logger.debug({ update }, 'chats.update: update missing id, skipping')
|
||||
continue
|
||||
}
|
||||
const conditionMatches = update.conditional ? update.conditional(data) : true
|
||||
if (conditionMatches) {
|
||||
delete update.conditional
|
||||
@@ -1057,7 +1062,10 @@ function append<E extends BufferableEvent>(
|
||||
const contactUpdates = eventData as BaileysEventMap['contacts.update']
|
||||
for (const update of contactUpdates) {
|
||||
const id = update.id
|
||||
if (!id) continue
|
||||
if (!id) {
|
||||
logger.debug({ update }, 'contacts.update: update missing id, skipping')
|
||||
continue
|
||||
}
|
||||
// merge into prior upsert
|
||||
const upsert = data.historySets.contacts[id] || data.contactUpserts[id]
|
||||
if (upsert) {
|
||||
@@ -1179,7 +1187,10 @@ function append<E extends BufferableEvent>(
|
||||
const groupUpdates = eventData as BaileysEventMap['groups.update']
|
||||
for (const update of groupUpdates) {
|
||||
const id = update.id
|
||||
if (!id) continue
|
||||
if (!id) {
|
||||
logger.debug({ update }, 'groups.update: update missing id, skipping')
|
||||
continue
|
||||
}
|
||||
const groupUpdate = data.groupUpdates[id] || {}
|
||||
if (!data.groupUpdates[id]) {
|
||||
data.groupUpdates[id] = Object.assign(groupUpdate, update)
|
||||
@@ -1212,7 +1223,10 @@ function append<E extends BufferableEvent>(
|
||||
// decrement chat unread counter
|
||||
// if the message has already been marked read by us
|
||||
const chatId = message.key.remoteJid
|
||||
if (!chatId) return
|
||||
if (!chatId) {
|
||||
logger.debug({ messageKey: message.key }, 'decrementChatReadCounter: remoteJid missing, skipping')
|
||||
return
|
||||
}
|
||||
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
|
||||
if (
|
||||
isRealMessage(message) &&
|
||||
|
||||
@@ -288,6 +288,7 @@ const processMessage = async (
|
||||
) => {
|
||||
const meUser = creds.me
|
||||
if (!meUser) {
|
||||
logger?.warn({ messageKey: message.key }, 'processMessage: creds.me not set, skipping message')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -548,6 +549,7 @@ const processMessage = async (
|
||||
} else if (content?.reactionMessage) {
|
||||
const reactionKey = content.reactionMessage.key
|
||||
if (!reactionKey) {
|
||||
logger?.warn({ messageKey: message.key }, 'processMessage: reactionMessage.key missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -565,6 +567,7 @@ const processMessage = async (
|
||||
const encEventResponse = content.encEventResponseMessage
|
||||
const creationMsgKey = encEventResponse.eventCreationMessageKey
|
||||
if (!creationMsgKey) {
|
||||
logger?.warn({ messageKey: message.key }, 'processMessage: eventCreationMessageKey missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -580,6 +583,7 @@ const processMessage = async (
|
||||
? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
|
||||
: eventCreatorKey
|
||||
if (!eventCreatorPn) {
|
||||
logger?.warn({ messageKey: message.key, eventCreatorKey }, 'processMessage: eventCreatorPn missing, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ export const transferDevice = (fromJid: string, toJid: string) => {
|
||||
const deviceId = fromDecoded?.device || 0
|
||||
const toDecoded = jidDecode(toJid)
|
||||
if (!toDecoded) {
|
||||
return ''
|
||||
throw new Error(`transferDevice: failed to decode toJid "${toJid}"`)
|
||||
}
|
||||
|
||||
const { server, user } = toDecoded
|
||||
|
||||
Reference in New Issue
Block a user