Completely remove message-status-update & user-status-update

This commit is contained in:
Adhiraj Singh
2021-01-04 14:19:44 +05:30
parent ac4b4c7384
commit 6cc5a910f7
7 changed files with 26 additions and 26 deletions

View File

@@ -12,9 +12,11 @@ WAConnectionTest('Messages', conn => {
it('should send a pending message', async () => {
const message = await sendAndRetreiveMessage(conn, 'hello fren', MessageType.text, { waitForAck: false })
await new Promise(resolve => conn.once('message-status-update', update => {
if (update.ids.includes(message.key.id)) {
assert.strictEqual(update.type, WA_MESSAGE_STATUS_TYPE.SERVER_ACK)
await new Promise(resolve => conn.on('chat-update', update => {
if (update.jid === testJid &&
update.messages &&
update.messages.first.key.id === message.key.id &&
update.messages.first.status === WA_MESSAGE_STATUS_TYPE.SERVER_ACK) {
resolve(undefined)
}
}))

View File

@@ -21,10 +21,10 @@ WAConnectionTest('Misc', conn => {
const newStatus = 'v cool status'
const waitForEvent = new Promise (resolve => {
conn.on ('user-status-update', ({jid, status}) => {
conn.on ('contact-update', ({jid, status}) => {
if (jid === conn.user.jid) {
assert.strictEqual (status, newStatus)
conn.removeAllListeners ('user-status-update')
conn.removeAllListeners ('contact-update')
resolve(undefined)
}
})

View File

@@ -625,11 +625,6 @@ export class WAConnection extends Base {
on (event: 'chats-update', listener: (chats: WAChatUpdate[]) => void): this
/** when a chat is updated (new message, updated message, read message, deleted, pinned, presence updated etc) */
on (event: 'chat-update', listener: (chat: WAChatUpdate) => void): this
/**
* when a message's status is updated (deleted, delivered, read, sent etc.)
* @deprecated will not be called anymore. Use `chat-update`
* */
on (event: 'message-status-update', listener: (message: WAMessageStatusUpdate) => void): this
/** when participants are added to a group */
on (event: 'group-participants-update', listener: (update: {jid: string, participants: string[], actor?: string, action: WAParticipantAction}) => void): this
/** when the group is updated */

View File

@@ -78,9 +78,6 @@ export class WAConnection extends Base {
]
)
this.emit ('contact-update', { jid: this.user.jid, status })
// emit deprecated
this.emit ('user-status-update', { jid: this.user.jid, status })
return response
}
async updateProfileName (name: string) {

View File

@@ -11,7 +11,7 @@ import {
WATextMessage,
WAMessageContent, WAMetric, WAFlag, WAMessage, BaileysError, WA_MESSAGE_STATUS_TYPE, WAMessageProto, MediaConnInfo, MessageTypeProto, URL_REGEX, WAUrlInfo, WA_DEFAULT_EPHEMERAL
} from './Constants'
import { generateMessageID, sha256, hmacSign, aesEncrypWithIV, randomBytes, generateThumbnail, getMediaKeys, decodeMediaMessageBuffer, extensionForMediaMessage, whatsappID, unixTimestampSeconds, getAudioDuration } from './Utils'
import { generateMessageID, sha256, hmacSign, aesEncrypWithIV, randomBytes, generateThumbnail, getMediaKeys, decodeMediaMessageBuffer, extensionForMediaMessage, whatsappID, unixTimestampSeconds, getAudioDuration, newMessagesDB } from './Utils'
import { Mutex } from './Mutex'
export class WAConnection extends Base {
@@ -288,9 +288,13 @@ export class WAConnection extends Base {
if (waitForAck) {
await promise
} else {
const emitUpdate = (status: WA_MESSAGE_STATUS_TYPE) => {
message.status = status
this.emit('chat-update', { jid: message.key.remoteJid, messages: newMessagesDB([ message ]) })
}
promise
.then(() => this.emit('message-status-update', { ids: [ mID ], to: message.key.remoteJid, type: WA_MESSAGE_STATUS_TYPE.SERVER_ACK }))
.catch(() => this.emit('message-status-update', { ids: [ mID ], to: message.key.remoteJid, type: WA_MESSAGE_STATUS_TYPE.ERROR }))
.then(() => emitUpdate(WA_MESSAGE_STATUS_TYPE.SERVER_ACK))
.catch(() => emitUpdate(WA_MESSAGE_STATUS_TYPE.ERROR))
}
await this.chatAddMessageAppropriate (message)
}