mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Removed loadProfilePicturesForChatsAutomatically
This commit is contained in:
@@ -51,6 +51,10 @@ async function example() {
|
|||||||
if (chat.presences) { // receive presence updates -- composing, available, etc.
|
if (chat.presences) { // receive presence updates -- composing, available, etc.
|
||||||
Object.values(chat.presences).forEach(presence => console.log( `${presence.name}'s presence is ${presence.lastKnownPresence} in ${chat.jid}`))
|
Object.values(chat.presences).forEach(presence => console.log( `${presence.name}'s presence is ${presence.lastKnownPresence} in ${chat.jid}`))
|
||||||
}
|
}
|
||||||
|
if(chat.imgUrl) {
|
||||||
|
console.log('imgUrl of chat changed ', chat.imgUrl)
|
||||||
|
return
|
||||||
|
}
|
||||||
// only do something when a new message is received
|
// only do something when a new message is received
|
||||||
if (!chat.hasNewMessage) {
|
if (!chat.hasNewMessage) {
|
||||||
if(chat.messages) {
|
if(chat.messages) {
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ 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
|
||||||
/** @deprecated won't be supported soon */
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* does not do anything
|
||||||
|
* */
|
||||||
loadProfilePicturesForChatsAutomatically = false
|
loadProfilePicturesForChatsAutomatically = false
|
||||||
|
|
||||||
lastChatsReceived: Date
|
lastChatsReceived: Date
|
||||||
|
|||||||
@@ -318,7 +318,8 @@ export class WAConnection extends Base {
|
|||||||
})
|
})
|
||||||
// profile picture updates
|
// profile picture updates
|
||||||
this.on('CB:Cmd,type:picture', async json => {
|
this.on('CB:Cmd,type:picture', async json => {
|
||||||
const jid = whatsappID(json[1].jid)
|
json = json[1]
|
||||||
|
const jid = whatsappID(json.jid)
|
||||||
const imgUrl = await this.getProfilePicture(jid).catch(() => '')
|
const imgUrl = await this.getProfilePicture(jid).catch(() => '')
|
||||||
const contact = this.contacts[jid]
|
const contact = this.contacts[jid]
|
||||||
if (contact) {
|
if (contact) {
|
||||||
@@ -340,8 +341,10 @@ export class WAConnection extends Base {
|
|||||||
this.on ('CB:Conn,pushname', json => {
|
this.on ('CB:Conn,pushname', json => {
|
||||||
if (this.user) {
|
if (this.user) {
|
||||||
const name = json[1].pushname
|
const name = json[1].pushname
|
||||||
this.user.name = name // update on client too
|
if(this.user.name !== name) {
|
||||||
this.emit ('contact-update', { jid: this.user.jid, name })
|
this.user.name = name // update on client too
|
||||||
|
this.emit ('contact-update', { jid: this.user.jid, name })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// read updates
|
// read updates
|
||||||
@@ -406,7 +409,7 @@ export class WAConnection extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** inserts an empty chat into the DB */
|
/** inserts an empty chat into the DB */
|
||||||
protected async chatAdd (jid: string, name?: string) {
|
protected chatAdd (jid: string, name?: string) {
|
||||||
const chat: WAChat = {
|
const chat: WAChat = {
|
||||||
jid,
|
jid,
|
||||||
name,
|
name,
|
||||||
@@ -416,11 +419,7 @@ export class WAConnection extends Base {
|
|||||||
modify_tag: '',
|
modify_tag: '',
|
||||||
spam: 'false'
|
spam: 'false'
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.chats.insertIfAbsent (chat).length) {
|
if(this.chats.insertIfAbsent (chat).length) {
|
||||||
if (this.loadProfilePicturesForChatsAutomatically) {
|
|
||||||
await this.setProfilePicture (chat)
|
|
||||||
}
|
|
||||||
this.emit ('chat-new', chat)
|
this.emit ('chat-new', chat)
|
||||||
return chat
|
return chat
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,21 +139,12 @@ export class WAConnection extends Base {
|
|||||||
* @param searchString optionally search for users
|
* @param searchString optionally search for users
|
||||||
* @returns the chats & the cursor to fetch the next page
|
* @returns the chats & the cursor to fetch the next page
|
||||||
*/
|
*/
|
||||||
async loadChats (count: number, before: string | null, options: WALoadChatOptions = {}) {
|
loadChats (count: number, before: string | null, options: WALoadChatOptions = {}) {
|
||||||
const searchString = options.searchString?.toLowerCase()
|
const searchString = options.searchString?.toLowerCase()
|
||||||
const chats = this.chats.paginated (before, count, options && (chat => (
|
const chats = this.chats.paginated (before, count, options && (chat => (
|
||||||
(typeof options?.custom !== 'function' || options?.custom(chat)) &&
|
(typeof options?.custom !== 'function' || options?.custom(chat)) &&
|
||||||
(typeof searchString === 'undefined' || chat.name?.toLowerCase().includes (searchString) || chat.jid?.includes(searchString))
|
(typeof searchString === 'undefined' || chat.name?.toLowerCase().includes (searchString) || chat.jid?.includes(searchString))
|
||||||
)))
|
)))
|
||||||
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)
|
|
||||||
))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
const cursor = (chats[chats.length-1] && chats.length >= count) && this.chatOrderingKey.key (chats[chats.length-1])
|
const cursor = (chats[chats.length-1] && chats.length >= count) && this.chatOrderingKey.key (chats[chats.length-1])
|
||||||
return { chats, cursor }
|
return { chats, cursor }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ export enum ReconnectMode {
|
|||||||
export type WALoadChatOptions = {
|
export type WALoadChatOptions = {
|
||||||
searchString?: string
|
searchString?: string
|
||||||
custom?: (c: WAChat) => boolean
|
custom?: (c: WAChat) => boolean
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* does not do anything now
|
||||||
|
*/
|
||||||
loadProfilePicture?: boolean
|
loadProfilePicture?: boolean
|
||||||
}
|
}
|
||||||
export type WAConnectOptions = {
|
export type WAConnectOptions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user