diff --git a/src/api/layers/profile.layer.ts b/src/api/layers/profile.layer.ts index 07894695c..19fb0afd8 100644 --- a/src/api/layers/profile.layer.ts +++ b/src/api/layers/profile.layer.ts @@ -114,7 +114,7 @@ export class ProfileLayer extends HostLayer { * Sets the user's current profile photo * @param name */ - public async setProfilePic(path: string) { + public async setProfilePic(path: string, to?: string) { let b64 = await downloadFileToBase64(path, [ 'image/gif', 'image/png', @@ -137,9 +137,13 @@ export class ProfileLayer extends HostLayer { _webb64_640 = await resizeImg(buff, { width: 640, height: 640 }); let obj = { a: _webb64_640, b: _webb64_96 }; - return await this.page.evaluate(({ obj }) => WAPI.setProfilePic(obj), { - obj, - }); + return await this.page.evaluate( + ({ obj, to }) => WAPI.setProfilePic(obj, to), + { + obj, + to, + } + ); } else { console.log('Not an image, allowed formats png, jpeg and webp'); return false; diff --git a/src/lib/wapi/functions/set-profile-pic.js b/src/lib/wapi/functions/set-profile-pic.js index 540cc9951..cb6865149 100644 --- a/src/lib/wapi/functions/set-profile-pic.js +++ b/src/lib/wapi/functions/set-profile-pic.js @@ -1,9 +1,7 @@ -export async function setProfilePic(obj) { - var id = await Store.Me.attributes, - base64 = 'data:image/jpeg;base64,'; - return await Store.Profile.sendSetPicture( - id.me._serialized, - base64 + obj.b, - base64 + obj.a - ); +export async function setProfilePic(obj, id) { + if (!id) { + id = Store.Me.attributes.wid._serialized; + } + let base64 = 'data:image/jpeg;base64,'; + return await Store.Profile.sendSetPicture(id, base64 + obj.b, base64 + obj.a); } diff --git a/src/types/WAPI.d.ts b/src/types/WAPI.d.ts index 3075e2892..2dcbf6177 100644 --- a/src/types/WAPI.d.ts +++ b/src/types/WAPI.d.ts @@ -243,7 +243,7 @@ interface WAPI { setMessagesAdminsOnly: (chatId: string, option: boolean) => boolean; setMyName: (name: string) => void; setMyStatus: (to: string) => void; - setProfilePic: (path: string) => Promise; + setProfilePic: (path: string, to?: string) => Promise; setTheme: (theme?: string) => boolean; startTyping: (to: string) => void; stopTyping: (to: string) => void;