Delete chat fix

This commit is contained in:
Adhiraj Singh
2021-03-18 13:21:33 +05:30
parent 4c2f954601
commit afea6c249e
2 changed files with 27 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
import * as QR from 'qrcode-terminal'
import { WAConnection as Base } from './3.Connect'
import { WAMessageStatusUpdate, WAMessage, WAContact, WAChat, WAMessageProto, WA_MESSAGE_STUB_TYPE, WA_MESSAGE_STATUS_TYPE, PresenceUpdate, BaileysEvent, DisconnectReason, WAOpenResult, Presence, AuthenticationCredentials, WAParticipantAction, WAGroupMetadata, WAUser, WANode, WAPresenceData, WAChatUpdate, BlocklistUpdate, WAContactUpdate, WAMetric, WAFlag } from './Constants'
import { whatsappID, unixTimestampSeconds, isGroupID, GET_MESSAGE_ID, WA_MESSAGE_ID, waMessageKey, newMessagesDB, shallowChanges, toNumber } from './Utils'
import { WAMessage, WAContact, WAChat, WAMessageProto, WA_MESSAGE_STUB_TYPE, WA_MESSAGE_STATUS_TYPE, PresenceUpdate, BaileysEvent, DisconnectReason, WAOpenResult, Presence, AuthenticationCredentials, WAParticipantAction, WAGroupMetadata, WAUser, WANode, WAPresenceData, WAChatUpdate, BlocklistUpdate, WAContactUpdate, WAMetric, WAFlag } from './Constants'
import { whatsappID, unixTimestampSeconds, GET_MESSAGE_ID, WA_MESSAGE_ID, waMessageKey, newMessagesDB, shallowChanges, toNumber } from './Utils'
import KeyedDB from '@adiwajshing/keyed-db'
import { Mutex } from './Mutex'
@@ -316,7 +316,7 @@ export class WAConnection extends Base {
const FUNCTIONS = {
'delete': () => {
chat['delete'] = 'true'
this.chats.delete(chat)
this.chats.deleteById(chat.jid)
return 'delete'
},
'clear': () => {

View File

@@ -378,13 +378,6 @@ export class WAConnection extends Base {
await this.relayWAMessage (waMessage)
return waMessage
}
/**
* Delete the chat of a given ID
* @deprecated -- use `modifyChat(jid, 'delete')` instead
* */
deleteChat (jid: string) {
return this.modifyChat(jid, 'delete')
}
/**
* Clear the chat messages
* @param jid the ID of the person/group you are modifiying
@@ -447,23 +440,31 @@ export class WAConnection extends Base {
const response = await this.setQuery ([['chat', chatAttrs, null]], [ WAMetric.chat, WAFlag.ignore ])
if (chat && response.status === 200) {
if (type === ChatModification.clear) {
if (includeStarred) {
chat.messages.clear ()
} else {
chat.messages = chat.messages.filter(m => m.starred)
}
switch(type) {
case ChatModification.clear:
if (includeStarred) {
chat.messages.clear()
} else {
chat.messages = chat.messages.filter(m => m.starred)
}
break
case ChatModification.delete:
this.chats.deleteById(jid)
this.emit('chat-update', { jid, delete: 'true' })
break
default:
this.chats.update(jid, chat => {
if (type.includes('un')) {
type = type.replace ('un', '') as ChatModification
delete chat[type.replace('un','')]
this.emit ('chat-update', { jid, [type]: false })
} else {
chat[type] = chatAttrs[type] || 'true'
this.emit ('chat-update', { jid, [type]: chat[type] })
}
})
break
}
this.chats.update(jid, chat => {
if (type.includes('un')) {
type = type.replace ('un', '') as ChatModification
delete chat[type.replace('un','')]
this.emit ('chat-update', { jid, [type]: false })
} else {
chat[type] = chatAttrs[type] || 'true'
this.emit ('chat-update', { jid, [type]: chat[type] })
}
})
}
return response
}