chore: lint
This commit is contained in:
@@ -30,8 +30,6 @@ export default defineConfig([globalIgnores([
|
||||
...base,
|
||||
{
|
||||
extends: [
|
||||
...compat.extends("plugin:@typescript-eslint/recommended"),
|
||||
...compat.extends("plugin:@typescript-eslint/recommended-requiring-type-checking"),
|
||||
...compat.extends("plugin:prettier/recommended"),
|
||||
],
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ export class LIDMappingStore {
|
||||
if (Object.keys(usyncFetch).length > 0) {
|
||||
const result = await this.pnToLIDFunc?.(Object.keys(usyncFetch)) // this function already adds LIDs to mapping
|
||||
if (result && result.length > 0) {
|
||||
this.storeLIDPNMappings(result)
|
||||
await this.storeLIDPNMappings(result)
|
||||
for (const pair of result) {
|
||||
const pnDecoded = jidDecode(pair.pn)
|
||||
const pnUser = pnDecoded?.user
|
||||
|
||||
@@ -16,7 +16,7 @@ export abstract class AbstractSocketClient extends EventEmitter {
|
||||
this.setMaxListeners(0)
|
||||
}
|
||||
|
||||
abstract connect(): Promise<void>
|
||||
abstract close(): Promise<void>
|
||||
abstract connect(): void
|
||||
abstract close(): void
|
||||
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export class WebSocketClient extends AbstractSocketClient {
|
||||
return this.socket?.readyState === WebSocket.CONNECTING
|
||||
}
|
||||
|
||||
async connect(): Promise<void> {
|
||||
connect() {
|
||||
if (this.socket) {
|
||||
return
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export class WebSocketClient extends AbstractSocketClient {
|
||||
}
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
close() {
|
||||
if (!this.socket) {
|
||||
return
|
||||
}
|
||||
|
||||
+18
-18
@@ -145,7 +145,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
logger.debug({ messageKey }, 'already requested resend')
|
||||
return
|
||||
} else {
|
||||
placeholderResendCache.set(messageKey?.id!, true)
|
||||
await placeholderResendCache.set(messageKey?.id!, true)
|
||||
}
|
||||
|
||||
await delay(5000)
|
||||
@@ -164,10 +164,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
setTimeout(async () => {
|
||||
if (placeholderResendCache.get(messageKey?.id!)) {
|
||||
logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline')
|
||||
placeholderResendCache.del(messageKey?.id!)
|
||||
await placeholderResendCache.del(messageKey?.id!)
|
||||
}
|
||||
}, 15_000)
|
||||
|
||||
@@ -403,14 +403,14 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
|
||||
// Use the new retry count for the rest of the logic
|
||||
const key = `${msgId}:${msgKey?.participant}`
|
||||
msgRetryCache.set(key, retryCount)
|
||||
await msgRetryCache.set(key, retryCount)
|
||||
} else {
|
||||
// Fallback to old system
|
||||
const key = `${msgId}:${msgKey?.participant}`
|
||||
let retryCount = (await msgRetryCache.get<number>(key)) || 0
|
||||
if (retryCount >= maxMsgRetryCount) {
|
||||
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing')
|
||||
msgRetryCache.del(key)
|
||||
await msgRetryCache.del(key)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1031,7 +1031,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
if (!ids[i]) continue
|
||||
|
||||
if (msg && (await willSendMessageAgain(ids[i], participant))) {
|
||||
updateSendMessageAgainCount(ids[i], participant)
|
||||
await updateSendMessageAgainCount(ids[i], participant)
|
||||
const msgRelayOpts: MessageRelayOptions = { messageId: ids[i] }
|
||||
|
||||
if (sendToAll) {
|
||||
@@ -1122,7 +1122,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
if (ids[0] && key.participant && (await willSendMessageAgain(ids[0], key.participant))) {
|
||||
if (key.fromMe) {
|
||||
try {
|
||||
updateSendMessageAgainCount(ids[0], key.participant)
|
||||
await updateSendMessageAgainCount(ids[0], key.participant)
|
||||
logger.debug({ attrs, key }, 'recv retry request')
|
||||
await sendMessagesAgain(key, ids, retryNode!)
|
||||
} catch (error: unknown) {
|
||||
@@ -1257,7 +1257,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
logger.debug(`[handleMessage] Attempting retry request for failed decryption`)
|
||||
|
||||
// Handle both pre-key and normal retries in single mutex
|
||||
retryMutex.mutex(async () => {
|
||||
await retryMutex.mutex(async () => {
|
||||
try {
|
||||
if (!ws.isOpen) {
|
||||
logger.debug({ node }, 'Connection closed, skipping retry')
|
||||
@@ -1499,7 +1499,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
|
||||
const offlineNodeProcessor = makeOfflineNodeProcessor()
|
||||
|
||||
const processNode = (
|
||||
const processNode = async (
|
||||
type: MessageType,
|
||||
node: BinaryNode,
|
||||
identifier: string,
|
||||
@@ -1510,31 +1510,31 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
if (isOffline) {
|
||||
offlineNodeProcessor.enqueue(type, node)
|
||||
} else {
|
||||
processNodeWithBuffer(node, identifier, exec)
|
||||
await processNodeWithBuffer(node, identifier, exec)
|
||||
}
|
||||
}
|
||||
|
||||
// recv a message
|
||||
ws.on('CB:message', (node: BinaryNode) => {
|
||||
processNode('message', node, 'processing message', handleMessage)
|
||||
ws.on('CB:message', async (node: BinaryNode) => {
|
||||
await processNode('message', node, 'processing message', handleMessage)
|
||||
})
|
||||
|
||||
ws.on('CB:call', async (node: BinaryNode) => {
|
||||
processNode('call', node, 'handling call', handleCall)
|
||||
await processNode('call', node, 'handling call', handleCall)
|
||||
})
|
||||
|
||||
ws.on('CB:receipt', node => {
|
||||
processNode('receipt', node, 'handling receipt', handleReceipt)
|
||||
ws.on('CB:receipt', async node => {
|
||||
await processNode('receipt', node, 'handling receipt', handleReceipt)
|
||||
})
|
||||
|
||||
ws.on('CB:notification', async (node: BinaryNode) => {
|
||||
processNode('notification', node, 'handling notification', handleNotification)
|
||||
await processNode('notification', node, 'handling notification', handleNotification)
|
||||
})
|
||||
ws.on('CB:ack,class:message', (node: BinaryNode) => {
|
||||
handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'))
|
||||
})
|
||||
|
||||
ev.on('call', ([call]) => {
|
||||
ev.on('call', async ([call]) => {
|
||||
if (!call) {
|
||||
return
|
||||
}
|
||||
@@ -1562,7 +1562,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
const protoMsg = proto.WebMessageInfo.fromObject(msg) as WAMessage
|
||||
upsertMessage(protoMsg, call.offline ? 'append' : 'notify')
|
||||
await upsertMessage(protoMsg, call.offline ? 'append' : 'notify')
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -946,7 +946,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
const tcTokenBuffer = contactTcTokenData[destinationJid]?.token
|
||||
|
||||
if (tcTokenBuffer) {
|
||||
(stanza.content as BinaryNode[]).push({
|
||||
;(stanza.content as BinaryNode[]).push({
|
||||
tag: 'tctoken',
|
||||
attrs: {},
|
||||
content: tcTokenBuffer
|
||||
@@ -1198,8 +1198,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
additionalNodes
|
||||
})
|
||||
if (config.emitOwnEvents) {
|
||||
process.nextTick(() => {
|
||||
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'))
|
||||
process.nextTick(async () => {
|
||||
await processingMutex.mutex(() => upsertMessage(fullMsg, 'append'))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -435,7 +435,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
}
|
||||
}).finish()
|
||||
)
|
||||
noise.finishInit()
|
||||
await noise.finishInit()
|
||||
startKeepAliveRequest()
|
||||
}
|
||||
|
||||
@@ -566,8 +566,8 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
}
|
||||
}
|
||||
|
||||
const onMessageReceived = (data: Buffer) => {
|
||||
noise.decodeFrame(data, frame => {
|
||||
const onMessageReceived = async (data: Buffer) => {
|
||||
await noise.decodeFrame(data, frame => {
|
||||
// reset ping timeout
|
||||
lastDateRecv = new Date()
|
||||
|
||||
@@ -968,9 +968,9 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
end(new Boom('Multi-device beta not joined', { statusCode: DisconnectReason.multideviceMismatch }))
|
||||
})
|
||||
|
||||
ws.on('CB:ib,,offline_preview', (node: BinaryNode) => {
|
||||
ws.on('CB:ib,,offline_preview', async (node: BinaryNode) => {
|
||||
logger.info('offline preview received', JSON.stringify(node))
|
||||
sendNode({
|
||||
await sendNode({
|
||||
tag: 'ib',
|
||||
attrs: {},
|
||||
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
||||
|
||||
@@ -75,7 +75,7 @@ export function makeCacheableSignalKeyStore(
|
||||
const item = fetched[id]
|
||||
if (item) {
|
||||
data[id] = item
|
||||
cache.set(getUniqueId(type, id), item as SignalDataTypeMap[keyof SignalDataTypeMap])
|
||||
await cache.set(getUniqueId(type, id), item as SignalDataTypeMap[keyof SignalDataTypeMap])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import EventEmitter from 'events'
|
||||
import { createReadStream } from 'fs'
|
||||
import { writeFile } from 'fs/promises'
|
||||
import { createInterface } from 'readline'
|
||||
import type { BaileysEventEmitter } from '../Types'
|
||||
import { delay } from './generics'
|
||||
import { makeMutex } from './make-mutex'
|
||||
|
||||
/**
|
||||
* Captures events from a baileys event emitter & stores them in a file
|
||||
* @param ev The event emitter to read events from
|
||||
* @param filename File to save to
|
||||
*/
|
||||
export const captureEventStream = (ev: BaileysEventEmitter, filename: string) => {
|
||||
const oldEmit = ev.emit
|
||||
// write mutex so data is appended in order
|
||||
const writeMutex = makeMutex()
|
||||
// monkey patch eventemitter to capture all events
|
||||
ev.emit = function (...args: any[]) {
|
||||
const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n'
|
||||
const result = oldEmit.apply(ev, args as any)
|
||||
|
||||
writeMutex.mutex(async () => {
|
||||
await writeFile(filename, content, { flag: 'a' })
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read event file and emit events from there
|
||||
* @param filename filename containing event data
|
||||
* @param delayIntervalMs delay between each event emit
|
||||
*/
|
||||
export const readAndEmitEventStream = (filename: string, delayIntervalMs = 0) => {
|
||||
const ev = new EventEmitter() as BaileysEventEmitter
|
||||
|
||||
const fireEvents = async () => {
|
||||
// from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
|
||||
const fileStream = createReadStream(filename)
|
||||
|
||||
const rl = createInterface({
|
||||
input: fileStream,
|
||||
crlfDelay: Infinity
|
||||
})
|
||||
// Note: we use the crlfDelay option to recognize all instances of CR LF
|
||||
// ('\r\n') in input.txt as a single line break.
|
||||
for await (const line of rl) {
|
||||
if (line) {
|
||||
const { event, data } = JSON.parse(line)
|
||||
ev.emit(event, data)
|
||||
delayIntervalMs && (await delay(delayIntervalMs))
|
||||
}
|
||||
}
|
||||
|
||||
fileStream.close()
|
||||
}
|
||||
|
||||
return {
|
||||
ev,
|
||||
task: fireEvents()
|
||||
}
|
||||
}
|
||||
@@ -153,8 +153,8 @@ export const makeEventBuffer = (logger: ILogger): BaileysBufferableEventEmitter
|
||||
|
||||
return {
|
||||
process(handler) {
|
||||
const listener = (map: BaileysEventData) => {
|
||||
handler(map)
|
||||
const listener = async (map: BaileysEventData) => {
|
||||
await handler(map)
|
||||
}
|
||||
|
||||
ev.on('event', listener)
|
||||
|
||||
@@ -10,7 +10,6 @@ export * from './history'
|
||||
export * from './chat-utils'
|
||||
export * from './lt-hash'
|
||||
export * from './auth-utils'
|
||||
export * from './baileys-event-stream'
|
||||
export * from './use-multi-file-auth-state'
|
||||
export * from './link-preview'
|
||||
export * from './event-buffer'
|
||||
|
||||
Reference in New Issue
Block a user