mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
changes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,7 +5,6 @@ output.csv
|
||||
.DS_Store
|
||||
.env
|
||||
auth_info_browser.json
|
||||
yarn.lock
|
||||
browser-messages.json
|
||||
decoded-ws.json
|
||||
auth_info2.json
|
||||
|
||||
2647
package-lock.json
generated
2647
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,7 @@
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha --timeout 240000 -r ts-node/register src/Tests/Tests.*.ts",
|
||||
"prepare": "npm run build:tsc",
|
||||
"prepack": "npm run build:tsc",
|
||||
"lint": "eslint '*/*.ts' --quiet --fix",
|
||||
"build:tsc": "tsc",
|
||||
"build:docs": "typedoc",
|
||||
|
||||
@@ -43,6 +43,7 @@ describe('Test Connect', () => {
|
||||
it('should reconnect', async () => {
|
||||
const conn = new WAConnection()
|
||||
conn.connectOptions.timeoutMs = 20*1000
|
||||
|
||||
await conn
|
||||
.loadAuthInfo (auth)
|
||||
.connect ()
|
||||
@@ -96,6 +97,7 @@ describe('Test Connect', () => {
|
||||
})
|
||||
describe ('Reconnects', () => {
|
||||
const verifyConnectionOpen = async (conn: WAConnection) => {
|
||||
assert.ok (conn.user.jid)
|
||||
// check that the connection stays open
|
||||
conn.on ('close', ({reason}) => (
|
||||
reason !== DisconnectReason.intentional && assert.fail ('should not have closed again')
|
||||
|
||||
@@ -23,7 +23,6 @@ export class WAConnection extends Base {
|
||||
options,
|
||||
diff > this.connectOptions.connectCooldownMs ? 0 : this.connectOptions.connectCooldownMs
|
||||
)
|
||||
|
||||
this.phoneConnected = true
|
||||
this.state = 'open'
|
||||
} catch (error) {
|
||||
@@ -64,7 +63,9 @@ export class WAConnection extends Base {
|
||||
|
||||
let task = ws
|
||||
.then (conn => this.conn = conn)
|
||||
.then (() => this.conn.on('message', data => this.onMessageRecieved(data as any)))
|
||||
.then (() => (
|
||||
this.conn.on('message', data => this.onMessageRecieved(data as any))
|
||||
))
|
||||
.then (() => (
|
||||
this.log(`connected to WhatsApp Web server, authenticating via ${reconnectID ? 'reconnect' : 'takeover'}`, MessageLogLevel.info)
|
||||
))
|
||||
@@ -72,7 +73,7 @@ export class WAConnection extends Base {
|
||||
.then (() => {
|
||||
this.conn
|
||||
.removeAllListeners ('error')
|
||||
.removeAllListeners('close')
|
||||
.removeAllListeners ('close')
|
||||
})
|
||||
|
||||
let cancelTask: () => void
|
||||
|
||||
@@ -226,7 +226,7 @@ export class WAConnection extends Base {
|
||||
} else if (!chat.messages.find(m => m.key.id === message.key.id)) {
|
||||
// this.log ('adding new message from ' + chat.jid)
|
||||
chat.messages.push(message)
|
||||
chat.messages = chat.messages.slice (-5) // only keep the last 5 messages
|
||||
chat.messages = chat.messages.slice (-this.maxCachedMessages) // only keep the last 5 messages
|
||||
|
||||
// only update if it's an actual message
|
||||
if (message.message) this.chatUpdateTime (chat)
|
||||
@@ -243,7 +243,6 @@ export class WAConnection extends Base {
|
||||
case WA_MESSAGE_STUB_TYPE.GROUP_PARTICIPANT_REMOVE:
|
||||
participants = message.messageStubParameters.map (whatsappID)
|
||||
this.emit ('group-participants-remove', { jid, actor, participants})
|
||||
|
||||
// mark the chat read only if you left the group
|
||||
if (participants.includes(this.user.jid)) {
|
||||
chat.read_only = 'true'
|
||||
|
||||
@@ -122,9 +122,7 @@ export class WAConnection extends Base {
|
||||
null,
|
||||
]
|
||||
const response = await this.query({json, binaryTags: [WAMetric.queryMessages, WAFlag.ignore], expect200: false})
|
||||
const messages = response[2] ? (response[2] as WANode[]).map(item => item[2] as WAMessage) : []
|
||||
|
||||
return messages
|
||||
return response[2]?.map(item => item[2] as WAMessage) || []
|
||||
}
|
||||
const chat = this.chats.get (jid)
|
||||
|
||||
@@ -137,7 +135,8 @@ export class WAConnection extends Base {
|
||||
}
|
||||
} else messages = await retreive (count, before)
|
||||
|
||||
const cursor = messages[0] && messages[0].key
|
||||
let cursor
|
||||
if (messages[0]) cursor = { id: messages[0].key.id, fromMe: messages[0].key.fromMe }
|
||||
return {messages, cursor}
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user