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 */ /** 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 = { const chat: WAChat = {
jid, jid,
name, name,
t: unixTimestampSeconds(), t: unixTimestampSeconds(),
messages: newMessagesDB(), messages: newMessagesDB(),
count: 0, count: 0,
modify_tag: '', ...(properties || {})
spam: 'false'
} }
if(this.chats.insertIfAbsent(chat).length) { if(this.chats.insertIfAbsent(chat).length) {
this.emit('chat-new', chat) this.emit('chat-new', chat)

View File

@@ -88,13 +88,7 @@ export class WAConnection extends Base {
metadata = await this.groupMetadata (gid) metadata = await this.groupMetadata (gid)
this.logger.warn (`group ID switched from ${gid} to ${response.gid}`) this.logger.warn (`group ID switched from ${gid} to ${response.gid}`)
} }
await this.chatAdd(response.gid, title) await this.chatAdd(response.gid, title, { metadata })
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 })
return response return response
} }
/** /**

View File

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