Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getProfilePicUrl #2365

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ declare namespace WAWebJS {
/** Get all Chats for a specific Label */
getChatsByLabelId(labelId: string): Promise<Chat[]>

/** Returns the contact ID's profile picture URL, if privacy settings allow it */
getProfilePicUrl(contactId: string): Promise<string>
/** Returns the chat/group/community/channel profile picture URL, if a client can retrieve it */
getProfilePicUrl(chatId: string): Promise<string>

/** Gets the Contact's common groups with you. Returns empty array if you don't have any common group. */
getCommonGroups(contactId: string): Promise<ChatId[]>
Expand Down Expand Up @@ -1223,7 +1223,7 @@ declare namespace WAWebJS {
/** @todo missing documentation */
verifiedName?: undefined,

/** Returns the contact's profile picture URL, if privacy settings allow it */
/** Returns the contact's profile picture URL, if a client can retrieve it */
getProfilePicUrl: () => Promise<string>,

/** Returns the Chat that corresponds to this Contact.
Expand Down Expand Up @@ -1408,6 +1408,8 @@ declare namespace WAWebJS {
unarchive: () => Promise<void>,
/** Unmutes this chat */
unmute: () => Promise<void>,
/** Returns the chat/group/community/channel profile picture URL, if a client can retrieve it */
getProfilePicUrl: () => Promise<string>,
/** Returns the Contact that corresponds to this Chat. */
getContact: () => Promise<Contact>,
/** Marks this Chat as unread */
Expand Down
20 changes: 10 additions & 10 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1242,21 +1242,21 @@ class Client extends EventEmitter {
}

/**
* Returns the contact ID's profile picture URL, if privacy settings allow it
* @param {string} contactId the whatsapp user's ID
* @returns {Promise<string>}
* Returns the chat/group/community/channel profile picture URL, if a client can retrieve it
* @param {string} chatId The ID of a chat/group/community/channel to get the profile picture URL of
* @returns {Promise<string>} The profile picture URL
*/
async getProfilePicUrl(contactId) {
const profilePic = await this.pupPage.evaluate(async contactId => {
async getProfilePicUrl(chatId) {
const profilePic = await this.pupPage.evaluate(async chatId => {
alechkos marked this conversation as resolved.
Show resolved Hide resolved
try {
const chatWid = window.Store.WidFactory.createWid(contactId);
return await window.Store.ProfilePic.profilePicFind(chatWid);
const chatWid = window.Store.WidFactory.createWid(chatId);
return await window.Store.ProfilePic.requestProfilePicFromServer(chatWid);
} catch (err) {
if(err.name === 'ServerStatusCodeError') return undefined;
if (err.name === 'ServerStatusCodeError') return undefined;
throw err;
}
}, contactId);
}, chatId);

return profilePic ? profilePic.eurl : undefined;
}

Expand Down
8 changes: 8 additions & 0 deletions src/structures/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ class Chat extends Base {
}, this.id._serialized);
}

/**
* Returns the chat/group/community profile picture URL, if a client can retrieve it
* @returns {Promise<string>}
*/
async getProfilePicUrl() {
return this.client.getProfilePicUrl(this.id._serialized);
}

/**
* Returns the Contact that corresponds to this Chat.
* @returns {Promise<Contact>}
Expand Down
4 changes: 2 additions & 2 deletions src/structures/Contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ class Contact extends Base {
}

/**
* Returns the contact's profile picture URL, if privacy settings allow it
* Returns the contact's profile picture URL, if a client can retrieve it
* @returns {Promise<string>}
*/
async getProfilePicUrl() {
return await this.client.getProfilePicUrl(this.id._serialized);
return this.client.getProfilePicUrl(this.id._serialized);
}

/**
Expand Down