WAChat update

This commit is contained in:
Adhiraj Singh
2021-04-29 23:17:09 +05:30
parent 1d31b7a20c
commit 66fb931fa3
3 changed files with 5 additions and 12 deletions

View File

@@ -446,15 +446,14 @@ export class WAConnection extends Base {
}
}
/** inserts an empty chat into the DB */
protected chatAdd (jid: string, name?: string) {
protected chatAdd (jid: string, name?: string, properties: Partial<WAChat> = {}) {
const chat: WAChat = {
jid,
name,
t: unixTimestampSeconds(),
messages: newMessagesDB(),
count: 0,
modify_tag: '',
spam: 'false'
...(properties || {})
}
if(this.chats.insertIfAbsent(chat).length) {
this.emit('chat-new', chat)

View File

@@ -88,13 +88,7 @@ export class WAConnection extends Base {
metadata = await this.groupMetadata (gid)
this.logger.warn (`group ID switched from ${gid} to ${response.gid}`)
}
await this.chatAdd(response.gid, title)
const chat = this.chats.get(response.gid)
chat.metadata = metadata
chat.name = title // in case the chat wasn't inserted
this.emit('chat-update', { jid: chat.jid, name: chat.name, metadata })
await this.chatAdd(response.gid, title, { metadata })
return response
}
/**

View File

@@ -222,8 +222,8 @@ export interface WAChat {
read_only?: 'true' | 'false'
mute?: string
pin?: string
spam: 'false' | 'true'
modify_tag: string
spam?: 'false' | 'true'
modify_tag?: string
name?: string
/** when ephemeral messages were toggled on */
eph_setting_ts?: string