fix(types): resolve all TypeScript compilation errors from non-null

fix(types): resolve all TypeScript compilation errors from non-null
This commit is contained in:
Renato Alcara
2026-02-08 22:08:02 -03:00
committed by GitHub
7 changed files with 20 additions and 21 deletions
+2 -2
View File
@@ -886,8 +886,8 @@ export const makeChatsSocket = (config: SocketConfig) => {
const { onMutation } = newAppStateChunkHandler(false) const { onMutation } = newAppStateChunkHandler(false)
const { mutationMap } = await decodePatches( const { mutationMap } = await decodePatches(
name, name,
[{ ...encodeResult?.patch, version: { version: encodeResult?.state?.version } }], [{ ...encodeResult!.patch, version: { version: encodeResult!.state.version } }],
initial ?? { version: 0, hash: Buffer.alloc(0), indexValueMap: {} }, initial!,
getAppStateSyncKey, getAppStateSyncKey,
config.options, config.options,
undefined, undefined,
+3 -3
View File
@@ -316,7 +316,7 @@ export const extractGroupMetadata = (result: BinaryNode) => {
descId = descChild.attrs.id descId = descChild.attrs.id
} }
const groupId = (group.attrs.id ?? '').includes('@') ? group.attrs.id : jidEncode(group.attrs.id ?? '', 'g.us') const groupId = (group.attrs.id ?? '').includes('@') ? (group.attrs.id ?? '') : jidEncode(group.attrs.id ?? '', 'g.us')
const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add' const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
const metadata: GroupMetadata = { const metadata: GroupMetadata = {
@@ -326,9 +326,9 @@ export const extractGroupMetadata = (result: BinaryNode) => {
subject: group.attrs.subject ?? '', subject: group.attrs.subject ?? '',
subjectOwner: group.attrs.s_o, subjectOwner: group.attrs.s_o,
subjectOwnerPn: group.attrs.s_o_pn, subjectOwnerPn: group.attrs.s_o_pn,
subjectTime: +group.attrs.s_t ?? '0', subjectTime: +(group.attrs.s_t ?? '0'),
size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length, size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
creation: +group.attrs.creation ?? '0', creation: +(group.attrs.creation ?? '0'),
owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined, owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined, ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
owner_country_code: group.attrs.creator_country_code, owner_country_code: group.attrs.creator_country_code,
+6 -5
View File
@@ -156,16 +156,17 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
throw new Boom('Not authenticated') throw new Boom('Not authenticated')
} }
if (await placeholderResendCache.get(messageKey?.id)) { const msgId = messageKey?.id ?? ''
if (await placeholderResendCache.get(msgId)) {
logger.debug({ messageKey }, 'already requested resend') logger.debug({ messageKey }, 'already requested resend')
return return
} else { } else {
await placeholderResendCache.set(messageKey?.id, true) await placeholderResendCache.set(msgId, true)
} }
await delay(2000) await delay(2000)
if (!(await placeholderResendCache.get(messageKey?.id))) { if (!(await placeholderResendCache.get(msgId))) {
logger.debug({ messageKey }, 'message received while resend requested') logger.debug({ messageKey }, 'message received while resend requested')
return 'RESOLVED' return 'RESOLVED'
} }
@@ -180,9 +181,9 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} }
setTimeout(async () => { setTimeout(async () => {
if (await placeholderResendCache.get(messageKey?.id)) { if (await placeholderResendCache.get(msgId)) {
logger.debug({ messageKey }, 'PDO message without response after 8 seconds. Phone possibly offline') logger.debug({ messageKey }, 'PDO message without response after 8 seconds. Phone possibly offline')
await placeholderResendCache.del(messageKey?.id) await placeholderResendCache.del(msgId)
} }
}, 8_000) }, 8_000)
+1 -5
View File
@@ -552,11 +552,7 @@ export const makeSocket = (config: SocketConfig) => {
}) })
if (sendMsg) { if (sendMsg) {
if (!onClose) { sendRawMessage(sendMsg).catch(onClose!)
throw new Error('onClose handler not initialized')
}
sendRawMessage(sendMsg).catch(onClose)
} }
return result return result
+1 -1
View File
@@ -1265,7 +1265,7 @@ function consolidateEvents(data: BufferedEventData) {
const messageUpsertList = Object.values(data.messageUpserts) const messageUpsertList = Object.values(data.messageUpserts)
if (messageUpsertList.length) { if (messageUpsertList.length) {
const type = messageUpsertList[0]?.type const type = messageUpsertList[0]?.type ?? 'notify'
map['messages.upsert'] = { map['messages.upsert'] = {
messages: messageUpsertList.map(m => m.message), messages: messageUpsertList.map(m => m.message),
type type
+6 -4
View File
@@ -264,9 +264,11 @@ export const prepareWAMessageMedia = async (
throw new Boom('Missing file path for processing') throw new Boom('Missing file path for processing')
} }
const filePath = originalFilePath!
if (requiresThumbnailComputation) { if (requiresThumbnailComputation) {
const { thumbnail, originalImageDimensions } = await generateThumbnail( const { thumbnail, originalImageDimensions } = await generateThumbnail(
originalFilePath, filePath,
mediaType as 'image' | 'video', mediaType as 'image' | 'video',
options options
) )
@@ -281,12 +283,12 @@ export const prepareWAMessageMedia = async (
} }
if (requiresDurationComputation) { if (requiresDurationComputation) {
uploadData.seconds = await getAudioDuration(originalFilePath) uploadData.seconds = await getAudioDuration(filePath)
logger?.debug('computed audio duration') logger?.debug('computed audio duration')
} }
if (requiresWaveformProcessing) { if (requiresWaveformProcessing) {
uploadData.waveform = await getAudioWaveform(originalFilePath, logger) uploadData.waveform = await getAudioWaveform(filePath, logger)
logger?.debug('processed waveform') logger?.debug('processed waveform')
} }
@@ -1767,7 +1769,7 @@ export const generateWAMessageFromContent = (
const innerContent = innerMessage[key as Exclude<keyof proto.IMessage, 'conversation'>] const innerContent = innerMessage[key as Exclude<keyof proto.IMessage, 'conversation'>]
const contextInfo: proto.IContextInfo = const contextInfo: proto.IContextInfo =
(innerContent && 'contextInfo' in innerContent && innerMessage[key as Exclude<keyof proto.IMessage, 'conversation'>]?.contextInfo) || {} (innerContent && typeof innerContent === 'object' && 'contextInfo' in innerContent && (innerContent as Record<string, unknown>).contextInfo as proto.IContextInfo) || {}
contextInfo.participant = jidNormalizedUser(participant ?? '') contextInfo.participant = jidNormalizedUser(participant ?? '')
contextInfo.stanzaId = quoted.key.id contextInfo.stanzaId = quoted.key.id
contextInfo.quotedMessage = quotedMsg contextInfo.quotedMessage = quotedMsg
+1 -1
View File
@@ -150,7 +150,7 @@ export const makeNoiseHandler = ({
while (true) { while (true) {
if (inBytes.length < 3) return if (inBytes.length < 3) return
size = (inBytes[0] << 16) | (inBytes[1] << 8) | inBytes[2] size = (inBytes[0]! << 16) | (inBytes[1]! << 8) | inBytes[2]!
if (inBytes.length < size + 3) return if (inBytes.length < size + 3) return