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
|
.DS_Store
|
||||||
.env
|
.env
|
||||||
auth_info_browser.json
|
auth_info_browser.json
|
||||||
yarn.lock
|
|
||||||
browser-messages.json
|
browser-messages.json
|
||||||
decoded-ws.json
|
decoded-ws.json
|
||||||
auth_info2.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": {
|
"scripts": {
|
||||||
"test": "mocha --timeout 240000 -r ts-node/register src/Tests/Tests.*.ts",
|
"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",
|
"lint": "eslint '*/*.ts' --quiet --fix",
|
||||||
"build:tsc": "tsc",
|
"build:tsc": "tsc",
|
||||||
"build:docs": "typedoc",
|
"build:docs": "typedoc",
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ describe('Test Connect', () => {
|
|||||||
it('should reconnect', async () => {
|
it('should reconnect', async () => {
|
||||||
const conn = new WAConnection()
|
const conn = new WAConnection()
|
||||||
conn.connectOptions.timeoutMs = 20*1000
|
conn.connectOptions.timeoutMs = 20*1000
|
||||||
|
|
||||||
await conn
|
await conn
|
||||||
.loadAuthInfo (auth)
|
.loadAuthInfo (auth)
|
||||||
.connect ()
|
.connect ()
|
||||||
@@ -96,6 +97,7 @@ describe('Test Connect', () => {
|
|||||||
})
|
})
|
||||||
describe ('Reconnects', () => {
|
describe ('Reconnects', () => {
|
||||||
const verifyConnectionOpen = async (conn: WAConnection) => {
|
const verifyConnectionOpen = async (conn: WAConnection) => {
|
||||||
|
assert.ok (conn.user.jid)
|
||||||
// check that the connection stays open
|
// check that the connection stays open
|
||||||
conn.on ('close', ({reason}) => (
|
conn.on ('close', ({reason}) => (
|
||||||
reason !== DisconnectReason.intentional && assert.fail ('should not have closed again')
|
reason !== DisconnectReason.intentional && assert.fail ('should not have closed again')
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ export class WAConnection extends Base {
|
|||||||
options,
|
options,
|
||||||
diff > this.connectOptions.connectCooldownMs ? 0 : this.connectOptions.connectCooldownMs
|
diff > this.connectOptions.connectCooldownMs ? 0 : this.connectOptions.connectCooldownMs
|
||||||
)
|
)
|
||||||
|
|
||||||
this.phoneConnected = true
|
this.phoneConnected = true
|
||||||
this.state = 'open'
|
this.state = 'open'
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -64,7 +63,9 @@ export class WAConnection extends Base {
|
|||||||
|
|
||||||
let task = ws
|
let task = ws
|
||||||
.then (conn => this.conn = conn)
|
.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 (() => (
|
.then (() => (
|
||||||
this.log(`connected to WhatsApp Web server, authenticating via ${reconnectID ? 'reconnect' : 'takeover'}`, MessageLogLevel.info)
|
this.log(`connected to WhatsApp Web server, authenticating via ${reconnectID ? 'reconnect' : 'takeover'}`, MessageLogLevel.info)
|
||||||
))
|
))
|
||||||
@@ -72,7 +73,7 @@ export class WAConnection extends Base {
|
|||||||
.then (() => {
|
.then (() => {
|
||||||
this.conn
|
this.conn
|
||||||
.removeAllListeners ('error')
|
.removeAllListeners ('error')
|
||||||
.removeAllListeners('close')
|
.removeAllListeners ('close')
|
||||||
})
|
})
|
||||||
|
|
||||||
let cancelTask: () => void
|
let cancelTask: () => void
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ export class WAConnection extends Base {
|
|||||||
} else if (!chat.messages.find(m => m.key.id === message.key.id)) {
|
} else if (!chat.messages.find(m => m.key.id === message.key.id)) {
|
||||||
// this.log ('adding new message from ' + chat.jid)
|
// this.log ('adding new message from ' + chat.jid)
|
||||||
chat.messages.push(message)
|
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
|
// only update if it's an actual message
|
||||||
if (message.message) this.chatUpdateTime (chat)
|
if (message.message) this.chatUpdateTime (chat)
|
||||||
@@ -243,7 +243,6 @@ export class WAConnection extends Base {
|
|||||||
case WA_MESSAGE_STUB_TYPE.GROUP_PARTICIPANT_REMOVE:
|
case WA_MESSAGE_STUB_TYPE.GROUP_PARTICIPANT_REMOVE:
|
||||||
participants = message.messageStubParameters.map (whatsappID)
|
participants = message.messageStubParameters.map (whatsappID)
|
||||||
this.emit ('group-participants-remove', { jid, actor, participants})
|
this.emit ('group-participants-remove', { jid, actor, participants})
|
||||||
|
|
||||||
// mark the chat read only if you left the group
|
// mark the chat read only if you left the group
|
||||||
if (participants.includes(this.user.jid)) {
|
if (participants.includes(this.user.jid)) {
|
||||||
chat.read_only = 'true'
|
chat.read_only = 'true'
|
||||||
|
|||||||
@@ -122,9 +122,7 @@ export class WAConnection extends Base {
|
|||||||
null,
|
null,
|
||||||
]
|
]
|
||||||
const response = await this.query({json, binaryTags: [WAMetric.queryMessages, WAFlag.ignore], expect200: false})
|
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 response[2]?.map(item => item[2] as WAMessage) || []
|
||||||
|
|
||||||
return messages
|
|
||||||
}
|
}
|
||||||
const chat = this.chats.get (jid)
|
const chat = this.chats.get (jid)
|
||||||
|
|
||||||
@@ -137,7 +135,8 @@ export class WAConnection extends Base {
|
|||||||
}
|
}
|
||||||
} else messages = await retreive (count, before)
|
} 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}
|
return {messages, cursor}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user