From 66fb931fa30659dc5a6324ab2bc0f74eab743a31 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 29 Apr 2021 23:17:09 +0530 Subject: [PATCH] WAChat update --- src/WAConnection/4.Events.ts | 5 ++--- src/WAConnection/8.Groups.ts | 8 +------- src/WAConnection/Constants.ts | 4 ++-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/WAConnection/4.Events.ts b/src/WAConnection/4.Events.ts index 02c361b..fafb3e5 100644 --- a/src/WAConnection/4.Events.ts +++ b/src/WAConnection/4.Events.ts @@ -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 = {}) { 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) diff --git a/src/WAConnection/8.Groups.ts b/src/WAConnection/8.Groups.ts index bbc4de9..379768d 100644 --- a/src/WAConnection/8.Groups.ts +++ b/src/WAConnection/8.Groups.ts @@ -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 } /** diff --git a/src/WAConnection/Constants.ts b/src/WAConnection/Constants.ts index 6675ca5..c5b16ad 100644 --- a/src/WAConnection/Constants.ts +++ b/src/WAConnection/Constants.ts @@ -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