mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
General cleanup
This commit is contained in:
@@ -181,14 +181,10 @@ Also, these events are fired regardless of whether they are initiated by the Bai
|
|||||||
on (event: 'open', listener: (result: WAOpenResult) => void): this
|
on (event: 'open', listener: (result: WAOpenResult) => void): this
|
||||||
/** when the connection is opening */
|
/** when the connection is opening */
|
||||||
on (event: 'connecting', listener: () => void): this
|
on (event: 'connecting', listener: () => void): this
|
||||||
/** when the connection has been validated */
|
|
||||||
on (event: 'connection-validated', listener: (user: WAUser) => void): this
|
|
||||||
/** when the connection has closed */
|
/** when the connection has closed */
|
||||||
on (event: 'close', listener: (err: {reason?: DisconnectReason | string, isReconnecting: boolean}) => void): this
|
on (event: 'close', listener: (err: {reason?: DisconnectReason | string, isReconnecting: boolean}) => void): this
|
||||||
/** when the socket is closed */
|
/** when the socket is closed */
|
||||||
on (event: 'ws-close', listener: (err: {reason?: DisconnectReason | string}) => void): this
|
on (event: 'ws-close', listener: (err: {reason?: DisconnectReason | string}) => void): this
|
||||||
/** when WA updates the credentials */
|
|
||||||
on (event: 'credentials-updated', listener: (auth: AuthenticationCredentials) => void): this
|
|
||||||
/** when a new QR is generated, ready for scanning */
|
/** when a new QR is generated, ready for scanning */
|
||||||
on (event: 'qr', listener: (qr: string) => void): this
|
on (event: 'qr', listener: (qr: string) => void): this
|
||||||
/** when the connection to the phone changes */
|
/** when the connection to the phone changes */
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as Curve from 'curve25519-js'
|
import * as Curve from 'curve25519-js'
|
||||||
import * as Utils from './Utils'
|
import * as Utils from './Utils'
|
||||||
import {WAConnection as Base} from './0.Base'
|
import {WAConnection as Base} from './0.Base'
|
||||||
import { WAMetric, WAFlag, BaileysError, Presence, WAUser, WAInitResponse } from './Constants'
|
import { WAMetric, WAFlag, BaileysError, Presence, WAUser, WAInitResponse, WAOpenResult } from './Constants'
|
||||||
|
|
||||||
export class WAConnection extends Base {
|
export class WAConnection extends Base {
|
||||||
|
|
||||||
@@ -87,21 +87,21 @@ export class WAConnection extends Base {
|
|||||||
response = await this.waitForMessage('s2', true)
|
response = await this.waitForMessage('s2', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const {user, auth} = this.validateNewConnection(response[1]) // validate the connection
|
const result = this.validateNewConnection(response[1])// validate the connection
|
||||||
if (user.jid !== this.user?.jid) {
|
if (result.user.jid !== this.user?.jid) {
|
||||||
isNewUser = true
|
result.isNewUser = true
|
||||||
// clear out old data
|
// clear out old data
|
||||||
this.chats.clear()
|
this.chats.clear()
|
||||||
this.contacts = {}
|
this.contacts = {}
|
||||||
}
|
}
|
||||||
this.user = user
|
this.user = result.user
|
||||||
|
|
||||||
this.logger.info('validated connection successfully')
|
this.logger.info('validated connection successfully')
|
||||||
|
|
||||||
this.sendPostConnectQueries ()
|
this.sendPostConnectQueries ()
|
||||||
this.logger.debug('sent init queries')
|
this.logger.debug('sent init queries')
|
||||||
|
|
||||||
return { user, auth, isNewUser }
|
return result
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Send the same queries WA Web sends after connect
|
* Send the same queries WA Web sends after connect
|
||||||
@@ -142,9 +142,9 @@ export class WAConnection extends Base {
|
|||||||
name: json.pushname,
|
name: json.pushname,
|
||||||
phone: json.phone,
|
phone: json.phone,
|
||||||
imgUrl: null
|
imgUrl: null
|
||||||
} as WAUser,
|
},
|
||||||
auth: this.authInfo
|
auth: this.authInfo
|
||||||
})
|
}) as WAOpenResult
|
||||||
|
|
||||||
if (!json.secret) {
|
if (!json.secret) {
|
||||||
// if we didn't get a secret, we don't need it, we're validated
|
// if we didn't get a secret, we don't need it, we're validated
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export class WAConnection extends Base {
|
|||||||
if (!willReconnect) throw error
|
if (!willReconnect) throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.newConnection = newConnection
|
if (newConnection) result.newConnection = newConnection
|
||||||
this.emit ('open', result)
|
this.emit ('open', result)
|
||||||
|
|
||||||
this.logger.info ('opened connection to WhatsApp Web')
|
this.logger.info ('opened connection to WhatsApp Web')
|
||||||
|
|||||||
@@ -608,8 +608,6 @@ export class WAConnection extends Base {
|
|||||||
on (event: 'open', listener: (result: WAOpenResult) => void): this
|
on (event: 'open', listener: (result: WAOpenResult) => void): this
|
||||||
/** when the connection is opening */
|
/** when the connection is opening */
|
||||||
on (event: 'connecting', listener: () => void): this
|
on (event: 'connecting', listener: () => void): this
|
||||||
/** when the connection has been validated */
|
|
||||||
on (event: 'connection-validated', listener: (item: { user: WAUser, auth: AuthenticationCredentials, isNewUser: boolean }) => void): this
|
|
||||||
/** when the connection has closed */
|
/** when the connection has closed */
|
||||||
on (event: 'close', listener: (err: {reason?: DisconnectReason | string, isReconnecting: boolean}) => void): this
|
on (event: 'close', listener: (err: {reason?: DisconnectReason | string, isReconnecting: boolean}) => void): this
|
||||||
/** when the socket is closed */
|
/** when the socket is closed */
|
||||||
|
|||||||
@@ -402,9 +402,9 @@ export interface WAMessageStatusUpdate {
|
|||||||
|
|
||||||
export interface WAOpenResult {
|
export interface WAOpenResult {
|
||||||
/** Was this connection opened via a QR scan */
|
/** Was this connection opened via a QR scan */
|
||||||
newConnection: boolean
|
newConnection?: true
|
||||||
user: WAUser
|
user: WAUser
|
||||||
isNewUser: boolean
|
isNewUser?: true
|
||||||
auth: AuthenticationCredentials
|
auth: AuthenticationCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,8 +420,8 @@ export interface PresenceUpdate {
|
|||||||
deny?: boolean
|
deny?: boolean
|
||||||
}
|
}
|
||||||
export interface BlocklistUpdate {
|
export interface BlocklistUpdate {
|
||||||
added: string[]
|
added?: string[]
|
||||||
removed: string[]
|
removed?: string[]
|
||||||
}
|
}
|
||||||
// path to upload the media
|
// path to upload the media
|
||||||
export const MediaPathMap = {
|
export const MediaPathMap = {
|
||||||
@@ -439,11 +439,6 @@ export const MimetypeMap = {
|
|||||||
audioMessage: Mimetype.ogg,
|
audioMessage: Mimetype.ogg,
|
||||||
stickerMessage: Mimetype.webp,
|
stickerMessage: Mimetype.webp,
|
||||||
}
|
}
|
||||||
export interface WASendMessageResponse {
|
|
||||||
status: number
|
|
||||||
messageID: string
|
|
||||||
message: WAMessage
|
|
||||||
}
|
|
||||||
export type WAParticipantAction = 'add' | 'remove' | 'promote' | 'demote'
|
export type WAParticipantAction = 'add' | 'remove' | 'promote' | 'demote'
|
||||||
export type BaileysEvent =
|
export type BaileysEvent =
|
||||||
'open' |
|
'open' |
|
||||||
|
|||||||
Reference in New Issue
Block a user