mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Explicit waitForConnection + option to not load profile picture for new chats
This commit is contained in:
@@ -65,6 +65,7 @@ export class WAConnection extends EventEmitter {
|
|||||||
messageLog: { tag: string, json: string, fromMe: boolean, binaryTags?: any[] }[] = []
|
messageLog: { tag: string, json: string, fromMe: boolean, binaryTags?: any[] }[] = []
|
||||||
|
|
||||||
maxCachedMessages = 50
|
maxCachedMessages = 50
|
||||||
|
loadProfilePicturesForChatsAutomatically = true
|
||||||
|
|
||||||
chats = new KeyedDB (Utils.waChatKey(false), value => value.jid)
|
chats = new KeyedDB (Utils.waChatKey(false), value => value.jid)
|
||||||
contacts: { [k: string]: WAContact } = {}
|
contacts: { [k: string]: WAContact } = {}
|
||||||
|
|||||||
@@ -199,8 +199,9 @@ export class WAConnection extends Base {
|
|||||||
name
|
name
|
||||||
}
|
}
|
||||||
this.chats.insert (chat)
|
this.chats.insert (chat)
|
||||||
|
if (this.loadProfilePicturesForChatsAutomatically) {
|
||||||
await this.setProfilePicture (chat)
|
await this.setProfilePicture (chat)
|
||||||
|
}
|
||||||
this.emit ('chat-new', chat)
|
this.emit ('chat-new', chat)
|
||||||
|
|
||||||
return chat
|
return chat
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from '../WAConnection/Constants'
|
} from '../WAConnection/Constants'
|
||||||
import { generateProfilePicture, waChatKey, whatsappID, unixTimestampSeconds } from './Utils'
|
import { generateProfilePicture, waChatKey, whatsappID, unixTimestampSeconds } from './Utils'
|
||||||
import { Mutex } from './Mutex'
|
import { Mutex } from './Mutex'
|
||||||
|
import { type } from 'os'
|
||||||
|
|
||||||
// All user related functions -- get profile picture, set status etc.
|
// 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?.custom !== 'function' || options?.custom(chat)) &&
|
||||||
(typeof options?.searchString === 'undefined' || chat.name?.includes (options.searchString) || chat.jid?.startsWith(options.searchString))
|
(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 (
|
await Promise.all (
|
||||||
chats.map (async chat => (
|
chats.map (async chat => (
|
||||||
typeof chat.imgUrl === 'undefined' && await this.setProfilePicture (chat)
|
typeof chat.imgUrl === 'undefined' && await this.setProfilePicture (chat)
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ export class WAConnection extends Base {
|
|||||||
}
|
}
|
||||||
/** Prepare a media message for sending */
|
/** Prepare a media message for sending */
|
||||||
async prepareMessageMedia(buffer: Buffer, mediaType: MessageType, options: MessageOptions = {}) {
|
async prepareMessageMedia(buffer: Buffer, mediaType: MessageType, options: MessageOptions = {}) {
|
||||||
|
await this.waitForConnection ()
|
||||||
|
|
||||||
if (mediaType === MessageType.document && !options.mimetype) {
|
if (mediaType === MessageType.document && !options.mimetype) {
|
||||||
throw new Error('mimetype required to send a document')
|
throw new Error('mimetype required to send a document')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user