mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
lint: lint pending files
This commit is contained in:
@@ -14,9 +14,9 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
auth: initialAuthInfo
|
auth: initialAuthInfo
|
||||||
} = config
|
} = config
|
||||||
const ev = new EventEmitter() as LegacyBaileysEventEmitter
|
const ev = new EventEmitter() as LegacyBaileysEventEmitter
|
||||||
|
|
||||||
const authInfo = initialAuthInfo || newLegacyAuthCreds()
|
const authInfo = initialAuthInfo || newLegacyAuthCreds()
|
||||||
|
|
||||||
const state: ConnectionState = {
|
const state: ConnectionState = {
|
||||||
legacy: {
|
legacy: {
|
||||||
phoneConnected: false,
|
phoneConnected: false,
|
||||||
@@ -39,7 +39,7 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
// if no reconnects occur
|
// if no reconnects occur
|
||||||
// send close event
|
// send close event
|
||||||
updateState({
|
updateState({
|
||||||
connection: 'close',
|
connection: 'close',
|
||||||
qr: undefined,
|
qr: undefined,
|
||||||
lastDisconnect: {
|
lastDisconnect: {
|
||||||
error,
|
error,
|
||||||
@@ -49,12 +49,12 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
})
|
})
|
||||||
/** Can you login to WA without scanning the QR */
|
/** Can you login to WA without scanning the QR */
|
||||||
const canLogin = () => !!authInfo?.encKey && !!authInfo?.macKey
|
const canLogin = () => !!authInfo?.encKey && !!authInfo?.macKey
|
||||||
|
|
||||||
const updateState = (update: Partial<ConnectionState>) => {
|
const updateState = (update: Partial<ConnectionState>) => {
|
||||||
Object.assign(state, update)
|
Object.assign(state, update)
|
||||||
ev.emit('connection.update', update)
|
ev.emit('connection.update', update)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs you out from WA
|
* Logs you out from WA
|
||||||
* If connected, invalidates the credentials with the server
|
* If connected, invalidates the credentials with the server
|
||||||
@@ -82,7 +82,7 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
curveKeys = Curve.generateKeyPair()
|
curveKeys = Curve.generateKeyPair()
|
||||||
const publicKey = Buffer.from(curveKeys.public).toString('base64')
|
const publicKey = Buffer.from(curveKeys.public).toString('base64')
|
||||||
let qrGens = 0
|
let qrGens = 0
|
||||||
|
|
||||||
const qrLoop = ttl => {
|
const qrLoop = ttl => {
|
||||||
const qr = [ref, publicKey, authInfo.clientID].join(',')
|
const qr = [ref, publicKey, authInfo.clientID].join(',')
|
||||||
updateState({ qr })
|
updateState({ qr })
|
||||||
@@ -96,7 +96,7 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
try {
|
try {
|
||||||
// request new QR
|
// request new QR
|
||||||
const { ref: newRef, ttl: newTTL } = await socket.query({
|
const { ref: newRef, ttl: newTTL } = await socket.query({
|
||||||
json: ['admin', 'Conn', 'reref'],
|
json: ['admin', 'Conn', 'reref'],
|
||||||
expect200: true,
|
expect200: true,
|
||||||
longTag: true,
|
longTag: true,
|
||||||
requiresPhoneConnection: false
|
requiresPhoneConnection: false
|
||||||
@@ -123,7 +123,7 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
const canDoLogin = canLogin()
|
const canDoLogin = canLogin()
|
||||||
const initQuery = (async() => {
|
const initQuery = (async() => {
|
||||||
const { ref, ttl } = await socket.query({
|
const { ref, ttl } = await socket.query({
|
||||||
json: ['admin', 'init', version, browser, authInfo.clientID, true],
|
json: ['admin', 'init', version, browser, authInfo.clientID, true],
|
||||||
expect200: true,
|
expect200: true,
|
||||||
longTag: true,
|
longTag: true,
|
||||||
requiresPhoneConnection: false
|
requiresPhoneConnection: false
|
||||||
@@ -168,7 +168,7 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
|
|
||||||
// wait for response with tag "s1"
|
// wait for response with tag "s1"
|
||||||
let response = await Promise.race(
|
let response = await Promise.race(
|
||||||
[
|
[
|
||||||
socket.waitForMessage('s1', false, undefined).promise,
|
socket.waitForMessage('s1', false, undefined).promise,
|
||||||
...(loginTag ? [socket.waitForMessage(loginTag, false, connectTimeoutMs).promise] : [])
|
...(loginTag ? [socket.waitForMessage(loginTag, false, connectTimeoutMs).promise] : [])
|
||||||
]
|
]
|
||||||
@@ -184,9 +184,9 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
if(response[1]?.challenge) {
|
if(response[1]?.challenge) {
|
||||||
const json = computeChallengeResponse(response[1].challenge, authInfo)
|
const json = computeChallengeResponse(response[1].challenge, authInfo)
|
||||||
logger.info('resolving login challenge')
|
logger.info('resolving login challenge')
|
||||||
|
|
||||||
await socket.query({ json, expect200: true, timeoutMs: connectTimeoutMs })
|
await socket.query({ json, expect200: true, timeoutMs: connectTimeoutMs })
|
||||||
|
|
||||||
response = await socket.waitForMessage('s2', true).promise
|
response = await socket.waitForMessage('s2', true).promise
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
// validate the new connection
|
// validate the new connection
|
||||||
const { user, auth } = validateNewConnection(response[1], authInfo, curveKeys)// validate the connection
|
const { user, auth } = validateNewConnection(response[1], authInfo, curveKeys)// validate the connection
|
||||||
const isNewLogin = user.id !== state.legacy!.user?.id
|
const isNewLogin = user.id !== state.legacy!.user?.id
|
||||||
|
|
||||||
Object.assign(authInfo, auth)
|
Object.assign(authInfo, auth)
|
||||||
updateEncKeys()
|
updateEncKeys()
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
ev.emit('connection.update', {
|
ev.emit('connection.update', {
|
||||||
...state
|
...state
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import { proto } from '../../WAProto'
|
||||||
import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types'
|
import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types'
|
||||||
import { generateMessageID } from '../Utils'
|
import { generateMessageID } from '../Utils'
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidEncode, jidNormalizedUser } from '../WABinary'
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidEncode, jidNormalizedUser } from '../WABinary'
|
||||||
import { makeSocket } from './socket'
|
import { makeSocket } from './socket'
|
||||||
import { proto } from '../../WAProto'
|
|
||||||
|
|
||||||
export const makeGroupsSocket = (config: SocketConfig) => {
|
export const makeGroupsSocket = (config: SocketConfig) => {
|
||||||
const sock = makeSocket(config)
|
const sock = makeSocket(config)
|
||||||
@@ -137,10 +137,10 @@ export const makeGroupsSocket = (config: SocketConfig) => {
|
|||||||
},
|
},
|
||||||
groupAcceptInviteV4: async(jid: string, inviteMessage: proto.IGroupInviteMessage) => {
|
groupAcceptInviteV4: async(jid: string, inviteMessage: proto.IGroupInviteMessage) => {
|
||||||
const results = await groupQuery(inviteMessage.groupJid, 'set', [{ tag: 'accept', attrs: {
|
const results = await groupQuery(inviteMessage.groupJid, 'set', [{ tag: 'accept', attrs: {
|
||||||
code: inviteMessage.inviteCode,
|
code: inviteMessage.inviteCode,
|
||||||
expiration: inviteMessage.inviteExpiration.toString(),
|
expiration: inviteMessage.inviteExpiration.toString(),
|
||||||
admin: jid} }])
|
admin: jid } }])
|
||||||
return results.attrs.from;
|
return results.attrs.from
|
||||||
},
|
},
|
||||||
groupToggleEphemeral: async(jid: string, ephemeralExpiration: number) => {
|
groupToggleEphemeral: async(jid: string, ephemeralExpiration: number) => {
|
||||||
const content: BinaryNode = ephemeralExpiration ?
|
const content: BinaryNode = ephemeralExpiration ?
|
||||||
|
|||||||
Reference in New Issue
Block a user