diff --git a/src/WAConnection/0.Base.ts b/src/WAConnection/0.Base.ts index f2ffcbe..93f1d9a 100644 --- a/src/WAConnection/0.Base.ts +++ b/src/WAConnection/0.Base.ts @@ -65,6 +65,7 @@ export class WAConnection extends EventEmitter { messageLog: { tag: string, json: string, fromMe: boolean, binaryTags?: any[] }[] = [] maxCachedMessages = 50 + loadProfilePicturesForChatsAutomatically = true chats = new KeyedDB (Utils.waChatKey(false), value => value.jid) contacts: { [k: string]: WAContact } = {} diff --git a/src/WAConnection/4.Events.ts b/src/WAConnection/4.Events.ts index d3c6113..3497d67 100644 --- a/src/WAConnection/4.Events.ts +++ b/src/WAConnection/4.Events.ts @@ -199,8 +199,9 @@ export class WAConnection extends Base { name } this.chats.insert (chat) - - await this.setProfilePicture (chat) + if (this.loadProfilePicturesForChatsAutomatically) { + await this.setProfilePicture (chat) + } this.emit ('chat-new', chat) return chat diff --git a/src/WAConnection/5.User.ts b/src/WAConnection/5.User.ts index 853ca24..a83a112 100644 --- a/src/WAConnection/5.User.ts +++ b/src/WAConnection/5.User.ts @@ -8,6 +8,7 @@ import { } from '../WAConnection/Constants' import { generateProfilePicture, waChatKey, whatsappID, unixTimestampSeconds } from './Utils' import { Mutex } from './Mutex' +import { type } from 'os' // All user related functions -- get profile picture, set status etc. @@ -101,7 +102,9 @@ export class WAConnection extends Base { (typeof options?.custom !== 'function' || options?.custom(chat)) && (typeof options?.searchString === 'undefined' || chat.name?.includes (options.searchString) || chat.jid?.startsWith(options.searchString)) ))) - if (options.loadProfilePicture !== false) { + let loadPP = this.loadProfilePicturesForChatsAutomatically + if (typeof options.loadProfilePicture !== 'undefined') loadPP = options.loadProfilePicture + if (loadPP) { await Promise.all ( chats.map (async chat => ( typeof chat.imgUrl === 'undefined' && await this.setProfilePicture (chat) diff --git a/src/WAConnection/6.MessagesSend.ts b/src/WAConnection/6.MessagesSend.ts index 8f5a571..57edc1a 100644 --- a/src/WAConnection/6.MessagesSend.ts +++ b/src/WAConnection/6.MessagesSend.ts @@ -85,6 +85,8 @@ export class WAConnection extends Base { } /** Prepare a media message for sending */ async prepareMessageMedia(buffer: Buffer, mediaType: MessageType, options: MessageOptions = {}) { + await this.waitForConnection () + if (mediaType === MessageType.document && !options.mimetype) { throw new Error('mimetype required to send a document') }