mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Delete chat fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import * as QR from 'qrcode-terminal'
|
import * as QR from 'qrcode-terminal'
|
||||||
import { WAConnection as Base } from './3.Connect'
|
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 { 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 { whatsappID, unixTimestampSeconds, GET_MESSAGE_ID, WA_MESSAGE_ID, waMessageKey, newMessagesDB, shallowChanges, toNumber } from './Utils'
|
||||||
import KeyedDB from '@adiwajshing/keyed-db'
|
import KeyedDB from '@adiwajshing/keyed-db'
|
||||||
import { Mutex } from './Mutex'
|
import { Mutex } from './Mutex'
|
||||||
|
|
||||||
@@ -316,7 +316,7 @@ export class WAConnection extends Base {
|
|||||||
const FUNCTIONS = {
|
const FUNCTIONS = {
|
||||||
'delete': () => {
|
'delete': () => {
|
||||||
chat['delete'] = 'true'
|
chat['delete'] = 'true'
|
||||||
this.chats.delete(chat)
|
this.chats.deleteById(chat.jid)
|
||||||
return 'delete'
|
return 'delete'
|
||||||
},
|
},
|
||||||
'clear': () => {
|
'clear': () => {
|
||||||
|
|||||||
@@ -378,13 +378,6 @@ export class WAConnection extends Base {
|
|||||||
await this.relayWAMessage (waMessage)
|
await this.relayWAMessage (waMessage)
|
||||||
return 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
|
* Clear the chat messages
|
||||||
* @param jid the ID of the person/group you are modifiying
|
* @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 ])
|
const response = await this.setQuery ([['chat', chatAttrs, null]], [ WAMetric.chat, WAFlag.ignore ])
|
||||||
|
|
||||||
if (chat && response.status === 200) {
|
if (chat && response.status === 200) {
|
||||||
if (type === ChatModification.clear) {
|
switch(type) {
|
||||||
if (includeStarred) {
|
case ChatModification.clear:
|
||||||
chat.messages.clear ()
|
if (includeStarred) {
|
||||||
} else {
|
chat.messages.clear()
|
||||||
chat.messages = chat.messages.filter(m => m.starred)
|
} 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
|
return response
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user